:root {
  /* Accent gradient (topbar rule, sign-in card) */
  --brand-cyan: #00eff9;
  --brand-lavender: #abc0ff;
  --brand-pink: #eb86ff;
  --brand-gradient: linear-gradient(90deg, var(--brand-cyan), var(--brand-lavender), var(--brand-pink));

  --bg: #f7f6fa;
  --surface: #ffffff;
  --surface-alt: #faf9fc;
  --text: #101831; /* the stattoo logo's ink */
  --muted: #6b6578;
  --border: #e6e3ec;
  --accent: #6741d9;
  --accent-ink: #ffffff;
  --link: #6741d9;
  --danger: #c92a2a;
  --danger-border: #f1c0c0;
  --ok-bg: #ebfbee;
  --ok-ink: #2b8a3e;
  --err-bg: #fff5f5;
  --err-ink: #c92a2a;
  --code-bg: #f1eff5;
  --spark: #00a3c4;
  --radius: 8px;
  color-scheme: light;
}

/* Dark: follows the system unless the theme toggle picked light, or forced
   by the toggle. Keep the two blocks below identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171519;
    --surface: #211e25;
    --surface-alt: #1c1a20;
    --text: #ece9f1;
    --muted: #a29dae;
    --border: #34303a;
    --accent: #00d9ea;
    --accent-ink: #171519;
    --link: #3fe4f2;
    --danger: #ff8787;
    --danger-border: #5c2b30;
    --ok-bg: #1d2b21;
    --ok-ink: #8ce99a;
    --err-bg: #2f1d20;
    --err-ink: #ffa8a8;
    --code-bg: #2a2630;
    --spark: #3fe4f2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171519;
  --surface: #211e25;
  --surface-alt: #1c1a20;
  --text: #ece9f1;
  --muted: #a29dae;
  --border: #34303a;
  --accent: #00d9ea;
  --accent-ink: #171519;
  --link: #3fe4f2;
  --danger: #ff8787;
  --danger-border: #5c2b30;
  --ok-bg: #1d2b21;
  --ok-ink: #8ce99a;
  --err-bg: #2f1d20;
  --err-ink: #ffa8a8;
  --code-bg: #2a2630;
  --spark: #3fe4f2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Author display rules (e.g. .stack label { display: flex }) would otherwise beat [hidden]. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h1 a { color: inherit; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 1.5rem; padding-bottom: 3rem; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: relative; }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--brand-gradient); }
.topbar .brand img { display: block; height: 42px; width: auto; }
.topbar__inner { display: flex; align-items: center; gap: 1.25rem; height: 56px; }
.topbar a { color: var(--muted); }
.topbar a.active, .topbar a:hover { color: var(--text); text-decoration: none; }
.topbar .brand { color: var(--text); font-weight: 700; }
.spacer { flex: 1; }
.brand { font-weight: 700; letter-spacing: -.02em; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }

.button, input[type=submit].button {
  display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: .45rem .9rem; border-radius: var(--radius); font: inherit; font-weight: 500; cursor: pointer; line-height: 1.3;
}
.button:hover { text-decoration: none; filter: brightness(1.05); }
.button--ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.button--danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.button--small { padding: .3rem .7rem; font-size: .9em; }
.link-button { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; }
.topbar .link-button { color: var(--muted); }
.button_to, form.button_to { display: inline; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin: 1rem 0; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card__head h2 { margin: 0; }
.card--danger { border-color: var(--danger-border); }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--muted); }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-alt); }
.table tr:last-child td { border-bottom: 0; }
.table--compact { border: 0; }
.table--compact td { padding: .4rem 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > * + * { margin-left: .75rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; }
.stat__label { display: block; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat__value { display: block; font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 1rem; }

.range-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .9rem; }
.range-form input[type=date] { padding: .3rem .4rem; }
.check { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
.narrow { max-width: 480px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%;
}
.range-form input[type=date] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }

.flash { padding: .6rem .9rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash ul { margin: 0; padding-left: 1.1rem; }
.flash--notice { background: var(--ok-bg); color: var(--ok-ink); }
.flash--alert { background: var(--err-bg); color: var(--err-ink); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.code { background: #101828; color: #e6edf3; border: 1px solid var(--border); padding: 1rem; border-radius: var(--radius); overflow-x: auto; white-space: pre; }
.token { font-size: 1rem; word-break: break-all; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .1rem .75rem; margin: 0; font-size: .85rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; }
.auth-card .brand { margin: 0 0 1.5rem; }
.auth-card .brand img { display: block; height: 106px; width: auto; margin: 0 auto; }
.auth-card { position: relative; overflow: hidden; }
.auth-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--brand-gradient); }
.auth-card .button { width: 100%; }

@media (max-width: 640px) {
  .table.events td:nth-child(4), .table.events th:nth-child(4) { display: none; }
}

.sankey { position: relative; width: 100%; }

.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin-right: -6px;
  border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.theme-toggle:hover { color: var(--text); background: var(--surface-alt); }
.theme-toggle:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.theme-toggle svg { width: 18px; height: 18px; display: none; }
.theme-toggle[data-theme-mode="system"] .icon-system,
.theme-toggle[data-theme-mode="light"] .icon-light,
.theme-toggle[data-theme-mode="dark"] .icon-dark { display: block; }

.spark-cell { padding-top: .35rem !important; padding-bottom: .35rem !important; width: 1%; }
.spark { display: block; overflow: visible; }
.spark__line { fill: none; stroke: var(--spark); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark__area { fill: var(--spark); opacity: .14; }
.spark__dot { fill: var(--spark); }
.spark--empty .spark__line { stroke: var(--border); }
@media (max-width: 640px) { .spark { width: 72px; } }

.suggestion { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin: 0 0 1rem; padding: .75rem 1rem; border: 1px solid var(--border); border-left: 3px solid var(--spark);
  border-radius: var(--radius); background: var(--surface); }
.suggestion__text { display: flex; flex-direction: column; gap: .15rem; }
.suggestion .actions form { margin: 0; }

.chart-panel { display: block; }
.chart-panel__loading { min-height: 4rem; }
.retention-scroll { overflow-x: auto; }
.retention { border-collapse: separate; border-spacing: 4px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.retention th { font-weight: 600; text-align: left; padding: .25rem .5rem; white-space: nowrap; }
.retention thead th { font-size: .8rem; color: var(--muted); text-align: center; }
.retention thead th:first-child { text-align: left; }
.retention td.num { padding: 0 .75rem 0 .25rem; color: var(--muted); }
.retention__cell { min-width: 3.75rem; padding: .45rem .5rem; border-radius: 6px; text-align: center; font-weight: 600;
  background: color-mix(in srgb, var(--spark) var(--mix, 0%), var(--surface-alt)); color: var(--text); }
.retention__cell--strong { color: #171519; }
.retention__cell--pending { background: var(--surface-alt); color: var(--muted); font-weight: 400; }

.page-foot { margin-top: 1.5rem; text-align: center; }
.notice-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.notice-bar p { margin: 0; }

/* Top events: chart icon with a hover/focus menu (app page). */
.top-events { overflow: visible; }
.top-events .chart-menu-cell { width: 1.75rem; padding-left: .5rem; text-align: right; }
.chart-menu { position: relative; display: inline-block; }
.chart-menu__trigger { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; opacity: .55; }
.chart-menu__trigger svg { width: 1rem; height: 1rem; }
.top-events tr:hover .chart-menu__trigger, .chart-menu:focus-within .chart-menu__trigger { opacity: 1; }
.chart-menu:hover .chart-menu__trigger, .chart-menu:focus-within .chart-menu__trigger { color: var(--accent); background: var(--code-bg); }
.chart-menu__popover {
  display: none; position: absolute; right: 0; top: 100%; z-index: 20; min-width: 12rem; max-width: 18rem;
  padding: .3rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / .14);
}
/* Hover bridge so the pointer can travel from the icon into the menu. */
.chart-menu__popover::before { content: ""; position: absolute; left: 0; right: 0; top: -.4rem; height: .4rem; }
.chart-menu:hover .chart-menu__popover, .chart-menu:focus-within .chart-menu__popover { display: block; }
.chart-menu__popover form { margin: 0; }
.chart-menu__item {
  display: block; width: 100%; padding: .45rem .6rem; border: 0; border-radius: 6px; background: none;
  color: var(--text); font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chart-menu__item:hover, .chart-menu__item:focus-visible { background: var(--code-bg); color: var(--link); outline: none; }
.chart-menu__item--done { color: var(--muted); cursor: default; }
.chart-menu__item--done:hover { background: none; color: var(--muted); }
.chart-menu__item--new { border-top: 1px solid var(--border); border-radius: 0 0 6px 6px; margin-top: .2rem; }
.chart-menu__popover > :first-child .chart-menu__item--new, .chart-menu__popover > .chart-menu__item--new:first-child { border-top: 0; margin-top: 0; }

/* Logo: dark ink in light mode, white in dark mode (same theme rules as the
   colour tokens above). */
.logo--on-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo--on-light { display: none !important; }
  :root:not([data-theme="light"]) .logo--on-dark { display: block !important; }
}
:root[data-theme="dark"] .logo--on-light { display: none !important; }
:root[data-theme="dark"] .logo--on-dark { display: block !important; }
