/* ═══════════════════════════════════════════════════════════════════════
   Ace Analytics — editorial financial instrument
   Warm ink and paper, high-contrast serif headings, tabular mono figures,
   hairline rules. Every figure is monospaced and tabular so columns align
   the way a printed financial table does.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  --plane:      #12110f;
  --surface:    #1a1916;
  --surface-2:  #211f1b;
  --surface-3:  #29261f;
  --ink:        #f5f1e8;
  --ink-2:      #b8b2a4;
  --ink-muted:  #8a857a;
  --rule:       #2c2a25;
  --rule-soft:  #211f1b;
  --accent:     #e0a338;
  --accent-ink: #12110f;
  --accent-dim: rgba(224, 163, 56, 0.14);

  /* Data series — validated for the dark surface #1a1916 (all-pairs, 3 slots) */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid:     #2c2c2a;
  --axis:     #383835;

  /* Status — fixed, never themed. Always paired with an icon and a label. */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --sans: "Schibsted Grotesk", ui-sans-serif, system-ui, sans-serif;
  --display: "Fraunces", ui-serif, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  --rail-w: 15rem;
  --pad: clamp(1.1rem, 3.2vw, 2.75rem);
  --radius: 3px;
  --radius-lg: 6px;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.55);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --plane:      #f2ede2;
  --surface:    #fdfbf5;
  --surface-2:  #f7f2e7;
  --surface-3:  #efe8d9;
  --ink:        #16150f;
  --ink-2:      #52504a;
  --ink-muted:  #6d6a5f;   /* 5.23:1 on surface, 4.64:1 on plane: AA for small text */
  --rule:       #ded7c8;
  --rule-soft:  #e9e2d4;
  --accent:     #8a5d0c;
  --accent-ink: #fdfbf5;
  --accent-dim: rgba(138, 93, 12, 0.10);

  /* Validated for the light surface #fdfbf5 */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid:     #e1e0d9;
  --axis:     #c3c2b7;

  --shadow: 0 1px 2px rgba(60,50,25,.07), 0 10px 28px -16px rgba(60,50,25,.22);
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none at the same specificity as a class,
   so any class that sets display (.gate is display:grid) silently beats it and
   the element never hides. Force it. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Paper grain. Very low opacity — atmosphere, not texture you notice. */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: .028; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--accent); color: var(--accent-ink); }

:where(a) { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

h1, h2, h3 { margin: 0; font-weight: 400; letter-spacing: -0.01em; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── Sign in ─────────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(120% 90% at 12% 0%, rgba(224,163,56,.10), transparent 55%),
    radial-gradient(90% 70% at 100% 100%, rgba(57,135,229,.08), transparent 60%),
    var(--plane);
}
.gate__panel {
  width: min(26rem, 100%);
  padding: clamp(1.75rem, 5vw, 2.75rem);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: rise .5s var(--ease) both;
}
.gate__mark { color: var(--accent); margin-bottom: 1rem; }
.gate__title {
  font-family: var(--display);
  font-size: clamp(1.9rem, 6vw, 2.4rem);
  font-weight: 300; letter-spacing: -0.03em; line-height: 1.05;
}
.gate__sub { margin: .35rem 0 1.75rem; color: var(--ink-muted); font-size: .875rem; }
.gate__form { display: grid; gap: 1rem; }
.gate__error {
  margin: 0; padding: .6rem .75rem; font-size: .82rem;
  color: var(--critical);
  border-left: 2px solid var(--critical);
  background: color-mix(in srgb, var(--critical) 9%, transparent);
}
.gate__note {
  margin: 1.5rem 0 0; padding-top: 1.25rem;
  border-top: 1px solid var(--rule-soft);
  color: var(--ink-muted); font-size: .78rem; line-height: 1.55;
}

.field { display: grid; gap: .4rem; }
.field__label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--ink-muted); font-weight: 600;
}
.field__input {
  width: 100%; padding: .7rem .8rem;
  background: var(--plane); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
  font-family: var(--mono); font-size: .875rem;
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.field__input:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .68rem 1.1rem; border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer;
  transition: transform .12s var(--ease), filter .16s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.08); }

