/* ==========================================================================
   PHP POS & Inventory — core stylesheet
   Design system: deep emerald identity (money / growth / trust), warm amber
   used sparingly as a highlight accent, Manrope for UI chrome + Inter for
   dense data, tabular numerals throughout for money. Layout borrows the
   bottom-tab-bar + floating action pattern from native commerce apps.
   ========================================================================== */

:root {
    --sidebar-width: 236px;
    --topbar-height: 60px;
    --bottom-nav-height: 62px;

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    --font-ui: 'Manrope', 'Hind Siliguri', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Hind Siliguri', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

body[data-lang="bn"] { font-family: 'Hind Siliguri', var(--font-body); }

h1, h2, h3, h4, h5, h6, .font-ui, .btn, .nav-link, .sidebar-brand, .stat-card h3 {
    font-family: var(--font-ui);
}

.money, .tabular {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

a { color: var(--primary); text-decoration: none; }

::selection { background: var(--primary-soft); color: var(--primary-dark); }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .pos-product-card:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

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

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-alt) 100%);
    color: var(--sidebar-text);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
}

.sidebar-brand {
    padding: 1.35rem 1.25rem 1.1rem;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: .65rem;
    color: #fff;
}
.sidebar-brand .mark {
    width: 34px; height: 34px; border-radius: 10px;
    background: var(--sidebar-active);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem; color: #fff; flex-shrink: 0;
}

.sidebar-nav { padding: .5rem .75rem; overflow-y: auto; flex: 1; }
.sidebar-section-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: rgba(255,255,255,.35); padding: .9rem .65rem .35rem; font-weight: 700;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .8rem;
    color: var(--sidebar-text);
    padding: .62rem .75rem;
    border-radius: var(--radius-sm);
    margin-bottom: .2rem;
    font-size: .875rem;
    font-weight: 600;
    text-decoration: none;
    position: relative;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .9; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; box-shadow: var(--shadow-sm); }

.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* ---------------------------------------------------------------------
   Top app bar
   ------------------------------------------------------------------ */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-spacer { flex: 1; }
.topbar-title { font-family: var(--font-ui); font-weight: 800; font-size: 1.02rem; letter-spacing: -0.01em; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.05rem;
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    transition: background .15s;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon:active { transform: scale(.94); }

.avatar-chip {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .3rem .7rem .3rem .35rem;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    font-size: .82rem; font-weight: 700; color: var(--text);
}
.avatar-chip .avatar-dot {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 800;
}

.page-content { padding: 1.25rem 1.25rem 2rem; flex: 1; max-width: 1400px; width: 100%; margin: 0 auto; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-header h4 { font-family: var(--font-ui); font-weight: 800; letter-spacing: -0.01em; margin: 0; font-size: 1.3rem; }
.page-header p { color: var(--muted); font-size: .85rem; margin: .15rem 0 0; }

/* ---------------------------------------------------------------------
   Bottom tab bar — native-app pattern, mobile only
   ------------------------------------------------------------------ */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 1040;
    box-shadow: 0 -4px 20px rgba(0,0,0,.05);
}
.bottom-nav-inner { display: flex; height: var(--bottom-nav-height); }
.bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .18rem; color: var(--muted); font-size: .66rem; font-weight: 700; text-decoration: none;
    position: relative; background: none; border: none;
}
.bottom-nav-item i { font-size: 1.28rem; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active::before {
    content: ''; position: absolute; top: 2px; width: 28px; height: 3px;
    border-radius: var(--radius-pill); background: var(--primary);
}

/* ---------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.2rem;
    display: flex;
    align-items: center;
    gap: .9rem;
    box-shadow: var(--shadow-sm);
}
.stat-card .icon {
    width: 46px; height: 46px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    color: #fff;
    flex-shrink: 0;
}
.stat-card h3 { margin: 0; font-size: 1.28rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
.stat-card p { margin: .1rem 0 0; color: var(--muted); font-size: .78rem; font-weight: 600; }

.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.1rem; box-shadow: var(--shadow-sm); }
.section-card h6 { font-family: var(--font-ui); font-weight: 800; font-size: .9rem; margin-bottom: .9rem; }

/* ---------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------ */
.btn {
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: .84rem;
    border-radius: var(--radius-sm);
    padding: .5rem 1.05rem;
    border: 1px solid transparent;
    transition: transform .1s, background .15s, box-shadow .15s;
    letter-spacing: -0.01em;
}
.btn:active { transform: scale(.97); }

.btn-primary, .btn-primary:focus {
    background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-secondary, .btn-outline-secondary {
    background: var(--surface); border-color: var(--border-strong); color: var(--text);
}
.btn-secondary:hover, .btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.92); color: #fff; }

.btn-warning { background: var(--accent); border-color: var(--accent); color: #3a2a06; }
.btn-warning:hover { filter: brightness(0.95); color: #3a2a06; }

.btn-danger, .btn-outline-danger {
    background: transparent; color: var(--danger); border-color: var(--danger-soft);
}
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-soft); }
.btn-danger:hover { filter: brightness(0.93); color: #fff; }

.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-soft); color: var(--primary-dark); }

