:root {
  --bg: #f3f0e9;
  --text: #534f49;
  --muted: #6e675f;
  --line: #e0d9ce;
  --hover: rgba(60, 52, 42, 0.045);
  --accent: #8f4d38;
  --accent-ink: #fbf7f2;
  --link: #8f4d38;
  --focus: #8f4d38;
  --input: #fbfaf6;
  --surface: #fbfaf6;
  --band-critical: #a56a62;
  --band-high: #a68456;
  --band-medium: #6f7d55;
  --band-low: #6a7882;
  --band-unscored: #8a847c;
  --shadow: 0 16px 40px rgba(60, 50, 40, 0.08);
  --sans: "Liberation Sans", "Noto Sans", "Segoe UI", sans-serif;
  --mono: "Liberation Mono", "Cascadia Mono", ui-monospace, monospace;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  color-scheme: light;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1e2128;
    --text: #e4e6ee;
    --muted: #a7adba;
    --line: #31363f;
    --hover: rgba(228, 230, 238, 0.06);
    --link: #f0d2c6;
    --focus: #f0d2c6;
    --input: #1e2128;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1e2128;
  --text: #e4e6ee;
  --muted: #a7adba;
  --line: #31363f;
  --hover: rgba(228, 230, 238, 0.06);
  --link: #f0d2c6;
  --focus: #f0d2c6;
  --input: #1e2128;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  font-weight: 400;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.wrap { max-width: 1120px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); }
.skip {
  position: absolute;
  left: var(--s2);
  top: -48px;
  background: var(--text);
  color: var(--bg);
  padding: var(--s2) var(--s3);
  z-index: 50;
}
.skip:focus { top: var(--s2); }
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3) var(--s5);
  padding-bottom: var(--s4);
  margin-bottom: var(--s5);
  border-bottom: 1px solid var(--line);
}
.mark {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: inherit;
  text-decoration: none;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 560;
  letter-spacing: -0.01em;
  margin-right: auto;
}
.mark .kicker { color: var(--muted); }
.nav { display: flex; flex-wrap: wrap; gap: var(--s1); }
.nav a {
  color: var(--muted);
  text-decoration: none;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: var(--s1) var(--s2);
  border-radius: 6px;
}
.nav a[aria-current="page"] { color: var(--text); background: var(--hover); }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.tools form { margin: 0; }
.mode { margin: 0; color: var(--muted); }
.quota { margin: 0; font-size: 13px; color: var(--muted); }
.meter { width: 72px; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; width: calc(var(--fill, 0) * 1%); background: var(--accent); }
h1, h2, h3 { font-weight: 560; letter-spacing: -0.015em; margin: 0 0 var(--s3); line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 var(--s3); }
.lede { color: var(--muted); margin: 0 0 var(--s5); max-width: 62ch; }
.muted { color: var(--muted); }
a { color: var(--link); }
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: var(--s4);
  margin-bottom: var(--s4);
  background: var(--surface);
}
.banner {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: var(--s3) var(--s4);
  margin: 0 0 var(--s4);
  background: transparent;
}
.banner.bad { border-left-color: var(--band-critical); }
.banner.ok { border-left-color: var(--band-medium); }
.summary {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: var(--s2);
  margin: 0 0 var(--s4);
}
.summary dl { display: contents; }
.metric {
  min-width: 0;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric dt {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric dd {
  margin: var(--s1) 0 0;
  font-size: 18px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric dd.is-text { font-size: 13px; font-weight: 500; }
.metric .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--band, var(--band-unscored));
  vertical-align: 1px;
}
.metric[data-band="critical"] { --band: var(--band-critical); }
.metric[data-band="high"] { --band: var(--band-high); }
.metric[data-band="medium"] { --band: var(--band-medium); }
.metric[data-band="low"] { --band: var(--band-low); }
.metric[data-band="unscored"] { --band: var(--band-unscored); }
.tabs { display: flex; gap: var(--s4); margin: 0 0 var(--s4); }
.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding-bottom: var(--s2);
  border-bottom: 2px solid transparent;
}
.tabs a[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: end; margin-bottom: var(--s4); }
.filters .grow { flex: 1 1 240px; }
.field { flex: 1 1 140px; min-width: 0; }
label, .field span, .lbl {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--s1);
}
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--input);
  border-radius: 6px;
  padding: var(--s2) var(--s3);
}
textarea { min-height: 12rem; line-height: 1.55; }
button, .button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  padding: var(--s2) var(--s4);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.secondary, .button.secondary, button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
button.ghost { border-color: transparent; color: var(--muted); padding-inline: var(--s2); }
.row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: end; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.table-wrap { min-height: 120px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: top; padding: var(--s3); border-bottom: 1px solid var(--line); }
.data { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data th, .data td { text-align: left; vertical-align: top; padding: var(--s3); border-bottom: 1px solid var(--line); overflow: hidden; }
.data th { font-size: 12px; font-weight: 500; color: var(--muted); }
.data th a { color: inherit; text-decoration: none; }
.data th a[aria-sort] { color: var(--text); }
.data tbody tr:hover { background: var(--hover); }
.data .c-score { width: 72px; }
.data .c-when { width: 168px; }
.data .c-from { width: 200px; }
.data td.from,
.data td.account { max-width: 200px; min-width: 0; }
.data td.subject { min-width: 0; max-width: 0; }
.from .who { display: block; min-width: 0; max-width: 100%; }
.from .addr { color: var(--muted); font-size: 13px; margin-top: 2px; }
.data .c-action { width: 88px; }
.data .c-cat { width: 112px; }
.data .c-alert { width: 112px; }
.subject a { color: inherit; text-decoration: none; }
.subject a:hover { color: var(--link); }
.clip {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.why { margin: var(--s1) 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.yes { color: var(--link); }
.band { box-shadow: inset 3px 0 0 var(--band, transparent); }
.band-critical { --band: var(--band-critical); }
.band-high { --band: var(--band-high); }
.band-medium { --band: var(--band-medium); }
.band-low { --band: var(--band-low); }
.band-unscored { --band: var(--band-unscored); }
.empty, .status-line { margin: var(--s4) 0; color: var(--muted); }
.status-line[data-error="true"] { color: var(--text); }
.pager { display: flex; gap: var(--s4); align-items: center; margin-top: var(--s4); }
.pager a { color: var(--link); }
.list-region.is-loading { opacity: 0.55; }
.backdrop, .drawer { position: fixed; }
.backdrop {
  inset: 0;
  background: rgba(6, 7, 10, 0.55);
  z-index: 30;
  opacity: 0;
}
.drawer {
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100%);
  z-index: 31;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: auto;
  padding: var(--s5);
  opacity: 0;
  transform: translateX(16px);
}
.backdrop[data-open="true"], .drawer[data-open="true"] { opacity: 1; transform: none; }
.drawer-head { display: flex; justify-content: space-between; gap: var(--s3); align-items: flex-start; margin-bottom: var(--s4); }
.drawer h2 { font-size: 22px; margin: 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: var(--s2) var(--s3); margin: 0 0 var(--s5); }
.kv dt { margin: 0; color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; }
.content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--line);
  padding-top: var(--s4);
  margin: 0 0 var(--s5);
}
.history { margin: 0 0 var(--s5); }
.history li { margin: 0 0 var(--s3); }
.login-card { max-width: 26rem; margin: 12vh auto; padding: var(--s6); border: 1px solid var(--line); border-radius: 8px; }
.prose p, .prose li { max-width: 68ch; }
.prose h2 { margin-top: var(--s5); }
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: 1fr; }
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .drawer, .backdrop, .list-region { transition: opacity 180ms ease-out, transform 180ms ease-out; }
}
@media (max-width: 960px) {
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .wrap { padding: var(--s4) var(--s4) var(--s6); }
  h1 { font-size: 24px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data, .data tbody { display: block; }
  .data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .data tr {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: var(--s3);
    margin-bottom: var(--s2);
  }
  .data td {
    display: flex;
    justify-content: space-between;
    gap: var(--s3);
    border: 0;
    padding: var(--s1) 0;
  }
  .data td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    flex: 0 0 38%;
  }
  .data td.from,
  .data td.subject,
  .data td.account { max-width: none; }
  .data td.from .who { flex: 1; min-width: 0; }
  .data td.subject { display: block; order: -1; padding-bottom: var(--s2); }
  .data td.subject::before { display: none; }
  .data td.subject .clip { white-space: normal; }
  .why { white-space: normal; }
  .drawer { width: 100%; border-left: 0; padding: var(--s4); }
  .kv { grid-template-columns: 1fr; gap: var(--s1); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
