/* Legarda General Merchandise — theme: white background, green accents, black text.
   Mobile-first with large touch targets. */

:root {
    --green: #1b7a3d;
    --green-dark: #0f5c2c;
    --green-darker: #0b3d20;
    --green-tint: #eaf6ee;
    --black: #16201a;
    --gray: #5b6b62;
    --border: #dbe6de;
    --danger: #c0392b;
    --danger-tint: #fbeceb;
    --warn: #b8860b;
    --warn-tint: #fdf5e2;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(11, 61, 32, 0.08), 0 1px 2px rgba(11, 61, 32, 0.06);
    font-size: 16px;
}

* { box-sizing: border-box; }

/* Guard against any later rule setting `display` on an element that also
   carries the `hidden` attribute — without this, author CSS specificity
   can silently defeat `hidden` and show things that should stay hidden. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: #ffffff;
    color: var(--black);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--green-dark); }

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    vertical-align: middle;
}
.btn .icon { width: 18px; height: 18px; margin-right: 6px; }

/* ---------- Sidebar shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--green-darker);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.18s ease;
    z-index: 25;
}
.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-user-info { display: none; }
.sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }

.sidebar-brand { display: flex; justify-content: center; padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.brand-link { display: flex; align-items: center; justify-content: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    font-size: 0.85rem;
}
.brand-text { white-space: nowrap; }

.sidebar-nav { flex: 1; padding: 10px 0; display: flex; flex-direction: column; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 14px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 12px 16px;
    min-height: 44px;
    white-space: nowrap;
    border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.12); color: #fff; border-left-color: var(--green); font-weight: 600; }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 22px; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.12); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-user { display: flex; align-items: center; justify-content: center; gap: 10px; color: #fff; padding: 6px 4px; }
.sidebar-user-info { display: flex; flex-direction: column; line-height: 1.3; font-size: 0.85rem; }
.sidebar-user-info small { color: rgba(255,255,255,0.7); }
.sidebar-logout .btn { color: #fff; justify-content: center; gap: 14px; }
.sidebar-logout .btn:hover { background: rgba(255,255,255,0.1); }
.sidebar-collapse-btn {
    display: none;
    align-self: flex-end;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.08);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
}
.sidebar-collapse-btn .icon { width: 17px; height: 17px; }
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.18); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 24;
}
.sidebar-backdrop.visible { display: block; }

.app-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 15;
}
.mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    color: var(--green-darker);
}
.mobile-menu-toggle:hover { background: var(--green-tint); }

.app-main {
    width: 100%;
    padding: 1rem;
}

/* Mobile: sidebar becomes an off-canvas drawer; collapse button hidden. */
@media (max-width: 899px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        width: 260px;
        transition: left 0.2s ease;
    }
    .sidebar.open { left: 0; }
    .sidebar.collapsed { width: 260px; }
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .sidebar-user-info { display: inline; }
}

/* Desktop: no drawer, collapse button visible, hamburger hidden. */
@media (min-width: 900px) {
    .topbar { display: none; }
    .sidebar-collapse-btn { display: flex; align-items: center; justify-content: center; }
    .mobile-menu-toggle { display: none; }
    .sidebar-backdrop { display: none !important; }
    .sidebar.collapsed .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
    .sidebar.collapsed .sidebar-logout .btn { padding-left: 0; padding-right: 0; }
    .sidebar.collapsed .sidebar-logout .btn .icon { margin-right: 0; }
    .sidebar.collapsed .sidebar-collapse-btn { align-self: center; }
    .sidebar.collapsed .sidebar-user { display: none; }
}

/* ---------- POS layout (helper) ---------- */

