:root {
    --ink: #1c1d1f;
    --ink-2: #55585e;
    --muted: #8a8d93;
    --line: #e4e2dd;
    --bg: #f6f5f2;
    --card: #ffffff;
    --accent: #1c1d1f;
    --brass: #a8854a;
    --ok: #2f7d4f;
    --ok-bg: #e7f3ec;
    --warn: #9a6a12;
    --warn-bg: #fbf1dc;
    --bad: #b23b2e;
    --bad-bg: #fbe9e6;
    --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; text-decoration-color: var(--brass); text-underline-offset: 3px; }
h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 22px 0 10px; }
h2:first-child { margin-top: 0; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* Top bar */
.topbar { position: relative;
    display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
    background: var(--ink); color: #fff; padding: 0 24px; min-height: 56px;
}
.topbar .brand { font-weight: 600; letter-spacing: .02em; text-decoration: none; color: #fff; }
.topbar .brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-logo { height: 13px; width: auto; display: block; }
.brand-tag { font-size: 10px; font-weight: 600; letter-spacing: .14em; color: var(--brass); border: 1px solid rgba(168,133,74,.55); border-radius: 3px; padding: 1px 5px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #c9cacd; text-decoration: none; padding: 16px 10px; border-bottom: 2px solid transparent; }
.topbar nav a:hover { color: #fff; }
.topbar nav a.active { color: #fff; border-bottom-color: var(--brass); }
.topbar .who { color: #c9cacd; font-size: 13px; }
.topbar .who a { color: #fff; }
.dot { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 600; }
.banner { background: var(--warn-bg); color: var(--warn); padding: 8px 24px; font-size: 14px; border-bottom: 1px solid #f0dfb8; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

/* Page head */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.crumbs { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.bigstock { text-align: center; }
.bigstock .stock { font-size: 28px; padding: 6px 16px; }
.bigstock small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Buttons & forms */
.btn {
    display: inline-block; background: var(--accent); color: #fff; border: 1px solid var(--accent);
    border-radius: 6px; padding: 9px 16px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #000; }
.btn.ghost { background: transparent; color: var(--ink); border-color: #cfccc5; }
.btn.ghost:hover { border-color: var(--ink); background: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
input, select {
    font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfccc5; border-radius: 6px;
    padding: 8px 10px; min-width: 0; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--brass); outline-offset: -1px; border-color: var(--brass); }
label { display: block; font-size: 13px; color: var(--ink-2); }
label input, label select { margin-top: 4px; }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0; }
form.inline input, form.inline select { width: auto; flex: 1 1 120px; }
form.inline .btn { flex: 0 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.form-grid.compact { gap: 10px; }
.form-grid .span { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.stack p { margin: 0 0 10px; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid2 > .card { margin-bottom: 20px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; gap: 0; } }

/* Stats */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stats > * { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; font-size: 13px; color: var(--ink-2); text-decoration: none; min-width: 120px; }
.stats span { display: block; font-size: 22px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.stats .warn span { color: var(--warn); }
.stats .bad span { color: var(--bad); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 260px; width: auto; }
.toolbar select, .toolbar input[type=date] { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border: 0; }
table { border-collapse: collapse; width: 100%; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px 12px; border-bottom: 1px solid #efede9; vertical-align: middle; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr[onclick] { cursor: pointer; }
table.list tbody tr:hover td { background: #faf9f7; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
tr.dim td { opacity: .5; }

.stock { display: inline-block; min-width: 36px; text-align: center; border-radius: 6px; padding: 2px 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stock.ok { background: var(--ok-bg); color: var(--ok); }
.stock.low { background: var(--warn-bg); color: var(--warn); }
.stock.out { background: var(--bad-bg); color: var(--bad); }
.tag { display: inline-block; font-size: 12px; border-radius: 4px; padding: 1px 7px; white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.muted { background: #efede9; color: var(--ink-2); }
.mv { font-size: 13px; white-space: nowrap; }
.mv::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.mv-sale::before, .mv-purchase_void::before { background: var(--bad); }
.mv-receive::before, .mv-return::before, .mv-sale_void::before, .mv-opening::before { background: var(--ok); }
.mv-adjust::before, .mv-count::before { background: var(--brass); }

/* Sale / receive lines */
table.lines { margin: 16px 0 8px; }
table.lines th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 6px 6px; }
table.lines td { padding: 4px 6px; }
table.lines .qty { width: 90px; }
table.lines .x { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }
table.lines .x:hover { color: var(--bad); }

/* Flash & misc */
.flash { border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.flash.success { background: var(--ok-bg); color: var(--ok); border-color: #c6e3d1; }
.flash.warning { background: var(--warn-bg); color: var(--warn); border-color: #f0dfb8; }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: #f1cbc5; }
.empty { background: var(--card); border: 1px dashed #cfccc5; border-radius: var(--radius); padding: 40px; text-align: center; color: var(--ink-2); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

.checklist { padding-left: 0; list-style: none; margin: 0; counter-reset: step; }
.checklist li { position: relative; padding: 0 0 12px 34px; counter-increment: step; }
.checklist li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 600; display: grid; place-items: center; background: #efede9; color: var(--ink-2); }
.checklist li.done::before { content: "✓"; background: var(--ok); color: #fff; }
.checklist li.todo::before { background: var(--warn-bg); color: var(--warn); }
.checklist .muted { display: block; font-size: 13px; }
.checklist code.copy { display: block; margin-top: 4px; background: var(--bg); padding: 6px 8px; border-radius: 4px; word-break: break-all; user-select: all; }

.log { list-style: none; padding: 0; margin: 0; font-size: 13px; max-height: 420px; overflow-y: auto; }
.log li { padding: 6px 0; border-bottom: 1px solid #efede9; }
.log .lv-error { color: var(--bad); }
.log .lv-warning { color: var(--warn); }

/* Auth pages */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-box { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 32px; width: 100%; max-width: 380px; }
.auth-box h1 { margin-bottom: 20px; }
.auth-logo { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.auth-logo img { width: 220px; height: auto; }
.auth-logo span { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--brass); }
.auth-box label { margin-bottom: 14px; }
.auth-box .btn { width: 100%; }

@media (max-width: 640px) {
    .wrap { padding: 16px; }
    .topbar { display: block; padding: 12px 16px 0; }
    .topbar .brand { display: flex; margin: 4px 0 6px; }
    .topbar nav { display: flex; flex-wrap: nowrap; overflow-x: auto; margin: 0 -8px; }
    .topbar nav a { padding: 10px 8px; white-space: nowrap; }
    .topbar .who { position: absolute; right: 16px; top: 12px; }
    .card { padding: 16px; }
}

.archive { margin-top: 18px; padding-top: 14px; border-top: 1px solid #efede9; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- Sales, purchases, dashboard ---- */
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 13px; }
.chip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
label.wide { grid-column: span 2; }
@media (max-width: 640px) { label.wide { grid-column: auto; } }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); }
label.check input { width: auto; margin: 0; }
table.lines .price { width: 130px; }
table.lines .total { width: 110px; font-variant-numeric: tabular-nums; }
table.lines tfoot td { padding-top: 12px; border-top: 1px solid var(--line); }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 1em; }
.hint.bad { color: var(--bad); }

.period { align-items: center; }
.seg { display: inline-flex; border: 1px solid #cfccc5; border-radius: 6px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.seg a { padding: 8px 12px; text-decoration: none; font-size: 14px; color: var(--ink-2); border-right: 1px solid #efede9; }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--ink); color: #fff; }
.kpis > * { flex: 1 1 140px; }
.h2-sub { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; margin-left: 6px; }

.hbars { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.hbar { display: grid; grid-template-columns: 90px 1fr 120px; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); border-radius: 4px; }
.hbar-label { font-size: 14px; }
.hbar-track { height: 18px; }
.hbar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 0; }
.hbar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; white-space: nowrap; }
.hbar-val small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.hbar.hover .hbar-label { text-decoration: underline; text-decoration-color: var(--brass); }
.cat-table { margin-top: 4px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart .grid { stroke: #efede9; stroke-width: 1; }
svg.chart .axis { stroke: #cfccc5; stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 11px; }
svg.chart .val { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
svg.chart .hit { fill: transparent; }
svg.chart .col.hover .hit { fill: rgba(28,29,31,.04); }
details summary { cursor: pointer; color: var(--ink-2); margin-top: 10px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.5;
       padding: 8px 10px; border-radius: 6px; white-space: pre-line; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 260px; }


table.list th.num, table.lines th.num { text-align: right; }
.grid2 > * { min-width: 0; }
.card > table.list { display: block; overflow-x: auto; }
@media (max-width: 640px) { .hbar { grid-template-columns: 76px 1fr auto; gap: 8px; } .doc-head dl { width: 100%; } }

/* ---- Printable invoice sheet (A4) ---- */
.sheet { position: relative; background: #fff; max-width: 820px; margin: 0 auto 24px; padding: 56px 60px 48px;
         border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
         color: #111; font-size: 13.5px; line-height: 1.5; overflow: hidden; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 32px; padding-bottom: 28px; border-bottom: 1px solid #111; }
.sheet-logo { width: 210px; height: auto; display: block; margin: 6px 0 18px; }
.sheet-from p { margin: 0; color: #55585e; font-size: 12px; line-height: 1.6; }
.sheet-title { text-align: right; }
.sheet-title h2 { font-size: 26px; font-weight: 300; letter-spacing: .28em; text-transform: uppercase; color: #111; margin: 0 -0.28em 14px 0; }
.sheet-title dl { display: grid; grid-template-columns: auto auto; gap: 3px 14px; margin: 0; font-size: 12.5px; justify-content: end; }
.sheet-title dt { color: #8a8d93; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; padding-top: 1px; }
.sheet-title dd { margin: 0; font-variant-numeric: tabular-nums; }
.sheet-party { padding: 22px 0 26px; }
.sheet-party .label, .sheet-lines th { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: #8a8d93; font-weight: 600; }
.sheet-party strong { font-size: 17px; font-weight: 600; display: block; margin-top: 4px; }
.sheet-lines { width: 100%; border-collapse: collapse; }
.sheet-lines th { display: table-cell; text-align: left; padding: 0 8px 10px; border-bottom: 1px solid #d9d6cf; }
.sheet-lines th.num { text-align: right; }
.sheet-lines td { padding: 12px 8px; border-bottom: 1px solid #efede9; vertical-align: top; }
.sheet-lines td small { display: block; color: #8a8d93; font-size: 11.5px; margin-top: 1px; }
.sheet-lines .n { width: 28px; color: #8a8d93; padding-left: 0; }
.sheet-lines .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet-lines td:last-child, .sheet-lines th:last-child { padding-right: 0; }
.sheet-totals { margin: 18px 0 0 auto; width: 280px; }
.sheet-totals > div { display: flex; justify-content: space-between; padding: 5px 0; color: #55585e; font-variant-numeric: tabular-nums; }
.sheet-totals .grand { border-top: 1px solid #111; margin-top: 6px; padding-top: 12px; color: #111; font-size: 17px; font-weight: 600; }
.sheet-note { margin: 28px 0 0; padding: 12px 14px; background: #f6f5f2; border-radius: 4px; font-size: 12.5px; }
.sheet-foot { margin-top: 44px; }
.sheet-foot .terms { font-size: 11.5px; color: #55585e; margin: 0 0 40px; max-width: 520px; }
.signs { display: flex; gap: 48px; }
.signs > div { flex: 1; font-size: 11px; color: #8a8d93; text-transform: uppercase; letter-spacing: .08em; }
.signs span { display: block; border-bottom: 1px solid #b9b6ae; height: 44px; margin-bottom: 8px; }
.thanks { text-align: center; margin: 40px 0 0; font-size: 12px; letter-spacing: .06em; color: #8a8d93; }
.void-stamp { position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); font-size: 120px; font-weight: 700;
              letter-spacing: .1em; color: rgba(178,59,46,.13); border: 8px solid rgba(178,59,46,.13); padding: 0 28px; pointer-events: none; }
.internal { max-width: 820px; margin: 0 auto 20px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
@media (max-width: 640px) {
    .sheet { padding: 28px 20px; }
    .sheet-head { flex-direction: column; gap: 16px; }
    .sheet-title { text-align: left; }
    .sheet-title dl { justify-content: start; }
    .sheet-totals { width: 100%; }
    .sheet-lines .n { display: none; }
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv dd { margin-bottom: 8px; }
}

@page { size: A4; margin: 14mm 14mm 16mm; }
@media print {
    .topbar, .foot, .noprint, .flash, .crumbs { display: none !important; }
    body { background: #fff; }
    .wrap { padding: 0; max-width: none; }
    .sheet { border: 0; box-shadow: none; padding: 0; max-width: none; margin: 0; font-size: 12.5px; }
    .sheet-lines tr { break-inside: avoid; }
    .sheet-foot { break-inside: avoid; }
    a { text-decoration: none; color: inherit; }
}

/* Setup page */
.auth-box.wide { max-width: 720px; }
.setup fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px 18px; margin: 0 0 18px; }
.setup legend { font-weight: 600; padding: 0 6px; font-size: 14px; }
.setup legend small { font-weight: 400; }
label.choice { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: 14px; margin-bottom: 12px; cursor: pointer; }
label.choice input { width: auto; margin: 3px 0 0; }
.mysql-fields { margin-top: 6px; }
textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfccc5; border-radius: 6px; padding: 8px 10px; width: 100%; margin-top: 4px; resize: vertical; }
.ok-t { color: var(--ok); margin-right: 10px; white-space: nowrap; }
.bad-t { color: var(--bad); margin-right: 10px; white-space: nowrap; }
