/* SwanBooks demo — the app's own warm chrome. Light only, like the real app. */
:root {
  --side: #3A2A21;
  --side-ink: #EADDCF;
  --side-dim: #A99381;
  --side-on: #57402F;
  --bg: #FAF7F3;
  --card: #FFFFFF;
  --ink: #2A211C;
  --dim: #7B6C61;
  --rule: #EAE2D9;
  --head: #F5EFE8;
  --accent: #8A5A3B;
  --accent-ink: #FFFFFF;
  --in: #2F7D4F;
  --in-bg: #E4F2E8;
  --out: #B4432D;
  --out-bg: #FBE8E3;
  --warn: #A36A12;
  --warn-bg: #FBF0DA;
  --banner: #1E6B4E;
  --banner-ink: #FFFFFF;
  --f-display: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--f-body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.m { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--dim); }
[hidden] { display: none !important; }

/* demo banner */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px;
  background: var(--banner); color: var(--banner-ink);
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  font-size: 13px;
}
.banner-actions { display: flex; gap: 16px; }
.b-link { background: none; border: 0; padding: 4px 0; color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.b-link.confirm { color: #FFE9A8; }

/* shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100% - 40px); }
.side { background: var(--side); color: var(--side-dim); display: flex; flex-direction: column; padding: 18px 12px; gap: 6px; position: sticky; top: 0; height: 100vh; }
.side-logo { display: flex; align-items: center; gap: 9px; color: var(--side-ink); text-decoration: none; font: 700 17px/1 var(--f-display); padding: 4px 8px 16px; }
.side-logo svg { width: 22px; height: 22px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a { color: var(--side-dim); text-decoration: none; padding: 8px 10px; border-radius: 7px; font-weight: 500; }
.side-nav a:hover { color: var(--side-ink); }
.side-nav a.on { background: var(--side-on); color: var(--side-ink); }
.side-group { font: 500 10.5px/1 var(--f-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--side-dim); opacity: .7; padding: 16px 10px 6px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.08); color: var(--side-ink); }
.side-user small { display: block; color: var(--side-dim); font-size: 11.5px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--side-on); display: grid; place-items: center; font: 600 12px/1 var(--f-mono); flex: none; }

.main { padding: 24px clamp(16px, 3vw, 36px) 64px; min-width: 0; outline: none; }
.noscript { padding: 24px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); gap: 8px; }
  .side-logo { padding: 4px 6px; font-size: 15px; }
  .side-logo span { display: none; }
  .side-nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 2px; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a { white-space: nowrap; padding: 8px 10px; }
  .side-group, .side-user { display: none; }
  .main { padding: 18px max(16px, env(safe-area-inset-right, 0px)) 64px max(16px, env(safe-area-inset-left, 0px)); }
}

/* page head */
.ph { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 20px; }
.ph h1 { font: 700 clamp(22px, 2.4vw, 28px)/1.15 var(--f-display); margin: 0; letter-spacing: -.01em; }
.ph p { margin: 4px 0 0; color: var(--dim); }
.crumb { font-size: 12.5px; color: var(--dim); margin-bottom: 4px; }
.crumb a { color: var(--accent); text-decoration: none; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent; font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-p { background: var(--accent); color: var(--accent-ink); }
.btn-p:hover { filter: brightness(1.07); }
.btn-g { background: var(--card); border-color: var(--rule); color: var(--ink); }
.btn-g:hover { border-color: var(--dim); }
.btn-d { background: var(--card); border-color: var(--out); color: var(--out); }
.btn-d.confirm { background: var(--out); color: #FFFFFF; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* cards & metrics */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); min-width: 0; }
a.metric:hover { border-color: var(--accent); }
.metric small { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.metric b { font: 600 20px/1.2 var(--f-mono); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric em { font-style: normal; font-size: 12px; color: var(--dim); }
.metric.bad b { color: var(--out); }
.metric.warn b { color: var(--warn); }
@media (max-width: 1000px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cols { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; min-width: 0; }
.card + .card { margin-top: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 14px; background: var(--head); border-bottom: 1px solid var(--rule); font-weight: 600; }
.card-h a { color: var(--accent); text-decoration: none; font-size: 12.5px; }
.card-b { padding: 14px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

/* tables */
.tw { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); background: var(--head); padding: 9px 12px; white-space: nowrap; }
.t td { padding: 10px 12px; border-top: 1px solid var(--rule); white-space: nowrap; vertical-align: middle; }
.t .r { text-align: right; }
.t tr.go { cursor: pointer; }
.t tr.go:hover td { background: #FCFAF7; }
.t tfoot td { font-weight: 600; background: var(--head); }
.t td.wrap { white-space: normal; min-width: 14em; }
.t a.rowlink { color: inherit; text-decoration: none; font-weight: 600; }
.t a.rowlink:hover { color: var(--accent); }
.empty { padding: 28px 14px; text-align: center; color: var(--dim); }

.st { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.st.ok { background: var(--in-bg); color: var(--in); }
.st.warn { background: var(--warn-bg); color: var(--warn); }
.st.bad { background: var(--out-bg); color: var(--out); }
.st.mute { background: var(--head); color: var(--dim); }
.qin { color: var(--in); }
.qout { color: var(--out); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--rule); background: var(--card); color: var(--dim); border-radius: 99px; padding: 5px 12px; font-size: 12.5px; cursor: pointer; }
.chip.on { background: var(--side); color: var(--side-ink); border-color: var(--side); }
.search { min-height: 36px; border: 1px solid var(--rule); border-radius: 8px; padding: 0 12px; background: var(--card); min-width: 0; width: 240px; max-width: 100%; }

/* activity list */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 70px minmax(0, 1fr) 76px; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--rule); align-items: baseline; }
.feed li:first-child { border-top: 0; }
.feed time { font: 11.5px var(--f-mono); color: var(--dim); }
.feed .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .q { text-align: right; font-family: var(--f-mono); }

/* key-value */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kv > div { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kv small { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.kv b { font-weight: 600; }

/* document */
.doc { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: clamp(18px, 3vw, 36px); display: flex; flex-direction: column; gap: 20px; max-width: 860px; }
.doc-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; }
.doc-from b { font: 700 18px/1.2 var(--f-display); display: block; }
.doc-from span, .doc-to span { color: var(--dim); display: block; font-size: 13px; }
.doc-no { text-align: right; }
.doc-no small, .doc-to small, .doc-meta small { display: block; font: 500 10.5px/1.4 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.doc-no b { font: 600 20px/1.3 var(--f-mono); }
.doc-mid { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; }
.doc-to b { font-weight: 600; font-size: 15px; }
.doc-meta { display: flex; gap: 24px; flex-wrap: wrap; }
.doc .t { border: 1px solid var(--rule); }
.doc-total { display: flex; justify-content: flex-end; }
.doc-total table { min-width: 260px; }
.doc-total td { padding: 6px 0 6px 24px; }
.doc-total tr.grand td { font-weight: 700; font-size: 16px; border-top: 2px solid var(--ink); padding-top: 10px; }
.doc-memo { color: var(--dim); font-size: 13px; border-top: 1px solid var(--rule); padding-top: 14px; }
.stamp { display: inline-block; font: 700 12px/1 var(--f-mono); letter-spacing: .14em; padding: 6px 10px; border: 2px solid currentColor; border-radius: 6px; transform: rotate(-4deg); }
.stamp.paid { color: var(--in); }
.stamp.void { color: var(--out); }
.stamp.received { color: var(--in); }
.stamp.cancelled { color: var(--dim); }
.note { font-size: 13px; padding: 10px 12px; border-radius: 8px; background: var(--head); border: 1px solid var(--rule); max-width: 860px; margin-bottom: 14px; }
.note.in { background: var(--in-bg); border-color: transparent; color: var(--in); }

/* forms */
.form { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: clamp(16px, 2.5vw, 26px); display: flex; flex-direction: column; gap: 18px; max-width: 980px; }
.frow { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld label, .lbl { font-weight: 600; font-size: 12.5px; }
.fld input, .fld select, .fld textarea, .lines input, .lines select {
  min-height: 40px; border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px; background: #FFFFFF; width: 100%; font-size: 16px;
}
.fld textarea { min-height: 70px; resize: vertical; }
.fld .hint { font-size: 12px; color: var(--dim); }
.lines { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); padding: 0 6px 6px; font-weight: 600; }
.lines td { padding: 4px 6px; vertical-align: top; }
.lines td.amt { text-align: right; font-family: var(--f-mono); padding-top: 13px; white-space: nowrap; }
.lines .c-item { width: 40%; }
.lines .c-qty { width: 12%; }
.lines .c-rate { width: 16%; }
.lines .c-amt { width: 16%; text-align: right; }
.lines .c-x { width: 44px; }
.lines .sub { font-size: 11.5px; color: var(--dim); padding: 3px 2px 0; display: block; }
.lines .sub.bad { color: var(--out); }
.lines input.desc { margin-top: 6px; }
.x { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--rule); background: var(--card); cursor: pointer; color: var(--dim); font-size: 18px; line-height: 1; margin-top: 2px; }
.x:hover { color: var(--out); border-color: var(--out); }
.form-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--rule); padding-top: 16px; }
.form-total { font: 600 18px/1.2 var(--f-mono); }
.form-total small { font: 500 11px var(--f-body); color: var(--dim); text-transform: uppercase; letter-spacing: .06em; display: block; }
.errs { background: var(--out-bg); color: var(--out); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.errs ul { margin: 4px 0 0; padding-left: 18px; }

@media (max-width: 700px) {
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100%; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 6px; padding: 10px 0; border-top: 1px solid var(--rule); }
  .lines td { padding: 0; }
  .lines td.c-item { grid-column: 1 / -1; }
  .lines td.amt { grid-column: 1 / 3; text-align: left; padding-top: 2px; }
  .lines td.c-x { grid-column: 3; grid-row: 2; }
  .lines .c-qty, .lines .c-rate, .lines .c-amt, .lines .c-x, .lines .c-item { width: auto; }
}

/* aging bar */
.agebar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--head); margin: 4px 0 12px; }
.agebar i { display: block; height: 100%; }
.a0 { background: var(--in); } .a1 { background: #C9A227; } .a2 { background: var(--warn); } .a3 { background: #C2653A; } .a4 { background: var(--out); }
.agekey { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--dim); }
.agekey span { display: inline-flex; align-items: center; gap: 6px; }
.agekey i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.bar-cell { width: 110px; }
.lvl { display: block; height: 6px; border-radius: 3px; background: var(--head); overflow: hidden; width: 100px; }
.lvl i { display: block; height: 100%; background: var(--in); }
.lvl.near i { background: var(--warn); }
.lvl.low i { background: var(--out); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--side); color: var(--side-ink); padding: 11px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 10px 30px -10px rgba(42, 33, 28, .5); max-width: calc(100% - 32px); z-index: 50;
}

/* print: just the document */
@media print {
  .banner, .side, .ph .actions, .note, .toast, .crumb { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .doc { border: 0; max-width: none; padding: 0; }
  body { background: #FFFFFF; }
}