.ghost {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: .5rem .6rem;
  background: none; border: 0; border-radius: var(--radius);
  color: var(--ink-muted); font: inherit; font-size: .82rem; cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.ghost:hover { background: var(--surface-2); color: var(--ink); }

/* ── Shell ───────────────────────────────────────────────────────────── */
.shell { position: relative; z-index: 1; min-height: 100%; }

.rail {
  position: fixed; inset: 0 auto 0 0; width: var(--rail-w);
  display: flex; flex-direction: column;
  padding: 1.35rem 1rem;
  background: var(--surface);
  border-right: 1px solid var(--rule);
}
.rail__head { display: flex; gap: .7rem; align-items: center; padding: 0 .35rem 1.35rem; }
.rail__mark { color: var(--accent); display: flex; }
.rail__id { display: grid; min-width: 0; }
.rail__name {
  font-family: var(--display); font-size: 1.02rem; font-weight: 400;
  letter-spacing: -0.02em; line-height: 1.15;
}
.rail__client {
  font-size: .68rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); font-weight: 500;
}
.rail__nav { display: grid; gap: 2px; padding-top: 1.1rem; border-top: 1px solid var(--rule-soft); }
.rail__foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--rule-soft); display: grid; gap: 2px; }

.navlink {
  display: flex; align-items: center; gap: .7rem;
  padding: .58rem .6rem; border-radius: var(--radius);
  color: var(--ink-2); font-size: .875rem; font-weight: 500;
  position: relative;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink[aria-current="page"] { background: var(--accent-dim); color: var(--ink); }
.navlink[aria-current="page"]::before {
  content: ""; position: absolute; left: -1rem; top: 50%; translate: 0 -50%;
  width: 2px; height: 1.15rem; background: var(--accent); border-radius: 0 2px 2px 0;
}

.main { margin-left: var(--rail-w); min-height: 100vh; padding-bottom: 4rem; }
.main:focus { outline: none; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1.25rem; flex-wrap: wrap;
  padding: clamp(1.5rem, 4vw, 2.6rem) var(--pad) 1.25rem;
  border-bottom: 1px solid var(--rule);
}
.topbar__title h1 {
  font-family: var(--display);
  font-size: clamp(1.65rem, 4.2vw, 2.5rem);
  font-weight: 300; letter-spacing: -0.032em; line-height: 1.02;
}
.topbar__sub { margin: .4rem 0 0; color: var(--ink-muted); font-size: .82rem; }
.topbar__tools { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.view { padding: clamp(1.25rem, 3.5vw, 2rem) var(--pad) 0; display: grid; gap: 1.5rem; }

/* ── Segmented control & selects ─────────────────────────────────────── */
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--rule); border-radius: var(--radius);
}
.seg__btn {
  padding: .38rem .72rem; border: 0; border-radius: 2px; cursor: pointer;
  background: none; color: var(--ink-muted);
  font: inherit; font-size: .78rem; font-weight: 600; letter-spacing: .01em;
  transition: background .14s var(--ease), color .14s var(--ease);
  white-space: nowrap;
}
.seg__btn:hover { color: var(--ink); }
.seg__btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.select {
  padding: .42rem .6rem; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
  font: inherit; font-size: .8rem; cursor: pointer;
}

/* ── Card ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: rise .45s var(--ease) both;
}
.card__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 1rem 1.15rem; border-bottom: 1px solid var(--rule-soft);
}
.card__title {
  font-family: var(--display); font-size: 1.12rem; font-weight: 400;
  letter-spacing: -0.02em;
}
.card__meta { color: var(--ink-muted); font-size: .76rem; }
.card__body { padding: 1.15rem; }
.card__body--flush { padding: 0; }

/* Staggered page-load reveal. One orchestrated entrance beats scattered
   micro-interactions. */