.pos-body { background: #f7faf8; margin: 0; }
.pos-header {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--green);
    color: #fff;
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow);
}
.pos-brand-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.pos-header-shift {
    display: flex;
    align-items: center;
    gap: 14px;
    overflow-x: auto;
    flex: 1;
    min-width: 0;
}
.pos-shift-item { font-size: 0.85rem; color: #fff; opacity: 0.9; white-space: nowrap; flex-shrink: 0; }
.pos-shift-item strong { color: #fff; opacity: 1; }
.pos-header-shift .btn { flex-shrink: 0; }

.pos-header-right { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.pos-user { font-size: 0.9rem; opacity: 0.9; white-space: nowrap; }

.icon-btn-header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
}
.icon-btn-header:hover { background: rgba(255,255,255,0.15); }
.icon-btn-header .icon { width: 19px; height: 19px; }

@media (max-width: 640px) {
    .pos-shift-item-optional, .pos-user { display: none; }
}
.pos-main { width: 100%; padding: 1rem; }

/* ---------- Buttons & Forms ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 18px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--green-tint);
    color: var(--green-darker);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: #eef2f0; color: var(--black); border-color: var(--border); }
.btn-secondary:hover { background: #e3ebe6; }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-danger:hover { background: #f6d9d6; }
.btn-ghost { background: transparent; color: var(--green-dark); }
.btn-ghost:hover { background: var(--green-tint); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 0.88rem; }

.field-label {
    display: block;
    font-weight: 600;
    margin: 14px 0 6px;
    font-size: 0.92rem;
    color: var(--black);
}
.field-input {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: #fff;
    color: var(--black);
}
.field-input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.field-input-spaced { margin-bottom: 16px; }

select.field-input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6b62' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
    cursor: pointer;
}
select.field-input::-ms-expand { display: none; }

.checkbox-label { display: flex; align-items: center; gap: 8px; margin: 14px 0; font-weight: 600; }
.checkbox-label input { width: 20px; height: 20px; }

.form-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.form-row { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 640px) {
    .form-row { grid-template-columns: 1fr 1fr; gap: 16px; }
}
.form-actions { margin-top: 18px; margin-bottom: 20px; display: flex; gap: 10px; flex-wrap: wrap; }
.form-inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.form-inline .field-input { width: auto; min-width: 160px; }
.inline-form { display: inline-block; margin: 0; }

.hint { color: var(--gray); font-size: 0.88rem; margin: 6px 0; }

/* ---------- Layout helpers ---------- */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.page-header h1 { margin: 0; font-size: 1.4rem; }
.section-title { font-size: 1.05rem; margin: 22px 0 10px; }

/* ---------- Flash messages ---------- */

.flash {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-weight: 600;
    border: 1px solid transparent;
}
.flash-success { background: var(--green-tint); color: var(--green-darker); border-color: #bfe3cc; }
.flash-error { background: var(--danger-tint); color: var(--danger); border-color: #f2c1bd; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.data-table th { background: var(--green-tint); color: var(--green-darker); font-weight: 700; position: sticky; top: 0; }
.data-table tbody tr:hover { background: #fafdfb; }
.row-low-stock { background: var(--warn-tint); }
.empty-row { text-align: center; color: var(--gray); padding: 24px; }
/* .actions is a wrapper <div> inside the actions <td>, never the <td>
   itself — applying flex directly to a table cell breaks row height/
   border alignment in some browsers. */
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.actions-header { text-align: right; }
.mono-cell { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.78rem; max-width: 260px; overflow-wrap: anywhere; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; background: #eee; color: var(--gray); }
.badge-warn { background: var(--warn-tint); color: var(--warn); }

.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.thumb-placeholder { display: flex; align-items: center; justify-content: center; background: var(--green-tint); color: var(--green-dark); }
.thumb-placeholder .icon { width: 18px; height: 18px; }
.thumb-preview { width: 96px; height: 96px; display: block; margin: 8px 0; }
.image-pick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- Dashboard ---------- */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .stat-grid { grid-template-columns: repeat(6, 1fr); } }
.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}
.stat-card-warn { border-color: #f0d38a; background: var(--warn-tint); }
.stat-card-highlight { border-color: var(--green); background: var(--green-tint); }
.stat-label { display: block; font-size: 0.78rem; color: var(--gray); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { display: block; font-size: 1.35rem; font-weight: 800; color: var(--green-darker); margin-top: 4px; }

.dash-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: 1fr 1fr; } }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.plain-list li:last-child { border-bottom: none; }

.helper-menu { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }

/* ---------- Point of Sale ---------- */

.pos-toolbar { margin-bottom: 16px; }
.pos-search-wrap { position: relative; }
.pos-search-input { font-size: 1.1rem; min-height: 54px; }

.pos-category-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-top: 12px;
    padding-bottom: 4px;
    scrollbar-width: thin;
}
.pos-cat-tab {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--black);
    padding: 9px 16px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}
.pos-cat-tab:hover { background: var(--green-tint); }
.pos-cat-tab.active { background: var(--green); color: #fff; border-color: var(--green); }

.pos-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 8px;
}
/* Fixed breakpoints on purpose (not auto-fit/auto-fill) — those size
   columns off however many tiles are currently visible, so filtering the
   grid down to a few matches made every remaining tile balloon in size. */
@media (min-width: 420px) { .pos-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 620px) { .pos-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 860px) { .pos-grid { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 1100px) { .pos-grid { grid-template-columns: repeat(6, 1fr); } }

.pos-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 10px 14px;
    cursor: pointer;
    text-align: center;
    box-shadow: var(--shadow);
}
.pos-tile:hover { border-color: var(--green); transform: translateY(-1px); }
.pos-tile:active { transform: scale(0.98); }
.pos-tile-oos,
.pos-tile:disabled { opacity: 0.5; cursor: not-allowed; }
.pos-tile-oos:hover,
.pos-tile:disabled:hover { border-color: var(--border); transform: none; }
.pos-tile-img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    background: var(--green-tint);
}
.pos-tile-placeholder { display: flex; align-items: center; justify-content: center; color: var(--green-dark); }
.pos-tile-placeholder .icon { width: 32px; height: 32px; }
.pos-tile-name {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.35;
    min-height: 2.7em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.pos-tile-price { font-weight: 800; color: var(--green-darker); font-size: 1.05rem; }
.pos-empty-msg { text-align: center; padding: 30px 10px; }

.qty-stepper { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0; }
.qty-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--green-tint);
    color: var(--green-dark);
    font-size: 1.6rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qty-btn:hover { background: var(--green); color: #fff; }
.qty-btn:active { transform: scale(0.95); }
.qty-display {
    width: 84px;
    min-height: 52px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    -moz-appearance: textfield;
}
.qty-display::-webkit-inner-spin-button,
.qty-display::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pos-subtotal { text-align: center; font-size: 1.1rem; margin: 4px 0 6px; }
.pos-subtotal strong { color: var(--green-darker); font-size: 1.4rem; }

/* ---------- Modals ---------- */

body.modal-open { overflow: hidden; }

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 32, 20, 0.6);
    align-items: center;
    justify-content: center;
    z-index: 60;
    padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.modal-box::-webkit-scrollbar { width: 8px; }
.modal-box::-webkit-scrollbar-track { background: transparent; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.modal-box::-webkit-scrollbar-thumb:hover { background: var(--gray); }
.modal-box-lg { max-width: 620px; }
.modal-title { margin: 0 0 16px; font-size: 1.15rem; color: var(--green-darker); padding-right: 30px; }
.modal-box .form-actions { justify-content: flex-end; }
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray);
    cursor: pointer;
}
.modal-close:hover { background: var(--green-tint); color: var(--green-dark); }
.modal-close .icon { width: 18px; height: 18px; }

