/* Light theme (default) */
:root {
  color-scheme: light;
  --bg: #f7f3f1;
  --surface: #fff;
  --surface-2: #fbf8f7;
  --hover: #f0eaec;
  --ink: #21191d;
  --text: #3f3239;
  --muted: #7a6a72;
  --line: #eadfe2;
  --line-strong: #d6c6cc;
  --brand: #381025;
  --brand-2: #642044;
  --brand-ink: #fff;
  --accent: #c72856;
  --accent-soft: #f3e6ea;
  --gold: #d8ae70;
  --gold-soft: #f1d7a6;
  --spend: #d8a24a;
  --violet: #7b61ff;
  --teal: #16a394;
  --grid: #efe6e9;
  --green: #227a3c;
  --green-bg: #e7f4ea;
  --amber: #99630c;
  --amber-bg: #fff4dc;
  --red: #b3182f;
  --red-bg: #fdecee;
  --topbar: rgba(255, 255, 255, .94);
  --shadow: 0 1px 2px rgba(56, 16, 37, .06), 0 8px 24px rgba(56, 16, 37, .05);
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

/* Dark theme: follows the system unless the user picked light or dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #150a10;
    --surface: #1f1118;
    --surface-2: #26151e;
    --hover: #2e1a25;
    --ink: #f5ecef;
    --text: #e2d3d9;
    --muted: #a8949d;
    --line: #3a2530;
    --line-strong: #4d3240;
    --brand: #f1d7a6;
    --brand-2: #ffe6b8;
    --brand-ink: #1f1118;
    --accent: #ff5d86;
    --accent-soft: #3a1a29;
    --spend: #e4b25f;
    --violet: #9d8cff;
    --teal: #4fd1c0;
    --grid: #2f1d27;
    --green: #6fd08e;
    --green-bg: #173323;
    --amber: #f3c46b;
    --amber-bg: #372911;
    --red: #ff7b8c;
    --red-bg: #3d1720;
    --topbar: rgba(21, 10, 16, .92);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #150a10;
  --surface: #1f1118;
  --surface-2: #26151e;
  --hover: #2e1a25;
  --ink: #f5ecef;
  --text: #e2d3d9;
  --muted: #a8949d;
  --line: #3a2530;
  --line-strong: #4d3240;
  --brand: #f1d7a6;
  --brand-2: #ffe6b8;
  --brand-ink: #1f1118;
  --accent: #ff5d86;
  --accent-soft: #3a1a29;
  --spend: #e4b25f;
  --violet: #9d8cff;
  --teal: #4fd1c0;
  --grid: #2f1d27;
  --green: #6fd08e;
  --green-bg: #173323;
  --amber: #f3c46b;
  --amber-bg: #372911;
  --red: #ff7b8c;
  --red-bg: #3d1720;
  --topbar: rgba(21, 10, 16, .92);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--sans); }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { padding: .05rem .3rem; border-radius: .3rem; background: var(--hover); font-size: .85em; }
.muted { color: var(--muted); }

.brand { color: var(--brand); font: 800 .85rem/1 var(--serif); letter-spacing: .14em; white-space: nowrap; }
.brand span { margin-left: .35rem; padding: .25rem .5rem; border-radius: .35rem; font: 750 .7rem/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; vertical-align: 1px; }
/* Digital = red badge, Physical = gold badge (same in light and dark) */
.brand span, [data-kind="digital"] .brand span { background: #d62b4f; color: #fff; }
[data-kind="physical"] .brand span { background: #d8ae70; color: #2a1a0c; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.product-picker select { min-height: 2.3rem; padding: .35rem 2rem .35rem .75rem; border-radius: .6rem; font-weight: 650; }
[data-kind="digital"] .product-picker select { border-color: rgba(214, 43, 79, .45); }
[data-kind="physical"] .product-picker select { border-color: rgba(216, 174, 112, .7); }
.demo-note { max-width: 84rem; margin: 1rem auto 0; padding: .75rem 1rem; border: 1px dashed #d8ae70; border-radius: .7rem; background: rgba(216, 174, 112, .12); color: var(--text); font-size: .9rem; }
.demo-note b { color: var(--ink); }

.button { min-height: 2.4rem; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--surface); color: var(--ink); font-weight: 650; cursor: pointer; transition: background .15s ease, border-color .15s ease; }
.button:hover { border-color: var(--line-strong); background: var(--surface-2); }
.button:disabled { opacity: .55; cursor: wait; }
.button.primary { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); }
.button.primary:hover { background: var(--brand-2); }
.button.ghost { border-color: transparent; background: transparent; }
.button.ghost:hover { background: var(--hover); }
.button.icon { min-width: 2.4rem; padding-inline: .5rem; }
.button.is-on { border-color: transparent; background: var(--green-bg); color: var(--green); }
.button.link { min-height: auto; padding: .1rem .4rem; border: 0; background: none; color: var(--muted); font-weight: 600; }
.button.link:hover { color: var(--red); }
.button:focus-visible, .tabs button:focus-visible, .segmented button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

input, select, textarea { min-height: 2.4rem; padding: .45rem .75rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--surface); }
textarea { width: 100%; min-height: 3.2rem; resize: vertical; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(24rem, 100%); display: grid; gap: .8rem; padding: 2rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); box-shadow: var(--shadow); }
.login-card h1 { margin: .6rem 0 .4rem; color: var(--ink); font: 600 1.6rem/1.2 var(--serif); }
.login-card label { font-weight: 650; }
.login-card input { width: 100%; min-height: 2.9rem; }
.login-card .button { min-height: 2.9rem; }
.error { color: var(--red); font-weight: 600; }