@keyframes rise { from { opacity: 0; transform: translateY(9px); } }
.view > * { animation: rise .45s var(--ease) both; }
.view > *:nth-child(1) { animation-delay: .02s; }
.view > *:nth-child(2) { animation-delay: .07s; }
.view > *:nth-child(3) { animation-delay: .12s; }
.view > *:nth-child(4) { animation-delay: .17s; }
.view > *:nth-child(n+5) { animation-delay: .21s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Stat tiles ──────────────────────────────────────────────────────── */
.tiles {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13.5rem), 1fr));
}
.tile {
  padding: 1.1rem 1.15rem 1rem;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  display: grid; gap: .5rem; align-content: start;
}
.tile__label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .13em;
  color: var(--ink-muted); font-weight: 600;
}
.tile__value {
  font-family: var(--mono); font-size: clamp(1.5rem, 3.6vw, 1.95rem);
  font-weight: 500; letter-spacing: -0.035em; line-height: 1; color: var(--ink);
}
.tile__foot { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.tile__spark { margin-top: .15rem; }

.delta {
  display: inline-flex; align-items: center; gap: .22rem;
  font-family: var(--mono); font-size: .78rem; font-weight: 500;
}
.delta--up   { color: var(--good); }
.delta--down { color: var(--critical); }
.delta--flat { color: var(--ink-muted); }
.delta__note { color: var(--ink-muted); font-family: var(--sans); font-size: .74rem; }

/* ── Status chips. Colour never carries meaning alone: always icon + word. */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .16rem .5rem .16rem .38rem;
  border-radius: 100px; border: 1px solid transparent;
  font-size: .7rem; font-weight: 600; letter-spacing: .02em;
  white-space: nowrap;
}
.chip__dot { width: .5rem; height: .5rem; border-radius: 50%; flex: none; }
.chip--critical { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 38%, transparent); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.chip--critical .chip__dot { background: var(--critical); }
.chip--serious  { color: var(--serious);  border-color: color-mix(in srgb, var(--serious) 40%, transparent);  background: color-mix(in srgb, var(--serious) 10%, transparent); }
.chip--serious .chip__dot { background: var(--serious); }
.chip--warning  { color: var(--warning);  border-color: color-mix(in srgb, var(--warning) 40%, transparent);  background: color-mix(in srgb, var(--warning) 10%, transparent); }
.chip--warning .chip__dot { background: var(--warning); }
.chip--good     { color: var(--good);     border-color: color-mix(in srgb, var(--good) 40%, transparent);     background: color-mix(in srgb, var(--good) 10%, transparent); }
.chip--good .chip__dot { background: var(--good); }
.chip--muted    { color: var(--ink-muted); border-color: var(--rule); background: var(--surface-2); }
.chip--muted .chip__dot { background: var(--ink-muted); }

:root[data-theme="light"] .chip--warning { color: #7a5400; }
:root[data-theme="light"] .chip--serious { color: #9c4a22; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
table.data th, table.data td {
  padding: .62rem .8rem; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--rule-soft);
}
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  font-size: .66rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-muted); font-weight: 700;
  border-bottom: 1px solid var(--rule);
}
table.data thead th[data-sortable] { cursor: pointer; user-select: none; }
table.data thead th[data-sortable]:hover { color: var(--ink); }
table.data thead th[aria-sort]:not([aria-sort="none"]) { color: var(--accent); }
table.data tbody tr { transition: background .12s var(--ease); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }
table.data td.text {
  /* Same reasoning as .product: a wrapping text column with no floor gets
     crushed to two or three words once a table carries a dozen numeric
     columns, and "medium size cost... mug" identifies nothing. Claim a floor
     and let .tablewrap scroll. */
  min-width: 11rem;
  max-width: 24rem; white-space: normal;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.35;
}
table.data td.key  { font-weight: 500; }
.rowlink { cursor: pointer; }
.rowlink:hover td.key { color: var(--accent); }

