:root {
  color-scheme: light;
  --bg: #f4f6f2; --card: #fff; --line: #dfe4dc; --text: #171b17; --muted: #5a635b;
  --brand: #1b6b3a; --brand-dark: #14522c; --brand-soft: #e6f2ea;
  --bad: #b3261e; --bad-soft: #fde8e6; --warn: #7a4d00; --warn-soft: #fff1cf; --ok: #14522c;
  --series-1: #2a78d6;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 16px; margin-bottom: 12px; } h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
.muted, .sub { color: var(--muted); font-size: 13px; }
.sub { display: block; }
.bad-text { color: var(--bad); font-weight: 600; }
.center { min-height: 70vh; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.shell { min-height: 100vh; }
.side { display: none; }
.main { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) 0 12px; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--muted); text-decoration: none; }
.bottom a.active { color: var(--brand); font-weight: 600; }
.bottom a.nav-sale .ico { background: var(--brand); color: #fff; border-radius: 50%; padding: 5px; width: 34px; height: 34px; margin-top: -14px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; }
.brand img { border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 16px; }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  .side { display: block; background: var(--card); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
  .side nav a { display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin: 2px 8px; border-radius: 8px; color: var(--text); text-decoration: none; }
  .side nav a:hover { background: var(--bg); }
  .side nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
  .bottom { display: none; }
  .main { padding: 0 28px 40px; width: 100%; }
}
.sync { font-size: 12px; padding: 4px 10px; border-radius: 99px; white-space: nowrap; background: var(--brand-soft); color: var(--ok); }
.sync.ok::before { content: "✓ "; } .sync.warn { background: var(--warn-soft); color: var(--warn); } .sync.busy { background: #e7eefb; color: #1c4f96; }
.demo { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.cols { display: grid; gap: 14px; grid-template-columns: 1fr; }
.cols > .card { margin: 0 0 14px; min-width: 0; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.tiles.three .tile-value { font-size: 16px; }
.tile-sub { font-size: 12px; color: var(--muted); }
.tile.warn { border-left: 4px solid #d99a00; } .tile.bad { border-left: 4px solid var(--bad); }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); }
.note { background: var(--brand-soft); border-radius: 8px; padding: 8px 12px; margin-top: 8px; font-size: 14px; }
.pad { padding: 10px 12px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: #fafbf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; background: #fafbf9; }
tr.click { cursor: pointer; } tr.click:hover, tr.click:focus { background: var(--brand-soft); outline: none; }
@media (max-width: 640px) { .hide-sm { display: none; } th, td { padding: 9px 10px; } }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eceeeb; color: var(--text); white-space: nowrap; }
.badge.ok { background: var(--brand-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.bad { background: var(--bad-soft); color: var(--bad); }

/* forms */
.field { display: block; margin-bottom: 12px; min-width: 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
input, select { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid #b9c1b8; border-radius: 8px; background: #fff; color: var(--text); min-height: 44px; }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; align-items: center; }
.toolbar input[type=search] { flex: 1 1 220px; } .toolbar select, .toolbar input[type=month] { flex: 0 1 190px; width: auto; }
.inline { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; padding: 10px 16px; min-height: 44px; border-radius: 8px; border: 1px solid #b9c1b8; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-outline { color: var(--bad); border-color: var(--bad); margin-right: auto; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; } .btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 4px 0; color: var(--brand); font: inherit; text-decoration: underline; cursor: pointer; }
.icon-btn { background: none; border: 0; font-size: 18px; width: 40px; height: 40px; border-radius: 8px; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--bg); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.actions.left { justify-content: flex-start; margin: 4px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 12px; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-weight: 600; font-size: 14px; }
.errors div + div { margin-top: 4px; }
[hidden] { display: none !important; }

/* suggestions + sale */
.sugg { display: flex; flex-direction: column; }
.sugg button { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; text-align: left; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-top: 0; background: #fff; cursor: pointer; min-height: 44px; }
.sugg button:first-child { border-top: 1px solid var(--line); margin-top: 6px; border-radius: 8px 8px 0 0; } .sugg button:last-child { border-radius: 0 0 8px 8px; } .sugg button:only-child { border-radius: 8px; }
.sugg button:hover:not(:disabled) { background: var(--brand-soft); } .sugg button:disabled { opacity: .55; cursor: default; }
.sugg strong { flex: 1 1 100%; } .sugg span { color: var(--muted); font-size: 13px; }
.sale-rows { margin-top: 12px; }
.sale-row { display: grid; grid-template-columns: 1fr 90px 110px 40px; grid-template-areas: "name name name x" "qty qty rate rate" "amt amt amt amt"; gap: 4px 10px; align-items: end; padding: 12px 0; border-top: 1px solid var(--line); }
.sale-row .row-name { grid-area: name; align-self: center; min-width: 0; } .sale-row .row-name small { display: block; color: var(--muted); font-size: 12px; }
.sale-row .field { margin: 0; } .sale-row .field:nth-of-type(1) { grid-area: qty; } .sale-row .field:nth-of-type(2) { grid-area: rate; }
.sale-row .row-amt { grid-area: amt; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; } .sale-row .icon-btn { grid-area: x; }
@media (min-width: 700px) { .sale-row { grid-template-columns: 1fr 100px 130px 130px 40px; grid-template-areas: "name qty rate amt x"; } .sale-row .row-amt { padding-bottom: 11px; } }
.sum { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.sum.big { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }

/* modal, toast */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(20,30,22,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; border-radius: 16px 16px 0 0; }
.modal.wide { max-width: 760px; }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 8px 12px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; overflow-wrap: anywhere; }
.modal-body { padding: 16px 18px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; }
@media (min-width: 700px) { .backdrop { align-items: center; padding: 20px; } .modal { border-radius: 16px; } }
.more-list { display: grid; gap: 10px; } .more-list .btn { justify-content: flex-start; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 14px; } .facts dt { color: var(--muted); } .facts dd { margin: 0; font-weight: 600; }
#toasts { position: fixed; z-index: 40; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #1d2a21; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 520px; }
.toast.err { background: var(--bad); } .toast.warn { background: #7a4d00; }

/* login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; } .login .field { text-align: left; } .login img { border-radius: 14px; }
.login.card { margin-left: auto; margin-right: auto; width: calc(100% - 32px); }

/* receipt */
.receipt .r-head { text-align: center; margin-bottom: 10px; } .receipt .r-head strong { font-size: 18px; }
.receipt .r-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 14px; margin-bottom: 10px; }
.receipt table { margin-bottom: 8px; } .receipt th, .receipt td { padding: 6px 4px; }

/* chart */
.chart { position: relative; padding-top: 20px; }
.chart-max { position: absolute; top: 0; left: 0; right: 0; font-size: 11px; color: var(--muted); border-bottom: 1px dashed var(--line); padding-bottom: 2px; }
.chart-plot { display: flex; align-items: stretch; gap: 2px; height: 170px; border-bottom: 1px solid #aab3a9; margin-bottom: 20px; }
.chart-col { flex: 1; min-width: 0; position: relative; display: flex; align-items: flex-end; justify-content: center; cursor: default; outline: none; }
.chart-bar { width: 100%; max-width: 44px; background: var(--series-1); border-radius: 4px 4px 0 0; }
.chart-col:hover .chart-bar, .chart-col:focus .chart-bar { filter: brightness(.82); }
.chart-x { position: absolute; top: 100%; margin-top: 4px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart-tip { position: absolute; top: 22px; transform: translateX(-50%); background: #1d2a21; color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 12px; display: flex; flex-direction: column; white-space: nowrap; pointer-events: none; z-index: 2; }

@media print {
  body { background: #fff; }
  .no-print, #toasts, .bottom, .side, .toolbar { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card, .tile { break-inside: avoid; }
  body:has(.backdrop.printing) #app, .backdrop:not(.printing) { display: none !important; }
  .backdrop.printing { position: static; background: none; display: block; padding: 0; }
  .backdrop.printing .modal { max-width: none; max-height: none; border-radius: 0; display: block; }
  .backdrop.printing .modal-body { overflow: visible; padding: 0; }
  .backdrop.printing header { border: 0; padding: 0 0 8px; }
  .hide-sm { display: table-cell !important; }
}

.nowrap { white-space: nowrap; }
@media (max-width: 640px) { .modal table { font-size: 13px; } .modal th, .modal td { padding: 8px 6px; } }

/* clickable tiles */
button.tile { font: inherit; color: inherit; text-align: left; cursor: pointer; display: block; width: 100%; }
button.tile:hover, button.tile:focus-visible { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); outline: none; }
.tile-label { display: flex; justify-content: space-between; gap: 6px; }
.tile-go { color: var(--brand); font-size: 16px; line-height: 1; font-weight: 700; }
@media (min-width: 1150px) { .tiles.four { grid-template-columns: repeat(4, 1fr); } }
.ret-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.ret-row small { display: block; color: var(--muted); font-size: 12px; }
.internal { margin-top: 14px; padding: 10px 12px; border: 1px dashed #b9c1b8; border-radius: 8px; font-size: 13px; background: #fafbf9; }
.internal-title { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.btn.danger-outline { margin-right: 0; }