/* App shell */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--topbar); backdrop-filter: blur(8px); }
.tabs { display: flex; gap: .25rem; }
.tabs button { position: relative; padding: .5rem .85rem; border: 0; border-radius: .55rem; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--ink); background: var(--hover); }
.tabs button.is-active { color: var(--ink); background: var(--accent-soft); }
.badge { min-width: 1.3rem; margin-left: .3rem; padding: .05rem .4rem; border-radius: 1rem; background: var(--accent); color: #fff; font-size: .75rem; font-weight: 800; }
.topbar-actions { display: flex; gap: .25rem; margin-left: auto; }
.banner { max-width: 84rem; margin: 1rem auto 0; padding: .8rem 1rem; border-radius: .7rem; background: var(--red-bg); color: var(--red); font-weight: 600; }

.period-bar { max-width: 84rem; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem 1rem; padding: 1.25rem 1.5rem 0; }
.product { color: var(--ink); font: 600 1.35rem/1.2 var(--serif); }
.product .tag { margin-left: .5rem; padding: .15rem .5rem; border-radius: 1rem; background: var(--hover); color: var(--muted); font: 650 .75rem/1.4 var(--sans); vertical-align: 3px; }

.panel { max-width: 84rem; margin: 0 auto; padding: 1.25rem 1.5rem 2.5rem; }
.panel > .card + .card, .panel > .grid-2 + .card { margin-top: 1rem; }
.product small { margin-left: .5rem; font: 500 .8rem/1 var(--sans); }
.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem; }
.panel-head h1 { color: var(--ink); font: 600 1.75rem/1.2 var(--serif); }
.panel-head small { margin-left: .5rem; color: var(--muted); font: 500 .95rem/1 var(--sans); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; }
.filters input[type="search"] { width: 16rem; }
.help { max-width: 52rem; margin: -.4rem 0 1.25rem; color: var(--muted); }
.note { margin-top: .8rem; color: var(--muted); font-size: .85rem; line-height: 1.55; }

