/* MailMark: one stylesheet for the sign-in page and the app. */
:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --ink: #1d2433;
  --ink-soft: #4a5468;
  --ink-faint: #7a8396;
  --line: #dde1ea;
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --ok: #1d7a4a;
  --warn: #9a6200;
  --bad: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 4px 16px rgba(20, 30, 60, 0.06);
  --bar-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141b;
    --panel: #1a1f29;
    --ink: #e8ebf2;
    --ink-soft: #b4bbca;
    --ink-faint: #8790a3;
    --line: #2c3342;
    --brand: #6f95ff;
    --brand-ink: #0c1020;
    --brand-soft: #1e2a4a;
    --ok: #57c48a;
    --warn: #e0a640;
    --bad: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h1 { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.8rem); }
h2 { font-size: 1.2rem; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar (pinned) ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar__inner {
  max-width: 1400px;
  margin: 0 auto;
  min-height: var(--bar-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  min-height: 44px;
  flex: none;
}
.brand__mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 800;
}
.brand small { display: block; font-weight: 400; font-size: 0.72rem; color: var(--ink-faint); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.nav a, .nav button {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px;
  border-radius: 8px; color: var(--ink-soft); text-decoration: none; font: inherit;
  background: none; border: 0; cursor: pointer;
}
.nav a:hover, .nav button:hover { background: var(--brand-soft); color: var(--ink); }
.nav a[aria-current='page'] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.bar .nav__toggle { display: none; margin-left: auto; }
@media (max-width: 900px) {
  .bar .nav__toggle { display: inline-flex; }
  .nav { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--panel);
    border-bottom: 1px solid var(--line); padding: 8px 16px 12px; flex-direction: column; align-items: stretch; }
  .nav.is-open { display: flex; }
  .nav a, .nav button { min-height: 44px; }
}

/* ---------- layout ---------- */
.page:focus { outline: none; }
.page { max-width: 1400px; margin: 0 auto; padding: 24px 16px 64px; }
.page__head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 20px; }
.page__head h1 { margin: 0; margin-right: auto; }
main h1, main h2 { scroll-margin-top: calc(var(--bar-h) + 12px); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.two { display: grid; gap: 20px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .two { grid-template-columns: minmax(0, 1fr); } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.grid > .card, .cards > .card { margin-top: 0; }
.stat { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat__label { color: var(--ink-faint); font-size: 0.9rem; }
.muted { color: var(--ink-faint); }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--brand-soft); margin-bottom: 16px; }
.notice--bad { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; background: var(--brand-soft); color: var(--ink-soft); white-space: nowrap; }
.pill--ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill--bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill--warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type='text'], input[type='email'], input[type='password'], input[type='search'], input[type='tel'], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.check { display: flex; gap: 10px; align-items: center; font-weight: 400; min-height: 40px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row > * { flex: 0 1 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--brand); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn--danger { color: var(--bad); }
.btn--small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.6; cursor: progress; }
.status { min-height: 1.5em; margin-top: 12px; }
.status[data-tone='bad'] { color: var(--bad); }
.status[data-tone='ok'] { color: var(--ok); }

/* ---------- tables: scroll in their own box, stack on phones ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); white-space: nowrap; }
th button { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; min-height: 32px; padding: 0; text-transform: inherit; letter-spacing: inherit; }
tr:last-child td { border-bottom: 0; }
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack td { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 8px; border: 0; padding: 6px 12px; }
  table.stack td::before { content: attr(data-label); font-weight: 600; color: var(--ink-faint); font-size: 0.85rem; }
}

/* ---------- list cards ---------- */
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min, 280px)), 1fr)); }
.cards[data-size='small'] { --card-min: 220px; }
.cards[data-size='large'] { --card-min: 380px; }
.list-card { container-type: inline-size; }
.list-card h3 { display: flex; gap: 8px; align-items: flex-start; }
.list-card h3 span { flex: 1; overflow-wrap: anywhere; }
.list-card__meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
@container (min-width: 360px) { .list-card__numbers { display: flex; gap: 24px; } }
.star { background: none; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--ink-faint); min-width: 40px; min-height: 40px; }
.star[aria-pressed='true'] { color: #e0a100; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type='search'] { flex: 1 1 220px; width: auto; }
.toolbar select { width: auto; flex: 0 1 auto; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 20px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 14, 24, 0.5); }
.secret { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: var(--bg); padding: 10px; border-radius: 8px; }

/* ---------- sign-in page ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth__box { width: min(440px, 100%); }
.auth__box .brand { justify-content: center; margin-bottom: 16px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-faint); margin: 18px 0; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.wide { width: 100%; }
.handoff { display: grid; place-items: center; min-height: 100vh; color: var(--ink-soft); }
.audit-change { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 48ch; }
