/* Secure Mail: plain, legible, light and dark, phone first. Brand neutral (it serves every tenant). */
:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1d1f21;
  --muted: #5d6166;
  --line: #dcdedf;
  --accent: #1f5fae;
  --accent-text: #ffffff;
  --held: #8a5a00;
  --held-bg: #fff3d6;
  --bad: #a3221d;
  --bad-bg: #fde5e3;
  --ok: #1d6b38;
  --ok-bg: #def3e4;
  --chip-bg: #eceeef;
  --dead-bg: #eceeef;
  --focus: #1f5fae;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --panel: #1d2024;
    --text: #e6e7e8;
    --muted: #a3a8ad;
    --line: #353a40;
    --accent: #6ea8f0;
    --accent-text: #0d1014;
    --held: #f2c26b;
    --held-bg: #3b2f17;
    --bad: #f19a93;
    --bad-bg: #42201e;
    --ok: #8fd5a5;
    --ok-bg: #1b3524;
    --chip-bg: #2b2f34;
    --dead-bg: #2b2f34;
    --focus: #6ea8f0;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
h1 { font-size: 1.5rem; margin: 0 0 4px; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1.1rem; margin: 28px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 6px; }
.empty { color: var(--muted); padding: 24px 0; }

/* header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.tenant { font-weight: 400; color: var(--muted); }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
#nav a[aria-current="page"] { background: var(--chip-bg); font-weight: 600; }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 0.9rem; }

main { max-width: 1040px; margin: 0 auto; padding: 16px; outline: none; }
main:focus, main:focus-visible { outline: none; }
.heading { margin-bottom: 12px; }
.heading p { margin: 0; }

/* controls */
button, .button, select, input {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; min-height: 36px;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button[aria-pressed="true"] { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; text-decoration: underline; }
input { min-width: 0; }
label { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 12px 0 16px; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.chip { display: inline-block; font-size: 0.8rem; padding: 1px 8px; border-radius: 999px; background: var(--chip-bg); white-space: nowrap; }
.chip.subtle { color: var(--muted); }
.d-held, .r-proposed { background: var(--held-bg); color: var(--held); }
.d-quarantined, .d-unscannable, .r-rejected { background: var(--bad-bg); color: var(--bad); }
.r-active { background: var(--ok-bg); color: var(--ok); }

/* inbox */
.messages { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.messages li + li { border-top: 1px solid var(--line); }
.messages a {
  display: grid; grid-template-columns: 14px minmax(120px, 220px) 1fr auto; grid-template-areas: "dot from subject time" "dot from meta time";
  gap: 2px 12px; padding: 10px 12px; color: var(--text); text-decoration: none;
}
.messages a:hover { background: var(--chip-bg); }
.messages .dot { grid-area: dot; width: 8px; height: 8px; border-radius: 50%; margin-top: 8px; }
.messages .unread .dot { background: var(--accent); }
.messages .unread .from, .messages .unread .subject { font-weight: 700; }
.messages .from { grid-area: from; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .subject { grid-area: subject; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .meta { grid-area: meta; display: flex; gap: 6px; flex-wrap: wrap; }
.messages time { grid-area: time; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }

/* message */
.message { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.body { border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; overflow-wrap: anywhere; max-width: 100%; contain: content; }
.body.text { white-space: pre-wrap; font: inherit; margin: 0; }
.body img { max-width: 100%; height: auto; }
.body table { max-width: 100%; }
.dead-link { background: var(--dead-bg); color: var(--muted); border-radius: 4px; padding: 0 4px; text-decoration: line-through; cursor: not-allowed; overflow-wrap: anywhere; }
.image-removed { color: var(--muted); font-style: italic; }
.links { padding-left: 20px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 8px; border-bottom: 1px solid var(--line); }
thead th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.verdict { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.verdict .mine { width: 100%; font-size: 0.9rem; color: var(--ok); }
.attachments { list-style: none; padding: 0; }
.attachments li { padding: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.attachments .file { font-weight: 600; overflow-wrap: anywhere; }
.thread li.current { font-weight: 600; }

/* rules */
.rules { list-style: none; padding: 0; display: grid; gap: 12px; }
.rule { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; }
.rule-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.rule p { margin: 6px 0; }
.rule-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin: 8px 0; }
.new-rule { margin-top: 24px; }
summary { cursor: pointer; color: var(--accent); }

/* dashboard */
.figures td, .figures th { white-space: nowrap; }
.figures td { text-align: right; }

/* mailboxes */
.mailboxes { list-style: none; padding: 0; }
.mailboxes > li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin-bottom: 8px; }

/* signed out */
.signed-out { max-width: 520px; margin: 48px auto; padding: 0 16px; }

/* reload overlay */
.reload { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.reload[hidden] { display: none; }
.reload-card { background: var(--panel); color: var(--text); border-radius: 10px; padding: 20px 24px; max-width: 420px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3); }
.reload-card h2 { margin-top: 0; }

/* phones */
@media (max-width: 640px) {
  .messages a { grid-template-columns: 12px 1fr auto; grid-template-areas: "dot from time" "dot subject subject" "dot meta meta"; }
  .who { margin-left: 0; width: 100%; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: 6px; }
  table.findings thead, table.per-day thead { display: none; }
  table.findings tr, table.per-day tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.findings td, table.per-day td { display: flex; gap: 8px; border: 0; padding: 4px 0; }
  table.findings td::before, table.per-day td::before { content: attr(data-label); color: var(--muted); min-width: 96px; flex: none; }
  .figures { font-size: 0.9rem; }
  .figures td, .figures th { white-space: normal; padding: 6px 4px; }
}
