/* Layout idea: one column that grows to a centered 720px sheet on tablets; thumb-reach bottom navigation. */
:root {
  --bg: #f2f5f7;
  --surface: #ffffff;
  --ink: #14202b;
  --muted: #5a6876;
  --line: #dbe2e8;
  --accent: #0c6a5e;
  --accent-ink: #ffffff;
  --accent-soft: #ddf0ec;
  --good: #146c43;
  --good-soft: #dcf2e6;
  --warn: #9a5400;
  --warn-soft: #fcefd7;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1419;
    --surface: #151f27;
    --ink: #e6edf2;
    --muted: #9aa9b6;
    --line: #25333d;
    --accent: #3fb8a1;
    --accent-ink: #04201a;
    --accent-soft: #173a35;
    --good: #5fd39a;
    --good-soft: #14352a;
    --warn: #f0b35a;
    --warn-soft: #3b2c12;
    --bad: #ff8a80;
    --bad-soft: #3c1b19;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .name { font-weight: 700; letter-spacing: 0.01em; }
.page { width: 100%; max-width: 720px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .inner { display: flex; width: 100%; max-width: 720px; }
.nav-btn {
  flex: 1; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 0.78rem; font-weight: 600;
}
.nav-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn[aria-current="page"] { color: var(--accent); }

/* ---------- pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--bg); }
.lang button { min-width: 44px; min-height: 36px; border: 0; background: none; font-weight: 700; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.btn {
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.55; cursor: default; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field .hint { font-size: 0.82rem; color: var(--muted); }
input, select {
  width: 100%; min-height: 48px; padding: 0 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
input:focus, select:focus { border-color: var(--accent); }
.form-error { color: var(--bad); font-size: 0.9rem; min-height: 1.2em; }
.form { display: flex; flex-direction: column; gap: 14px; }

.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.pill.trial { background: var(--accent-soft); color: var(--accent); }
.pill.paid, .pill.admin { background: var(--good-soft); color: var(--good); }
.pill.expired { background: var(--warn-soft); color: var(--warn); }
.pill.suspended { background: var(--bad-soft); color: var(--bad); }

.status .big { font-size: 2.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.status.trial { border-color: var(--accent); }
.status.expired { border-color: var(--warn); background: var(--warn-soft); }
.status.suspended { border-color: var(--bad); background: var(--bad-soft); }
.progress { height: 8px; border-radius: 99px; background: var(--accent-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.roadmap { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.roadmap li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.roadmap li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }

.banner { padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 0.92rem; }

/* ---------- auth ---------- */
.auth { width: 100%; max-width: 440px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 32px; display: flex; flex-direction: column; gap: 18px; }
.auth-top { display: flex; justify-content: flex-end; }
.brand { display: flex; flex-direction: column; gap: 6px; }
.brand p { color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.tab { min-height: 42px; border: 0; border-radius: 9px; background: none; font-weight: 700; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.trial-note { padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 0.92rem; }

/* ---------- admin ---------- */
.users { display: flex; flex-direction: column; gap: 12px; }
.user { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); }
.user-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.user-head .who { min-width: 0; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.meta dt { font-size: 0.78rem; color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.date-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-row input { width: auto; flex: 1; min-width: 150px; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 0.92rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

.status-line { font-size: 0.9rem; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.status-line::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; transform: translateY(-1px); }
.status-line.paid::before, .status-line.admin::before { background: var(--good); }
.status-line.expired { color: var(--warn); }
.status-line.expired::before { background: var(--warn); }
.status-line.suspended { color: var(--bad); }
.status-line.suspended::before { background: var(--bad); }

/* ---------- catalog ---------- */
.tabs.three { grid-template-columns: repeat(3, 1fr); }
.toolbar { display: flex; gap: 8px; }
.toolbar input { flex: 1; min-width: 0; }
.toolbar .btn { flex: none; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.item-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.item-form { width: 100%; }
.row-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.row-form .form-error { grid-column: 1 / -1; min-height: 0; }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.pill.plain { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.hint-line { flex-basis: 100%; }

/* ---------- navigation: bottom bar on phones, side menu on tablets ---------- */
.shell.wide { flex-direction: row; }
.shell.wide .main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.shell.wide .page { padding-bottom: 32px; }
.side-nav {
  width: 232px; flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: calc(16px + env(safe-area-inset-top)) 12px 16px; display: flex; flex-direction: column; gap: 4px;
}
.side-nav .brand-name { font-weight: 800; padding: 6px 10px 14px; }
.side-nav .side-sep { height: 1px; background: var(--line); margin: 8px 0; }
.side-btn {
  display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border: 0; border-radius: 10px;
  background: none; cursor: pointer; font-weight: 600; color: var(--muted); text-align: left;
}
.side-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-btn[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.more-list { display: flex; flex-direction: column; gap: 10px; }
.more-item { display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 600; cursor: pointer; width: 100%; text-align: left; }
.more-item svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- purchases and suppliers ---------- */
.btn.block { width: 100%; }
.item.clickable { cursor: pointer; }
.item .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.good { background: var(--good-soft); color: var(--good); }
.line-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.line-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.sum-row strong { font-variant-numeric: tabular-nums; }
.sum-row.big strong { font-size: 1.4rem; }
.pay-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.debt-warn { color: var(--warn); font-weight: 700; }
.back-link { align-self: flex-start; min-height: 40px; padding: 0 4px; border: 0; background: none; color: var(--accent); font-weight: 700; cursor: pointer; }
.line-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.line-row:first-child { border-top: 0; }
.line-row .nums { text-align: right; font-variant-numeric: tabular-nums; }
.stock-batch { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); font-size: 0.9rem; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-grid .num-big { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tabs.four { grid-template-columns: repeat(4, 1fr); }
.tabs.four .tab { font-size: 0.82rem; padding: 0 2px; }

.profit-good { color: var(--good, #0b7a53); }

/* ---- printable documents (invoices, statements) ---- */
#print-area { display: none; }
.doc { font-family: system-ui, sans-serif; color: #111; background: #fff; max-width: 720px; margin: 0 auto; padding: 24px; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 2px solid #111; padding-bottom: 10px; }
.doc-head h1 { font-size: 1.4rem; margin: 0 0 4px; }
.doc-head p { margin: 0; color: #444; }
.doc-from { font-weight: 700; font-size: 1.1rem; }
.doc-party { margin: 14px 0; font-size: 1.05rem; }
.doc table { width: 100%; border-collapse: collapse; }
.doc th, .doc td { padding: 8px 6px; border-bottom: 1px solid #ccc; text-align: left; }
.doc .r { text-align: right; white-space: nowrap; }
.doc-sum { margin: 16px 0 0 auto; width: min(100%, 300px); }
.doc-sum > div { display: flex; justify-content: space-between; padding: 5px 0; }
.doc-sum .due { border-top: 2px solid #111; font-size: 1.1rem; margin-top: 4px; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; }
  body.printing { background: #fff !important; }
  .doc { padding: 0; }
}

/* on-screen document viewer */
.doc-view { position: fixed; inset: 0; z-index: 200; background: #e4e8ec; overflow: auto; }
.doc-bar { position: sticky; top: 0; display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface, #fff); border-bottom: 1px solid #cfd6dc; z-index: 1; }
.doc-bar .grow { flex: 1; }
.doc-paper { background: #fff; margin: 12px auto; max-width: 760px; box-shadow: 0 1px 6px rgba(0,0,0,.15); min-height: 60vh; }
body.doc-open { overflow: hidden; }
.doc-paper { overflow-x: auto; }
@media (max-width: 520px) {
  .doc-paper .doc { padding: 14px; }
  .doc-paper .doc table { font-size: 0.68rem; }
  .doc-paper .doc th, .doc-paper .doc td { padding: 6px 2px; }
}

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; }
.month-nav strong::first-letter { text-transform: uppercase; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; }

.finder { display: flex; gap: 8px; align-items: center; margin: 12px 0 8px; }
.finder .icon-btn { width: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.finder .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.finder .icon-btn[aria-pressed="true"] { background: var(--primary-soft, #dcf2e6); }
.finder-input { width: 100%; margin: 0 0 10px; }

.sum-row.sub { padding-left: 14px; font-size: 0.9rem; }

/* type-ahead product lists */
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 30; margin: 0; padding: 4px; list-style: none; max-height: 240px; overflow-y: auto;
  background: var(--surface, #fff); border: 1px solid var(--line, #cfd6dc); border-radius: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.combo-list[hidden] { display: none; }
.combo-list li { display: flex; flex-direction: column; gap: 1px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.combo-list li:hover, .combo-list li:active { background: var(--accent-soft, #dcf2e6); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }

.reveal-row { display: flex; justify-content: flex-end; margin: 0 0 8px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); color: inherit; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 0.9rem; cursor: pointer; min-height: 38px; }
.chip-btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat strong { font-size: 1.15rem; }
