/* Layout: one narrow reading column, sticky top bar, lists as rows not cards. Opened = green, waiting = slate, hot = amber. */
:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --fg: #1c2420;
  --muted: #5f6b65;
  --line: #e1e5e2;
  --accent: #1d6b48;
  --accent-soft: #e3f1e9;
  --warn: #a35d00;
  --warn-soft: #fdf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --surface: #1a201d; --fg: #e5ebe7; --muted: #9aa8a0; --line: #2b332f;
    --accent: #5cc694; --accent-soft: #1d3329; --warn: #f0b45c; --warn-soft: #3a2c16; --bad: #f28b82; --bad-soft: #3b1f1d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --surface: #1a201d; --fg: #e5ebe7; --muted: #9aa8a0; --line: #2b332f;
  --accent: #5cc694; --accent-soft: #1d3329; --warn: #f0b45c; --warn-soft: #3a2c16; --bad: #f28b82; --bad-soft: #3b1f1d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 var(--font-body); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: .85em; }
.num { font-variant-numeric: tabular-nums; }

.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { max-width: 960px; margin: 0 auto; display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--fg); }
.brand:hover { text-decoration: none; }
.ticks { color: var(--accent); letter-spacing: -4px; font-weight: 700; margin-right: 4px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
nav a.on { color: var(--fg); background: var(--accent-soft); }
nav a:hover { text-decoration: none; color: var(--fg); }

.wrap { max-width: 960px; margin: 0 auto; padding-block: 24px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 20px; }
.panel > h2 { margin-bottom: 12px; }

input[type=text], input[type=search], input[type=number], input[type=date], select, textarea {
  font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
input[type=number] { width: 5.5em; }
textarea { width: 100%; min-height: 5em; font-family: var(--font-mono); font-size: .85rem; }
button, .btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 7px 14px; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button:disabled { opacity: .55; cursor: default; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: inherit; font-size: .9rem; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* Email list */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.item { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--fg); }
.item:first-child { border-top: 0; }
.item:hover { background: var(--bg); text-decoration: none; }
.mark { font-weight: 700; letter-spacing: -4px; color: var(--muted); padding-top: 1px; }
.mark.open { color: var(--accent); }
.subj { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { color: var(--muted); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: .88rem; text-align: right; white-space: nowrap; }
.meta { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: .78rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); letter-spacing: .02em; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .92rem; }
.timeline .x { color: var(--muted); font-size: .88rem; }
.not-counted { opacity: .6; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; }
.stat .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .d { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font: 11px var(--font-body); }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); white-space: nowrap; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-top: 0; }
td.r, th.r { text-align: right; }

/* Settings */
.field { display: grid; grid-template-columns: minmax(0, 15em) minmax(0, 1fr); gap: 8px 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field > label:first-child, .field > .lbl { font-weight: 600; }
.field .help { grid-column: 2; color: var(--muted); font-size: .88rem; margin-top: -4px; }
.check { display: inline-flex; gap: 8px; align-items: center; margin-right: 16px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg);
  padding: 10px 18px; border-radius: 6px; font-weight: 600; z-index: 20; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.signin { max-width: 26em; margin: 12vh auto 0; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.token { font-family: var(--font-mono); font-size: .85rem; background: var(--bg); padding: 8px 10px; border-radius: 6px; word-break: break-all; }

@media (max-width: 640px) {
  .item { grid-template-columns: 1.8em minmax(0, 1fr); }
  .when { grid-column: 2; text-align: left; }
  .meta { grid-column: 2; }
  .field { grid-template-columns: minmax(0, 1fr); }
  .field .help { grid-column: 1; }
  .timeline li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
