/* ==========================================================================
   Chai Ledger - accounting dashboard theme on Bootstrap 5
   Font stack covers Latin + Tamil, Malayalam, Telugu, Kannada and Devanagari.
   ========================================================================== */
:root {
    --app-font: "Noto Sans", "Noto Sans Tamil", "Noto Sans Malayalam", "Noto Sans Telugu", "Noto Sans Kannada",
        "Noto Sans Devanagari", "Latha", "Nirmala UI", "Kartika", "Gautami", "Tunga", "Mangal", system-ui, -apple-system,
        "Segoe UI", Roboto, sans-serif;
    --brand: #1d6b52;
    --brand-600: #175a45;
    --brand-50: #e8f3ee;
    --accent: #c9821a;
    --accent-50: #fbf2e3;
    --ink: #1f2a26;
    --muted: #6b7a74;
    --line: #e4e8e5;
    --surface: #ffffff;
    --canvas: #f4f6f3;
    --sidebar: #12302a;
    --sidebar-ink: #c9d8d2;
    --sidebar-w: 248px;
    --radius: 12px;

    --bs-body-font-family: var(--app-font);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--canvas);
    --bs-primary: var(--brand);
    --bs-primary-rgb: 29, 107, 82;
    --bs-link-color: var(--brand);
    --bs-link-color-rgb: 29, 107, 82;
    --bs-link-hover-color: var(--brand-600);
    --bs-border-color: var(--line);
    --bs-border-radius: 8px;
}

body { font-family: var(--app-font); font-size: .925rem; -webkit-font-smoothing: antialiased; }
.text-local { font-family: var(--app-font); line-height: 1.45; }

.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); }
.text-bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus { border-color: #7fb7a4; box-shadow: 0 0 0 .2rem rgba(29,107,82,.15); }
.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .3rem; }
.form-text { font-size: .78rem; }
.page-link { color: var(--brand); }
.active > .page-link { background: var(--brand); border-color: var(--brand); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); background: var(--sidebar); color: var(--sidebar-ink);
    position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 1040;
    transition: transform .2s ease, width .2s ease;
}
.sidebar-brand { display: flex; align-items: center; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-text { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .6rem 1rem; scrollbar-width: thin; }
.nav-heading { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7f9a91; padding: 1rem .7rem .35rem; }
.sidebar .nav-link {
    display: flex; align-items: center; gap: .7rem; color: var(--sidebar-ink); padding: .5rem .7rem;
    border-radius: 8px; font-size: .88rem; white-space: nowrap;
}
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .9; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active { background: var(--brand); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { padding: .8rem 1.1rem; border-top: 1px solid rgba(255,255,255,.07); color: #9fb7ae; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; transition: margin .2s ease; }
.topbar {
    position: sticky; top: 0; z-index: 1020; height: 60px; display: flex; align-items: center; gap: .75rem;
    padding: 0 1.25rem; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 600; font-size: 1rem; }
.btn-icon { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--ink); border: 0; }
.btn-icon:hover { background: var(--canvas); }
.btn-user { display: flex; align-items: center; gap: .5rem; border: 0; padding: .25rem .5rem; border-radius: 10px; }
.btn-user:hover { background: var(--canvas); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-50); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.notif-dot { position: absolute; top: 3px; right: 1px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: #d63c3c; color: #fff; font-size: .65rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.content { padding: 1.5rem; flex: 1; }

body.sidebar-collapsed .sidebar { width: 72px; }
body.sidebar-collapsed .sidebar .brand-text,
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .nav-heading,
body.sidebar-collapsed .sidebar-foot { display: none; }
body.sidebar-collapsed .sidebar .nav-link { justify-content: center; }
body.sidebar-collapsed .main { margin-left: 72px; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); width: 270px; }
    .main, body.sidebar-collapsed .main { margin-left: 0; }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1035; }
    .content { padding: 1rem; }
    .topbar { padding: 0 .75rem; }
}

