:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e5e9f0;
    --text: #1e2430;
    --muted: #6b7488;
    --primary: #2563eb;
    --primary-600: #1d4ed8;
    --primary-soft: #dbeafe;
    --success: #059669;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
    --radius: 10px;
    --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth ---------- */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: radial-gradient(1200px 600px at 20% -10%, #dbeafe 0%, transparent 55%),
                radial-gradient(1000px 500px at 110% 110%, #bfdbfe 0%, transparent 50%), var(--bg);
}
.auth-card {
    width: 380px; max-width: 92vw;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 32px; box-shadow: 0 12px 40px rgba(16,24,40,.10);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-logo {
    width: 48px; height: 48px; border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    color: #fff; font-size: 26px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.auth-brand h1 { font-size: 20px; margin: 0; }
.auth-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.auth-card label { display: block; font-weight: 600; font-size: 12.5px; margin: 14px 0 6px; }
.auth-card input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; background: var(--surface-2);
}
.auth-card input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.auth-card button {
    width: 100%; margin-top: 22px; padding: 11px; border: 0; border-radius: 8px;
    background: var(--primary); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
.auth-card button:hover { background: var(--primary-600); }
.auth-hint { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0 0; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca;
    padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a;
    padding: 10px 12px; border-radius: 8px; font-size: 13px; }
/* Line pulled from a Delivery Note: fully locked (no change, no delete) — grey every cell. */
.line-grid tr.src-locked input, .line-grid tr.src-locked select {
    background: #f3f4f6; color: #6b7280; cursor: not-allowed; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0; background: #111827; color: #cbd2e0;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    transition: margin-left .22s ease, transform .22s ease;
}
.nav-backdrop { display: none; }

/* Desktop: toggled = auto-hide the sidebar as a fixed overlay (content goes full width).
   It peeks back in when the mouse hits the extreme left edge (.nav-peek), and slides away on leave/click. */
@media (min-width: 992px) {
    .shell.nav-toggled .sidebar {
        position: fixed; left: 0; top: 0; height: 100vh; margin-left: 0; z-index: 200;
        transform: translateX(-100%); box-shadow: 4px 0 24px rgba(0,0,0,.18);
    }
    .shell.nav-toggled.nav-peek .sidebar { transform: translateX(0); }
}

/* Mobile/tablet: sidebar is an off-canvas drawer */
@media (max-width: 991px) {
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 200; height: 100vh;
        transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.4);
    }
    .shell.nav-toggled .sidebar { transform: translateX(0); }
    .shell.nav-toggled .nav-backdrop {
        display: block; position: fixed; inset: 0; z-index: 150;
        background: rgba(15,20,30,.5);
    }
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px; color: #fff; }
.sidebar-brand .logo {
    width: 34px; height: 34px; border-radius: 9px; font-weight: 700; font-size: 18px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    display: flex; align-items: center; justify-content: center;
}
.sidebar-brand strong { font-size: 16px; }
.nav { padding: 8px; overflow-y: auto; flex: 1; }
.nav-group { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit; text-align: left; color: #cbd5e1; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 12px 6px; }
.nav-group:hover { color: #fff; }
.nav-group::after { content: "\25BE"; font-size: 11px; transition: transform .15s ease; }
.nav-sec.collapsed .nav-group::after { transform: rotate(-90deg); }
.nav-sec.collapsed .nav-links { display: none; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
    color: #e6ebf5; font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: 1; }

/* Quick Links — a collapsible section like the others, with a subtle accent */
.nav-sec-quick .nav-links a { font-weight: 600; color: #f1f5ff; }
.nav-sec-quick .nav-links a:hover { background: #2563eb22; }
.nav-sec-quick .ico { color: #7dd3fc; }

/* Transactions: coloured bands grouping related documents */
.nav-band { border-radius: 8px; padding: 3px; margin: 3px 0; border-left: 3px solid transparent; }
.nav-band-1 { background: #1e293b; border-left-color: #38bdf8; }  /* accounting vouchers */
.nav-band-2 { background: #1c2b22; border-left-color: #34d399; }  /* sales + service */
.nav-band-3 { background: #2b241c; border-left-color: #fbbf24; }  /* purchase */
.nav-band-4 { background: #2a2136; border-left-color: #a78bfa; }  /* stock / manufacturing */
.nav-band-5 { background: #10262b; border-left-color: #22d3ee; }  /* collections */
.nav-band-6 { background: #2c1d24; border-left-color: #fb7185; }  /* pdc */
.nav-band a:hover { background: #ffffff1a; }

/* Company logo in the top bar (falls back to the 🏢 icon on load error) */
.co-logo-wrap { display: inline-flex; align-items: center; }
.co-logo { height: 28px; max-width: 90px; object-fit: contain; border-radius: 6px; display: inline-block; }
.co-logo-fallback { font-size: 20px; align-items: center; }

/* User dropdown menu */
.user-menu { position: relative; }
.user-menu > summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; padding: 4px 6px; border-radius: 8px; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: var(--surface-2); }
.user-caret { color: var(--muted); font-size: 12px; }
.user-menu[open] > summary .user-caret { transform: rotate(180deg); }
.user-menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.16); min-width: 190px; padding: 6px; z-index: 50; }
.user-menu-list button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 7px; cursor: pointer; font-size: 13.5px; color: var(--text); font-family: inherit; }
.user-menu-list button:hover { background: var(--surface-2); }
.user-menu-list .ico { width: 18px; text-align: center; }

/* Company / workspace context — an inline row on desktop/tablet, a tap-to-open dropdown on phones */
.ctx { position: relative; display: inline-flex; align-items: center; gap: 14px; }
.ctx-summary { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; background: none; border: 0; font-family: inherit; padding: 4px 6px; border-radius: 8px; }
.ctx-co { color: var(--text); font-weight: 600; font-size: 13px; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.ctx-caret { color: var(--muted); font-size: 11px; display: none; transition: transform .15s ease; }
.ctx-list { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 12.5px; }   /* desktop/tablet: always inline */
.ctx-list b { color: var(--text); font-weight: 600; }
@media (max-width: 600px) {
    .ctx-summary { cursor: pointer; }
    .ctx-summary:hover { background: var(--surface-2); }
    .ctx-caret { display: inline; }
    .ctx.open .ctx-caret { transform: rotate(180deg); }
    .ctx-list { position: absolute; left: 0; top: calc(100% + 8px); flex-direction: column; align-items: stretch; gap: 9px;
        background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 10px;
        box-shadow: 0 12px 32px rgba(0,0,0,.16); padding: 12px; min-width: 232px; z-index: 50; }
    .ctx:not(.open) .ctx-list { display: none; }
    .ctx.open .ctx-list { display: flex; }
    .ctx-list .chip { justify-content: flex-start; }
    .ctx-list .fy-chip select { max-width: 100%; }
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
    position: sticky; top: 0; z-index: 10;
}
.topbar .context { display: flex; gap: 18px; align-items: center; color: var(--muted); font-size: 12.5px; }
.topbar .context b { color: var(--text); font-weight: 600; }
.topbar .chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; }
.topbar .user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
    font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.btn-logout { background: none; border: 1px solid var(--border); color: var(--muted); padding: 6px 12px;
    border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.btn-logout:hover { border-color: var(--danger); color: var(--danger); }

.nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; cursor: pointer; color: var(--text); flex-shrink: 0;
}
.nav-toggle:hover { background: var(--surface-2); }
.nav-toggle svg { width: 18px; height: 18px; }
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }

/* Card that holds a wide table scrolls horizontally instead of breaking the page */
.card:has(table.grid) { overflow-x: auto; }

@media (max-width: 991px) {
    .topbar { padding: 0 14px; }
    .content { padding: 16px; }
    .topbar .context { display: none; }
    .topbar .context.context-compact { display: flex; gap: 8px; }
    .topbar .user b { display: none; }
    .page-head { flex-wrap: wrap; gap: 10px; }
}
@media (max-width: 600px) {
    .topbar .context.context-compact { display: none; }
    .stat-row { grid-template-columns: 1fr 1fr; }
}

.content { padding: 24px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Cards / tables / buttons ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 18px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr:hover td { background: var(--surface-2); }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13.5px;
    font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-danger { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.btn-danger:hover { background: #fee2e2; }

.form-grid { display: grid; gap: 16px; max-width: 560px; }
.form-grid label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 6px; }
.form-grid input, .form-grid textarea, .form-grid select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: var(--surface-2); font-family: inherit; }
.form-grid input:focus, .form-grid textarea:focus, .form-grid select:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.btn:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.form-wide { max-width: none; }
/* Auto-fit columns: wide screens get 3-4 columns, mobile collapses to 1. */
.form-2col { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.form-2col .col-span { grid-column: 1 / -1; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
    font-weight: 700; margin: 22px 0 4px; padding-top: 14px; border-top: 1px solid var(--border); }
.section-title:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
@media (max-width: 640px) { .form-2col { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.field-error { color: var(--danger); font-size: 12.5px; }
.field-hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; display: inline-block; }
.bom-results { position: absolute; left: 8px; right: 8px; top: 100%; z-index: 30; background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 240px;
    overflow-y: auto; }
.bom-results:empty { display: none; }
.bom-opt { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.bom-opt:hover { background: var(--primary-soft); }

/* Input with an inline + (quick-add) button */
.input-add { display: flex; gap: 6px; align-items: stretch; }
.input-add > select, .input-add > input { flex: 1; min-width: 0; }
.btn-add { flex-shrink: 0; width: 40px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; cursor: pointer; font-size: 18px; color: var(--primary); line-height: 1; }
.btn-add:hover { background: var(--primary-soft); }

/* Modal / popup */
.modal-overlay { position: fixed; inset: 0; z-index: 300; background: rgba(15,20,30,.5);
    display: none; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; width: 480px; max-width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,.3); margin-top: 6vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-body label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 6px; }
.modal-body input, .modal-body select { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; background: var(--surface-2); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-err { color: var(--danger); font-size: 12.5px; }

.child-add { margin: 6px 0 4px; }
table.grid td .cellsub { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px;
    background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.toolbar { margin-bottom: 14px; }
.toolbar input[type="search"] {
    width: 100%; max-width: 360px; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; background: var(--surface); }
.toolbar input[type="search"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
table.grid th[data-sort] { user-select: none; white-space: nowrap; }
table.grid th[data-sort]:hover { color: var(--text); }

/* Voucher-type applicable-taxes checkbox grid */
.check-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:6px 16px;margin-bottom:8px}
.check-item{display:flex;align-items:center;gap:8px;font-weight:400;cursor:pointer}
.check-item input{width:auto;margin:0}
/* inline checkbox label (checkbox + text on one line) */
.check{display:inline-flex;align-items:center;gap:8px;font-weight:600;cursor:pointer}
.form-grid label.check{display:inline-flex;margin-bottom:0}
.check input[type=checkbox],.check input[type=radio]{width:auto;flex:none;margin:0;padding:0;box-shadow:none}
.form-grid input[type=checkbox],.form-grid input[type=radio]{width:auto;padding:0;box-shadow:none}

/* Reusable typeahead picker (pricing masters) */
.picker-results{position:fixed;z-index:9999;background:var(--surface,#fff);border:1px solid var(--border,#d5d8e2);border-radius:8px;box-shadow:0 8px 24px rgba(20,20,50,.18);max-height:280px;overflow-y:auto}
.picker-opt{padding:8px 12px;cursor:pointer;font-size:.9rem}
.picker-opt:hover,.picker-opt.active{background:var(--indigo-50,#eff6ff)}
/* customer grid picker */
.cust-pick{padding:0}
.cust-row{display:grid;grid-template-columns:1fr 110px 110px 100px 60px;gap:8px;padding:7px 12px;font-size:.86rem;align-items:center}
.cust-row .num{text-align:right;font-variant-numeric:tabular-nums}
.cust-head{position:sticky;top:0;background:var(--surface-2,#f1f3f8);font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:.03em;color:var(--muted,#6b7280);cursor:default}
.cust-opt{cursor:pointer;border-top:1px solid var(--border,#eef0f4)}
.cust-opt:hover,.cust-opt.active{background:var(--indigo-50,#eff6ff)}
.cust-over{color:#dc2626}
.cust-info{font-size:.82rem;color:var(--muted,#6b7280);margin-top:4px;min-height:1em}
.cust-info.cust-over{color:#dc2626;font-weight:600}
/* Product grid picker: Code | Category | Name | Rate */
.prod-pick{padding:0}
.prod-row{display:grid;grid-template-columns:110px 140px 1fr 90px;gap:8px;padding:7px 12px;font-size:.86rem;align-items:center}
.prod-row .num{text-align:right;font-variant-numeric:tabular-nums}
.prod-head{position:sticky;top:0;background:var(--surface-2,#f1f3f8);font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:.03em;color:var(--muted,#6b7280);cursor:default}
.prod-opt{cursor:pointer;border-top:1px solid var(--border,#eef0f4)}
.prod-opt:hover,.prod-opt.active{background:var(--indigo-50,#eff6ff)}
.prod-filter{position:sticky;top:0;z-index:1;display:flex;align-items:center;gap:8px;padding:6px 12px;background:var(--surface-2,#f1f3f8);border-bottom:1px solid var(--border,#e5e9f0);font-size:12px;color:var(--muted,#6b7280)}
.prod-filter select{height:auto;padding:2px 6px;font-size:12px;width:auto}
.prod-none{padding:10px 12px;font-size:.86rem;color:var(--muted,#6b7280)}
.prod-newbtn{position:sticky;bottom:0;padding:8px 12px;font-size:.86rem;font-weight:600;color:var(--primary);background:var(--surface-2,#f1f3f8);border-top:1px solid var(--border,#e5e9f0);cursor:pointer}
.prod-newbtn:hover{background:var(--primary-soft)}
/* Stock bar above the items grid (current + per-store), like legacy. */
.stock-bar{background:var(--surface-2,#f1f5f9);border:1px solid var(--border,#e5e9f0);border-radius:6px;padding:6px 12px;margin-bottom:8px;font-size:.85rem;color:var(--muted,#374151)}
.stock-bar b{color:var(--text,#1e2430);font-variant-numeric:tabular-nums}
/* Defaulter PIN-lock bar (below the product grid). */
.pin-lock{display:flex;flex-wrap:wrap;align-items:center;gap:10px;margin:10px 0;padding:10px 14px;
    background:var(--danger-soft,#fef2f2);border:1px solid #fecaca;border-radius:8px;font-size:.9rem;color:var(--danger,#dc2626)}
.pin-lock input{width:110px;padding:6px 9px;border:1px solid #fecaca;border-radius:6px}
.pin-lock .pin-lock-msg b{color:var(--danger,#dc2626)}
.pin-msg{color:var(--danger,#dc2626);font-weight:600}
/* Big screens: inline grid + "Add line" (hide the popup add). Small screens: swap to the "Add product" popup. */
.btn-add-popup{display:none}
@media (max-width:820px){
    /* Only the Sales grid swaps its "Add line" for the "Add product" popup on mobile — other forms
       (vouchers, physical stock) reuse #addLine WITHOUT a popup, so keep their add button visible. */
    .txn-bar:has(.btn-add-popup) #addLine{display:none}
    .btn-add-popup{display:inline-flex}
    .sec-items #lineGrid{font-size:.9rem}
}
/* clear-× button on search/picker inputs */
input[type=search]::-webkit-search-cancel-button{-webkit-appearance:none;appearance:none}
.clr-wrap{position:relative;display:block}
.clr-wrap>input{width:100%;box-sizing:border-box;padding-right:26px}
.clr-x{position:absolute;right:4px;top:50%;transform:translateY(-50%);border:none;background:transparent;color:var(--muted,#6b7280);font-size:18px;line-height:1;cursor:pointer;padding:0 5px;display:none;border-radius:4px}
.clr-x:hover{color:var(--text,#1f2430);background:var(--surface-2,#eef0f4)}

/* Transaction (sales document) line-items grid */
.line-grid{width:100%;border-collapse:collapse}
.line-grid thead th{padding:8px 10px;font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted,#6b7280);border-bottom:1px solid var(--border,#e5e7eb);text-align:left}
.line-grid tbody td{padding:5px 8px;border-bottom:1px solid var(--border,#eef0f4);vertical-align:middle}
.line-grid tbody tr:hover{background:var(--indigo-50,#eff6ff)}
.line-grid input,.line-grid select{width:100%;box-sizing:border-box;padding:7px 9px;border:1px solid var(--border,#d5d8e2);border-radius:6px;background:var(--surface,#fff);font-size:.9rem}
.line-grid input:focus,.line-grid select:focus{outline:none;border-color:var(--primary,#2563eb);box-shadow:0 0 0 3px rgba(37,99,235,.15)}
.line-grid .l-qty,.line-grid .l-rate{text-align:right}
.line-grid .l-amount{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap;font-weight:600;color:var(--text,#1f2430)}
.line-grid .l-remove{padding:4px 9px;line-height:1}
.line-grid td.col-prod{min-width:240px}
.line-grid th.col-check,.line-grid td.col-check{width:34px;min-width:0;text-align:center}
.line-grid input[type=checkbox]{width:auto;padding:0;box-shadow:none;cursor:pointer}
.txn-bar{display:flex;justify-content:space-between;align-items:center;gap:16px;flex-wrap:wrap;margin-top:12px}
.txn-total{margin-left:auto;font-size:1.05rem}
.txn-total b{font-size:1.35rem;font-variant-numeric:tabular-nums;color:var(--primary,#2563eb);margin-left:8px}
/* Compact edit page header: back link inline beside a smaller title. */
.page-head-compact{justify-content:space-between;gap:12px;margin-bottom:12px}
.page-head-compact h2{font-size:16px}
.page-head-compact .back-link{color:var(--muted,#6b7280);font-size:12px;text-decoration:none}
.page-head-compact .back-link:hover{text-decoration:underline}

/* Section background tints on the sales form (light) — visually separate header fields, the product
   grid, and additional costs. The calculation/totals panel stays white (it's its own .card). */
.sec{border-radius:10px;padding:14px 16px;margin-bottom:16px}
.sec-fields{background:#eff6ff}   /* header fields — light teal */
.sec-items{background:#fffbeb;overflow-x:auto}    /* product grid — light amber/yellow */
.sec-addl{background:#f0f9ff}     /* additional costs — light sky blue */
.txn-secondary .txn-totals{background:var(--surface)} /* calculation panel stays white */

/* Bottom Save/Cancel aligned right. */
.form-actions-end{justify-content:flex-end}

/* Field tabs (Main / Other details). */
.form-tabs{display:flex;gap:4px;border-bottom:1px solid var(--border,#e5e7eb);margin-bottom:14px}
.form-tab{border:0;background:none;padding:8px 14px;font-size:.9rem;color:var(--muted,#6b7280);cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px}
.form-tab.active{color:var(--primary,#2563eb);border-bottom-color:var(--primary,#2563eb);font-weight:600}
.narration{min-height:44px}
/* Sales main fields: fixed 6-per-row so the first row holds the key fields (incl. Salesman+Cash);
   rows 2+ collapse behind a Show more/less link. */
.form-2col.sales-grid{display:flex;flex-wrap:wrap;gap:16px 14px;align-items:flex-start}
.form-2col.sales-grid > div{flex:0 1 165px;min-width:0}   /* default field width */
.form-2col.sales-grid > .f-xs{flex-basis:115px}           /* Exchange rate, Credit period */
.form-2col.sales-grid > .f-sm{flex-basis:150px}           /* Date */
.form-2col.sales-grid > .f-lg{flex-basis:240px}           /* Voucher Number */
.form-2col.sales-grid > .f-xl{flex-basis:275px}           /* Customer */
.form-2col.sales-grid > .f-xxl{flex-basis:480px}          /* Manual DO (double) */
.form-2col.sales-grid > .salesman-cash{flex-basis:255px}  /* half salesman + Cash checkbox */
.form-2col.sales-grid > .fld-wide{flex:0 1 240px}         /* Narration */
.form-2col.sales-grid.collapsed > div:nth-child(n+7){display:none}
@media (max-width:640px){ .form-2col.sales-grid > div{flex:1 1 100% !important} }
.sales-more{margin:2px 0 6px}
.sales-more .more-link{font-size:12.5px;color:var(--primary);cursor:pointer}
/* Salesman (half width) sharing its cell with the Cash-invoice checkbox. */
.salesman-cash{display:flex;align-items:flex-start;gap:10px}
.salesman-cash .sm-field{flex:1 1 120px;min-width:0}
.salesman-cash .sm-cash{flex:0 0 auto;align-self:flex-end;margin:0 0 9px;white-space:nowrap}
/* Customer field: search input + quick-add (+) button. */
.cust-row-input{display:flex;gap:6px;align-items:center}
.cust-row-input input{flex:1 1 auto;min-width:0}
.btn-quick-add{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;
    border:1px solid var(--border);border-radius:8px;background:var(--surface);color:var(--primary);font-size:18px;
    line-height:1;text-decoration:none;cursor:pointer;padding:0;font-family:inherit}
.btn-quick-add:hover{background:var(--primary-soft);text-decoration:none}
/* Two checkboxes sharing one grid cell. A hidden spacer label keeps them at the input baseline so they
   don't drift up/down when the column count changes (e.g. when the side nav toggles). */
.spacer-label{visibility:hidden}
.check-pair{display:flex;flex-wrap:wrap;gap:8px 20px;align-items:center;min-height:38px}
.check-pair .check{margin:0}

.voucher-summary{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.voucher-list{display:flex;flex-direction:column;gap:8px;max-height:50vh;overflow-y:auto;margin:8px 0 4px}
.voucher-item{display:inline-flex;align-items:center;gap:8px;margin:0;font-weight:400;white-space:nowrap}
.voucher-item input[type=checkbox]{width:auto;flex:none}
.txn-secondary{display:flex;gap:20px;align-items:flex-start;margin-top:1.25rem;flex-wrap:wrap}
.txn-secondary-left{flex:1 1 340px;min-width:300px}
.txn-right{flex:0 0 360px;display:flex;flex-direction:column;gap:8px}
.txn-secondary .txn-totals{margin:0;width:100%}
/* Small print/email options above the calculation panel. */
.print-opts{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;font-size:12.5px}
.print-opts .print-mode{padding:4px 8px;font-size:12.5px;height:auto;width:auto;max-width:150px}
.print-opts .po-lbl{margin:0;font-size:12px;color:var(--muted,#6b7280)}
.print-opts .check{margin:0;font-size:12.5px}
.print-opts-slim{justify-content:flex-end;margin-top:.6rem}
.sr-summary{margin:0 0 12px;padding:8px 12px;border-radius:8px;background:#fee2e2;color:#b91c1c;font-size:.9rem;border:1px solid #fecaca}
.sr-summary .sr-link{color:#b91c1c;font-weight:700;text-decoration:underline;cursor:pointer}
.sr-summary .sr-link:hover{color:#991b1b}
.modal-box.modal-wide{max-width:760px;width:92%}
.txn-totals{max-width:380px;margin-left:auto;margin-top:10px}
.txn-totals .card-body{padding:12px 16px}

/* ---- Sales form on small screens (placed after the base txn rules so it wins) ---- */
@media (max-width: 640px) {
    .sec{padding:12px}
    .txn-secondary-left{min-width:0}                    /* let the additional-cost panel shrink */
    .txn-right{flex:1 1 100%}                            /* totals column spans full width */
    .txn-totals{max-width:none}
    .totrow input{width:120px}
    .page-head-compact{align-items:baseline}
}
.totrow{display:flex;justify-content:space-between;align-items:center;gap:12px;padding:4px 0}
.totrow span{color:var(--muted,#6b7280);font-size:.9rem}
.totrow label{margin:0;font-size:.9rem;color:var(--muted,#6b7280)}
.totrow input{width:130px;text-align:right}
.totrow b{font-variant-numeric:tabular-nums}
.totrow.grand{border-top:1px solid var(--border,#e5e7eb);margin-top:4px;padding-top:8px}
.totrow.grand b{font-size:1.2rem;color:var(--primary,#2563eb)}
/* simple modal/popup */
.modal-backdrop{position:fixed;inset:0;background:rgba(20,20,50,.45);z-index:10000;display:flex;align-items:center;justify-content:center}
.modal-box{background:var(--surface,#fff);border-radius:12px;box-shadow:0 20px 60px rgba(0,0,0,.3);padding:22px 24px;width:min(440px,92vw);max-height:90vh;overflow-y:auto}
.modal-box h3{margin:0 0 14px}
.line-grid .l-mrp,.line-grid .l-salesrate,.line-grid .l-purchaserate{font-variant-numeric:tabular-nums;color:var(--muted,#6b7280)}
.line-grid .l-barcode{background:var(--surface-2,#f7f8fa)}
/* settings-driven column visibility (mirrors legacy dgvSalesInvoice) */
.line-grid.hide-barcode [data-col="barcode"]{display:none}
.line-grid.hide-unit [data-col="unit"]{display:none}
.line-grid.hide-mrp [data-col="mrp"]{display:none}
.line-grid.hide-salesrate [data-col="salesrate"]{display:none}
.line-grid.hide-purchaserate [data-col="purchaserate"]{display:none}
.line-grid.hide-disc [data-col="disc"]{display:none}
.line-grid.hide-discpct [data-col="discpct"]{display:none}
.line-grid.hide-brand [data-col="brand"]{display:none}
.line-grid.hide-rack [data-col="rack"]{display:none}
.line-grid.hide-batch [data-col="batch"]{display:none}
.line-grid.hide-tax [data-col="tax"]{display:none}
/* Base-currency rate column: hidden by default, shown only when a non-default currency is picked (.show-baserate). */
.line-grid [data-col="baserate"]{display:none}
.line-grid.show-baserate [data-col="baserate"]{display:table-cell}

/* ---- Stacked line rows as cards: the "Add product" modal (always) + the grid on mobile ---- */
.line-stacked thead,
.sec-items .line-grid thead { }
.line-stacked, .line-stacked tbody, .line-stacked tr, .line-stacked td { display:block; width:auto; }
.line-stacked thead { display:none; }
.line-stacked tr { border:1px solid var(--border,#e5e9f0); border-radius:8px; padding:8px 12px; margin-bottom:10px; background:var(--surface,#fff); }
.line-stacked td { border:0; padding:5px 0; }
.line-stacked td:first-child { min-width:0; }
.line-stacked td::before { content:attr(data-label); display:block; color:var(--muted,#6b7280); font-size:.75rem; font-weight:600; margin-bottom:3px; }
.line-stacked input, .line-stacked select { width:100%; }
.line-stacked .l-remove-cell { text-align:right; padding-top:6px; }
.line-stacked .l-remove { width:auto; }
.line-stacked .l-amount, .line-stacked .l-mrp, .line-stacked .l-purchaserate, .line-stacked .l-brand { text-align:left; }
@media (max-width:820px) {
    /* Grid = SWIPE carousel: JS shows one product card at a time (swipe / Prev-Next), with an "X of N" counter. */
    .sec-items .line-grid, .sec-items .line-grid tbody, .sec-items .line-grid tr, .sec-items .line-grid td { display:block; width:auto; }
    .sec-items .line-grid thead { display:none; }
    /* The block rule above re-shows the base-rate cell on mobile — keep it hidden unless a foreign currency is picked. */
    .sec-items .line-grid:not(.show-baserate) td[data-col="baserate"] { display:none; }
    .sec-items .line-grid tr { border:1px solid var(--border,#e5e9f0); border-radius:8px; padding:10px 12px; margin:0; background:var(--surface,#fff); touch-action:pan-y; }
    .sec-items .line-grid td { border:0; padding:5px 0; }
    .sec-items .line-grid td:first-child { min-width:0; }
    .sec-items .line-grid td.col-prod { min-width:0; }
    .sec-items .line-grid td.col-check { text-align:left; }
    .sec-items .line-grid td::before { content:attr(data-label); display:block; color:var(--muted,#6b7280); font-size:.75rem; font-weight:600; margin-bottom:3px; }
    .sec-items .line-grid .l-remove-cell { text-align:right; }
    .sec-items .line-grid .l-remove { width:auto; }
    .sec-items { overflow-x:visible; }
}
.line-grid tr.lc-hide { display:none !important; }   /* carousel: hide non-current cards (mobile only, set by JS) */
/* Line carousel nav (mobile only): ‹ Prev · "1 of 2" · Next › */
.line-nav { display:none; }
@media (max-width:820px) {
    .line-nav { display:flex; align-items:center; justify-content:center; gap:10px; margin:8px 0; }
    .line-counter { font-size:.85rem; color:var(--text,#1e2430); font-weight:600; min-width:52px; text-align:center; }
    .swipe-hint { font-size:1.1rem; color:var(--primary,#2563eb); }
    .swipe-tip { font-size:.75rem; color:var(--muted,#6b7280); margin-left:6px; }
}

/* Role-privilege tabbed matrix */
.priv-tabs{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:0}
.priv-tab{background:var(--surface-2,#eef0f4);border:1px solid var(--border,#d5d8e2);border-bottom:none;border-radius:8px 8px 0 0;padding:8px 16px;cursor:pointer;font-weight:600;font-size:.88rem;color:var(--text-muted,#5b6472)}
.priv-tab.active{background:#fff;color:var(--primary,#2563eb);box-shadow:0 -2px 0 var(--primary,#2563eb) inset}
.priv-panel{border-top-left-radius:0}
.priv-tools td{background:var(--surface-2,#f7f8fa)}

/* Role-privilege box grid (per-form boxes, like the legacy tabbed form) */
.priv-toolbar{display:flex;gap:14px;margin-bottom:10px;font-size:.85rem}
.priv-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(270px,1fr));gap:10px}
.priv-box{border:1px solid var(--border,#e5e9f0);border-radius:8px;padding:10px 12px;background:var(--surface-2,#f8fafc)}
.priv-box-title{font-weight:600;font-size:.9rem;margin-bottom:8px}
.priv-box-title .text-muted{font-weight:400;font-size:.72rem}
.priv-box-actions{display:flex;flex-wrap:wrap;gap:6px 14px}
.priv-opt,.priv-single{display:inline-flex;align-items:center;gap:5px;font-weight:400;font-size:.85rem;cursor:pointer;margin:0}
.priv-opt input,.priv-single input{width:auto;margin:0}

/* Top-nav financial-year switcher */
.fy-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 10px}
.fy-chip select{border:0;background:transparent;font-weight:600;color:var(--text);font-size:12.5px;cursor:pointer;max-width:180px}
.fy-chip select:focus{outline:none}
.fy-warn{cursor:help}

/* Print dropdown menu (Edit + list actions) — native <details> */
.print-menu{position:relative;display:inline-block}
.print-menu>summary{cursor:pointer;list-style:none;user-select:none}
.print-menu>summary::-webkit-details-marker{display:none}
.print-menu>summary::marker{content:""}
.print-menu-list{position:absolute;z-index:60;top:calc(100% + 4px);left:0;background:var(--surface,#fff);border:1px solid var(--border,#d0d5dd);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.16);min-width:220px;padding:4px}
.print-menu-list.print-menu-right{left:auto;right:0}
.print-menu-list a{display:block;padding:8px 11px;border-radius:6px;text-decoration:none;color:var(--text,#222);white-space:nowrap;font-size:13px}
.print-menu-list a:hover{background:var(--primary-soft,#eef2ff)}
.print-menu-list.print-menu-up{top:auto;bottom:calc(100% + 4px)}
/* A row print menu lives inside a .card whose overflow-x:auto also clips vertically — un-clip while it's open so the dropdown shows in full (esp. short lists with few rows). */
.card:has(table.grid):has(.print-menu[open]){overflow:visible}
