:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #e2e5ea; --text: #1c1e21; --muted: #667085;
  --accent: #2563eb; --accent-text: #ffffff; --hover: #eef2f7; --unread: #ffffff; --read: #f8f9fb;
  --danger: #c62828; --ok: #15803d; --notice: #fff8e1; --notice-line: #f1d48a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --panel: #1d2026; --line: #2e333c; --text: #e6e8eb; --muted: #98a2b3;
    --accent: #5b8def; --accent-text: #0b1220; --hover: #262b33; --unread: #232830; --read: #1a1d22;
    --danger: #ef6b6b; --ok: #4ade80; --notice: #2c2715; --notice-line: #5c4d1c;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 18px; margin: 12px 0 8px; overflow-wrap: anywhere; }
small { color: var(--muted); }
[hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.wide { width: 100%; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; max-width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; flex: none; }

.flashes { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 20; display: grid; gap: 6px; width: min(560px, 92vw); }
.flash { padding: 9px 13px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.flash.error { border-color: var(--danger); color: var(--danger); box-shadow: none; }
.notice { background: var(--notice); border: 1px solid var(--notice-line); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

/* login */
body.centered { display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.login { width: min(340px, 100%); display: grid; gap: 12px; }
.login label, .compose label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.login input { width: 100%; }

/* main layout */
body.app { display: flex; flex-direction: column; overflow: hidden; }
.top { display: flex; align-items: center; gap: 10px; padding: 8px 12px 0; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: thin; }
.tab { display: inline-flex; align-items: center; padding: 9px 13px; border-radius: 8px 8px 0 0; color: var(--text); white-space: nowrap; border-bottom: 3px solid transparent; }
.tab:hover { background: var(--hover); text-decoration: none; }
.tab.active { border-bottom-color: var(--accent); font-weight: 600; background: var(--bg); }
.badge { margin-left: 7px; background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.tools { display: flex; gap: 6px; padding-bottom: 8px; flex: none; }
.tools form { margin: 0; }

.cols { flex: 1; min-height: 0; display: grid; grid-template-columns: 190px minmax(340px, 38%) 1fr; }
.folders { padding: 12px; overflow-y: auto; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.folders ul { list-style: none; margin: 0; padding: 0; flex: 1; }
.folders li a { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px; color: var(--text); }
.folders li a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folders li a:hover { background: var(--hover); text-decoration: none; }
.folders li a.active { background: var(--hover); font-weight: 600; }
.folders li b { color: var(--accent); }

.list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.search { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.search input[type=search] { flex: 1; min-width: 0; }
.fresh { padding: 8px 12px; background: var(--notice); border-bottom: 1px solid var(--notice-line); }
#bulk { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.bar select { padding: 3px 6px; font-size: 13px; max-width: 130px; }
.pager { margin-left: auto; display: flex; gap: 5px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.rows { overflow-y: auto; flex: 1; }
.row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); background: var(--read); }
.row > .check { padding: 0 4px 0 10px; }
.row.unread { background: var(--unread); }
.row.unread .who, .row.unread .subject { font-weight: 700; }
.row.unread { box-shadow: inset 3px 0 0 var(--accent); }
.row.selected { background: var(--hover); }
.row:hover { background: var(--hover); }
.open { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "who meta" "what what"; gap: 1px 8px; padding: 8px 10px 8px 6px; color: var(--text); }
.open:hover { text-decoration: none; }
.who { grid-area: who; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.what { grid-area: what; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snippet { color: var(--muted); margin-left: 6px; }
.meta { grid-area: meta; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.tag { border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.star { color: #d99a00; }
.mark { color: var(--muted); }

.reader { overflow-y: auto; padding: 14px 18px; }
.msg-actions { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.msg-actions form.inline, form.inline { display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: 0; }
.msg-actions select { padding: 3px 6px; font-size: 13px; max-width: 130px; }
body.app .back { display: none; }
.msg-head { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 10px; }
.msg-head dt { color: var(--muted); }
.msg-head dd { margin: 0; overflow-wrap: anywhere; }
.attachments { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.attachments li { border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px; background: var(--panel); }
iframe.body { width: 100%; min-height: 240px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* single-column pages */
body.single { overflow: auto; }
.page { max-width: 980px; margin: 0 auto; padding: 18px 14px 40px; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.compose { display: grid; gap: 12px; }
.compose input:not([type=checkbox]):not([type=color]), .compose select { width: 100%; }
.compose label.check { display: flex; color: var(--text); font-size: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.actions, .presets { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.stats b { font-size: 16px; overflow-wrap: anywhere; }
.ok { color: var(--ok); } .bad { color: var(--danger); }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table .right { text-align: right; white-space: nowrap; }
.table .flash { margin-top: 6px; font-size: 13px; }

@media (max-width: 900px) {
  body.app { overflow: auto; }
  .cols { display: block; }
  .folders { border-right: 0; border-bottom: 1px solid var(--line); }
  .folders ul { display: flex; flex-wrap: wrap; gap: 4px; }
  .reader { display: none; }
  .rows { overflow: visible; }
  .two, .three { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}