/* ---------- Page elements ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--muted); font-size: .85rem; }
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,40,32,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; padding: .85rem 1.1rem; }
.card-body { padding: 1.1rem; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .75rem; }

.kpi { position: relative; padding: 1rem 1.1rem; height: 100%; }
.kpi .kpi-label { font-size: .78rem; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: .4rem; }
.kpi .kpi-value { font-size: 1.45rem; font-weight: 700; margin-top: .25rem; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .kpi-foot { font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: .95rem; }
.kpi-icon.green { background: var(--brand-50); color: var(--brand); }
.kpi-icon.amber { background: var(--accent-50); color: var(--accent); }
.kpi-icon.red { background: #fdecec; color: #c43b3b; }
.kpi-icon.blue { background: #e9f0fb; color: #2f62b5; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #fafbfa; border-bottom-width: 1px; white-space: nowrap; }
.table td, .table th { vertical-align: middle; padding: .6rem .75rem; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f7faf8; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge-status { font-weight: 600; font-size: .72rem; padding: .35em .7em; }
.filter-bar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; margin-bottom: 1rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.4rem; color: #b8c6c0; display: block; margin-bottom: .5rem; }
.dl-grid { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; font-size: .88rem; }
.dl-grid dt { color: var(--muted); font-weight: 500; }
.dl-grid dd { margin: 0; }
.amount-pos { color: #b4441f; }
.amount-neg { color: var(--brand); }
.chart-box { position: relative; height: 260px; }

/* ---------- Fast sale entry (POS) ---------- */
.pos-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .pos-grid { grid-template-columns: minmax(0, 1fr); } }
.pos-grid > * { min-width: 0; }
.cat-chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: thin; }
.cat-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .3rem .8rem; font-size: .8rem; white-space: nowrap; }
.cat-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .6rem; }
.product-tile {
    border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: .7rem .7rem .6rem; text-align: left;
    transition: border-color .12s, transform .06s; min-height: 92px; display: flex; flex-direction: column; position: relative;
}
.product-tile:hover { border-color: #9cc7b8; }
.product-tile:active { transform: scale(.98); }
.product-tile .pt-name { font-weight: 600; font-size: .86rem; line-height: 1.25; }
.product-tile .pt-local { font-size: .78rem; color: var(--muted); }
.product-tile .pt-price { margin-top: auto; font-weight: 700; color: var(--brand); font-size: .9rem; }
.product-tile .pt-qty { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #fff; border-radius: 999px; font-size: .7rem; font-weight: 700; padding: 0 .45rem; }
.cart { position: sticky; top: 76px; }
.cart-lines { max-height: 42vh; overflow-y: auto; }
.cart-line { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .55rem 0; border-bottom: 1px dashed var(--line); }
.qty-ctl { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.qty-ctl button { border: 0; background: #f4f6f3; width: 30px; height: 30px; }
.qty-ctl input { width: 46px; border: 0; text-align: center; font-weight: 600; height: 30px; }
.qty-ctl input:focus { outline: none; }
.quick-qty .btn { min-width: 42px; }
.cart-total { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pay-methods .btn-check + .btn { min-width: 72px; }
.buyer-results { position: absolute; z-index: 30; left: 0; right: 0; max-height: 260px; overflow-y: auto; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art { background: radial-gradient(1200px 500px at 10% 10%, #2a7d62 0%, #12302a 60%); color: #e8f1ed; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art h2 { font-weight: 800; font-size: 2rem; line-height: 1.2; }
.auth-art .lang-sample { font-size: 1.05rem; opacity: .9; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
@media (max-width: 767.98px) { .auth-wrap { grid-template-columns: 1fr; } .auth-art { display: none; } }

/* ---------- Print ---------- */
.print-doc { max-width: 820px; margin: 0 auto; background: #fff; padding: 2rem; border: 1px solid var(--line); border-radius: var(--radius); }
.print-doc .doc-title { font-size: 1.4rem; font-weight: 800; letter-spacing: .02em; }
@media print {
    @page { margin: 12mm; }
    body { background: #fff !important; font-size: 11pt; }
    .sidebar, .topbar, .no-print, .toast-container, .filter-bar .btn { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    .card, .print-doc { border: 0 !important; box-shadow: none !important; padding: 0 !important; }
    a { text-decoration: none; color: inherit; }
    .table > thead th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.pos-mobile-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
@media (max-width: 1199.98px) { .pos-grid { padding-bottom: 72px; } }
