:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1f2328; --muted: #6b7280; --line: #e3e6ea;
  --accent: #1d4ed8; --accent-text: #fff; --danger: #b42318; --unread: #eef3ff; --ok: #067647; --bad: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --panel: #1a1e24; --text: #e6e8eb; --muted: #9aa3ad; --line: #2b313a;
          --accent: #4f7ff0; --unread: #1d2840; --ok: #4ade80; --bad: #f87171; --danger: #f87171; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
code { background: var(--line); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.layout { display: flex; min-height: calc(100vh - 49px); }
.side { width: 210px; flex-shrink: 0; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.content { flex: 1; min-width: 0; padding: 16px; }
.folder { padding: 7px 10px; border-radius: 6px; text-decoration: none; color: var(--text); display: flex; justify-content: space-between; }
.folder:hover { background: var(--line); }
.folder.active { background: var(--unread); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; }

.btn { display: inline-block; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-decoration: none; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); text-align: center; margin-bottom: 10px; }
.btn.danger { color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.toolbar h2 { margin: 0; font-size: 18px; }
.search input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); width: 220px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: grid; grid-template-columns: minmax(120px, 240px) 1fr auto; gap: 12px; padding: 10px 14px; text-decoration: none; color: var(--text); }
.list a:hover { background: var(--bg); }
.list li.unread a { background: var(--unread); font-weight: 600; }
.who, .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; padding: 10px 2px; color: var(--muted); }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.actions form { margin: 0; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 0 0 10px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.auth { font-size: 12px; padding: 1px 6px; border-radius: 4px; border: 1px solid currentColor; }
.auth.ok { color: var(--ok); } .auth.bad { color: var(--bad); }
.notice { background: var(--unread); border-radius: 6px; padding: 8px 12px; margin: 0 0 10px; }
.error { background: #fde8e8; color: #8a1c1c; border-radius: 6px; padding: 8px 12px; }
iframe.body { width: 100%; height: 65vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.atts { margin-top: 12px; }
.atts h3 { font-size: 14px; margin: 0 0 4px; }
.atts ul { margin: 0; padding-left: 18px; }

.compose { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.compose .row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.compose .row span { width: 60px; color: var(--muted); flex-shrink: 0; }
.compose .row input { flex: 1; border: 0; padding: 6px 0; background: transparent; color: var(--text); font: inherit; outline: none; min-width: 0; }
.editor-wrap { margin: 12px 0; border: 1px solid var(--line); border-radius: 6px; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); background: var(--bg); border-radius: 6px 6px 0 0; }
.editor-toolbar button, .editor-toolbar select, .editor-toolbar .color { border: 1px solid transparent; background: none; color: var(--text); padding: 3px 7px; border-radius: 4px; cursor: pointer; font: inherit; }
.editor-toolbar button:hover, .editor-toolbar .color:hover { border-color: var(--line); background: var(--panel); }
.editor-toolbar select { border-color: var(--line); background: var(--panel); }
.editor-toolbar .color { position: relative; }
.editor-toolbar .color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.source-toggle.on { background: var(--accent) !important; color: var(--accent-text) !important; }
.editor, .source { min-height: 320px; max-height: 60vh; overflow: auto; padding: 12px; outline: none; background: #fff; color: #1f2328; font-family: Arial, Helvetica, sans-serif; }
.source { width: 100%; border: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical; display: block; }
.editor img { max-width: 100%; }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 2px solid #ccc; padding-left: 1ex; }
.files { margin-bottom: 12px; }
.fwd-atts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.login .btn { margin: 4px 0 0; }

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px 0; }
  .side .btn.primary { margin: 0; }
  .list a { grid-template-columns: 1fr auto; }
  .list .subj { grid-column: 1 / -1; grid-row: 2; }
  .search input { width: 140px; }
}
