:root {
  --bg: #f4f8f7;
  --card: #ffffff;
  --ink: #15292a;
  --muted: #57696a;
  --line: #dde7e5;
  --navy: #0f3b3a;
  --teal: #0e8a7a;
  --mint: #bff0e6;
  --amber: #f4b44a;
  --accent: #0f3b3a;
  --accent-ink: #ffffff;
  --rev: #9fd9cf;
  --profit: #0e8a7a;
  --good: #1a7f52;
  --bad: #c0392b;
  --bad-bg: #fdecea;
  --warn: #9a5a00;
  --warn-bg: #fff3dd;
  --field: #ffffff;
  --shadow: 0 1px 2px rgba(21, 41, 42, .05), 0 6px 18px rgba(21, 41, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a1a;
    --card: #142626;
    --ink: #e9f3f1;
    --muted: #9fb5b2;
    --line: #26403f;
    --teal: #4fd1bd;
    --accent: #f4b44a;
    --accent-ink: #0d1a1a;
    --rev: #2f5e58;
    --profit: #4fd1bd;
    --good: #5ccf98;
    --bad: #ff8a7a;
    --bad-bg: #3a1f22;
    --warn: #f4c46e;
    --warn-bg: #33291a;
    --field: #0f1f1f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
.wrap { max-width: 1140px; margin-inline: auto; padding-inline: 16px; }
a { color: var(--teal); }
h2 { font-size: 1.35rem; margin: 8px 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.hero { background: var(--navy); color: #fff; margin-bottom: 18px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 16px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 12px; flex: none; }
h1 { font-size: 1.3rem; margin: 0; line-height: 1.2; }
.brand p { margin: 0; color: var(--mint); font-size: .9rem; }
.badge { background: var(--amber); color: #14201f; font-weight: 700; font-size: .8rem; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: #d3e6e3; text-decoration: none; padding: 10px 12px; border-radius: 10px 10px 0 0;
  white-space: nowrap; font-weight: 600; font-size: .93rem;
}
.tabs a:hover { background: rgba(255, 255, 255, .08); }
.tabs a[aria-current="page"] { background: var(--bg); color: var(--ink); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--amber); color: #14201f; font-size: .75rem; text-align: center; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 760px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two, .three { grid-template-columns: 1fr; }
}
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi span { display: block; color: var(--muted); font-size: .85rem; }
.kpi strong { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.kpi small { color: var(--muted); }
.kpi.warn strong { color: var(--warn); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.head { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.head h2 { margin: 0; }

/* Buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .95rem; font-family: inherit;
  text-decoration: none; border: 1px solid var(--line); color: var(--ink); background: var(--card); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--bad); background: var(--bad-bg); }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tabs a:focus-visible, .chip:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
input[aria-invalid="true"] { border-color: var(--bad); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters label { margin: 0; flex: 1 1 160px; }
.filters .check { flex: 0 0 auto; padding-bottom: 10px; }

/* Messages */
.msg { border-radius: 10px; padding: 10px 14px; margin: 0 0 14px; }
.msg.error { background: var(--bad-bg); color: var(--bad); }
.msg.warn { background: var(--warn-bg); }
.msg.info { background: var(--card); border: 1px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  max-width: calc(100% - 32px);
}

/* Tables */
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: rgba(14, 138, 122, .06); }
td a.name { color: var(--ink); font-weight: 600; text-decoration: none; }
td a.name:hover { text-decoration: underline; }
td .sub { display: block; color: var(--muted); font-size: .8rem; }
.neg { color: var(--bad); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--line); white-space: nowrap; }
.pill.low { background: var(--warn-bg); color: var(--warn); }
.pill.out { background: var(--bad-bg); color: var(--bad); }
.pill.in { background: rgba(26, 127, 82, .14); color: var(--good); }
.pill.sale { background: rgba(14, 138, 122, .14); color: var(--teal); }
@media (max-width: 640px) { .hide-sm { display: none; } }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .btn { margin-top: 10px; }

/* Period chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 13px; font: inherit; font-size: .88rem; cursor: pointer; }
.chip:hover { border-color: var(--teal); }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Bar chart */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 170px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; position: relative; }
.chart .rev { width: 100%; background: var(--rev); border-radius: 4px 4px 0 0; position: relative; min-height: 1px; }
.chart .pro { position: absolute; left: 22%; right: 22%; bottom: 0; background: var(--profit); border-radius: 3px 3px 0 0; }
.chart .col:hover .rev { outline: 2px solid var(--teal); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.list .sub { display: block; }

/* Sale / purchase form lines */
.lines { display: grid; gap: 10px; margin-bottom: 12px; }
.line { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 1.3fr) minmax(0, 1.6fr) minmax(0, 1.5fr) 36px; gap: 8px; align-items: end; }
.line label { margin: 0; }
.line .total { padding: 10px 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.line .icon-btn { margin-bottom: 6px; }
@media (max-width: 640px) {
  .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .line .pick { grid-column: 1 / -1; }
  .line .total { grid-column: 1 / 3; text-align: left; padding: 0; }
  .line .icon-btn { grid-column: 3; grid-row: 2; }
}
.summary { display: flex; gap: 18px; flex-wrap: wrap; justify-content: flex-end; font-variant-numeric: tabular-nums; margin: 6px 0 14px; }
.summary b { font-size: 1.1rem; }

/* Locked (Pro) preview */
.locked { position: relative; }
.locked .blur { filter: blur(4px); pointer-events: none; user-select: none; opacity: .6; }
.locked .over { position: absolute; inset: 0; display: grid; place-items: start center; padding: 40px 16px 16px; }
.locked .over .card { max-width: 440px; text-align: center; }

/* Welcome */
.welcome { max-width: 680px; margin: 10px auto 30px; }
.welcome ul { padding-left: 20px; }
.welcome li { margin-bottom: 6px; }
.loading { color: var(--muted); padding: 30px 0; text-align: center; }
.foot { color: var(--muted); font-size: .85rem; padding-top: 10px; padding-bottom: 30px; }
.tabs a.locked-tab::after { content: " 🔒"; font-size: .8em; }
code { background: var(--line); border-radius: 5px; padding: 1px 5px; font-size: .9em; }
details summary { cursor: pointer; font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 6px; text-decoration: none; font-size: .9rem; }
@media (prefers-color-scheme: dark) {
  .chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #0d1a1a; }
  .toast { background: #26403f; }
}
