:root {
  color-scheme: dark;
  --bg: #0b0f16;
  --bg-soft: #111823;
  --card: #141c28;
  --card-hover: #18222f;
  --line: #22303f;
  --line-soft: #1a2432;
  --fg: #e6edf5;
  --fg-dim: #94a5b8;
  --fg-faint: #63768a;
  --accent: #38bdf8;
  --accent-dim: #0e7490;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --new: #a78bfa;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ------------------------------------------------------------------ login */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
}

.login h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: -0.01em; }
.login p { margin: 0 0 24px; color: var(--fg-dim); font-size: 13px; }

.pin-input {
  width: 100%;
  padding: 14px;
  font: 600 24px/1 var(--mono);
  letter-spacing: 0.4em;
  text-align: center;
  text-indent: 0.4em;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.pin-input:focus { border-color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--fg);
  padding: 9px 14px;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: var(--card-hover); border-color: var(--accent-dim); }
button:disabled { opacity: .5; cursor: default; }

.btn-primary {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent);
  color: #06212e;
}
.btn-primary:hover:not(:disabled) { background: #7dd3fc; border-color: #7dd3fc; }

.error { margin-top: 14px; color: var(--bad); font-size: 13px; min-height: 18px; }

/* ------------------------------------------------------------------ inbox */

html, body { height: 100%; }
body.inbox { display: flex; flex-direction: column; overflow: hidden; }

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-soft);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand img { width: 22px; height: 22px; display: block; }
.address {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  font: 12px/1.3 var(--mono); color: var(--fg-dim);
}
.address span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.top button, .toolbar button { padding: 6px 11px; font-size: 13px; }
button.small { padding: 3px 8px; font-size: 12px; }

.panes { flex: 1; display: flex; min-height: 0; }

.list-pane {
  width: 380px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line-soft);
  min-height: 0;
}
.search { padding: 10px; border-bottom: 1px solid var(--line-soft); }
.search input {
  width: 100%; padding: 8px 11px; font: inherit; font-size: 14px;
  color: var(--fg); background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 9px; outline: none;
}
.search input:focus { border-color: var(--accent); }

.list { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.list li {
  padding: 11px 14px 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  position: relative;
}
.list li:hover { background: var(--card-hover); }
.list li.active { background: var(--card); box-shadow: inset 3px 0 0 var(--accent); }
.list li.unread::before {
  content: ""; position: absolute; left: 8px; top: 17px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.list .row1 { display: flex; gap: 8px; align-items: baseline; }
.list .who { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li.unread .who, .list li.unread .subj { font-weight: 650; }
.list .when { font-size: 12px; color: var(--fg-faint); white-space: nowrap; }
.list .subj { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .snip {
  font-size: 13px; color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list .clip { color: var(--fg-faint); font-size: 12px; margin-left: 4px; }

.empty { padding: 40px 24px; text-align: center; color: var(--fg-dim); font-size: 14px; }
.empty code { font-family: var(--mono); font-size: 12px; color: var(--fg); word-break: break-all; }

.reader { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.reader-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--line-soft); }
.reader h2 { margin: 0 0 10px; font-size: 19px; line-height: 1.3; letter-spacing: -0.01em; word-wrap: break-word; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.meta dt { color: var(--fg-faint); }
.meta dd { margin: 0; color: var(--fg-dim); word-break: break-word; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.toolbar button.on { border-color: var(--accent); color: var(--accent); }
.toolbar .danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.back { display: none; }

.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.atts a {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 5px 10px; font-size: 13px; text-decoration: none;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-soft); color: var(--fg);
}
.atts a:hover { border-color: var(--accent-dim); }
.atts small { color: var(--fg-faint); }

.body { flex: 1; min-height: 0; overflow: auto; }
.body iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.body pre {
  margin: 0; padding: 18px 20px;
  font: 13.5px/1.6 var(--mono); white-space: pre-wrap; word-wrap: break-word;
}
.headers {
  margin: 0; padding: 14px 20px; border-bottom: 1px solid var(--line-soft);
  font: 12px/1.5 var(--mono); color: var(--fg-dim); white-space: pre-wrap; word-break: break-all;
  max-height: 40vh; overflow: auto;
}

@media (max-width: 760px) {
  .list-pane { width: 100%; border-right: 0; }
  .reader { display: none; }
  body.reading .list-pane { display: none; }
  body.reading .reader { display: flex; }
  .back { display: inline-block; }
  .address { order: 3; width: 100%; }
}
