:root {
  --bg:        #f6f7f9;
  --panel:     #ffffff;
  --panel-alt: #fbfcfd;
  --ink:       #1c2530;
  --ink-soft:  #5a6672;
  --ink-faint: #8b98a5;
  --line:      #e3e7ec;
  --line-soft: #eef1f4;
  --accent:    #2f6fb5;
  --pos:       #17825a;
  --neg:       #b2453d;
  --warn:      #9a6714;
  --warn-bg:   #fdf5e4;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #12161b;
    --panel:     #1a1f26;
    --panel-alt: #1e242c;
    --ink:       #e7ecf2;
    --ink-soft:  #a7b2bf;
    --ink-faint: #74808d;
    --line:      #2a323c;
    --line-soft: #232a33;
    --accent:    #6fa8e6;
    --pos:       #4bbd8c;
    --neg:       #e0796e;
    --warn:      #d8a952;
    --warn-bg:   #2b2418;
    --shadow:    0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px 64px; }

/* ------------------------------------------------------------ top bar */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; min-height: 56px;
}
.brand { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; color: var(--ink); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 6px 12px; border-radius: 7px; color: var(--ink-soft); font-weight: 500;
}
.nav a:hover { background: var(--line-soft); text-decoration: none; color: var(--ink); }
.nav a.on { background: var(--line-soft); color: var(--ink); }
.whoami { color: var(--ink-faint); font-size: 13px; white-space: nowrap; }

/* -------------------------------------------------------------- pieces */

