/* PostBox — "sorting desk" design system.
   Signature: the airmail stripe across the header. Everything else stays quiet. */

:root {
  --bg: #f6f4ee;          /* manila-tinted paper */
  --panel: #fffdf8;
  --fg: #211f1a;          /* ink */
  --muted: #7e786c;
  --line: #e2ded2;
  --accent: #23479e;      /* postal blue */
  --accent-ink: #fffdf8;
  --warn: #b3261e;        /* postal red */
  --ok: #2f6b44;
  --pend: #8a6d1f;
  --stripe-red: #c4302b;
  --stripe-blue: #23479e;
  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171613;
    --panel: #1e1d18;
    --fg: #ece9e0;
    --muted: #98917f;
    --line: #33312a;
    --accent: #9db2e8;
    --accent-ink: #171613;
    --warn: #e8a19b;
    --ok: #93c9a5;
    --pend: #d6b95e;
    --stripe-red: #a8352f;
    --stripe-blue: #3d5daa;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.55 var(--font-ui);
  background: var(--bg);
  color: var(--fg);
  display: grid;
  grid-template-columns: 210px 1fr;
  grid-template-rows: auto 1fr;
}

/* ---------- header + airmail stripe ---------- */
header {
  grid-column: 1 / 3;
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.65rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
}
header::before,
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: repeating-linear-gradient(
    -45deg,
    var(--stripe-red) 0 14px,
    var(--bg) 14px 26px,
    var(--stripe-blue) 26px 40px,
    var(--bg) 40px 52px
  );
}
.brand {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--fg);
}
.searchform { flex: 1; max-width: 26rem; }
.searchform input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

