/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #0b0c0b;
  --surface: #121412;
  --surface-2: #181b18;
  --line: #242824;
  --line-2: #323732;
  --text: #e8e6df;
  --muted: #8a8f86;
  --faint: #5b6058;
  --accent: #a8c98a;      /* matcha */
  --accent-ink: #0f140c;
  --warn: #e3b866;
  --danger: #e38371;
  --good: #8fc79a;
  --radius: 10px;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { font-weight: 500; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 400; }
p { margin: 0; }
.num, td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.good { color: var(--good); }
.bad { color: var(--danger); }
.warn { color: var(--warn); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- layout helpers */
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* ---------------------------------------------------------------- controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 9px 11px; width: 100%; min-width: 0; outline: none; transition: border-color .15s;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=number] { font-family: var(--mono); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.field > span { padding-left: 2px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px;
  white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: #4a2e29; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.linkbtn:hover { color: var(--text); }

/* ---------------------------------------------------------------- surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font: 500 22px/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--good); border-color: #2f4733; }
.pill.warn { color: var(--warn); border-color: #4d3f22; }
.pill.bad { color: var(--danger); border-color: #4a2e29; }
.pill.accent { color: var(--accent); border-color: #3a4a2d; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a, .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--muted); cursor: pointer; text-decoration: none; white-space: nowrap; font-size: 14px; }
.tabs .on { color: var(--text); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 400; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tfoot td { border-top: 1px solid var(--line-2); border-bottom: 0; font-weight: 500; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- dialogs + toasts */
dialog.modal {
  background: var(--surface); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 22px; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
}
dialog.modal.wide { width: min(860px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(2px); }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--surface-2); border: 1px solid var(--line-2); padding: 9px 16px; border-radius: 9px; font-size: 14px; transition: opacity .3s; max-width: calc(100vw - 32px); }
.toast.err { border-color: #6a3a32; color: #f0b3a7; }
.toast.out { opacity: 0; }

/* ---------------------------------------------------------------- app shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; text-decoration: none; }
.brand b { font-weight: 500; font-size: 17px; letter-spacing: -0.01em; }
.brand small { color: var(--faint); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: 7px 10px; border-radius: 7px; color: var(--muted); text-decoration: none; font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.on { color: var(--text); background: var(--surface-2); }
.nav .sep { height: 1px; background: var(--line); margin: 8px 10px; }
.side .foot { margin-top: auto; padding: 0 10px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.side .foot a { color: var(--muted); text-decoration: none; }
.main { padding: 28px clamp(16px, 4vw, 44px) 80px; max-width: 1180px; width: 100%; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.pagehead .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.monthnav { display: inline-flex; align-items: center; gap: 4px; }
.monthnav span { min-width: 92px; text-align: center; font-size: 14px; }
.loading { color: var(--muted); padding: 40px 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px; background: var(--bg); border-right: 0; border-bottom: 1px solid var(--line); }
  .brand small, .side .foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
  .nav::-webkit-scrollbar { display: none; }
  .nav .sep { display: none; }
  .nav a { white-space: nowrap; }
  .main { padding: 20px 16px 80px; }
  th, td { padding: 9px 8px; }
}

/* ---------------------------------------------------------------- landing */
.landing { min-height: 100vh; display: flex; flex-direction: column; padding: 28px clamp(16px, 5vw, 64px); }
.landing header { display: flex; justify-content: space-between; align-items: center; }
.wordmark { font: 500 14px/1 var(--mono); letter-spacing: .02em; color: var(--muted); }
.landing main { flex: 1; display: flex; flex-direction: column; justify-content: center; max-width: 760px; width: 100%; margin: 0 auto; }
.hello { color: var(--faint); font-size: 14px; margin-bottom: 18px; font-family: var(--mono); }
.apps { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.apps li { border-bottom: 1px solid var(--line); }
.apps a, .apps .slot { display: grid; grid-template-columns: 44px 1fr auto; align-items: baseline; gap: 12px; padding: 22px 4px; text-decoration: none; }
.apps .idx { font: 13px var(--mono); color: var(--faint); }
.apps .name { font-size: clamp(24px, 4vw, 34px); letter-spacing: -0.02em; font-weight: 450; }
.apps .desc { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; letter-spacing: 0; }
.apps .go { font-size: 22px; color: var(--faint); transition: transform .2s, color .2s; }
.apps a:hover .go { color: var(--accent); transform: translateX(4px); }
.apps a:hover .name { color: #fff; }
.apps .slot { opacity: .35; }
.login { width: min(340px, 100%); margin: 0 auto; }
.login h1 { font-size: 26px; margin-bottom: 4px; }
.landing footer { color: var(--faint); font-size: 12px; font-family: var(--mono); }

/* ---------------------------------------------------------------- doc editor */
.items { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: 1fr 90px 110px 100px 110px 32px; gap: 8px; align-items: start; }
.item .amt { padding-top: 9px; }
.item-head { font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  .item { grid-template-columns: 1fr 1fr 1fr; }
  .item textarea { grid-column: 1 / -1; }
  .item-head { display: none; }
}
.x { background: none; border: 0; color: var(--faint); cursor: pointer; font-size: 18px; padding: 6px; line-height: 1; }
.x:hover { color: var(--danger); }

/* ---------------------------------------------------------------- charts */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; height: 150px; padding-top: 4px; }
.bars .b { display: grid; grid-template-rows: 1fr 1fr auto; justify-items: center; height: 100%; }
.bars .up, .bars .down { width: 100%; max-width: 26px; display: flex; }
.bars .up { align-items: flex-end; border-bottom: 1px solid var(--line-2); }
.bars .down { align-items: flex-start; }
.bars .bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.bars .down .bar { background: var(--danger); border-radius: 0 0 3px 3px; }
.bars .bar.live { opacity: .45; }
.bars .lbl { font-size: 11px; color: var(--faint); margin-top: 4px; font-family: var(--mono); }

/* ---------------------------------------------------------------- printable paper (quotes, invoices, payslips) */
.paperwrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.paper {
  background: #fff; color: #111; width: 210mm; min-height: 297mm; padding: 18mm 16mm;
  font: 10.5pt/1.45 Arial, Helvetica, sans-serif; box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.paper .num { font-family: Arial, Helvetica, sans-serif; }
.paper table { font-size: 10.5pt; }
.paper th, .paper td { border-bottom: 0; padding: 6px 8px; color: #111; }
.paper th { text-transform: none; letter-spacing: 0; font-weight: 700; font-size: 10.5pt; }
.doc-top { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr; gap: 16px; }
.doc-title { font-size: 26pt; font-weight: 400; line-height: 1.1; }
.doc-lbl { font-weight: 700; }
.doc-items { margin-top: 26mm; }
.doc-items thead th { border-bottom: 1px solid #111; }
.doc-items tbody td { padding-top: 10px; padding-bottom: 10px; }
.doc-items .desc { white-space: pre-line; max-width: 62mm; }
.doc-totals { width: 70mm; margin-left: auto; margin-top: 8px; }
.doc-totals td { padding: 5px 8px; }
.doc-totals tr.grand td { font-weight: 700; border-top: 1px solid #111; }
.doc-terms { margin-top: 14mm; }
.doc-terms ol { margin: 4px 0 0; padding-left: 22px; }
.doc-foot { margin-top: 10mm; font-size: 9.5pt; color: #444; }
.slip h1 { font-size: 16pt; font-weight: 700; }
.slip .meta { margin: 6px 0 16px; font-size: 10pt; }
.slip h2 { font-size: 13pt; font-weight: 700; margin: 14px 0 6px; }
.slip table { margin-top: 10px; border: 1px solid #111; }
.slip th, .slip td { border: 1px solid #111; }
.slip tr.total td { font-weight: 700; }

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; }
  .side, .noprint, #toasts { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .paperwrap { display: block; }
  .paper { box-shadow: none; width: auto; min-height: 0; }
}
@media (max-width: 860px) { .paper { width: 100%; padding: 8mm 6mm; min-height: 0; } .doc-top { grid-template-columns: 1fr 1fr; } }
