/* Tokens mirror workspace/frontend/src/index.css so the service reads as one
   surface with its parent. One accent, everything else grey. */
:root {
  --bg: #ffffff;
  --surface: #f5f5f7;
  --line: #e4e4e8;
  --line-strong: #c9c9d0;
  --ink: #18181c;
  --ink-muted: #70707a;
  --ink-faint: #a0a0aa;
  --accent: #2b4c7e;
  --accent-soft: #e8eef8;
  --danger: #b93a2b;
  --danger-soft: #f9e9e6;
  --ok: #2f7d4f;
  --warn: #b8791c;
  --radius-sm: 6px;
  --radius-md: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141417;
    --surface: #1c1c21;
    --line: #2a2a31;
    --line-strong: #3a3a44;
    --ink: #ececf0;
    --ink-muted: #9a9aa6;
    --ink-faint: #61616c;
    --accent: #7e9fd4;
    --accent-soft: #1f2a3d;
    --danger: #e06a5a;
    --danger-soft: #3a211d;
    --ok: #5cb57f;
    --warn: #d9a04a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }

.boot { padding: 24px; color: var(--ink-muted); }

/* ---- page frame ---- */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 24px 96px; }
@media (max-width: 720px) { .page { padding: 16px 16px 96px; } }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0; min-width: 0; overflow-wrap: anywhere; }
h2 { font-size: 15px; font-weight: 500; margin: 0; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); margin-bottom: 12px; }
.back:hover { color: var(--ink); }

section { margin-top: 28px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius-md);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink); opacity: 0.9; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; color: var(--ink-muted); }
.btn-ghost:hover { color: var(--ink); }
.btn-sm { height: 28px; padding: 0 10px; }

/* Segmented control: quiet, the active option gets the only tinted fill. */
.seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--radius-md); background: var(--surface); }
.seg button { height: 26px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--ink-muted); }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.dates { display: inline-flex; align-items: center; gap: 6px; }
.dates input { height: 28px; padding: 0 6px; border: 0; border-bottom: 1px solid var(--line-strong); background: transparent; }
.dates input:focus { outline: 0; border-bottom-color: var(--ink); }

/* Icon buttons, 28px square. Row actions hide until hover on pointer devices. */
.icon {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--ink-muted);
}
.icon:hover { background: var(--surface); color: var(--ink); }
.icon.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Inline result next to the button that caused it: grey fades, red stays. */
.status { color: var(--ink-muted); min-height: 1.45em; transition: opacity 0.6s; }
.status.err { color: var(--danger); }
.status.fade { opacity: 0; }

/* ---- spinner lives inside the button ---- */
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- chart ---- */
.chart { position: relative; margin-top: 12px; height: 180px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .area { fill: var(--accent); fill-opacity: 0.08; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .cursor { stroke: var(--line-strong); stroke-width: 1; }
.chart .dot { fill: var(--bg); stroke: var(--accent); stroke-width: 1.75; }
.chart .peak { fill: var(--accent); }
.chart-labels { display: flex; justify-content: space-between; color: var(--ink-faint); font-size: 12px; margin-top: 4px; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none;
  padding: 2px 8px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line);
  white-space: nowrap; font-size: 12px;
}
.chart-tip b { font-weight: 600; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-faint); }

/* Text under the chart carries the numbers; the chart itself has no axis. */
.digest { margin-top: 12px; display: grid; gap: 2px; }
.digest .row { display: flex; flex-wrap: wrap; gap: 0 20px; }
.digest strong { font-weight: 600; }