.empty { padding: 2.5rem 1.15rem; text-align: center; color: var(--ink-muted); font-size: .875rem; }

/* ── Notes ("How to read this") ──────────────────────────────────────── */
.notes { border-top: 1px solid var(--rule-soft); }
.notes__toggle {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .7rem 1.15rem; background: none; border: 0; cursor: pointer;
  color: var(--ink-muted); font: inherit; font-size: .78rem; font-weight: 600;
  transition: color .14s var(--ease);
}
.notes__toggle:hover { color: var(--ink); }
.notes__toggle i { transition: rotate .18s var(--ease); }
.notes[open] .notes__toggle i { rotate: 90deg; }
.notes__body {
  padding: 0 1.15rem 1.1rem;
  display: grid; gap: .55rem;
  color: var(--ink-2); font-size: .8rem; line-height: 1.6;
  max-width: 62ch;
}
.notes__body li { list-style: none; padding-left: .95rem; position: relative; }
.notes__body li::before {
  content: ""; position: absolute; left: 0; top: .55em;
  width: .32rem; height: .32rem; border-radius: 50%; background: var(--accent); opacity: .65;
}
.notes__body ul { margin: 0; padding: 0; display: grid; gap: .55rem; }

/* ── Charts ──────────────────────────────────────────────────────────── */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--sans); fill: var(--ink-muted); }
.chart .tick { font-size: 10px; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .mark { transition: opacity .14s var(--ease); }
.chart:hover .mark[data-dim="true"] { opacity: .35; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; padding: 0 0 .85rem; }
.legend__item { display: inline-flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--ink-2); }
.legend__swatch { width: .7rem; height: .7rem; border-radius: 2px; flex: none; }

.tip {
  position: fixed; z-index: 30; pointer-events: none;
  padding: .55rem .7rem; max-width: 17rem;
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: .76rem; line-height: 1.45;
  opacity: 0; transition: opacity .12s var(--ease);
}
.tip[data-show="true"] { opacity: 1; }
.tip__title { font-weight: 600; margin-bottom: .2rem; }
.tip__row { display: flex; justify-content: space-between; gap: 1rem; font-family: var(--mono); font-size: .74rem; }
.tip__row span:first-child { color: var(--ink-muted); font-family: var(--sans); }

/* ── Attention list ──────────────────────────────────────────────────── */
.attn { display: grid; }
.attn__item {
  display: grid; gap: .3rem; padding: .85rem 1.15rem;
  border-bottom: 1px solid var(--rule-soft);
  grid-template-columns: 1fr auto; align-items: center;
}
.attn__item:last-child { border-bottom: 0; }
.attn__main { min-width: 0; }
.attn__head { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.attn__what { font-weight: 600; font-size: .875rem; }
.attn__why { color: var(--ink-muted); font-size: .78rem; margin-top: .15rem; }
.attn__num { font-family: var(--mono); font-size: .95rem; font-weight: 500; text-align: right; white-space: nowrap; }

/* ── Skeleton ────────────────────────────────────────────────────────── */
.skel { border-radius: var(--radius); background: var(--surface-2); position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 5%, transparent), transparent);
  animation: sweep 1.3s infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }
.skel--tile { height: 6.5rem; }
.skel--card { height: 15rem; }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; translate: -50% 0; z-index: 40;
  padding: .65rem 1rem; max-width: min(30rem, calc(100vw - 2rem));
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--rule); border-left: 2px solid var(--critical);
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: .82rem; animation: rise .28s var(--ease) both;
}