.btn-sm { padding: .35rem .75rem; font-size: .78rem; }

/* ---------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------ */
.form-label { font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: .3rem; }
.form-control, .form-select {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .9rem;
    padding: .55rem .75rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: var(--surface);
    color: var(--text);
}
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* ---------------------------------------------------------------------
   Badges
   ------------------------------------------------------------------ */
.badge { font-family: var(--font-ui); font-weight: 700; font-size: .72rem; padding: .32rem .6rem; border-radius: var(--radius-pill); }
.badge-due { background: var(--danger-soft); color: var(--danger); }
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-inactive { background: var(--surface-2); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: #8a5a10; }

/* ---------------------------------------------------------------------
   Data table -> stacked cards on mobile
   ------------------------------------------------------------------ */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
    background: transparent;
    border-bottom: 1.5px solid var(--border);
    font-family: var(--font-ui);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    font-weight: 800;
    padding: .55rem .6rem;
    text-align: left;
}
.data-table tbody td { padding: .7rem .6rem; border-bottom: 1px solid var(--border); font-size: .87rem; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }

@media (max-width: 767.98px) {
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: .7rem;
        padding: .5rem .8rem;
        box-shadow: var(--shadow-sm);
    }
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: .75rem;
        padding: .45rem 0;
        border-bottom: 1px dashed var(--border);
        text-align: right;
    }
    .data-table td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label);
        font-family: var(--font-ui);
        font-weight: 700;
        font-size: .68rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
    }
    .data-table td.cell-actions { justify-content: flex-end; gap: .4rem; }
    .data-table td.cell-actions::before { display: none; }
}

/* ---------------------------------------------------------------------
   Modals
   ------------------------------------------------------------------ */
.modal-content { border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); }
.modal-title { font-family: var(--font-ui); font-weight: 800; font-size: 1rem; }

/* ---------------------------------------------------------------------
   Auth screen
   ------------------------------------------------------------------ */
