/* =====================================================================
   Aparna Gold Buyers - billing app styles
   Layout: fixed dark sidebar + top bar on desktop; off-canvas sidebar,
   stacked item cards and a sticky Save bar on phones.
   ===================================================================== */
:root {
    --gold: #b8860b;
    --gold-strong: #8a6508;
    --gold-soft: #fbf5e3;
    --gold-line: #ecd99a;
    --ink: #1e293b;
    --ink-2: #475569;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #e2e8f0;
    --bg: #f5f6f8;
    --card: #ffffff;
    --side: #141414;
    --side-2: #262626;
    --accent: #2563eb;
    --ok: #15803d;
    --ok-bg: #ecfdf3;
    --warn: #b45309;
    --warn-bg: #fffbeb;
    --bad: #dc2626;
    --bad-bg: #fef2f2;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
    --viz-1: #b8860b;
    --viz-2: #2563eb;
    --viz-3: #0d9488;
    --viz-other: #94a3b8;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.app {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--ink);
    background: var(--bg);
}
.app h1, .app h2, .app h3, .app h4 { margin: 0; line-height: 1.25; color: var(--ink); }
.app h2 { font-size: 20px; }
.app h3 { font-size: 16px; }
.app a { color: var(--accent); }
.app button { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mobile-only { display: none !important; }

/* ---------- Form controls ---------- */
.app input, .app select, .app textarea {
    font: inherit;
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.app textarea { min-height: 70px; resize: vertical; }
.app input:focus, .app select:focus, .app textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184, 134, 11, .18); }
.app input[readonly], .app .input-readonly { background: #f8fafc; color: var(--ink-2); }
.app input.is-invalid { border-color: var(--bad); background: var(--bad-bg); }
.app label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-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: #f8fafc; color: var(--ink); opacity: 1; }
.field-hint { display: block; margin-top: 3px; font-size: 12px; color: var(--faint); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 14px;
    font-weight: 600; font-size: 14px; white-space: nowrap;
    border: 1px solid transparent; border-radius: 8px; cursor: pointer;
    text-decoration: none; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--gold-strong); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #0f172a; }
.btn-secondary { background: #fff; color: var(--ink); border-color: #cbd5e1; }
.btn-secondary:hover:not(:disabled) { background: #f1f5f9; }
.btn-blue { background: var(--accent); color: #fff; }
.btn-green { background: var(--ok); color: #fff; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger-ghost { background: #fff; color: var(--bad); border-color: #fecaca; }
.btn-danger-ghost:hover:not(:disabled) { background: var(--bad-bg); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.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: #fff;
    padding: 20px 0 16px;
}
.sidebar-header { padding: 0 20px 18px; border-bottom: 1px solid var(--side-2); margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.sidebar-header img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; background: #fff1; }
.sidebar-header strong { display: block; color: #e8c45c; font-size: 16px; letter-spacing: .3px; }
.sidebar-header span { display: block; color: var(--faint); font-size: 12px; }
.sidebar-menu { display: flex; flex-direction: column; gap: 4px; padding: 0 12px; flex: 1; overflow-y: auto; }
.menu-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    color: #e2e8f0; text-decoration: none; font-weight: 500;
    background: transparent; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.app .menu-btn { color: #e2e8f0; }
.menu-btn:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.menu-btn.active { background: linear-gradient(135deg, #d4af37, #b8860b); color: #111 !important; font-weight: 700; }
.menu-btn .icon { width: 22px; text-align: center; }
.sidebar-user { padding: 12px 20px 0; border-top: 1px solid var(--side-2); font-size: 12px; color: var(--faint); }
.sidebar-user strong { color: #e2e8f0; display: block; font-size: 13px; }
.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: 66px; padding: 10px 24px;
    background: #fff; border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title h1 { font-size: 19px; }
.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); border-radius: 8px; background: #fff; font-size: 20px; cursor: pointer; }
.top-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.mode-badge { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.mode-badge-edit { background: var(--warn-bg); color: var(--warn); }
.mode-badge-view { background: #eff6ff; color: var(--accent); }
.page-body { padding: 20px 24px 32px; flex: 1; }
.page-head { margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Cards, alerts ---------- */
.section-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.section-card > h2 { font-size: 16px; margin-bottom: 12px; color: var(--gold-strong); }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid transparent; font-size: 14px; }
.alert-error { background: var(--bad-bg); color: #991b1b; border-color: #fecaca; }
.alert-warn { background: var(--warn-bg); color: #92400e; border-color: #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-ok { background: var(--ok-bg); color: #166534; border-color: #bbf7d0; }
.banner-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.banner-actions { display: flex; gap: 8px; }
.empty-text { color: var(--muted); padding: 16px 0; }

/* ---------- Invoice entry ---------- */
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 20px; align-items: start; }
.preview-col { position: sticky; top: 86px; display: flex; flex-direction: column; gap: 16px; }
.invoice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.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(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.photo-card > h2 { font-size: 16px; color: var(--gold-strong); margin-bottom: 10px; }
.photo-summary { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.photo-summary-error { color: var(--bad); font-weight: 600; }
.photo-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.id-proof-section { margin-top: 14px; }
.id-proof-section h3 { font-size: 14px; margin-bottom: 4px; }
.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 #cbd5e1; border-radius: 10px; padding: 10px; background: #fcfcfd; min-width: 0; }
.photo-box h4 { font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.side-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: #e0e7ff; color: #3730a3; }
.side-badge-back { background: #fce7f3; color: #9d174d; }
.photo-empty { margin: 6px 0 10px; color: var(--faint); font-size: 13px; }
.photo-removed { color: var(--warn); }
.photo-note { font-size: 12px; color: var(--warn); margin: 0 0 6px; }
.preview-image { display: block; width: 100%; max-height: 180px; object-fit: contain; border-radius: 8px; background: #f1f5f9; }
.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: 8px; background: #f1f5f9; }
.photo-unavailable { display: flex; align-items: center; justify-content: center; text-align: center; font-size: 11px; color: var(--faint); padding: 6px; min-height: 80px; }
.photo-status { font-size: 11px; color: var(--muted); margin-top: 4px; }
.photo-slot-done .photo-status { color: var(--ok); }
.photo-slot-error .photo-status { color: var(--bad); }
.photo-progress { height: 4px; background: #e2e8f0; border-radius: 2px; overflow: hidden; margin-top: 3px; }
.photo-progress div { height: 100%; background: var(--accent); transition: width .2s; }
.photo-error { font-size: 11px; 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(15, 23, 42, .75); color: #fff; cursor: pointer; font-size: 12px; line-height: 24px; padding: 0; }
.photo-input-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.photo-btn { flex: 1 1 auto; min-height: 36px; padding: 6px 10px; font-size: 13px; font-weight: 600; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; cursor: pointer; color: var(--ink); }
.photo-btn:hover { background: #f8fafc; }
.camera-btn { border-color: #bfdbfe; color: #1d4ed8; background: #eff6ff; }
.remove-btn { color: var(--bad); border-color: #fecaca; }
.photo-retry-btn { align-self: flex-start; border: 1px solid #fecaca; background: #fff; color: var(--bad); border-radius: 6px; font-size: 11px; padding: 2px 8px; cursor: pointer; }

.table-scroll { 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: 600; text-transform: uppercase; letter-spacing: .3px; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.items-table td { padding: 6px 4px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.items-table .cell-sl { width: 28px; color: var(--muted); font-weight: 600; text-align: center; }
.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-weight: 600; white-space: nowrap; }
.items-table .cell-amount { font-weight: 700; white-space: nowrap; text-align: right; }
.items-table .cell-amount.no-rate { color: var(--bad); }
.items-table .cell-action { width: 44px; text-align: center; }
.delete-icon-btn { width: 36px; height: 36px; border: 0; background: none; color: var(--bad); cursor: pointer; border-radius: 8px; }
.delete-icon-btn:hover { background: var(--bad-bg); }
.add-item-btn { margin-top: 10px; }

.payment-grid, .amount-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

.side-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.side-card h3 { margin-bottom: 10px; font-size: 15px; }
.search-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 8px; }
.search-result { margin-top: 10px; padding: 10px; border: 1px solid var(--gold-line); background: var(--gold-soft); border-radius: 8px; font-size: 14px; }
.search-result p { margin: 2px 0; }
.search-msg { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

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

/* ---------- Receipt (preview, print, PDF) ---------- */
.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;
    -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: 6px; }
.receipt-title { text-align: center; color: #b00000; margin: 10px 0 4px; font-size: 18px; font-weight: 700; letter-spacing: .5px; }
.receipt-address { text-align: center; margin-bottom: 4px; font-size: 12px; }
.receipt-info { display: flex; justify-content: space-between; margin: 8px 0; gap: 6px; }
.receipt-info-start { justify-content: flex-start; }
.receipt-line { border-bottom: 1px dashed #000; padding: 5px 0; margin-bottom: 6px; 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-bottom { display: flex; margin-top: 10px; }
.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 5px; }
.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: 6px; }
.receipt-terms ol { margin: 2px 0 0 15px; padding: 0; }
.receipt-company { text-align: right; color: #b00000; margin-top: 10px; font-weight: 700; }
.receipt-signatures { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 30px; font-size: 11px; }
.receipt-signatures span { border-top: 1px solid #000; padding-top: 3px; min-width: 120px; text-align: center; }

/* ---------- Lists (history, customers) ---------- */
.list-container { max-width: 980px; }
.history-search { margin-bottom: 14px; min-height: 46px !important; font-size: 15px; }
.invoice-card {
    display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 16px; margin-bottom: 10px;
}
.invoice-card h3 { color: var(--gold-strong); font-size: 16px; }
.invoice-card p { margin: 2px 0; font-size: 14px; color: var(--ink-2); }
.invoice-card .meta { font-size: 13px; color: var(--muted); }
.invoice-card .amount { font-size: 20px; font-weight: 700; text-align: right; color: var(--ink); }
.invoice-card .amount small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.history-buttons { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.load-more { display: block; margin: 12px auto; }

/* ---------- Rates, settings ---------- */
.rates-form { max-width: 720px; }
.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.rate-group-title { font-size: 14px; margin: 6px 0 10px; color: var(--ink-2); }
.market-card { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.market-card .figures { display: flex; gap: 24px; flex-wrap: wrap; }
.market-card .figure strong { display: block; font-size: 20px; }
.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: 46px; }
.password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 34px; border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 13px; }
.user-meta { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }

/* ---------- Reports ---------- */
.report-filters { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.report-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.report-chip { min-height: 36px; padding: 6px 14px; border-radius: 999px; border: 1px solid #cbd5e1; background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.report-chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.report-fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.report-fields label { margin: 0; }
.report-fields label input, .report-fields label select { margin-top: 4px; min-width: 150px; }
.report-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.report-heading { display: none; }
.report-stale { opacity: .55; transition: opacity .2s; }
.report-hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; background: linear-gradient(135deg, #1f1f1f, #3a2f12); color: #fff; border-radius: 14px; padding: 20px 22px; margin-bottom: 16px; }
.report-hero-label { font-size: 13px; color: #e8c45c; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.report-hero-value { font-size: 34px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.report-hero-breakdown { font-size: 13px; color: #cbd5e1; margin-top: 6px; }
.report-hero-spark { flex: 0 1 260px; min-width: 160px; }
.report-hero-spark rect { fill: #e8c45c; }
.report-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.report-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.report-tile-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.report-tile-value { font-size: 22px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.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: 600; padding: 1px 8px; border-radius: 999px; }
.report-delta.is-up { background: var(--ok-bg); color: var(--ok); }
.report-delta.is-down { background: var(--bad-bg); color: var(--bad); }
.report-delta.is-flat { background: #f1f5f9; color: var(--muted); }
.report-hero .report-delta.is-flat { background: #ffffff1f; color: #e2e8f0; }
.report-delta-label { font-weight: 500; opacity: .85; }
.report-note { font-size: 13px; color: var(--warn); }
.report-section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; 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: 12px; }
.report-section-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.report-section-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.report-toggle { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
.report-toggle button { border: 0; background: #fff; padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.report-toggle button + button { border-left: 1px solid #cbd5e1; }
.report-toggle button.active { background: var(--ink); color: #fff; }
.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: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.report-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.report-empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.report-empty-icon { font-size: 36px; }
.viz-group-title { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 6px 0; }
.hbar-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.hbar-label { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--viz-1); border-radius: 6px; min-width: 2px; transition: width .4s; }
.hbar-value { text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hbar-value small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.share-bar { display: flex; height: 18px; border-radius: 9px; overflow: hidden; background: #f1f5f9; margin-bottom: 12px; }
.share-bar div { height: 100%; }
.share-legend { display: flex; flex-direction: column; gap: 8px; }
.share-legend-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.share-dot { width: 12px; height: 12px; border-radius: 3px; }
.share-legend-row small { color: var(--muted); }
.trend-chart { width: 100%; height: 240px; display: block; }
.trend-chart .bar { fill: var(--viz-1); }
.trend-chart .bar:hover, .trend-chart .bar.focus { fill: var(--gold-strong); }
.trend-chart .grid { stroke: #e2e8f0; stroke-width: 1; }
.trend-chart text { font-size: 11px; fill: var(--muted); }
.trend-tip { min-height: 40px; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.trend-tip strong { color: var(--ink); }

/* ---------- 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: 10px; align-items: flex-start; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: var(--ink); color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-size: 14px; animation: toast-in .2s ease-out; }
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }
.toast-warning { background: #92400e; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; opacity: .8; font-size: 14px; padding: 0 2px; }
.toast .toast-action { text-decoration: underline; font-weight: 600; 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, 23, 42, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal-card h3 { margin-bottom: 8px; font-size: 17px; }
.modal-card p { margin: 0 0 16px; color: var(--ink-2); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.loading-line { color: var(--muted); padding: 10px 0; }

/* ---------- Login ---------- */
body.login-page {
    margin: 0; min-height: 100vh; min-height: 100dvh;
    display: flex; align-items: center; justify-content: center; padding: 16px;
    background: radial-gradient(circle at top, #2c2c2c 0%, #121212 100%);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: #fff;
}
.login-card { width: 100%; max-width: 380px; background: #161616; border: 1px solid rgba(212, 175, 55, .4); border-radius: 16px; box-shadow: 0 0 25px rgba(191, 161, 74, .22); padding: 36px 28px; text-align: center; }
.login-logo { width: 88px; height: auto; margin-bottom: 14px; }
.login-title { color: #d4af37; font-weight: 600; margin: 0 0 4px; font-size: 1.5rem; letter-spacing: .5px; }
.login-sub { color: #94a3b8; font-size: 14px; margin: 0 0 22px; }
.login-card input { width: 100%; height: 46px; margin-bottom: 14px; padding: 0 12px; font-size: 16px; color: #fff; background: #1f1f1f; border: 1px solid #bfa14a; border-radius: 8px; outline: none; }
.login-card input:focus { border-color: #d4af37; box-shadow: 0 0 8px rgba(212, 175, 55, .6); }
.login-card .btn-gold { width: 100%; height: 46px; border: 0; border-radius: 8px; font-weight: 700; font-size: 16px; color: #000; background: linear-gradient(135deg, #d4af37, #b8860b); cursor: pointer; }
.login-card .btn-gold:disabled { opacity: .6; }
.login-msg { min-height: 20px; margin-bottom: 10px; font-size: 14px; color: #f87171; }
.login-foot { margin-top: 22px; font-size: 12px; color: #777; }

/* =====================================================================
   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 .25s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, .25);
        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(0, 0, 0, .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(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); flex-wrap: wrap; }
    .page-body { padding: 14px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left)); }
}

/* Phone */
@media (max-width: 640px) {
    body.app { font-size: 15px; }
    /* 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: 6px 8px; font-size: 13px; }
    .top-buttons .save-btn { display: none; }
    .invoice-grid { grid-template-columns: 1fr 1fr; }
    .span-2 { grid-column: 1 / -1; }
    .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 10px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fcfcfd; }
    .items-table td { padding: 0; border: 0; }
    .items-table td::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
    .items-table .cell-sl { position: absolute; top: 10px; left: 12px; width: auto; text-align: left; }
    .items-table .cell-sl::before { content: "Item "; display: inline; font-size: 13px; }
    .items-table .cell-sl { font-size: 13px; }
    .items-table .cell-name { grid-column: 1 / -1; margin-top: 18px; }
    .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: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(15, 23, 42, .08);
    }
    .mobile-action-bar .btn { flex: 1; min-height: 48px; font-size: 16px; }
    .page-body.has-action-bar { padding-bottom: calc(90px + 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; }
    .invoice-card .amount { text-align: left; }
    .history-buttons .btn { flex: 1 1 40%; }
    .report-fields label { flex: 1 1 45%; }
    .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-value { font-size: 28px; }
    .hbar-row { grid-template-columns: 80px 1fr auto; }
    .toast-stack { left: 12px; right: 12px; bottom: calc(80px + 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; }
    .report-heading { display: flex; justify-content: space-between; margin-bottom: 10px; }
    .report-section, .report-tile, .report-hero { break-inside: avoid; box-shadow: none; }
    .report-hero { background: #fff !important; color: #000; border: 1px solid #000; }
    .report-hero-label, .report-hero-breakdown { color: #000; }
    .report-two-col { grid-template-columns: 1fr 1fr; }
}
