:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #6b7785;
  --line: #dde3ea;
  --brand: #0f5c8c;
  --brand-ink: #ffffff;
  --ok: #1f7a4d;
  --warn: #b15b00;
  --bad: #b3261e;
  --wholesale: #0f5c8c;
  --retail: #e0822b;
  --radius: 10px;
  font-family: "Tahoma", "Sukhumvit Set", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; min-height: 1.2em; margin: 4px 0 8px; }
.msg { min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--bad); }

/* ----- start screen ----- */
.start { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.start-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(480px, 100%); box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.start-card h1 { margin: 0 0 4px; color: var(--brand); }
.start-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.alert { background: #fdecea; color: var(--bad); padding: 10px 12px; border-radius: 8px; margin: 12px 0; font-size: 14px; }

/* ----- buttons & inputs ----- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px; }
.btn:hover { border-color: #b8c3cf; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 5px 10px; }
input, select { font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus { outline: 2px solid #9cc7e6; border-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
label input, label select { color: var(--ink); }
.form h3, .panel h3 { margin: 0 0 12px; font-size: 16px; }
.form h2 { font-size: 18px; margin: 0 0 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { margin: 0; min-width: 160px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ----- app shell ----- */
.app { min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--brand); color: #fff; flex-wrap: wrap; gap: 8px; }
.topbar .muted { color: #cfe3f2; }
.brand { font-weight: 700; font-size: 18px; }
.status { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pill { background: rgba(255,255,255,.18); padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.tabs { display: flex; gap: 4px; padding: 8px 14px 0; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 0; z-index: 5; }
.tab { border: 0; background: none; padding: 10px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
main { padding: 18px 20px 40px; max-width: 1280px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.form { display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font: inherit; font-size: 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; }
.period { display: inline-flex; gap: 6px; align-items: center; }
.period-label { min-width: 170px; text-align: center; font-weight: 600; }
#histSearch { max-width: 280px; }

/* ----- dashboard cards ----- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card.good .v { color: var(--ok); }
.card.bad .v { color: var(--bad); }

/* ----- tables ----- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f7f9fb; color: var(--muted); font-weight: 600; font-size: 13px; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; background: #f7f9fb; }
tr.neg td.num { color: var(--bad); }
tr.pos td.num { color: var(--ok); }
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; color: #fff; }
.tag.w { background: var(--wholesale); }
.tag.r { background: var(--retail); }
.tag.rc { background: var(--ok); }
.tag.sl { background: #5d4ab3; }
.tag.ex { background: #7a5c3a; }
.price-form { width: auto; }
.price-form th, .price-form td { padding: 6px 8px; }
.price-form input { width: 150px; }
.tag.void { background: var(--bad); }
.del { color: var(--bad); background: none; border: 0; cursor: pointer; font: inherit; font-size: 13px; }
.bar { height: 10px; background: #e9eef3; border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.r > span { background: var(--retail); }

/* ----- chart (plain CSS, no library) ----- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 200px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1; min-width: 4px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart .stack { display: flex; flex-direction: column-reverse; width: 100%; }
.chart .seg-w { background: var(--wholesale); }
.chart .seg-r { background: var(--retail); }
.chart .lbl { font-size: 10px; color: var(--muted); text-align: center; margin-top: 4px; white-space: nowrap; overflow: hidden; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.stock-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.lot-list { font-size: 13px; color: var(--muted); margin-top: 8px; }

.dialog { position: fixed; inset: 0; background: rgba(15,30,45,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.dialog-box { background: #fff; border-radius: 12px; padding: 22px; width: min(440px, 100%); box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.dialog-box h3 { margin: 0 0 8px; }
.dialog-box p { color: var(--muted); white-space: pre-line; }
.dialog-box input { margin: 10px 0 4px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #22303e; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--bad); }

@media print {
  .tabs, .topbar, .toolbar, .dialog, .toast, button { display: none !important; }
  .page { display: block !important; }
  .panel { break-inside: avoid; box-shadow: none; }
}

/* ----- multi-fuel receipt ----- */
table.multi td { padding: 6px 6px; vertical-align: middle; }
table.multi input, table.multi select { padding: 6px 8px; font-size: 14px; }
table.multi td:nth-child(3) input { width: 130px; }
table.multi td:nth-child(4) input { width: 170px; }
table.multi td.m-sum { white-space: nowrap; min-width: 110px; }

/* ----- danger zone (reset) ----- */
.danger-zone { border-color: #e7a6a1; background: #fff8f7; }
.danger-zone h3 { color: var(--bad); }
.danger-zone ul { margin: 6px 0 10px 18px; padding: 0; color: var(--muted); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(1.05); }
.switch { margin-left: 4px; }
code { background: #eef2f6; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