.segmented { display: inline-flex; flex-wrap: wrap; padding: .2rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.segmented button { padding: .35rem .75rem; border: 0; border-radius: .5rem; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; white-space: nowrap; }
.segmented button.is-active { background: var(--brand); color: var(--brand-ink); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.kpi { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); box-shadow: var(--shadow); }
.kpi p { color: var(--muted); font-size: .82rem; font-weight: 650; }
.kpi strong { display: block; margin-top: .3rem; color: var(--ink); font: 700 1.6rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.kpi small { display: block; margin-top: .25rem; color: var(--muted); font-size: .8rem; }
.kpi.is-good strong { color: var(--green); }
.kpi.is-bad strong, .kpi.is-alert strong { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; }
.profit-top { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); box-shadow: var(--shadow); }
.card h2 { margin-bottom: .9rem; color: var(--ink); font: 600 1.1rem/1.2 var(--serif); }
.card h2.mt { margin-top: 1.4rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: .9rem; }
.card-head h2 { margin: 0; }
.legend { display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .8rem; }
.dot { width: .6rem; height: .6rem; margin-left: .5rem; border-radius: 2px; }
.dot.rev { background: var(--accent); }
.dot.spend { background: var(--spend); }
.dot.profit { height: 2px; background: var(--green); }
.sync { display: flex; align-items: center; gap: .75rem; font-size: .85rem; }

/* Charts: smooth SVG area/line charts with a hover guide */
.chart { position: relative; height: 16rem; outline: none; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--line-strong); }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.chart .series { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .series.thin { stroke-width: 1.75; stroke-dasharray: 5 4; }
.chart .guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .point { stroke: var(--surface); stroke-width: 2; }
.chart .tip { position: absolute; top: 0; z-index: 3; min-width: 9.5rem; padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: .6rem; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); font-size: .8rem; line-height: 1.5; pointer-events: none; white-space: nowrap; }
.chart .tip b { display: block; margin-bottom: .15rem; font-weight: 750; }
.chart .tip i { display: inline-block; width: .55rem; height: .55rem; margin-right: .4rem; border-radius: 50%; font-style: normal; }
.chart .tip span { display: flex; justify-content: space-between; gap: 1rem; }
.chart .tip em { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 650; }
.chart:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; border-radius: .5rem; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .6rem; color: var(--text); font-size: .8rem; }
.legend .dot { width: .6rem; height: .6rem; margin-left: .45rem; border-radius: 50%; }
.legend .dot:first-child { margin-left: 0; }
.card-total { color: var(--ink); font: 700 1.5rem/1 var(--serif); font-variant-numeric: tabular-nums; }
.card-head .muted { margin-top: .2rem; font-size: .82rem; }

