/* PMG quarantine portal
   One typeface (Atkinson Hyperlegible, built for legibility), cool envelope-grey
   ground, and one memorable element: spam scores drawn as postmark stamps. */

@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

:root {
  --ground: #e9edf1;
  --surface: #ffffff;
  --ink: #16202a;
  --muted: #5a6673;
  --line: #d3dae1;
  --line-strong: #b4bfc9;
  --release: #11735f;
  --release-ink: #ffffff;
  --release-soft: #e1f2ed;
  --high: #b3261e;
  --mid: #9a5800;
  --low: #4f6b7a;
  --danger-soft: #fbe9e7;
  --focus: #1d5fd1;
  --radius: 6px;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #12181e;
    --surface: #1a2229;
    --ink: #e6ebef;
    --muted: #9aa7b3;
    --line: #2c3740;
    --line-strong: #44525e;
    --release: #3fb497;
    --release-ink: #07231c;
    --release-soft: #173a31;
    --high: #f0796f;
    --mid: #e0a24a;
    --low: #8fb0c0;
    --danger-soft: #3b1d1b;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Atkinson", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  font-variant-numeric: tabular-nums;
}

a { color: inherit; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: var(--step-2); }
h2 { font-size: var(--step-1); }
p { margin: 0 0 1em; max-width: 68ch; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: var(--step-1); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
.brand svg { flex: none; }
.topbar nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none; padding: 0.35rem 0.7rem; border-radius: var(--radius); color: var(--muted);
}
.topbar nav a[aria-current="page"] { color: var(--ink); background: var(--ground); font-weight: 700; }
.topbar nav a:hover { color: var(--ink); }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: var(--step--1); }
.topbar .who form { margin: 0; }

.domain-switch select { font-weight: 700; }

main { padding: clamp(1rem, 3vw, 2rem); max-width: 1400px; margin: 0 auto; }
main.narrow { max-width: 760px; }

/* ---------- form controls ---------- */

label { display: block; font-weight: 700; margin-bottom: 0.25rem; }
.hint { display: block; color: var(--muted); font-size: var(--step--1); font-weight: 400; margin-top: 0.2rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="url"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 0.5rem 0.65rem; min-height: 2.5rem; width: 100%;
}
textarea { min-height: 7rem; font-size: var(--step--1); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 0; }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--release); margin: 0; vertical-align: middle; }

.check { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 0.2rem; }

.field { margin-bottom: 1.1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1.25rem; align-items: end; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.5rem; padding: 0.45rem 1rem;
  border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--release); color: var(--release-ink); border-color: var(--release); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--high); }