.pagehead {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 28px 0 18px;
}
.pagehead h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.015em; }
.pagehead .sub { color: var(--ink-faint); font-size: 13px; margin-top: 3px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card > h2 {
  margin: 0; padding: 14px 18px; font-size: 13px; font-weight: 620;
  letter-spacing: .02em; text-transform: uppercase; color: var(--ink-faint);
  border-bottom: 1px solid var(--line-soft);
}
.card .body { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.c3, .grid.c4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------- stat tiles */

.stat { padding: 16px 18px; }
.stat .k {
  font-size: 11px; font-weight: 620; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-faint);
}
.stat .v {
  font-size: 26px; font-weight: 620; letter-spacing: -.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat .n { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- tables */

table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-size: 11px; font-weight: 620; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.t td {
  padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle;
}
table.t tbody tr:hover { background: var(--panel-alt); }
table.t tbody tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

.muted { color: var(--ink-faint); }
.small { font-size: 12px; }
.trunc { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -------------------------------------------------------------- chips */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--line-soft); color: var(--ink-soft); white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip.pending { background: var(--warn-bg); color: var(--warn); }

/* ---------------------------------------------------------- bar charts */

.bars { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding-top: 8px; }
.barcol { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.barpair { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: 100%; justify-content: center; }
.bar { width: 44%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.in  { background: var(--pos); opacity: .85; }
.bar.out { background: var(--neg); opacity: .85; }
.barlabel { font-size: 11px; color: var(--ink-faint); white-space: nowrap; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-soft); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }

/* category meter rows */
.meter { display: grid; grid-template-columns: 1fr auto; gap: 3px 14px; margin-bottom: 13px; }
.meter .name { font-weight: 500; }
.meter .amt { font-variant-numeric: tabular-nums; font-weight: 550; }
.meter .track {
  grid-column: 1 / -1; height: 6px; border-radius: 3px;
  background: var(--line-soft); overflow: hidden;
}
.meter .fill { height: 100%; border-radius: 3px; }
.meter .note { grid-column: 1 / -1; font-size: 12px; color: var(--ink-faint); }

/* -------------------------------------------------------------- forms */

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 1px; border-color: var(--accent);
}
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }

.btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 7px; padding: 7px 14px;
}
.btn:hover { background: var(--panel-alt); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.filters {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}

.notice {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 16px;
  background: var(--warn-bg); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}
.notice a { color: inherit; text-decoration: underline; }
.error { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.ok    { background: color-mix(in srgb, var(--pos) 12%, transparent); color: var(--pos); border-color: color-mix(in srgb, var(--pos) 30%, transparent); }

/* ------------------------------------------------------------- signin */

.signin { max-width: 380px; margin: 12vh auto; padding: 0 20px; }
.signin .card .body { padding: 26px; }
.signin h1 { font-size: 19px; margin: 0 0 4px; }
.signin p.sub { margin: 0 0 22px; color: var(--ink-faint); font-size: 13px; }
.signin label.f { margin-top: 14px; }
.signin input { width: 100%; }
.signin .btn { width: 100%; margin-top: 20px; }

.pager { display: flex; gap: 8px; align-items: center; padding: 14px 18px; color: var(--ink-faint); font-size: 13px; }
.pager .spacer { flex: 1; }

select.catsel {
  border-color: transparent; background: transparent; padding: 3px 6px;
  font-size: 13px; color: var(--ink-soft); max-width: 180px;
}
select.catsel:hover { border-color: var(--line); background: var(--panel); }
tr.saving { opacity: .5; }

/* ------------------------------------------------------- review tab */
.insight-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.insight-head h3 { margin: 8px 0 0; font-size: 16px; font-weight: 620; letter-spacing: -.01em; }
.insight-amt { text-align: right; white-space: nowrap; }
.insight-amt .v { font-size: 20px; font-weight: 620; font-variant-numeric: tabular-nums; }
.insight.closed { opacity: .62; }
.insight-actions { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0; }
@media (max-width: 620px) {
  .insight-head { flex-direction: column; }
  .insight-amt { text-align: left; }
}

/* --------------------------------------------------- bars / pie switch */

.card > h2.withtoggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.chartswitch { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.chartswitch button {
  font: inherit; font-size: 11px; font-weight: 620; letter-spacing: .04em;
  text-transform: uppercase; cursor: pointer;
  border: 0; border-right: 1px solid var(--line); background: var(--panel);
  color: var(--ink-faint); padding: 4px 11px;
}
.chartswitch button:last-child { border-right: 0; }
.chartswitch button:hover { background: var(--line-soft); color: var(--ink); }
.chartswitch button.on { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- donut */

.donutwrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.donut { width: 232px; height: 232px; flex: none; }
.donut .slice {
  /* 2px of surface between fills comes from the angular gap in the path;
     the stroke keeps that gap clean where segments nearly meet. */
  stroke: var(--panel); stroke-width: 1;
  transition: opacity .12s ease;
  cursor: default; outline: none;
}
.donutwrap:hover .donut .slice { opacity: .45; }
.donut .slice:hover, .donut .slice:focus-visible { opacity: 1; }
.donut .slice:focus-visible { stroke: var(--ink); stroke-width: 2; }

.donut .slicelabel {
  font-size: 12px; font-weight: 620; fill: #fff;
  text-anchor: middle; dominant-baseline: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(0,0,0,.28); stroke-width: 2.5px;
}
.donut .donuttotal {
  font-size: 24px; font-weight: 650; fill: var(--ink);
  text-anchor: middle; font-variant-numeric: tabular-nums;
}
.donut .donutcap {
  font-size: 11px; font-weight: 600; fill: var(--ink-faint);
  text-anchor: middle; letter-spacing: .06em; text-transform: uppercase;
}

.donutlegend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 210px; }
.donutlegend li {
  display: grid; grid-template-columns: auto 1fr auto auto;
  gap: 9px; align-items: baseline;
  padding: 5px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.donutlegend li:last-child { border-bottom: 0; }
.donutlegend .swatch { width: 10px; height: 10px; border-radius: 2px; align-self: center; }
.donutlegend .amt { font-variant-numeric: tabular-nums; font-weight: 550; }
.donutlegend .pc  { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
@media (max-width: 560px) { .donut { width: 100%; height: auto; max-width: 260px; margin: 0 auto; } }

/* ------------------------------------------------- categorical palette

   Validated with the dataviz palette checker: light and dark each pass the
   lightness band, chroma floor, adjacent-pair CVD separation and the
   normal-vision floor. Dark is its own set of steps for the dark surface,
   NOT a flip of the light values. Slot order is fixed and assigned by
   all-time spend, so a category keeps its hue as the period changes.      */

:root {
  --cat-0: #8b98a5;   /* beyond the ramp / "Other" */
  --cat-1: #2a78d6;   --cat-2: #eb6834;   --cat-3: #1baf7a;   --cat-4: #eda100;
  --cat-5: #e87ba4;   --cat-6: #008300;   --cat-7: #4a3aa7;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cat-0: #74808d;
    --cat-1: #3987e5;  --cat-2: #d95926;  --cat-3: #199e70;  --cat-4: #c98500;
    --cat-5: #d55181;  --cat-6: #008300;  --cat-7: #9085e9;
  }
}

.donut .cat-0 { fill: var(--cat-0); }  .donut .cat-1 { fill: var(--cat-1); }
.donut .cat-2 { fill: var(--cat-2); }  .donut .cat-3 { fill: var(--cat-3); }
.donut .cat-4 { fill: var(--cat-4); }  .donut .cat-5 { fill: var(--cat-5); }
.donut .cat-6 { fill: var(--cat-6); }  .donut .cat-7 { fill: var(--cat-7); }

.swatch.cat-0, .fill.cat-0 { background: var(--cat-0); }
.swatch.cat-1, .fill.cat-1 { background: var(--cat-1); }
.swatch.cat-2, .fill.cat-2 { background: var(--cat-2); }
.swatch.cat-3, .fill.cat-3 { background: var(--cat-3); }
.swatch.cat-4, .fill.cat-4 { background: var(--cat-4); }
.swatch.cat-5, .fill.cat-5 { background: var(--cat-5); }
.swatch.cat-6, .fill.cat-6 { background: var(--cat-6); }
.swatch.cat-7, .fill.cat-7 { background: var(--cat-7); }

/* ------------------------------------------------------- subscriptions */
table.subs td { vertical-align: top; }
table.subs tr.status-cancelled, table.subs tr.status-ignored { opacity: .5; }
table.subs tr.status-cancel { background: color-mix(in srgb, var(--pos) 7%, transparent); }
table.subs input[type=text] { font-size: 13px; }
table.subs .catsel { border-color: var(--line); background: var(--panel); max-width: 160px; }
