:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1b1f24; --muted: #667085; --line: #e3e6ea;
  --accent: #2f6fde; --accent-text: #ffffff; --hover: #eef2f7; --unread: #1b1f24; --danger: #c43a31;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --panel: #181c21; --text: #e6e9ed; --muted: #98a2b3; --line: #2a3038;
    --accent: #5b8ff0; --accent-text: #0b0d10; --hover: #222831; --unread: #ffffff; --danger: #ef6b62; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; font-family: inherit; }
.primary { background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 8px 14px; font-weight: 600; }
.primary:disabled { opacity: .6; cursor: wait; }
.icon { padding: 6px 9px; border-radius: 6px; font-size: 16px; }
.icon:hover, .nav-item:hover { background: var(--hover); }

.app { display: grid; grid-template-columns: 220px 380px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 8px 12px; }
.compose-btn { margin: 0 4px 14px; }
.nav-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 14px 8px 4px; }
.nav-item { display: flex; justify-content: space-between; width: 100%; text-align: left; padding: 7px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.nav-item.active { background: var(--hover); font-weight: 600; }
.count { color: var(--accent); font-weight: 600; }
.me { margin-top: auto; color: var(--muted); font-size: 12px; padding: 8px; overflow-wrap: anywhere; }

.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-width: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.pane-head h1, .pane-head h2 { font-size: 16px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.messages li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.messages li:hover { background: var(--hover); }
.messages li.selected { background: var(--hover); box-shadow: inset 3px 0 var(--accent); }
.row1 { display: flex; gap: 8px; }
.who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .who, .unread .subj { font-weight: 700; color: var(--unread); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-right: 4px; }
.more { padding: 10px; color: var(--accent); }
.list-empty { color: var(--muted); padding: 24px 14px; cursor: default !important; }

.read-pane { overflow-y: auto; min-width: 0; background: var(--bg); }
.empty { color: var(--muted); display: grid; place-items: center; height: 100%; }
.thread-head { padding: 14px 20px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; }
.thread-head h2 { flex: 1; margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin: 14px 20px; }
.card-head { padding: 12px 14px; display: flex; gap: 10px; cursor: pointer; }
.card-head .meta { flex: 1; min-width: 0; }
.card-head .addr { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.card-body { border-top: 1px solid var(--line); }
.card.collapsed > :not(.card-head) { display: none; }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; padding: 14px; margin: 0; font: inherit; }
iframe.html-body { width: 100%; height: 65vh; border: 0; background: #fff; display: block; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); align-items: center; }
.card-actions button, .card-actions a { color: var(--accent); font-size: 13px; text-decoration: none; }
.card-actions .danger { color: var(--danger); }
.atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); }
.atts a { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; color: var(--text); text-decoration: none; font-size: 13px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(680px, calc(100vw - 32px)); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.fields { padding: 12px 14px; display: grid; gap: 8px; }
.fields label { display: grid; gap: 3px; color: var(--muted); font-size: 12px; }
.from-row { display: flex; gap: 6px; align-items: center; color: var(--text); }
.from-row input { flex: 1; } .from-row select { flex: 1.4; }
dialog footer { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.error { color: var(--danger); flex: 1; }

.only-mobile { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 5; transform: translateX(-105%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgb(0 0 0 / .3); }
  .only-mobile { display: inline-block; }
  .app[data-view="list"] .read-pane, .app[data-view="read"] .list-pane { display: none; }
  .card { margin: 10px 0; border-radius: 0; border-inline: 0; }
  .thread-head { padding: 12px 16px; }
}