/* ── Icons ───────────────────────────────────────────────────────────── */
i[data-icon] { display: inline-flex; width: 1.05rem; height: 1.05rem; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* ── Utilities ───────────────────────────────────────────────────────── */
.grid2 { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); }
.stack { display: grid; gap: 1.5rem; }
.muted { color: var(--ink-muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.tabbar { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 60rem) {
  .rail {
    position: sticky; top: 0; inset: auto; width: auto; z-index: 5;
    flex-direction: row; align-items: center; justify-content: space-between;
    padding: .7rem var(--pad);
    border-right: 0; border-bottom: 1px solid var(--rule);
  }
  .rail__head { padding: 0; }
  .rail__nav { display: none; }
  .rail__foot { margin: 0; padding: 0; border: 0; display: flex; gap: .25rem; }
  .rail__foot .ghost { width: auto; padding: .45rem .55rem; }
  .rail__foot .ghost span { display: none; }
  .main { margin-left: 0; padding-bottom: 5.5rem; }

  .tabbar {
    position: fixed; inset: auto 0 0 0; z-index: 10;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    display: grid; justify-items: center; gap: .18rem; padding: .6rem .25rem .55rem;
    color: var(--ink-muted); font-size: .64rem; font-weight: 600;
    letter-spacing: .02em;
  }
  .tab[aria-current="page"] { color: var(--accent); }
}

/* Below this width a wide numeric table stops being readable, so each row
   becomes a card built from the column labels the API already gives us. */
@media (max-width: 46rem) {
  table.data.stackable thead { display: none; }
  table.data.stackable, table.data.stackable tbody,
  table.data.stackable tr, table.data.stackable td { display: block; width: 100%; }
  table.data.stackable tr {
    padding: .85rem 1.05rem; border-bottom: 1px solid var(--rule-soft);
  }
  table.data.stackable td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    padding: .2rem 0; border: 0; white-space: normal; text-align: right;
  }
  table.data.stackable td::before {
    content: attr(data-label);
    font-size: .68rem; text-transform: uppercase; letter-spacing: .1em;
    color: var(--ink-muted); font-weight: 700; text-align: left; flex: none;
  }
  table.data.stackable td.key {
    font-size: .95rem; font-weight: 600; padding-bottom: .5rem;
  }
  table.data.stackable td.key::before { display: none; }
  .attn__item { grid-template-columns: 1fr; }
  .attn__num { text-align: left; }
}

@media (max-width: 30rem) {
  .topbar { padding-bottom: 1rem; }
  .card__body { padding: .9rem; }
}

/* ═══════════════════════════════════════════════════════════════════════
   Administration — users, grants, sessions
   Same ink and hairlines as the analytics side. A dialog is a sheet of the
   same paper lifted off the page, not a different visual language.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Small text & inline helpers ─────────────────────────────────────── */
.small { font-size: .74rem; }
.chiprow { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.stackcell { display: grid; gap: .1rem; }
.field__hint { font-size: .72rem; color: var(--ink-muted); }

.linkish {
  background: none; border: 0; padding: 0;
  color: var(--ink-muted); font: inherit; font-size: .78rem;
  text-decoration: underline; text-underline-offset: .22em;
  text-decoration-color: var(--rule); cursor: pointer;
}
.linkish:hover { color: var(--accent); text-decoration-color: currentColor; }

.btn--quiet {
  background: var(--surface-2); color: var(--ink-2); border-color: var(--rule);
  padding: .5rem .8rem; font-size: .8rem;
}
.btn--quiet:hover { background: var(--surface-3); color: var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; flex: none;
  background: none; border: 0; border-radius: var(--radius);
  color: var(--ink-muted); cursor: pointer;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }

/* ── Rail additions ──────────────────────────────────────────────────── */
.rail__account {
  display: grid; gap: .35rem; padding: 0 .35rem 1rem;
  border-bottom: 1px solid var(--rule-soft);
}
.rail__account .select { width: 100%; }
.rail__who {
  display: block; padding: .35rem .6rem .6rem;
  color: var(--ink-muted); font-size: .74rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 1.25rem;
  background: color-mix(in srgb, #000 58%, transparent);
  backdrop-filter: blur(3px);
  animation: fade .18s var(--ease) both;
}
.modal__panel {
  width: min(100%, 34rem); max-height: min(88vh, 52rem);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  animation: rise .24s var(--ease) both;
}
.modal__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: 1.15rem 1.15rem .9rem;
  border-bottom: 1px solid var(--rule-soft);
}
.modal__title {
  margin: 0; font-family: var(--display); font-weight: 400;
  font-size: 1.15rem; line-height: 1.25; letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.modal__sub { margin: .3rem 0 0; color: var(--ink-muted); font-size: .78rem; }
.modal__body { padding: 1.15rem; overflow-y: auto; }
.modal__text { margin: 0; font-size: .875rem; color: var(--ink-2); line-height: 1.6; }
.modal__foot {
  display: flex; justify-content: flex-end; gap: .6rem;
  padding: .9rem 1.15rem; border-top: 1px solid var(--rule-soft);
}
.modal__danger {
  display: flex; gap: .6rem; flex-wrap: wrap;
  padding-top: 1rem; border-top: 1px solid var(--rule-soft);
}

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* ── Forms inside dialogs ────────────────────────────────────────────── */
.formgrid { display: grid; gap: 1.05rem; }

.check {
  width: 1.05rem; height: 1.05rem; flex: none; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}
.checkrow {
  display: flex; align-items: flex-start; gap: .65rem; cursor: pointer;
  padding: .7rem .8rem; border: 1px solid var(--rule);
  border-radius: var(--radius); background: var(--plane);
}
.checkrow:hover { border-color: var(--ink-muted); }
.checkrow__label { display: block; font-size: .85rem; font-weight: 600; }
.checkrow .muted { display: block; margin-top: .1rem; }

/* ── Grant picker ────────────────────────────────────────────────────── */
/* Grouped by client for scanning; every control is still one credential, so
   nothing here can grant access the administrator did not tick. */
.grants {
  display: grid; gap: .1rem;
  max-height: 20rem; overflow-y: auto;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--plane);
}
.grantgroup { border-bottom: 1px solid var(--rule-soft); }
.grantgroup:last-child { border-bottom: 0; }
.grantgroup__head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .55rem .8rem;
  background: var(--surface-2); border-bottom: 1px solid var(--rule-soft);
  position: sticky; top: 0; z-index: 1;
}
.grantgroup__name {
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em; color: var(--ink-2);
}
.grantgroup__items { display: grid; padding: .25rem 0; }
.grantitem {
  display: flex; align-items: center; gap: .65rem;
  padding: .45rem .8rem; cursor: pointer;
}
.grantitem:hover { background: var(--surface-2); }
.grantitem__id { font-size: .8rem; }

/* ── One-time secret ─────────────────────────────────────────────────── */
.secret {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1rem;
  background: var(--plane); border: 1px dashed var(--accent);
  border-radius: var(--radius);
}
.secret__value {
  font-size: 1.02rem; font-weight: 600; letter-spacing: .04em;
  color: var(--ink); user-select: all; overflow-wrap: anywhere;
}

@media (max-width: 46rem) {
  .modal { padding: 0; place-items: end stretch; }
  .modal__panel {
    width: 100%; max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
  }
  .modal__foot { padding-bottom: calc(.9rem + env(safe-area-inset-bottom)); }
  .modal__foot .btn { flex: 1; }
}

/* ═══════════════════════════════════════════════════════════════════════
   Product identity in ASIN cells
   An ASIN is ten opaque characters. The picture and name sit beside the
   identifier, never instead of it — the ASIN is what people search, paste
   and quote back to Amazon.
   ═══════════════════════════════════════════════════════════════════════ */

.product {
  display: flex; align-items: center; gap: .6rem;
  /* Every title in a catalogue like this opens with the same brand, so a
     narrow column truncates to "Kimm & ..." on every row and says nothing.
     Claim real width and let .tablewrap scroll: a legible name is worth more
     than fitting nine columns on one screen. */
  min-width: 15.5rem; max-width: 24rem;
  border-radius: var(--radius);
}
.product:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.product__thumb {
  width: 2.1rem; height: 2.1rem; flex: none;
  object-fit: contain; border-radius: 2px;
  /* Amazon product shots are on white; a light plate keeps them from
     floating on the dark surface. */
  background: #fff; border: 1px solid var(--rule);
}
.product__thumb--none {
  background: var(--surface-2);
  border-style: dashed;
}

.product__text { display: grid; gap: .05rem; min-width: 0; }
.product__title {
  font-size: .82rem; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.product__asin {
  font-size: .7rem; color: var(--ink-muted); letter-spacing: .02em;
}
.product__asin--only { font-size: .82rem; color: var(--ink); }

/* ── Hover card ──────────────────────────────────────────────────────── */
.pcard {
  position: fixed; z-index: 60; left: 0; top: 0;
  width: 17rem; padding: .7rem;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .12s var(--ease);
}
.pcard[data-show="true"] { opacity: 1; }
.pcard__img {
  width: 100%; height: 11rem; object-fit: contain;
  background: #fff; border-radius: var(--radius); margin-bottom: .55rem;
}
.pcard__title {
  font-size: .84rem; font-weight: 600; line-height: 1.35;
  /* Four lines is enough for an Amazon title to be recognisable without the
     card becoming a wall. */
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.pcard__asin { font-size: .72rem; color: var(--ink-muted); margin-top: .3rem; }

/* Hover cards are useless on touch, where the row tap opens the ASIN anyway. */
@media (hover: none) {
  .pcard { display: none; }
}
@media (max-width: 46rem) {
  .product { max-width: none; }
  .product__title { white-space: normal; }
}

/* ── ASIN as a link to the live detail page ──────────────────────────── */
.product__link {
  color: var(--ink-muted);
  text-decoration: none;
  display: inline-flex; align-items: baseline; gap: .2rem;
  width: fit-content;
  border-radius: 2px;
}
.product__link:hover,
.product__link:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: .18em;
}
.product__link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.product__ext { font-size: .68em; opacity: 0; transition: opacity .12s var(--ease); }
.product__link:hover .product__ext,
.product__link:focus-visible .product__ext { opacity: 1; }

/* The attention banner carries the same cell, so its rows need the same room
   as a table cell and the title must not fight the exposure figure. */
.attn__head .product { min-width: 0; max-width: 30rem; }
.attn__item.rowlink:hover { background: var(--surface-2); }
.attn__item.rowlink:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* ── ASIN page identity header ───────────────────────────────────────── */
.phead {
  display: flex; gap: 1.1rem; align-items: center;
  padding: 1rem 1.15rem;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.phead__img {
  width: 5.5rem; height: 5.5rem; flex: none;
  object-fit: contain; background: #fff;
  border: 1px solid var(--rule); border-radius: var(--radius);
}
.phead__text { display: grid; gap: .4rem; min-width: 0; }
.phead__title {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(1rem, 2.4vw, 1.25rem); line-height: 1.3;
  margin: 0; text-wrap: balance;
}
.phead__meta { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.phead__asin { font-size: .78rem; }

/* ── Selected keyword funnel ─────────────────────────────────────────── */
.funnelstage {
  padding: 1.15rem;
  border-bottom: 1px solid var(--rule-soft);
}
.funnelstage__head {
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
  margin-bottom: .25rem;
}
.funnelstage__term { font-weight: 600; font-size: .95rem; }

/* A column with an explanation earns a hint that one exists. */
th[title] { cursor: help; text-decoration: underline dotted var(--rule); text-underline-offset: .25em; }

@media (max-width: 46rem) {
  .phead { flex-direction: column; align-items: flex-start; }
  .phead__img { width: 4.5rem; height: 4.5rem; }
}
