:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #16171a;
  --muted: #6a6d76;
  --border: #e2e4e9;
  --accent: #2f5bea;
  --accent-soft: #e8eefe;
  --selected: #eaf0ff;
  --ok: #1e7a3c;
  --ok-bg: #e6f4ea;
  --bad: #b42318;
  --bad-bg: #fdecec;
  --neutral: #4a4d55;
  --neutral-bg: #eef0f3;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111215;
    --surface: #1a1b1f;
    --surface-2: #202227;
    --text: #ececf1;
    --muted: #9a9ca6;
    --border: #2c2e35;
    --accent: #8aa6ff;
    --accent-soft: #1f2a4d;
    --selected: #1e2742;
    --ok: #6fd38f;
    --ok-bg: #15301d;
    --bad: #ff8a80;
    --bad-bg: #3a1a1a;
    --neutral: #c4c6ce;
    --neutral-bg: #2a2c33;
  }
}

* { box-sizing: border-box; }

/* Author display rules (grid/flex) would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font: 14px/1.45 var(--font);
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 24px; }
code { font: 12px var(--mono); overflow-wrap: anywhere; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn.icon { width: 34px; padding: 6px 0; font-size: 16px; }

.ico { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ top bar */

.topbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 16px; }
.brand p { margin: 0; font-size: 12px; }
.logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner {
  flex: 0 0 auto;
  margin: 12px 20px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bad-bg);
  color: var(--bad);
}
.banner.inline { margin: 16px 0; }
.loading { padding: 24px 20px; margin: 0; }

/* ------------------------------------------------------------ layout */

.app {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
}

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.detail-pane {
  min-height: 0;
  overflow-y: auto;
}

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

.list-tools { display: flex; gap: 8px; padding: 12px 12px 8px; }
.list-tools input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

.tabs { display: flex; gap: 4px; padding: 0 12px 8px; border-bottom: 1px solid var(--border); }
.tabs button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.count { font-size: 11px; opacity: 0.8; margin-left: 2px; }

.list { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.item { border-bottom: 1px solid var(--border); }
.item-btn {
  display: block;
  width: 100%;
  padding: 10px 14px 10px 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.item-btn:hover { background: var(--surface-2); }
.item.selected .item-btn { background: var(--selected); border-left-color: var(--accent); }

.row1 { display: flex; align-items: center; gap: 8px; }
.from { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.new-badge {
  flex: 0 0 auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-transform: uppercase;
}
.item.fresh .item-btn { animation: fresh-flash 2s ease-out 1; }
@keyframes fresh-flash { from { background: var(--accent-soft); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .item.fresh .item-btn { animation: none; } }

.dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

.subject { margin: 2px 0 0 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.rejected .subject { color: var(--bad); font-size: 13px; }
.row3 { display: flex; align-items: center; gap: 8px; margin-left: 16px; }
.snippet { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }

.empty { padding: 24px; text-align: center; margin: 0; }

.list-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.check { display: flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------ reader */

.placeholder { height: 100%; display: grid; place-items: center; padding: 24px; }

.reader { max-width: 960px; margin: 0 auto; padding: 20px 24px 40px; }
.reader-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-bottom: 12px; }
.reader-head h2 { flex: 1 1 320px; min-width: 0; font-size: 20px; overflow-wrap: anywhere; }
.pills { display: flex; gap: 6px; }
.back { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.neutral { background: var(--neutral-bg); color: var(--neutral); }

.meta { margin: 0 0 16px; display: grid; gap: 4px; }
.meta-row { display: grid; grid-template-columns: 88px 1fr; gap: 8px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.meta.small { font-size: 12px; }

.notice { padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 10px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg { font: inherit; font-size: 12px; color: inherit; background: var(--surface); border: 0; padding: 4px 12px; cursor: pointer; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.mail-frame {
  display: block;
  width: 100%;
  height: 60vh;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.mail-text {
  margin: 0;
  padding: 12px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.5 var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.body-view + .muted { margin: 8px 0 0; }

.forwarded summary { cursor: pointer; font-weight: 600; overflow-wrap: anywhere; }
.forwarded[open] summary { margin-bottom: 10px; }
.fwd-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.forwarded .forwarded { margin-top: 12px; }

/* attachments */
.att-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.att {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.att-icon {
  display: grid;
  place-items: center;
  height: 36px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}
.att-info { min-width: 0; }
.att-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-actions { display: flex; gap: 6px; }

/* timeline */
.timeline { list-style: none; margin: 0 0 12px; padding: 0; }
.step { position: relative; display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding-bottom: 14px; }
.step:last-child { padding-bottom: 0; }
.step::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 16px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.step:last-child::before { display: none; }
.marker { width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; border: 2px solid var(--muted); background: var(--surface); }
.step.done .marker { border-color: var(--ok); background: var(--ok); }
.step.bad .marker { border-color: var(--bad); background: var(--bad); }
.step.pending .marker { border-style: dashed; }
.step-label { font-weight: 600; }
.step.pending .step-label { color: var(--muted); font-weight: 500; }
.step time { display: block; }

.verdicts { display: flex; flex-wrap: wrap; gap: 6px; }

/* ------------------------------------------------------------ viewer */

.viewer {
  width: min(1100px, calc(100vw - 32px));
  height: min(88vh, 1000px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: rgba(0, 0, 0, 0.55); }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.viewer-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; background: var(--surface-2); overflow: auto; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ------------------------------------------------------------ narrow screens */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .detail-pane { display: none; }
  body.reading .list-pane { display: none; }
  body.reading .detail-pane { display: block; }
  .back { display: inline-flex; }
  .reader { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .brand p { display: none; }
  .att { grid-template-columns: 36px 1fr; }
  .att-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .viewer-bar .btn:not(.icon) { padding: 4px 8px; font-size: 12px; }
}
