:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2025; --muted: #6b7280; --line: #e3e6ea;
  --accent: #2563eb; --accent-text: #fff; --danger: #b91c1c; --unread: #eef3ff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15171a; --panel: #1e2125; --text: #e6e8eb; --muted: #9aa1ab; --line: #2e3238;
    --accent: #4f8cff; --unread: #1f2a3d; --danger: #f87171; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { margin: 0 0 12px; font-size: 20px; }
h2 small { font-size: 13px; color: var(--muted); font-weight: normal; margin-left: 8px; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top .brand { font-weight: 700; color: var(--text); }
.top .who { margin-left: auto; color: var(--muted); font-size: 13px; }
.app { display: flex; min-height: calc(100vh - 47px); }
.side { width: 190px; padding: 16px; display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.side a:not(.btn) { padding: 7px 10px; border-radius: 6px; color: var(--text); }
.side a.active { background: var(--panel); font-weight: 600; }
.side .btn { margin-bottom: 10px; text-align: center; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; float: right; }
main { flex: 1; padding: 16px; min-width: 0; }
main.center { display: flex; justify-content: center; padding-top: 12vh; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);
  color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.login { width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); width: 100%; }
label.inline input { width: auto; }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 14px; resize: vertical; }
.error { color: var(--danger); margin: 0 0 8px; }
.note { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.msgs { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.msgs li + li { border-top: 1px solid var(--line); }
.msgs a { display: flex; gap: 14px; padding: 10px 14px; color: var(--text); }
.msgs a:hover { text-decoration: none; background: var(--bg); }
.msgs .unread { background: var(--unread); }
.msgs .unread .from, .msgs .unread .subj { font-weight: 600; }
.msgs .from { width: 200px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs .subj { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgs .snip { color: var(--muted); font-weight: normal; }
.msgs .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.toolbar form { margin: 0; }
.hdrs { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0 0 12px; font-size: 14px; }
.hdrs dt { color: var(--muted); }
.hdrs dd { margin: 0; word-break: break-word; }
.atts { list-style: none; padding: 10px 0; margin: 0 0 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px 18px; }
.atts small { color: var(--muted); }
pre.body { white-space: pre-wrap; word-wrap: break-word; font: 14px/1.5 ui-monospace, Consolas, monospace; margin: 0; }
iframe.body { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.compose { display: flex; flex-direction: column; gap: 10px; max-width: 900px; }

@media (max-width: 700px) {
  .app { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; padding: 8px 16px; }
  .side .btn { margin: 0; }
  .msgs a { flex-wrap: wrap; gap: 2px 10px; }
  .msgs .from { width: auto; flex: 1; }
  .msgs .subj { flex-basis: 100%; order: 3; }
  .top .who { display: none; }
}