/* Today strip */
.today { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; margin-bottom: 1.5rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.today div { padding: .85rem 1.1rem; border-left: 1px solid var(--line); }
.today div:first-child { border-left: 0; }
.today p { color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.today strong { display: block; margin-top: .2rem; color: var(--ink); font: 700 1.35rem/1.15 var(--serif); font-variant-numeric: tabular-nums; }
.delta { font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }

.section-label { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .25rem 1rem; margin: 1.75rem 0 .8rem; }
.section-label:first-of-type { margin-top: 0; }
.section-label h2 { color: var(--ink); font: 650 1.3rem/1.2 var(--serif); }
.section-label .eyebrow { width: 100%; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.grid-2.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2 + .grid-2 { margin-top: 1rem; }
.kpi.is-link { cursor: pointer; transition: border-color .15s ease; }
.kpi.is-link:hover { border-color: var(--line-strong); }

/* Funnel */
.funnel li + li { margin-top: 1rem; }
.funnel .row { display: flex; justify-content: space-between; gap: 1rem; color: var(--text); }
.funnel .row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.funnel .row small { color: var(--muted); font-weight: 600; }
.funnel .track { height: .6rem; margin-top: .4rem; border-radius: 1rem; background: var(--hover); overflow: hidden; }
.funnel .fill { height: 100%; border-radius: 1rem; background: var(--violet); }

.empty { padding: 2rem 1rem; color: var(--muted); text-align: center; }

.bars li + li { margin-top: .7rem; }
.bars .row { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.bars .row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .track { height: .45rem; margin-top: .3rem; border-radius: 1rem; background: var(--hover); overflow: hidden; }
.bars .fill { height: 100%; border-radius: 1rem; background: var(--accent); }

/* P&L */
.pnl { width: 100%; border-collapse: collapse; font-size: .95rem; }
.pnl td { padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.pnl td:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pnl tr.minus td:first-child { padding-left: 1rem; color: var(--muted); }
.pnl tr.minus td:last-child { color: var(--muted); }
.pnl tr.sub td { font-weight: 700; }
.pnl tr.total td { padding-top: .7rem; border-top: 2px solid var(--ink); border-bottom: 0; font: 700 1.15rem/1.2 var(--serif); }
.pnl tr.total.pos td:last-child { color: var(--green); }
.pnl tr.total.neg td:last-child { color: var(--red); }
.pnl small { color: var(--muted); font-size: .78rem; font-weight: 500; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); box-shadow: var(--shadow); }
.table-wrap.flat { border-radius: .6rem; box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { position: sticky; top: 0; padding: .65rem .85rem; border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .03em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.table td { padding: .65rem .85rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .sub { display: block; color: var(--muted); font-size: .82rem; }
.table .nowrap { white-space: nowrap; }
.table tfoot td { border-top: 2px solid var(--line-strong); font-weight: 700; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.est { color: var(--muted); font-size: .75rem; }

.pill { display: inline-block; padding: .15rem .55rem; border-radius: 1rem; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.pill.paid, .pill.buyer, .pill.done { background: var(--green-bg); color: var(--green); }
.pill.pending, .pill.abandoned, .pill.called { background: var(--amber-bg); color: var(--amber); }
.pill.failed { background: var(--red-bg); color: var(--red); }
.pill.refunded, .pill.none { background: var(--hover); color: var(--muted); }
.pill.todo { background: var(--accent-soft); color: var(--accent); }

.expense-form { display: grid; grid-template-columns: 9.5rem 11rem minmax(0, 1fr) 8rem auto; gap: .5rem; margin-bottom: .9rem; }

/* Physical: shipping through the fulfilment centre */
.ship-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.ship-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.ship-msg { margin-bottom: 1rem; padding: .7rem 1rem; border-radius: .7rem; background: var(--green-bg); color: var(--green); font-weight: 600; }
.ship-msg.warn { background: var(--amber-bg); color: var(--amber); }
.table .check { width: 2.25rem; }
.table input[type="checkbox"] { width: 1.05rem; height: 1.05rem; min-height: 0; accent-color: var(--accent); }
.pill.new { background: var(--accent-soft); color: var(--accent); }
.pill.exported, .pill.packed { background: var(--amber-bg); color: var(--amber); }
.pill.shipped { background: rgba(123, 97, 255, .15); color: var(--violet); }
.pill.delivered { background: var(--green-bg); color: var(--green); }
.pill.returned, .pill.refused, .pill.cancelled { background: var(--red-bg); color: var(--red); }
.pill.cod { background: rgba(216, 174, 112, .2); color: var(--amber); }
.pill.card { background: var(--hover); color: var(--text); }

/* Fulfilment queue */
.queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: 1rem; }
.job { display: grid; gap: .8rem; padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: .9rem; background: var(--surface); box-shadow: var(--shadow); }
.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.job-head h3 { color: var(--ink); font: 600 1.15rem/1.25 var(--serif); }
.job-head small { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.job-contact { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-weight: 600; }
.job-contact a { text-decoration: none; }
.job-contact a:hover { text-decoration: underline; }
.job-items { padding: .7rem .85rem; border-radius: .6rem; background: var(--surface-2); font-size: .9rem; }
.job-items li::before { content: "•"; margin-right: .45rem; color: var(--accent); }
.job-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.job-row label { color: var(--muted); font-size: .85rem; font-weight: 650; }
.job-row select { flex: 1; min-width: 9rem; }
.job-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.job-actions .button { min-height: 2.6rem; }
.job-actions small { display: block; font-size: .72rem; font-weight: 600; opacity: .8; }

@media (max-width: 1000px) {
  .grid-2, .grid-2.even, .profit-top { grid-template-columns: 1fr; }
  .today { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .today div:nth-child(odd) { border-left: 0; }
  .today div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .expense-form { grid-template-columns: 1fr 1fr; }
  .expense-form input[name="description"] { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: .6rem 1rem; padding: .6rem 1rem; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .period-bar { padding: 1rem 1rem 0; }
  .panel { padding: 1rem; }
  .filters, .filters input[type="search"] { width: 100%; }
  .filters select { flex: 1; }
  .queue { grid-template-columns: 1fr; }
}