/* ---------- sidebar ---------- */
nav {
  border-right: 1px solid var(--line);
  padding: 1rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  align-content: start;
}
.navgroup { display: flex; flex-direction: column; gap: 2px; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0.5rem 0.25rem;
}
nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--fg);
  padding: 0.28rem 0.55rem;
  border-radius: 6px;
  text-transform: capitalize;
  line-height: 1.4;
}
nav a:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
nav a.active { background: var(--accent); color: var(--accent-ink); }
nav .count {
  font-family: var(--font-mono);
  font-size: 0.72em;
  line-height: 1;
  padding: 0.22em 0.5em;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
nav a.active .count { background: color-mix(in srgb, var(--accent-ink) 22%, transparent); }

/* ---------- main ---------- */
main { padding: 1.1rem 1.6rem 3rem; max-width: 62rem; min-width: 0; }
h1 { text-transform: capitalize; font-size: 1.25rem; margin: 0.2rem 0 0.9rem; letter-spacing: -0.01em; }
h1.plain { text-transform: none; }
h2 { font-size: 1rem; margin: 1.6rem 0 0.5rem; }
.cap { text-transform: capitalize; }
.lede { color: var(--muted); margin: -0.4rem 0 1rem; max-width: 44rem; }
.empty { color: var(--muted); max-width: 40rem; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.dim { color: var(--muted); }

/* ---------- thread list ---------- */
.threads { list-style: none; margin: 0; padding: 0; }
.threads li a {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr) auto;
  gap: 0.9rem;
  padding: 0.55rem 0.5rem;
  text-decoration: none;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
  align-items: baseline;
  border-left: 3px solid transparent;
}
.threads li a:hover { background: var(--panel); }
.threads li.unread a { border-left-color: var(--accent); }
.threads li.unread .who, .threads li.unread .subj { font-weight: 600; }
.who, .line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { color: var(--muted); }
.meta {
  display: flex;
  gap: 0.45rem;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* ---------- thread view ---------- */
.thread-top {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.backlink { color: var(--muted); text-decoration: none; }
.backlink:hover { color: var(--accent); }
.thread-move { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.thread-move form { display: inline; }
.thread-subject { margin-top: 0; }
.sender-note {
  display: flex;
  gap: 0.7rem 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--pend);
  border-radius: 8px;
  margin-bottom: 0.9rem;
  max-width: 44rem;
}
.sender-note-actions { display: flex; gap: 0.5rem; align-items: center; }
.sender-note-actions form { display: inline; }
.message {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0.9rem 0;
  padding: 1rem 1.1rem;
  background: var(--panel);
}
.msg-head { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.msg-head .addr { color: var(--muted); font-size: 0.8rem; }
.msg-head .date { color: var(--muted); font-size: 0.8rem; margin-left: auto; }
.msg-route {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
  overflow-wrap: anywhere;
}
.msg-route + .text-body, .msg-route + iframe, .msg-head + .text-body, .msg-head + iframe { margin-top: 0.7rem; }
.text-body { white-space: pre-wrap; font: inherit; margin: 0; overflow-wrap: anywhere; }
.html-body { width: 100%; min-height: 10rem; border: none; background: #fff; border-radius: 6px; display: block; }
.atts { margin-top: 0.8rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.att {
  display: inline-flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
  max-width: 100%;
}
.att:hover { border-color: var(--accent); color: var(--accent); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { color: var(--muted); font-size: 0.78rem; }

/* ---------- badges: rubber-stamp register ---------- */
.badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.org { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.badge.st-approved { color: var(--ok); border-color: var(--ok); }
.badge.st-pending { color: var(--pend); border-color: var(--pend); }
.badge.st-blocked { color: var(--warn); border-color: var(--warn); }

/* ---------- tables (contacts, settings) ---------- */
.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; }
.table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0.4rem 0.7rem 0.4rem 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 0.5rem 0.7rem 0.5rem 0; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.table td time { white-space: nowrap; }
.table .num { text-align: right; }
.cell-stack { display: flex; flex-direction: column; gap: 0.05rem; min-width: 0; }
.cell-name { font-weight: 500; }
.cell-sub { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-block; }
.row-actions form + form { margin-left: 0.4rem; }
.revoke-others { margin-top: 0.6rem; }

/* ---------- forms + controls ---------- */
button {
  cursor: pointer;
  padding: 0.3rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  font-size: 0.88rem;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--warn); }
button.danger:hover { border-color: var(--warn); }
button.ghost {
  margin-top: 0.5rem;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
}
button:disabled { cursor: default; opacity: 0.6; }
button.ghost:hover:not(:disabled) { color: var(--accent); }
.add-identity { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.add-identity input, .add-identity select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
}

/* ---------- login ---------- */
.login-body { display: block; }
.login-card {
  position: relative;
  overflow: hidden;
  max-width: 22rem;
  margin: 16vh auto 0;
  padding: 2rem 1.6rem 1.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card .brand { font-size: 1.2rem; }
.login-sub { color: var(--muted); margin: 0.3rem 0 1.2rem; }
.login-error {
  color: var(--warn);
  border: 1px dashed var(--warn);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin: 0 0 1rem;
}
.login-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.login-card input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
.login-card .cf-turnstile { margin-top: 0.8rem; }
.login-card button { margin-top: 0.8rem; padding: 0.5rem 1.2rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- mobile: header, chip nav, content ---------- */
@media (max-width: 760px) {
  body { display: flex; flex-direction: column; }
  header { flex-wrap: wrap; gap: 0.6rem; }
  .searchform { max-width: none; min-width: 12rem; }
  nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.8rem 1.4rem;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0.6rem 0.9rem;
    background: var(--panel);
  }
  .navgroup { flex-direction: row; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
  .eyebrow { padding: 0 0.2rem 0 0; }
  nav a { display: inline-flex; padding: 0.2rem 0.6rem; border: 1px solid var(--line); border-radius: 999px; font-size: 0.85rem; }
  nav a.active { border-color: var(--accent); }
  main { padding: 0.9rem 1rem 3rem; }
  .threads li a { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; row-gap: 0.1rem; }
  .threads li a .who { grid-column: 1; }
  .threads li a .meta { grid-column: 2; grid-row: 1; }
  .threads li a .line { grid-column: 1 / 3; grid-row: 2; }
  .threads li a .snip { display: none; }
  .thread-top { flex-direction: column; align-items: flex-start; }
  .msg-head .date { margin-left: 0; }
}
