:root {
  --bg: #ffffff; --bg2: #f5f6f8; --bg3: #e9ecf1; --fg: #1d2127; --muted: #6b7380; --line: #dfe3e9;
  --accent: #2456d6; --accent-fg: #ffffff; --unread: #101418; --danger: #b3261e; --sel: #e4ecff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --bg2: #1a1e25; --bg3: #232832; --fg: #e4e7ec; --muted: #8d95a3; --line: #2b313b;
    --accent: #6c93ff; --accent-fg: #0b1020; --unread: #ffffff; --danger: #ff8a80; --sel: #24325a; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 24px 12px; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
.spacer { flex: 1; }
button.primary { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 6px; padding: 8px 14px; font-weight: 600; }
button.ghost, label.button { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; display: inline-block; }
button.ghost:hover, label.button:hover, button.icon:hover { background: var(--bg3); }
button.icon { background: transparent; border: 0; border-radius: 6px; padding: 6px 9px; }
button.link { background: none; border: 0; color: var(--accent); padding: 0 8px 0 0; }
button.wide { width: 100%; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .messages li:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--bg2); }
.login form { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
label { display: grid; gap: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; }

.app { height: 100%; display: grid; grid-template-columns: 220px minmax(280px, 380px) 1fr; grid-template-rows: auto 1fr; }
.top { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.brand { font-size: 16px; letter-spacing: .3px; }
#search-form { flex: 1; max-width: 460px; }
.folders { border-right: 1px solid var(--line); padding: 12px 8px; overflow: auto; background: var(--bg2); }
.folders ul { list-style: none; margin: 12px 0 0; padding: 0; }
.folders li button { width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 7px 10px; display: flex; gap: 8px; }
.folders li button:hover { background: var(--bg3); }
.folders li button[aria-current=true] { background: var(--sel); font-weight: 600; }
.folders li .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.folders li .n.unread { color: var(--accent); font-weight: 700; }
.list-pane { border-right: 1px solid var(--line); overflow: auto; min-height: 0; }
.list-head { display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.messages { list-style: none; margin: 0; padding: 0; }
.messages li { padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.messages li:hover { background: var(--bg2); }
.messages li[aria-selected=true] { background: var(--sel); }
.messages .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.messages .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .prev { grid-column: 1 / -1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.messages li.unread .from, .messages li.unread .subj { font-weight: 700; color: var(--unread); }
.messages li .flag { color: #d9a400; }

.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: auto; }
.reader .placeholder { margin: auto; }
.msg-head { padding: 14px 18px 8px; border-bottom: 1px solid var(--line); }
.msg-head h2 { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
.msg-head .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.msg-head .meta b { color: var(--fg); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.banner { margin: 8px 18px 0; padding: 8px 12px; background: var(--bg3); border-radius: 6px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 16px 18px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13.5px; margin: 0; }
iframe.msg-html { flex: 1; min-height: 360px; width: 100%; border: 0; background: #fff; }
.actions select { width: auto; padding: 5px 8px; }
.attachments { padding: 8px 18px; display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); }
.attachments a { border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; color: var(--accent); text-decoration: none; }

.compose { position: fixed; right: 18px; bottom: 0; width: min(640px, 100vw); max-height: 92vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.25); display: flex; flex-direction: column; z-index: 20; }
.compose-head { display: flex; align-items: center; padding: 8px 12px; background: var(--bg3); }
.compose .row { display: grid; grid-template-columns: 64px 1fr; align-items: center; padding: 3px 12px; gap: 6px; border-bottom: 1px solid var(--line); }
.compose .row.links { display: block; padding: 2px 12px; border: 0; }
.compose .row input, .compose .row select { border: 0; padding: 6px 4px; background: transparent; }
.compose textarea { border: 0; border-radius: 0; min-height: 240px; resize: vertical; padding: 10px 12px; font-family: inherit; }
.compose .files { list-style: none; margin: 0; padding: 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.compose .files li { background: var(--bg3); border-radius: 6px; padding: 3px 8px; display: flex; gap: 6px; }
.compose .files button { background: none; border: 0; padding: 0; }
.compose #c-status { padding: 0 12px; margin: 4px 0; min-height: 1.2em; }
.compose-foot { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); align-items: center; }
.settings { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--fg); width: min(640px, calc(100vw - 24px)); max-height: 90vh; }
.settings::backdrop { background: rgba(0,0,0,.45); }
.settings .close { float: right; }
.settings section { margin-bottom: 18px; display: grid; gap: 8px; }
.settings h2, .settings h3 { margin: 0; }
.settings textarea { font-family: ui-monospace, Menlo, monospace; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 40; max-width: 90vw; }
.only-narrow { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; position: relative; }
  .only-narrow { display: inline-block; }
  .folders { position: absolute; top: 49px; bottom: 0; left: 0; width: 260px; z-index: 10; transform: translateX(-100%); transition: transform .15s; }
  .app.show-folders .folders { transform: none; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  .reader { display: none; position: absolute; inset: 49px 0 0 0; background: var(--bg); z-index: 5; }
  .app.show-reader .reader { display: flex; }
  .list-pane { border-right: 0; }
  .compose { right: 0; max-height: 100vh; height: 100vh; border-radius: 0; }
  button.back { display: inline-block; }
}
button.back { display: none; }

.admin { width: min(760px, calc(100vw - 24px)); }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rows li { display: flex; gap: 8px; align-items: center; padding: 5px 8px; background: var(--bg2); border-radius: 6px; flex-wrap: wrap; }
.rows li .grow { flex: 1; overflow-wrap: anywhere; }
.rows li button { padding: 3px 8px; }
.rows li.ok::before { content: "✓"; color: #2e8b57; }
.rows li.warn::before { content: "!"; color: #d9a400; font-weight: 700; }
.rows li.error::before { content: "✗"; color: var(--danger); font-weight: 700; }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline input { flex: 1; min-width: 160px; }
pre.zone { background: var(--bg2); padding: 10px; border-radius: 6px; overflow: auto; font-size: 12.5px; max-height: 260px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.fill { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.fill > .fill { flex: 1; }
.thread .card { border-bottom: 1px solid var(--line); }
.card-head { width: 100%; display: flex; gap: 12px; align-items: baseline; text-align: left; background: none; border: 0; padding: 10px 18px; }
.card-head:hover { background: var(--bg2); }
.card-head .who { font-weight: 600; flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head.unread .who, .card-head.unread .prev { color: var(--unread); font-weight: 700; }
.card-head .prev { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-head .date { color: var(--muted); font-size: 12px; flex: none; }
.card:not(.open) .card-body { display: none; }
.card.open .card-head { background: var(--bg2); }
.message .msg-head.meta, .fill > .msg-head.meta { padding-top: 8px; }
.thread iframe.msg-html { flex: none; height: 480px; min-height: 0; }
