/* =====================================================================
   Akshari Gold Buyers - billing app styles
   Direction: a jeweller's buying counter. Steady, exact, counter-side.
   Graphite neutrals, one accent (Akshari ruby from the logo), metal gold for hallmarks and charts,
   IBM Plex Sans for the interface, IBM Plex Mono for weights and rupees.
   Signature: purity shown as a hallmark stamp (.hallmark).
   Layout: dark sidebar + top bar on desktop; off-canvas sidebar, stacked
   item cards and a sticky Save bar on phones.
   Visual pass informed by unslop (Damir Sokolovsky, @heydamir, CC BY 4.0).
   ===================================================================== */
:root {
    /* Neutral ramp (graphite, light) */
    --bg: #fafafa;
    --card: #ffffff;
    --raised: #f4f4f5;
    --line: rgba(23, 23, 23, .08);
    --line-strong: rgba(23, 23, 23, .16);
    --text: #171717;
    --text-2: #525252;
    --muted: #737373;

    /* Sidebar (graphite, dark) */
    --side: #0f0f10;
    --side-raised: #232325;
    --side-line: rgba(237, 237, 237, .08);
    --side-text: #ededed;
    --side-text-2: #a1a1a6;
    --side-muted: #85858b;

    /* Accent: Akshari ruby (the logo wordmark). Passes 4.5:1 with white text and as text on white.
       (Variables keep the --gold names so the shared stylesheet stays the same across clients.) */
    --gold: #8f1a20;
    --gold-hover: #73151a;
    --gold-bright: #d9b24c;           /* logo gold, only on the dark sidebar */
    --gold-soft: #fbf3f3;
    --gold-line: rgba(143, 26, 32, .25);

    /* Metal gold: purity hallmarks, IBJA-filled rates, charts */
    --hm: #8a6508;
    --hm-soft: #faf6ea;
    --hm-line: rgba(138, 101, 8, .28);

    /* Semantic */
    --ok: #16a34a;
    --ok-bg: #f0fdf4;
    --warn: #a15c07;
    --warn-bg: #fffbeb;
    --bad: #dc2626;
    --bad-bg: #fef2f2;

    /* Chart: gold leads, neutrals follow */
    --viz-1: #b8860b;
    --viz-2: #525252;
    --viz-3: #a3a3a3;
    --viz-other: #d4d4d4;

    --sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
    --r-control: 8px;
    --r-card: 12px;
    --r-panel: 16px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.app {
    margin: 0;
    padding: 0;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}
.app h1, .app h2, .app h3, .app h4 { margin: 0; line-height: 1.25; color: var(--text); font-weight: 500; }
.app h2 { font-size: 20px; }
.app h3 { font-size: 16px; }
.app a { color: var(--gold); }
.app button { font: inherit; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mobile-only { display: none !important; }

/* Icons: Lucide, one size, one stroke, colour of the text around them */
.i { width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.i-18 { width: 18px; height: 18px; }

/* Signature: purity as a hallmark stamp */
.hallmark {
    display: inline-flex; align-items: center; height: 20px; padding: 0 6px;
    font: 500 12px/1 var(--mono); letter-spacing: .02em; white-space: nowrap;
    color: var(--hm); border: 1px solid var(--hm-line); border-radius: 4px; background: var(--hm-soft);
}

/* :focus-visible ring for keyboard users, everywhere */
.app :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Form controls ---------- */
.app input, .app select, .app textarea {
    font: inherit;
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-control);
    outline: none;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.app textarea { min-height: 72px; resize: vertical; }
.app input:focus, .app select:focus, .app textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(143, 26, 32, .14); }
.app input[readonly], .app .input-readonly { background: var(--raised); color: var(--text-2); }
.app input.is-invalid { border-color: var(--bad); background: var(--bad-bg); }
.app label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }
.app fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.app fieldset:disabled input, .app fieldset:disabled select, .app fieldset:disabled textarea { background: var(--raised); color: var(--text); opacity: 1; }
.field-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 8px 16px;
    font-weight: 500; font-size: 14px; white-space: nowrap;
    border: 1px solid transparent; border-radius: var(--r-control); cursor: pointer;
    text-decoration: none;
    transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--gold-hover); }