/* ---- table ---- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.search { height: 32px; width: 240px; max-width: 100%; padding: 0 8px; border: 0; border-bottom: 1px solid var(--line); background: transparent; }
.search:hover { border-bottom-color: var(--line-strong); }
.search:focus { outline: 0; border-bottom-color: var(--ink); }
.search::placeholder { color: var(--ink-faint); }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-weight: 500; color: var(--ink-muted); padding: 10px 8px;
  border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--ink); }
thead th.sorted { color: var(--ink); }
thead th .arrow { display: inline-block; width: 1em; color: var(--ink-faint); }
tbody td { padding: 0 8px; height: 44px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: var(--surface); }
tbody tr.deleted .slug, tbody tr.deleted .dest { color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--line-strong); }
tbody tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
td.check, th.check { width: 36px; padding-right: 0; }
td.check input, th.check input { display: block; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
td.slug-cell { min-width: 140px; }
.slug { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; cursor: pointer; max-width: 100%; }
.slug:hover { text-decoration: underline; text-underline-offset: 3px; }
td.dest { max-width: 320px; color: var(--ink-muted); }
.ellip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.src { color: var(--ink-muted); white-space: nowrap; max-width: 140px; }
td.num { width: 84px; }
td.acts { width: 100px; white-space: nowrap; text-align: right; }
.acts .icon { opacity: 0; transition: opacity 0.12s; }
tr:hover .acts .icon, tr:focus-within .acts .icon, .acts .icon.show { opacity: 1; }
@media (hover: none) { .acts .icon { opacity: 1; } }
td.confirm { color: var(--ink-muted); }
td.confirm .btn { margin-left: 8px; }
.empty { padding: 32px 8px; color: var(--ink-muted); }
.table-foot { display: flex; justify-content: flex-end; gap: 16px; padding: 10px 8px; color: var(--ink-muted); }
.table-foot label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.table-foot input { accent-color: var(--accent); margin: 0; }

/* Phones: each row becomes a block. Columns are placed by grid areas so the
   markup stays one <table> for both layouts. */
@media (max-width: 720px) {
  thead { display: none; }
  table, tbody { display: block; }
  tbody tr {
    display: grid; grid-template-columns: 24px 1fr auto; grid-template-areas:
      "check slug acts"
      ". dest dest"
      ". nums nums";
    padding: 10px 0; border-bottom: 1px solid var(--line); gap: 2px 8px;
  }
  tbody tr:hover { background: transparent; }
  tbody tr.selected td:first-child { box-shadow: none; }
  tbody tr.selected { box-shadow: inset 2px 0 0 var(--accent); padding-left: 6px; }
  tbody td { display: block; height: auto; padding: 0; border: 0; }
  td.check { grid-area: check; padding-top: 3px; }
  td.slug-cell { grid-area: slug; }
  td.dest { grid-area: dest; max-width: none; }
  td.src { display: none; }
  td.acts { grid-area: acts; width: auto; }
  td.confirm { grid-column: 2 / -1; }
  td.nums { grid-area: nums; display: flex; gap: 16px; color: var(--ink-muted); }
  td.nums b { color: var(--ink); font-weight: 500; }
  td.num.d { display: none; }
  .table-foot { justify-content: flex-start; }
}
@media (min-width: 721px) { td.nums { display: none; } }

/* ---- floating add button ---- */
.fab {
  position: fixed; right: 24px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--ink); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.fab:hover { transform: scale(1.05); }
.fab svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }
@media (max-width: 720px) { .fab { right: 16px; } }

/* ---- forms: a list of facts, not a wall of inputs ---- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0 24px; }
.facts > div { display: contents; }
.facts dt { color: var(--ink-muted); padding: 10px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.facts dd { margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); min-width: 0; display: flex; align-items: center; gap: 8px; }
.facts dd.plain { padding: 10px 0; }
.field {
  width: 100%; padding: 4px 0; border: 0; border-bottom: 1px solid transparent; background: transparent;
  border-radius: 0; min-width: 0;
}
.field:hover { border-bottom-color: var(--line-strong); }
.field:focus { outline: 0; border-bottom-color: var(--ink); }
.field::placeholder { color: var(--ink-faint); }
.field:disabled { color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
textarea.field { resize: vertical; min-height: 56px; line-height: 1.45; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.preview { color: var(--ink-muted); font-size: 13px; }
@media (max-width: 720px) {
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { padding: 10px 0 0; border: 0; font-size: 12px; }
  .facts dd { padding-top: 2px; }
}

/* Create form slides the table down, no modal. */
.create { margin-top: 16px; padding: 4px 0 16px; border-bottom: 1px solid var(--line); }
.create h2 { margin-bottom: 6px; }

/* ---- link page ---- */
.link-url { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); min-width: 0; }
.link-url .u { overflow-wrap: anywhere; }
.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 40px; }
.bd h3 { font-size: 14px; font-weight: 500; color: var(--ink-muted); margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.bd ul { list-style: none; margin: 0; padding: 0; }
.bd li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.bd li .n { color: var(--ink); }
.bd li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd .none { padding: 8px 0; color: var(--ink-faint); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.feed .when { color: var(--ink-muted); white-space: nowrap; }
.feed .where { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .what { color: var(--ink-muted); white-space: nowrap; }
.feed .bot { color: var(--ink-faint); }
@media (max-width: 720px) {
  .feed li { grid-template-columns: 1fr; gap: 0; }
}
.more { margin-top: 12px; }
.danger-zone { margin-top: 40px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