.auth-body { background: var(--bg); display:flex; align-items:center; justify-content:center; min-height:100vh; }
.auth-wrapper { width: 100%; max-width: 400px; padding: 1.25rem; }
.auth-card { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg); padding: 2.1rem 1.9rem; box-shadow: var(--shadow-lg); }
.auth-brand { text-align:center; margin-bottom: 1.6rem; }
.auth-brand .mark {
    width: 56px; height: 56px; border-radius: var(--radius-md);
    background: var(--primary); color: #fff;
    display:flex; align-items:center; justify-content:center; margin: 0 auto .8rem;
    font-size: 1.6rem; box-shadow: var(--shadow-md);
}
.auth-brand h4 { font-family: var(--font-ui); font-weight: 800; margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.small-link { color: var(--primary); text-decoration:none; font-size:.85rem; font-weight: 600; }

/* ---------------------------------------------------------------------
   POS screen
   ------------------------------------------------------------------ */
.pos-grid { display: grid; grid-template-columns: 1fr 360px; gap: 1.1rem; align-items: start; }

.category-scroller { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .4rem; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.category-scroller::-webkit-scrollbar { display: none; }
.category-pill {
    flex-shrink: 0;
    padding: .5rem 1.05rem; border-radius: var(--radius-pill); border: 1.5px solid var(--border);
    cursor: pointer; font-size: .82rem; font-weight: 700; background: var(--surface); color: var(--text);
    white-space: nowrap; transition: all .15s;
}
.category-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.pos-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: .8rem; }
.pos-product-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: .9rem .8rem; cursor: pointer; text-align:left; transition: all .15s; position: relative;
}
.pos-product-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.pos-product-card:active { transform: scale(.97); }
.pos-product-card .icon-tile {
    width: 38px; height: 38px; border-radius: 10px; background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem; margin-bottom: .55rem;
}
.pos-product-card .name { font-size: .84rem; font-weight: 700; line-height: 1.25; margin-bottom: .3rem; min-height: 2.1em; }
.pos-product-card .price { color: var(--primary); font-weight: 800; font-size: .92rem; }
.pos-product-card .stock { font-size: .7rem; color: var(--muted); margin-top: .15rem; font-weight: 600; }
.pos-product-card .stock.low { color: var(--danger); }

.pos-cart {
    background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg);
    padding: 1.1rem; display:flex; flex-direction:column; position: sticky; top: calc(var(--topbar-height) + 14px);
    box-shadow: var(--shadow-sm);
}
.cart-item { display:flex; align-items:center; justify-content:space-between; padding:.55rem 0; border-bottom:1px dashed var(--border); font-size:.85rem; gap: .5rem; }
.cart-item:last-child { border-bottom: none; }
.cart-summary-row { display: flex; justify-content: space-between; font-size: .85rem; padding: .2rem 0; }
.cart-summary-row.total { font-weight: 800; font-size: 1rem; padding-top: .5rem; border-top: 1px solid var(--border); margin-top: .3rem; }
.cart-summary-row.due { color: var(--danger); font-weight: 700; }
.sheet-drag-handle { display: none; }

/* Mobile POS: cart becomes a floating bar + slide-up sheet */
.cart-fab-bar { display: none; }
.cart-sheet-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .app-main { padding-bottom: var(--bottom-nav-height); }
    .bottom-nav { display: block; }
    .page-content { padding: 1rem 1rem 1.25rem; }

    .pos-grid { grid-template-columns: 1fr; }

    body.pos-page .app-main { padding-bottom: calc(var(--bottom-nav-height) + 64px); }

    .cart-fab-bar {
        display: flex; align-items: center; justify-content: space-between; gap: .75rem;
        position: fixed; left: .75rem; right: .75rem; bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + 10px);
        background: var(--primary); color: #fff; border-radius: var(--radius-pill);
        padding: .75rem 1.1rem; box-shadow: var(--shadow-lg); z-index: 1035; cursor: pointer;
        font-family: var(--font-ui); font-weight: 700; font-size: .85rem; border: none; width: calc(100% - 1.5rem);
    }
    .cart-fab-bar .count-pill {
        background: rgba(255,255,255,.22); border-radius: var(--radius-pill);
        width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center;
        font-size: .75rem; margin-right: .5rem;
    }

    .cart-sheet-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(9,15,12,.45); z-index: 1050;
    }
    .cart-sheet-backdrop.show { display: block; }

    /* The single .pos-cart element becomes a slide-up bottom sheet on mobile */
    .pos-cart {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        max-height: 86vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        z-index: 1060; transform: translateY(100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
        overflow-y: auto; padding-bottom: calc(1.1rem + env(safe-area-inset-bottom));
    }
    .pos-cart.show { transform: translateY(0); }
    .sheet-drag-handle { width: 42px; height: 5px; border-radius: var(--radius-pill); background: var(--border-strong); margin: 0 auto .8rem; }
}

/* ---------------------------------------------------------------------
   Utility
   ------------------------------------------------------------------ */
.text-muted-app { color: var(--muted) !important; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; opacity: .5; margin-bottom: .6rem; display: block; }