.btn.danger:hover { border-color: var(--high); }
.btn.small { min-height: 2rem; padding: 0.2rem 0.65rem; font-size: var(--step--1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ---------- notices ---------- */

.notice { border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; border: 1px solid var(--line); background: var(--surface); }
.notice.ok { border-color: var(--release); background: var(--release-soft); }
.notice.error { border-color: var(--high); background: var(--danger-soft); }
.notice p:last-child, .notice ul:last-child { margin-bottom: 0; }
.notice ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }

/* ---------- sign in ---------- */

.signin {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.signin .panel { width: 100%; max-width: 400px; }
.signin h1 { font-size: var(--step-3); letter-spacing: -0.01em; }
.signin .lede { color: var(--muted); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: clamp(1.25rem, 3vw, 2rem);
}

/* ---------- quarantine list ---------- */

.listhead { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.listhead h1 { margin: 0; }
.listhead .count { color: var(--muted); }

.filters {
  display: grid; grid-template-columns: minmax(200px, 2fr) minmax(180px, 1.5fr) 140px 160px;
  gap: 0.75rem; align-items: end; margin-bottom: 1rem;
}
.filters fieldset { grid-column: 1 / -1; order: -1; }
.filters label { font-size: var(--step--1); }
.ranges { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); width: fit-content; }
.ranges label.range { margin: 0; font-weight: 400; border-right: 1px solid var(--line); }
.ranges label.range:last-child { border-right: 0; }
.ranges label.range span { display: block; padding: 0.45rem 0.85rem; color: var(--muted); cursor: pointer; white-space: nowrap; min-height: 2.5rem; line-height: 1.6rem; }
.ranges label.range:hover span { color: var(--ink); }
.ranges input:checked + span { background: var(--ink); color: var(--surface); font-weight: 700; }
.ranges input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -3px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.split.has-preview { grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr); }

.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.mail { width: 100%; border-collapse: collapse; }
table.mail th, table.mail td { padding: 0.6rem 0.75rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.mail thead th { font-size: var(--step--1); color: var(--muted); font-weight: 700; background: var(--surface); position: sticky; top: 0; }
table.mail tbody tr:last-child td { border-bottom: 0; }
table.mail tbody tr:hover { background: color-mix(in srgb, var(--ground) 55%, var(--surface)); }
table.mail tbody tr.is-open { background: var(--release-soft); }
table.mail tbody tr.is-selected { background: color-mix(in srgb, var(--release-soft) 60%, var(--surface)); }
td.sel, th.sel { width: 2.5rem; }
td.stamp-cell { width: 4rem; padding-left: 0.25rem; padding-right: 0.25rem; }
td.when { white-space: nowrap; color: var(--muted); font-size: var(--step--1); width: 8.5rem; }
td.size { white-space: nowrap; color: var(--muted); font-size: var(--step--1); text-align: right; width: 4.5rem; }
.msg { min-width: 0; }
.msg .subject { font-weight: 700; text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 52ch; }
.msg .subject:hover { text-decoration: underline; }
.msg .meta { color: var(--muted); font-size: var(--step--1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60ch; }
.msg .meta b { color: var(--ink); font-weight: 400; }

/* The postmark: the score, stamped. */
.stamp {
  --c: var(--low);
  display: inline-grid; place-items: center;
  width: 2.9rem; height: 2.9rem; border-radius: 50%;
  border: 2px solid var(--c); color: var(--c);
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 4px var(--c);
  font-weight: 700; font-size: 0.74rem; line-height: 1; letter-spacing: -0.02em;
  transform: rotate(-9deg);
}
.stamp.high { --c: var(--high); }
.stamp.mid { --c: var(--mid); }
.stamp.big { width: 3.6rem; height: 3.6rem; font-size: 1.05rem; box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 5.5px var(--c); }

.empty { padding: 3rem 1.5rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: var(--step-1); margin-bottom: 0.25rem; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--step--1); }

/* Sticky action bar, shown once something is ticked. */
.actionbar {
  position: sticky; bottom: 1rem; z-index: 5;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  margin-top: 1rem; padding: 0.6rem 0.75rem 0.6rem 1rem;
  background: var(--ink); color: var(--surface); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 32, 0.25);
}
.actionbar[hidden] { display: none; }
.actionbar .picked { font-weight: 700; margin-right: auto; }
.actionbar .btn { background: transparent; color: var(--surface); border-color: color-mix(in srgb, var(--surface) 40%, transparent); }
.actionbar .btn.primary { background: var(--release); border-color: var(--release); color: var(--release-ink); }
@media (prefers-color-scheme: dark) {
  .actionbar { background: #e6ebef; color: #12181e; }
  .actionbar .btn { color: #12181e; border-color: #8a96a1; }
}

/* ---------- preview ---------- */

.preview {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  position: sticky; top: 1rem; max-height: calc(100vh - 2rem); display: flex; flex-direction: column; overflow: hidden;
}
.preview:empty { display: none; }
.preview header { padding: 1rem 1.1rem 0.75rem; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; }
.preview h2 { font-size: var(--step-1); margin: 0 0 0.5rem; overflow-wrap: anywhere; }
.preview dl { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0; font-size: var(--step--1); }
.preview dt { color: var(--muted); }
.preview dd { margin: 0; overflow-wrap: anywhere; }
.preview .toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; padding: 0.6rem 1.1rem; border-bottom: 1px solid var(--line); }
.preview .toolbar .view-toggle { margin-left: auto; }
.preview .body { overflow: auto; flex: 1; min-height: 12rem; }
.preview pre.text { margin: 0; padding: 1rem 1.1rem; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: var(--step--1); }
.preview iframe { width: 100%; height: 100%; min-height: 26rem; border: 0; display: block; background: #fff; }
.preview .close { align-self: start; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { font: inherit; font-size: var(--step--1); border: 0; background: var(--surface); color: var(--muted); padding: 0.3rem 0.65rem; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 700; }

/* ---------- redirect dialog ---------- */

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 2rem));
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(10, 16, 22, 0.45); }
dialog form { padding: 1.4rem; }
dialog h2 { margin-bottom: 0.4rem; }

/* ---------- admin ---------- */

.admin-grid { display: grid; gap: 1.25rem; }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: clamp(1rem, 2.5vw, 1.5rem); }
.section > h2 { margin-bottom: 0.25rem; }
.section > .hint { margin-bottom: 1rem; }
.section + .section { margin-top: 1.25rem; }

table.plain { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
table.plain th, table.plain td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.plain th { color: var(--muted); }
table.plain tr:last-child td { border-bottom: 0; }
table.plain td form { display: inline; }
.tag { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: var(--step--1); border: 1px solid var(--line-strong); color: var(--muted); }
.tag.ok { border-color: var(--release); color: var(--release); }
.tag.bad { border-color: var(--high); color: var(--high); }
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0.25rem 0.15rem 0.6rem; border: 1px solid var(--line-strong); border-radius: 999px; font-size: var(--step--1); }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; padding: 0 0.35rem; border-radius: 999px; }
.chip button:hover { color: var(--high); }
.inline-form { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; }
.inline-form .field { margin: 0; flex: 1 1 200px; }
.result-ok { color: var(--release); font-weight: 700; }
.result-bad { color: var(--high); font-weight: 700; }
details summary { cursor: pointer; font-weight: 700; }
code, .secret { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; }
.secret { font-size: var(--step-1); letter-spacing: 0.08em; padding: 0.6rem 0.8rem; background: var(--ground); border-radius: var(--radius); display: inline-block; }

.htmx-request.btn, .htmx-request .btn { opacity: 0.6; cursor: progress; }

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  .split.has-preview { grid-template-columns: minmax(0, 1fr); }
  .preview { position: fixed; inset: 0.75rem; top: 0.75rem; max-height: none; z-index: 20; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
}

@media (max-width: 860px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }
  td.size, th.size, td.when.long { display: none; }
  .msg .subject, .msg .meta { max-width: 32ch; }
}

@media (max-width: 560px) {
  td.when, th.when { display: none; }
  .stamp { width: 2.6rem; height: 2.6rem; font-size: 0.68rem; box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 3px var(--c); }
  td.sel, th.sel { width: 2rem; padding-right: 0; }
  .ranges label.range span { padding: 0.45rem 0.6rem; }
  .msg .subject, .msg .meta { max-width: 22ch; }
  .topbar .who span { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .preview { animation: slide-in 160ms ease-out; }
  @keyframes slide-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
}