/* ---------- Icon-only action buttons (with native title tooltip) ---------- */

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--gray);
    cursor: pointer;
}
.icon-btn:hover { background: var(--green-tint); color: var(--green-dark); border-color: #bfe3cc; }
.icon-btn-danger:hover { background: var(--danger-tint); color: var(--danger); border-color: #f2c1bd; }
.icon-btn .icon { width: 17px; height: 17px; }

/* ---------- Login ---------- */

.login-body { background: var(--green-tint); min-height: 100vh; }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-title { color: var(--green-darker); margin: 0 0 4px; font-size: 1.3rem; }
.login-sub { color: var(--gray); margin: 0 0 18px; font-size: 0.9rem; }
.login-card .field-input { text-align: left; }
.login-card .field-label { text-align: left; }
.login-card button[type="submit"] { margin-top: 22px; }

.password-field { position: relative; }
.password-field .field-input { padding-right: 46px; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 40px;
    height: 38px;
    border: none;
    background: transparent;
    color: var(--gray);
    font-size: 1.05rem;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.password-toggle:hover { background: var(--green-tint); color: var(--green-dark); }
.password-toggle.is-active { color: var(--green); }
.password-toggle .icon { width: 19px; height: 19px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle.is-active .icon-eye { display: none; }
.password-toggle.is-active .icon-eye-off { display: block; }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