.btn-dark { background: var(--text); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #000; }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--raised); }
.btn-secondary .i { color: var(--text-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger-ghost { background: var(--card); color: var(--bad); border-color: rgba(220, 38, 38, .24); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--bad-bg); }
/* Links styled as buttons keep the button colours, not the link gold */
.app a.btn { text-decoration: none; }
.app a.btn-secondary { color: var(--text); }
.app a.btn-primary, .app a.btn-dark { color: #fff; }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; gap: 6px; }
.btn-block { width: 100%; }
.lbl-short { display: none; }

/* ---------- Shell ---------- */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000;
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    background: var(--side); color: var(--side-text);
    padding: 20px 0 16px;
}
.sidebar-header { padding: 0 20px 20px; border-bottom: 1px solid var(--side-line); margin-bottom: 12px; display: flex; align-items: center; gap: 12px; }
.sidebar-header img { width: 40px; height: 40px; object-fit: contain; }
.sidebar-header strong { display: block; color: var(--side-text); font-size: 16px; font-weight: 500; }
.sidebar-header span { display: block; color: var(--side-muted); font-size: 12px; }
.sidebar-menu { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; overflow-y: auto; }
.menu-btn {
    display: flex; align-items: center; gap: 12px;
    min-height: 36px; padding: 8px 12px; border-radius: var(--r-control);
    color: var(--side-text-2); text-decoration: none; font-size: 14px; font-weight: 400;
    background: transparent; border: 0; width: 100%; text-align: left; cursor: pointer;
    transition: background-color .15s var(--ease), color .15s var(--ease);
}
.app .menu-btn { color: var(--side-text-2); }
.menu-btn .i { color: var(--side-muted); }
.menu-btn:hover { background: var(--side-raised); color: var(--side-text); text-decoration: none; }
.app .menu-btn.active { background: var(--side-raised); color: var(--side-text); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08); }
.menu-btn.active .i { color: var(--gold-bright); }
.sidebar-user { padding: 12px 20px 0; border-top: 1px solid var(--side-line); font-size: 12px; color: var(--side-muted); }
.sidebar-user strong { color: var(--side-text); display: block; font-size: 13px; font-weight: 500; }
.sidebar-backdrop { display: none; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 64px; padding: 12px 32px;
    background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title h1 { font-size: 20px; font-weight: 500; }
.topbar-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.menu-toggle-btn { display: none; width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: var(--r-control); background: var(--card); color: var(--text); cursor: pointer; }
.top-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.mode-badge { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 500; }
.mode-badge-edit { color: var(--warn); }
.mode-badge-view { color: var(--text-2); }
.page-body { padding: 24px 32px 32px; flex: 1; }
.page-head { margin-bottom: 16px; }
.page-head h2 { font-size: 16px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }

/* ---------- Cards, alerts ---------- */
.section-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.section-card > h2 { font-size: 16px; margin-bottom: 16px; }
.alert { padding: 12px 16px; border-radius: var(--r-control); margin-bottom: 12px; border: 1px solid transparent; font-size: 14px; }
.alert-error { background: var(--bad-bg); color: #991b1b; border-color: rgba(220, 38, 38, .2); }
.alert-warn { background: var(--warn-bg); color: #854d0e; border-color: rgba(161, 92, 7, .2); }
.alert-info { background: var(--raised); color: var(--text); border-color: var(--line); }
.alert-ok { background: var(--ok-bg); color: #166534; border-color: rgba(22, 163, 74, .2); }
.banner-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.banner-actions { display: flex; gap: 8px; }
.empty-text { color: var(--text-2); padding: 16px 0; }

/* ---------- Invoice entry ---------- */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 24px; align-items: start; }
.preview-col { position: sticky; top: 88px; display: flex; flex-direction: column; gap: 16px; }
.invoice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.address-box { min-height: 64px; }

.photo-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.photo-card > h2 { font-size: 16px; margin-bottom: 12px; }
.photo-summary { font-size: 13px; color: var(--text-2); margin: -4px 0 12px; }
.photo-summary-error { color: var(--bad); font-weight: 500; }
.photo-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.id-proof-section { margin-top: 16px; }
.id-proof-section h3 { font-size: 14px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.id-proof-section h3 .i { color: var(--muted); }
.photo-helper { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.id-proof-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-box { border: 1px dashed var(--line-strong); border-radius: var(--r-control); padding: 12px; background: var(--bg); min-width: 0; }
.photo-box h4 { font-size: 13px; font-weight: 500; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.photo-box h4 .i { color: var(--muted); }
.side-badge { font: 500 12px/1 var(--mono); color: var(--muted); }
.photo-empty { margin: 4px 0 8px; color: var(--muted); font-size: 13px; }
.photo-removed { color: var(--warn); }
.photo-note { font-size: 12px; color: var(--warn); margin: 0 0 8px; }
.preview-image { display: block; width: 100%; max-height: 180px; object-fit: contain; border-radius: 4px; background: var(--raised); }
.product-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.product-preview .photo-slot { position: relative; width: 92px; }
.preview-small { display: block; width: 92px; height: 92px; object-fit: cover; border-radius: 4px; background: var(--raised); }
.photo-unavailable { display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; color: var(--muted); padding: 8px; min-height: 80px; }
.photo-status { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.photo-slot-done .photo-status { color: var(--ok); }
.photo-slot-error .photo-status { color: var(--bad); }
.photo-progress { width: 100%; height: 4px; background: var(--raised); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.photo-progress div { height: 100%; width: 100%; background: var(--gold); transform-origin: left; transition: transform .2s var(--ease); }
.photo-error { font-size: 12px; color: var(--bad); display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.remove-photo-btn { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(23, 23, 23, .72); color: #fff; cursor: pointer; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.remove-photo-btn .i { width: 14px; height: 14px; }
.photo-input-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-btn {
    flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 36px; padding: 4px 12px; font-size: 13px; font-weight: 500; border-radius: var(--r-control);
    border: 1px solid var(--line-strong); background: var(--card); cursor: pointer; color: var(--text);
    transition: background-color .15s var(--ease);
}
.photo-btn .i { color: var(--text-2); }
.photo-btn:hover { background: var(--raised); }
.remove-btn { color: var(--bad); border-color: rgba(220, 38, 38, .24); }
.remove-btn .i { color: var(--bad); }
.photo-retry-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; border: 1px solid rgba(220, 38, 38, .24); background: var(--card); color: var(--bad); border-radius: 4px; font-size: 12px; padding: 2px 8px; cursor: pointer; }
.photo-retry-btn .i { width: 12px; height: 12px; }

.table-scroll { position: relative; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.items-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.items-table .cell-sl { width: 28px; color: var(--muted); text-align: center; font: 400 13px var(--mono); }
.items-table .cell-name { min-width: 124px; }
.items-table td input { min-width: 64px; }
.items-table td select[data-f="purity"] { min-width: 104px; }
.items-table .cell-net { font: 500 14px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.items-table .cell-amount { font: 500 14px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.items-table .cell-amount.no-rate { color: var(--bad); font-family: var(--sans); }
.items-table .cell-action { width: 44px; text-align: center; }
.delete-icon-btn { width: 36px; height: 36px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: var(--r-control); display: inline-flex; align-items: center; justify-content: center; transition: background-color .15s var(--ease), color .15s var(--ease); }
.delete-icon-btn:hover { background: var(--bad-bg); color: var(--bad); }
.add-item-btn { margin-top: 12px; }

.payment-grid, .amount-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 12px 16px; }
.amount-grid input { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.side-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 16px; }
.side-card h3 { margin-bottom: 12px; font-size: 15px; }
.search-row { display: grid; grid-template-columns: 132px 1fr auto; gap: 8px; }
.search-result { margin-top: 12px; padding: 12px; border: 1px solid var(--line); background: var(--raised); border-radius: var(--r-control); font-size: 14px; }
.search-result p { margin: 2px 0; }
.search-msg { margin: 8px 0 0; font-size: 13px; color: var(--text-2); }

.mobile-action-bar { display: none; }

/* ---------- Receipt (preview, print, PDF) ----------
   A printed document: black on white, red stamp-ink title. Kept as the screen's one rich object. */
.bill-preview { overflow-x: auto; }
.bill-paper {
    position: relative; overflow: hidden;
    width: 500px; max-width: 100%; margin: 0 auto; padding: 12px;
    color: #000; background: #fff; border: 2px solid #000;
    font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 1.35;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .06);
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.bill-watermark { position: absolute; top: 50%; left: 50%; width: 60%; transform: translate(-50%, -50%); opacity: .07; pointer-events: none; z-index: 0; }
.bill-paper > :not(.bill-watermark) { position: relative; z-index: 1; }
.receipt-header { display: flex; justify-content: space-between; font-size: 11px; font-weight: 700; gap: 8px; }
.receipt-title { text-align: center; color: #8f1a20; margin: 12px 0 4px; font-size: 18px; font-weight: 700; letter-spacing: .04em; }
.receipt-address { text-align: center; margin-bottom: 4px; font-size: 12px; }
.receipt-info { display: flex; justify-content: space-between; margin: 8px 0; gap: 8px; }
.receipt-line { border-bottom: 1px dashed #000; padding: 4px 0; margin-bottom: 8px; word-wrap: break-word; }
.receipt-address-line { min-height: 32px; }
.receipt-table { width: 100%; border-collapse: collapse; }
.receipt-table th, .receipt-table td { border: 1px solid #000; padding: 4px; text-align: center; font-size: 11px; }
.receipt-table td { height: 22px; }
.receipt-table .hallmark { height: 16px; padding: 0 4px; font: 700 10px/1 Arial, sans-serif; color: #000; border-color: #000; background: none; letter-spacing: 0; }
.receipt-bottom { display: flex; margin-top: 12px; }
.receipt-payment { width: 58%; border: 1px solid #000; }
.receipt-amounts { width: 42%; border: 1px solid #000; border-left: 0; }
.receipt-payment div, .receipt-amounts div { border-bottom: 1px solid #000; padding: 4px; }
.receipt-payment div:last-child, .receipt-amounts div:last-child { border-bottom: 0; }
.receipt-amounts div { display: flex; justify-content: space-between; gap: 8px; }
.receipt-amounts .receipt-paid { font-weight: 700; }
.receipt-terms { margin-top: 12px; font-size: 10px; line-height: 1.3; border-top: 1px dashed #999; padding-top: 8px; }
.receipt-terms ol { margin: 2px 0 0 16px; padding: 0; }
.receipt-company { text-align: right; color: #8f1a20; margin-top: 12px; font-weight: 700; }
.receipt-signatures { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 32px; font-size: 11px; }
.receipt-signatures span { border-top: 1px solid #000; padding-top: 4px; min-width: 120px; text-align: center; }

/* ---------- Lists (history, customers) ---------- */
.list-container { max-width: 960px; }
.history-search { margin-bottom: 16px; min-height: 44px !important; }
.invoice-card {
    display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: start;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow);
    padding: 16px 20px; margin-bottom: 8px;
}
.invoice-card h3 { font: 500 15px var(--mono); color: var(--text); }
.invoice-card h3.card-name { font: 500 16px var(--sans); }
.invoice-card p { margin: 2px 0; font-size: 14px; color: var(--text-2); }
.invoice-card .meta { font-size: 13px; color: var(--muted); }
.invoice-card .amount { font: 500 18px var(--mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--text); }
.invoice-card .amount small { display: block; margin-top: 2px; font: 400 12px var(--sans); color: var(--muted); }
.history-buttons { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.load-more { display: flex; margin: 16px auto; }

/* ---------- Rates, settings ---------- */
.rates-form { max-width: 960px; }
.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(192px, 1fr)); gap: 12px 16px; margin-bottom: 20px; }
.rate-grid label { display: flex; align-items: center; gap: 8px; }
.rate-grid input { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.rate-group-title { font-size: 14px; margin: 4px 0 12px; color: var(--text-2); }
.market-card { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.market-card .figures { display: flex; gap: 32px; flex-wrap: wrap; }
.market-card .figure strong { display: block; font: 500 20px var(--mono); font-variant-numeric: tabular-nums; }
.market-card .figure span { font-size: 12px; color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.password-wrap { position: relative; margin-bottom: 12px; }
.password-wrap input { padding-right: 64px; }
.password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); height: 32px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; color: var(--text-2); font-size: 13px; }
.password-toggle:hover { background: var(--raised); }
.user-meta { font-size: 13px; color: var(--muted); margin: -8px 0 12px; }

/* ---------- Reports ---------- */
.report-filters { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.report-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.report-chip { min-height: 32px; padding: 4px 12px; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--card); cursor: pointer; font-weight: 500; font-size: 13px; color: var(--text-2); transition: background-color .15s var(--ease), color .15s var(--ease); }
.report-chip:hover { background: var(--raised); }
.report-chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.report-fields { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.report-fields label { margin: 0; }
.report-fields label input, .report-fields label select { margin-top: 4px; min-width: 152px; }
.report-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.report-heading { display: none; }
.report-stale { opacity: .55; transition: opacity .2s var(--ease); }

/* The moment: amount paid, set large, with its trend beside it */
.report-hero {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: var(--shadow);
    padding: 24px; margin-bottom: 16px;
}
.report-hero-label { font-size: 14px; color: var(--text-2); }
.report-hero-value { font: 500 40px/1.1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: 8px 0; color: var(--text); }
.report-hero-breakdown { font-size: 13px; color: var(--muted); margin-top: 8px; }
.report-hero-breakdown .num { color: var(--text-2); }
.report-hero-spark { flex: 0 1 320px; min-width: 160px; }
.report-hero-spark rect { fill: var(--viz-3); }
.report-hero-spark rect:last-child { fill: var(--viz-1); }
.report-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 12px; margin-bottom: 16px; }
.report-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 16px; }
.report-tile-label { font-size: 13px; color: var(--text-2); }
.report-tile-value { font: 500 24px/1.2 var(--mono); font-variant-numeric: tabular-nums; margin: 8px 0 4px; }
.report-tile-sub { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.report-delta { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; font-weight: 500; }
.report-delta .i { width: 14px; height: 14px; }
.report-delta.is-up { color: var(--ok); }
.report-delta.is-down { color: var(--bad); }
.report-delta.is-flat { color: var(--muted); }
.report-delta-label { font-weight: 400; color: var(--muted); }
.report-note { font-size: 13px; color: var(--warn); }
.report-section { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; min-width: 0; }
.report-section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.report-section-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.report-section-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.report-toggle { display: inline-flex; padding: 2px; gap: 2px; background: var(--raised); border-radius: var(--r-control); }
.report-toggle button { border: 0; background: transparent; padding: 4px 12px; min-height: 28px; font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; border-radius: 6px; transition: background-color .15s var(--ease), color .15s var(--ease); }
.report-toggle button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.report-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.report-two-col .report-section { margin-bottom: 0; }
.report-two-col + .report-section { margin-top: 16px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.report-table td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.report-table .num { text-align: right; }
.report-table th.num { font-family: var(--sans); }
.report-table tfoot td { font-weight: 500; border-top: 1px solid var(--line-strong); border-bottom: 0; }
.report-empty { text-align: center; padding: 48px 12px; color: var(--text-2); }
.report-empty-icon { color: var(--muted); }
.report-empty-icon .i { width: 32px; height: 32px; stroke-width: 1.25; }
.report-empty span { color: var(--muted); font-size: 14px; }
.viz-group-title { font-size: 12px; font-weight: 500; color: var(--muted); margin: 4px 0 8px; }
.hbar-row { display: grid; grid-template-columns: 112px 1fr auto; gap: 12px; align-items: center; margin-bottom: 12px; }
.hbar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 8px; background: var(--raised); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--viz-3); border-radius: 4px; min-width: 2px; }
.hbar-row:first-child .hbar-fill { background: var(--viz-1); }
.hbar-value { text-align: right; font: 500 13px var(--mono); font-variant-numeric: tabular-nums; }
.hbar-value small { display: block; font: 400 12px var(--sans); color: var(--muted); }
.share-bar { display: flex; gap: 2px; height: 12px; border-radius: 4px; overflow: hidden; background: var(--raised); margin-bottom: 16px; }
.share-bar div { height: 100%; }
.share-legend { display: flex; flex-direction: column; gap: 8px; }
.share-legend-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.share-legend-row strong { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; }
.share-dot { width: 8px; height: 8px; border-radius: 50%; }
.share-legend-row small { color: var(--muted); font-family: var(--sans); font-weight: 400; }
.trend-chart { width: 100%; height: 280px; display: block; }
.trend-chart .bar { fill: var(--viz-1); transition: fill .15s var(--ease); }
.trend-chart .bar:hover, .trend-chart .bar.focus { fill: var(--hm); }
.trend-chart .grid { stroke: var(--line); stroke-width: 1; }
.trend-chart text { font: 11px var(--mono); fill: var(--muted); }
.trend-tip { min-height: 40px; font-size: 13px; color: var(--text-2); margin-top: 8px; }
.trend-tip strong { color: var(--text); font-weight: 500; }

/* ---------- Toasts, dialogs ---------- */
.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 3000; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 16px; border-radius: var(--r-control); background: var(--text); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .16); font-size: 14px; animation: toast-in .3s var(--ease); }
.toast-success { background: #14532d; }
.toast-error { background: #7f1d1d; }
.toast-warning { background: #713f12; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; opacity: .8; padding: 0; display: inline-flex; }
.toast .toast-action { text-decoration: underline; font-weight: 500; opacity: 1; white-space: nowrap; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-backdrop-x { position: fixed; inset: 0; z-index: 4000; background: rgba(15, 15, 16, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--card); border-radius: var(--r-panel); padding: 24px; width: 100%; max-width: 420px; box-shadow: 0 8px 24px rgba(0, 0, 0, .16); }
.modal-card h3 { margin-bottom: 8px; font-size: 17px; font-weight: 500; }
.modal-card p { margin: 0 0 20px; color: var(--text-2); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.loading-line { color: var(--muted); padding: 12px 0; }

/* ---------- Login ----------
   Two panels on a warm ivory page: the full Akshari logo on the left, the sign-in form on the right.
   Stacks on phones with a smaller logo above the form. */
body.login-page {
    margin: 0; min-height: 100vh; min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    background: #f7f3ec;
    font-family: var(--sans); color: var(--text);
}
.login-shell {
    width: 100%; max-width: 880px;
    display: grid; grid-template-columns: 1fr 1fr;
    background: #fff; border: 1px solid rgba(143, 26, 32, .12); border-radius: 20px;
    box-shadow: 0 8px 24px rgba(60, 30, 10, .06);
    overflow: hidden;
}
.login-brand {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
    padding: 48px 40px; background: #fffdf9; border-right: 1px solid rgba(143, 26, 32, .1);
}
.login-logo { display: block; width: 100%; max-width: 300px; height: auto; }
.login-card { padding: 48px 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.login-title { color: var(--text); font-weight: 500; margin: 0 0 4px; font-size: 24px; }
.login-sub { color: var(--text-2); font-size: 14px; margin: 0 0 24px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }
.login-card input {
    width: 100%; height: 44px; margin-bottom: 16px; padding: 0 12px;
    font: 16px var(--sans); color: var(--text); background: #fff;
    border: 1px solid var(--line-strong); border-radius: var(--r-control); outline: none;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.login-card input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(143, 26, 32, .12); }
.login-card .btn-gold {
    width: 100%; height: 44px; margin-top: 8px; border: 0; border-radius: var(--r-control);
    font: 500 15px var(--sans); color: #fff; background: var(--gold); cursor: pointer;
    transition: background-color .15s var(--ease), transform .12s var(--ease);
}
.login-card .btn-gold:hover:not(:disabled) { background: var(--gold-hover); }
.login-card .btn-gold:active:not(:disabled) { transform: scale(.98); }
.login-card .btn-gold:disabled { opacity: .6; }
.login-card :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.login-msg { min-height: 20px; margin-bottom: 8px; font-size: 14px; color: var(--bad); }
.login-foot { margin-top: 24px; font-size: 12px; color: var(--muted); }
@media (max-width: 720px) {
    .login-shell { grid-template-columns: 1fr; max-width: 420px; }
    .login-brand { padding: 32px 24px 8px; border-right: 0; background: #fff; }
    .login-logo { max-width: 180px; }
    .login-card { padding: 16px 24px 32px; }
    .login-title { text-align: center; font-size: 22px; }
    .login-sub { text-align: center; }
    .login-foot { text-align: center; }
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1600px) {
    .invoice-layout { grid-template-columns: minmax(0, 1fr) 460px; }
}

/* Receipt goes under the form once the form column would get cramped */
@media (max-width: 1360px) {
    .invoice-layout { grid-template-columns: minmax(0, 1fr); }
    .preview-col { position: static; }
    .report-two-col { grid-template-columns: 1fr; }
}

/* Off-canvas sidebar */
@media (max-width: 900px) {
    .mobile-only { display: revert !important; }
    .sidebar {
        width: min(280px, 85vw);
        transform: translateX(-100%);
        transition: transform .3s var(--ease);
        box-shadow: 8px 0 24px rgba(0, 0, 0, .2);
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        overscroll-behavior: contain;
    }
    .sidebar.sidebar-open { transform: none; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; z-index: 999; background: rgba(15, 15, 16, .45); }
    .main { margin-left: 0; }
    .menu-toggle-btn { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
    .top-buttons [data-action="logout"] { display: none; } /* it's in the slide-out menu */
    .top-buttons:empty, .top-buttons:not(:has(.btn:not([data-action="logout"]))) { display: none; }
    .topbar { padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); flex-wrap: wrap; }
    .page-body { padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
}

/* Phone */
@media (max-width: 640px) {
    /* 16px inputs stop iOS from zooming in on focus */
    .app input, .app select, .app textarea { font-size: 16px; min-height: 44px; }
    .lbl-long { display: none; }
    .lbl-short { display: inline; }
    .topbar-title h1 { font-size: 17px; }
    .topbar-subtitle { display: none; }
    .top-buttons { width: 100%; justify-content: stretch; }
    .top-buttons .btn { flex: 1 1 0; min-width: 0; padding: 4px 8px; font-size: 13px; gap: 6px; }
    .top-buttons .save-btn { display: none; }
    .invoice-grid { grid-template-columns: 1fr 1fr; }
    .span-2 { grid-column: 1 / -1; }
    .section-card, .photo-card { padding: 16px; }
    .photo-grid, .id-proof-grid { grid-template-columns: 1fr; }
    .search-row { grid-template-columns: 1fr 1fr; }
    .search-row input { grid-column: 1 / -1; grid-row: 1; }

    /* Item rows become cards */
    .items-table thead { display: none; }
    .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100%; }
    .items-table tr { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--r-control); background: var(--bg); }
    .items-table td { padding: 0; border: 0; }
    .items-table td::before { content: attr(data-label); display: block; font: 500 12px var(--sans); color: var(--muted); margin-bottom: 4px; }
    .items-table .cell-sl { position: absolute; top: 12px; left: 12px; width: auto; text-align: left; font-size: 13px; }
    .items-table .cell-sl::before { content: "Item "; display: inline; font: 500 13px var(--sans); color: var(--muted); }
    .items-table .cell-name { grid-column: 1 / -1; margin-top: 20px; }
    .items-table .cell-amount { text-align: left; font-size: 16px; }
    .items-table .cell-action { position: absolute; top: 4px; right: 4px; width: auto; }
    .items-table .cell-action::before { display: none; }
    .add-item-btn { width: 100%; }

    .mobile-action-bar {
        display: flex; gap: 8px;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
        padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
        background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
    }
    .mobile-action-bar .btn { flex: 1; min-height: 48px; font-size: 16px; }
    .page-body.has-action-bar { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
    /* Hide the sticky bar while the on-screen keyboard is open so it doesn't cover the field */
    body.keyboard-open .mobile-action-bar { display: none; }

    .invoice-card { grid-template-columns: 1fr; padding: 16px; }
    .invoice-card .amount { text-align: left; }
    .history-buttons .btn { flex: 1 1 40%; }
    .report-fields label { flex: 1 1 40%; }
    .report-fields label input, .report-fields label select { min-width: 0; }
    .report-actions { width: 100%; margin-left: 0; }
    .report-actions .btn { flex: 1; }
    .report-hero { padding: 20px; }
    .report-hero-value { font-size: 32px; }
    .hbar-row { grid-template-columns: 80px 1fr auto; }
    .toast-stack { left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: none; }
    .modal-actions .btn { flex: 1; }
}

@media (max-width: 420px) {
    .invoice-grid { grid-template-columns: 1fr; }
    .receipt-bottom { flex-direction: column; }
    .receipt-payment, .receipt-amounts { width: 100%; border-left: 1px solid #000; }
    .receipt-amounts { border-top: 0; }
}

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

/* ---------- Print ---------- */
@media print {
    @page { margin: 10mm; }
    body.app { background: #fff; }
    .sidebar, .sidebar-backdrop, .topbar, .mobile-action-bar, .toast-stack, .no-print { display: none !important; }
    .main { margin: 0; }
    .page-body { padding: 0; }
    /* Invoice screen prints only the receipt */
    body.page-invoice .page-body > :not(.invoice-layout),
    body.page-invoice .form-col,
    body.page-invoice .preview-col > :not(.bill-preview) { display: none !important; }
    body.page-invoice .invoice-layout { display: block; }
    body.page-invoice .bill-paper { width: 100%; max-width: 190mm; border-width: 2px; box-shadow: none; }
    .report-heading { display: flex; justify-content: space-between; margin-bottom: 12px; }
    .report-section, .report-tile, .report-hero { break-inside: avoid; box-shadow: none; }
    .report-two-col { grid-template-columns: 1fr 1fr; }
}

/* ---------- Customer records (ornaments and proofs) ---------- */
.record-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.record-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.record-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.record-card-head h2 { font-size: 16px; }
.record-card-head .meta { font-size: 13px; color: var(--muted); }
.record-card-head .meta .num { color: var(--text); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 24px; }
.info-item-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.info-item-value { font-size: 15px; color: var(--text); word-break: break-word; }
.info-item-wide { grid-column: 1 / -1; }
.ornament-thumb { display: block; width: 48px; height: 48px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.doc-name { display: inline-flex; align-items: center; gap: 8px; }
.doc-name .i { color: var(--muted); }
.status-text { font-size: 13px; color: var(--muted); }
.status-text.ok { color: var(--ok); }
.row-actions { display: inline-flex; gap: 8px; justify-content: flex-end; }
.report-table .btn { font-family: var(--sans); }
.record-table td { vertical-align: middle; }
.record-table input[type="file"] { padding: 6px 8px; font-size: 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 640px) { .form-actions { flex-direction: column-reverse; } .form-actions .btn { width: 100%; } }
@media (max-width: 640px) {
    #ornamentRows .cell-name, #proofRows .cell-name { margin-top: 0; padding-right: 40px; }
    #proofRows td:nth-child(2) { grid-column: 1 / -1; }
}

/* ---------- Gold rates: reference cards and IBJA fill ---------- */
.ref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ref-grid .section-card { margin-bottom: 16px; }
.ref-rows { display: flex; flex-direction: column; }
.ref-row { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ref-row:last-child { border-bottom: 0; }
.ref-label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.ref-value { font-size: 15px; font-weight: 500; text-align: right; }
.ref-sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.fill-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; align-items: start; }
.fill-grid input { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.fill-action { padding-top: 20px; }
.fill-action .btn { width: 100%; }
.app input.is-filled { border-color: var(--hm-line); background: var(--hm-soft); }
@media (max-width: 760px) { .ref-grid { grid-template-columns: 1fr; } .ref-grid .section-card { margin-bottom: 0; } .ref-grid { margin-bottom: 16px; } .fill-action { padding-top: 0; } }
.thumb-row { display: inline-flex; flex-wrap: wrap; gap: 4px; max-width: 220px; }

/* ---------- Settings: staff logins ---------- */
.user-card .meta { font-size: 13px; font-weight: 400; color: var(--muted); }
.user-card.is-disabled { background: var(--raised); }
.user-card.is-disabled h2 { color: var(--text-2); }
.account-form select { margin-bottom: 12px; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pw-details { border-top: 1px solid var(--line); padding-top: 12px; }
.pw-details summary { cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-2); margin-bottom: 12px; list-style-position: inside; }
.pw-details:not([open]) summary { margin-bottom: 0; }
