/* Prism application styles.
   Tokens mirror the chart chrome in render.py so the page and the charts sit on
   the same surfaces in both themes.  No inline styles anywhere: the CSP is
   style-src 'self' with nothing relaxed. */

:root {
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --edge: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d03b3b;
  --good: #006300;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --edge: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --danger: #e66767;
    --good: #0ca30c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --edge: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --danger: #e66767;
  --good: #0ca30c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 25px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; letter-spacing: -0.005em; }
p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }
.meta { color: var(--muted); font-size: 12.5px; }
.meta.err { color: var(--danger); }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink2); }
code.small { font-size: 11px; word-break: break-all; }

/* Header ----------------------------------------------------------------- */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--edge);
  position: sticky;
  top: 0;
  z-index: 10;
}
.bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { font-weight: 620; color: var(--ink); letter-spacing: -0.02em; font-size: 16px; }
.bar nav { display: flex; gap: 18px; flex: 1; }
.bar nav a { color: var(--ink2); font-size: 14px; padding: 4px 0; }
.bar nav a.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.account { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.who { color: var(--ink2); display: flex; gap: 6px; align-items: baseline; }
.who em { font-style: normal; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

main.container { max-width: 1040px; margin: 0 auto; padding: 28px 24px 72px; }
main.wide { max-width: 1400px; margin: 0 auto; padding: 28px 24px 72px; }

/* Cards ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 18px;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-head h2 { flex: 1; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-actions.row { margin-bottom: 18px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }

.empty { padding: 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }
.empty p { margin: 0 0 12px; }

/* Lists and tables ------------------------------------------------------- */

ul.list { list-style: none; margin: 0; padding: 0; }
ul.list li {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
ul.list li:last-child { border-bottom: 0; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 0; }
tbody tr:last-child td { border-bottom: 0; }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--edge); color: var(--ink2); }
.pill.active { color: var(--good); border-color: currentColor; }
.pill.revoked, .pill.expired { color: var(--danger); border-color: currentColor; }

/* Forms ------------------------------------------------------------------ */

form.stack { display: grid; gap: 14px; }
form.inline { display: inline; }
form.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: grid; gap: 5px; font-size: 13px; color: var(--ink2); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.45; }

input, select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--plane);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 0; display: grid; gap: 12px; }
legend { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0 6px; }

.btn {
  display: inline-block;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }

.flash { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin: 0 0 16px; border: 1px solid var(--edge); }
.flash.error { color: var(--danger); border-color: currentColor; }
.flash.ok { color: var(--good); border-color: currentColor; }

/* Sign-in ---------------------------------------------------------------- */

.signin {
  max-width: 380px;
  margin: 8vh auto;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 28px;
}
.signin h1 { margin-bottom: 2px; }

/* Chart builder ---------------------------------------------------------- */

.builder { display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .builder { grid-template-columns: 1fr; } }

.builder-controls .builder-form {
  display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 18px;
  position: sticky; top: 72px;
  max-height: calc(100vh - 96px); overflow-y: auto;
}
.builder-buttons { display: flex; gap: 8px; }

.chart-frame {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 8px;
  overflow-x: auto;
}
.chart-frame svg { width: 100%; height: auto; display: block; max-width: 100%; }

/* Dashboard grid --------------------------------------------------------- */

.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; margin-bottom: 20px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 8px;
  overflow: hidden;
  min-width: 0;
}
.tile svg { width: 100%; height: auto; display: block; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; }
.span-10 { grid-column: span 10; }
.span-11 { grid-column: span 11; }
.span-12 { grid-column: span 12; }
@media (max-width: 800px) {
  .dash-grid { grid-template-columns: 1fr; }
  .tile[class*="span-"] { grid-column: 1 / -1; }
}

/* Public share and embed ------------------------------------------------- */

body.public { background: var(--plane); }
body.embed { background: transparent; }

.share-wrap { max-width: 1000px; margin: 0 auto; padding: 20px; }
body.embed .share-wrap { padding: 0; max-width: none; }
body.embed .chart-frame { border: 0; border-radius: 0; padding: 0; background: transparent; }

.public-head { margin-bottom: 14px; }
.public-head h1 { font-size: 22px; }
.share-actions { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
body.embed .share-actions { margin: 8px 0 0; }
.caption { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }
.datatable {
  background: var(--surface); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 14px; margin-top: 6px;
}
.public-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 40px; }

input.copy, textarea.copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
input.copy { cursor: pointer; }

/* Share links: shown in full for as long as the link exists. */
.share-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  display: grid;
  gap: 12px;
}
.share-card.fresh { border-color: var(--accent); }
.share-card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.share-card-head strong { font-size: 14px; }
.share-card-head .facts { color: var(--muted); font-size: 12.5px; flex: 1; }
.share-card details > summary,
.new-share > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 550;
  list-style: none;
}
.share-card details > summary::-webkit-details-marker,
.new-share > summary::-webkit-details-marker { display: none; }
.share-card details > summary::before,
.new-share > summary::before { content: "▸ "; }
.share-card details[open] > summary::before,
.new-share[open] > summary::before { content: "▾ "; }
.share-card details > .stack { margin-top: 12px; }
.new-share { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.new-share > form { margin-top: 14px; }

/* Viewer filters ---------------------------------------------------------
   One row above the charts, per the data-viz standard. Wraps rather than
   scrolls, so a phone stacks them instead of hiding them. */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 16px;
}
.filter { display: grid; gap: 4px; min-width: 150px; flex: 0 1 auto; }
.filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.filter select, .filter input { font-size: 13.5px; padding: 6px 9px; }
.filter-range { display: flex; align-items: center; gap: 6px; }
.filter-range input { width: 100%; min-width: 96px; }
.filter-sep { color: var(--muted); font-size: 12px; }
.filter-actions { display: flex; gap: 8px; margin-left: auto; }
.filter-bar.compact { padding: 8px 10px; gap: 8px; }

@media (max-width: 620px) {
  .filter { min-width: 0; flex: 1 1 100%; }
  .filter-actions { margin-left: 0; width: 100%; }
}

/* Hover tooltip (progressive enhancement only) --------------------------- */

.pz-tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  line-height: 1.4;
  padding: 6px 9px;
  border-radius: 7px;
  max-width: 260px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.pz-tip b { display: block; font-weight: 600; }

@media print {
  .top, .share-actions, .builder-controls { display: none; }
  .card, .tile, .chart-frame { border-color: #ccc; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
