/* athanas mail — mobile-first webmail UI */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --surface-3: #e7eaf2;
  --text: #1c1f26;
  --text-2: #4b5160;
  --muted: #747b8b;
  --border: #e2e5ee;
  --accent: #e8590c;
  --accent-2: #ff7a2f;
  --accent-soft: #ffe8d9;
  --accent-text: #b8420a;
  --unread-bg: #ffffff;
  --read-bg: #f8f9fc;
  --select-bg: #fff1e6;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --shadow-1: 0 1px 2px rgba(20, 24, 40, 0.06), 0 1px 3px rgba(20, 24, 40, 0.08);
  --shadow-2: 0 8px 30px rgba(20, 24, 40, 0.18), 0 2px 6px rgba(20, 24, 40, 0.08);
  --radius: 16px;
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #22262f;
    --surface-3: #2c313c;
    --text: #e8eaf0;
    --text-2: #c2c7d2;
    --muted: #8d94a3;
    --border: #2d323d;
    --accent: #ff7a2f;
    --accent-2: #ff9a5c;
    --accent-soft: #3a2518;
    --accent-text: #ffb089;
    --unread-bg: #1d2129;
    --read-bg: #1a1d24;
    --select-bg: #33241a;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 34px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.filled { fill: currentColor; }

/* ---------- brand ---------- */
.logo-mark {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: inline-block;
  background: radial-gradient(circle at 50% 50%, #0b0b0f 0 38%, #ffd29a 44%, #ff6a1a 58%, rgba(255, 106, 26, 0.0) 72%), #0b0b0f;
  box-shadow: inset 0 0 0 2px rgba(255, 140, 60, 0.35);
}
.logo-mark.big { width: 64px; height: 64px; }
.wordmark { font-size: 20px; letter-spacing: -0.02em; color: var(--text-2); font-weight: 400; }
.wordmark b { font-weight: 650; color: var(--text); margin-left: 2px; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.boot .logo-mark { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.88); opacity: 0.7; } }

/* ---------- buttons ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  color: var(--text-2); transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:active { background: var(--border); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }
.icon-btn.on { color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 18px;
  border-radius: 20px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); box-shadow: var(--shadow-1); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; height: 46px; border-radius: 23px; font-size: 15px; }
.btn[disabled] { opacity: 0.6; pointer-events: none; }
.link-btn { color: var(--accent-text); font-weight: 600; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--accent-soft); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-bottom)); }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px; padding: 36px 28px 28px;
  box-shadow: var(--shadow-1); border: 1px solid var(--border);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card h1 { font-size: 26px; font-weight: 600; margin: 0 0 2px; letter-spacing: -0.01em; }
.login-card > .muted { margin: 0 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin: 0 0 6px 2px; }
.field input, .field textarea, .field select {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 72px; }
.pw-toggle { position: absolute; right: 6px; top: 6px; height: 36px; padding: 0 12px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--accent-text); }
.pw-toggle:hover { background: var(--accent-soft); }
.form-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 10px 12px; border-radius: 10px; margin: 4px 0 14px; font-size: 13px; }
.form-ok { color: var(--ok); font-size: 13px; margin: 6px 0 0; }
.login .btn.primary { margin-top: 6px; }

/* ---------- app layout ---------- */
.app { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 12px 0 calc(8px + var(--safe-left));
  display: flex; align-items: center; gap: 8px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 0 8px; width: calc(var(--sidebar-w) - 56px); flex: none; }
.search {
  flex: 1; max-width: 720px; height: 48px; display: flex; align-items: center; gap: 2px; padding: 0 4px;
  background: var(--surface-3); border-radius: 24px; transition: background 0.15s, box-shadow 0.15s;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow-1); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; padding: 0 6px; }
.search input::-webkit-search-cancel-button { display: none; }
.search .search-menu, .search .search-avatar { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.avatar-btn { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 650; font-size: 15px; color: #fff; background: var(--accent); margin-left: 4px; }

.sidebar {
  position: fixed; z-index: 40; top: calc(var(--topbar-h) + var(--safe-top)); bottom: 0; left: 0; width: var(--sidebar-w);
  padding: 8px 12px 16px calc(8px + var(--safe-left)); overflow-y: auto; display: flex; flex-direction: column; background: var(--bg);
}
.drawer-head { display: none; }
.compose-btn {
  display: inline-flex; align-items: center; gap: 14px; height: 56px; padding: 0 24px 0 18px; margin: 0 0 14px 2px; align-self: flex-start;
  border-radius: 18px; background: var(--accent-soft); color: var(--accent-text); font-weight: 650; font-size: 15px;
  transition: box-shadow 0.15s, background 0.15s;
}
.compose-btn:hover { box-shadow: var(--shadow-1); }
.compose-btn svg.i { width: 22px; height: 22px; }
.folders { list-style: none; margin: 0; padding: 0; }
.folder-link {
  display: flex; align-items: center; gap: 16px; width: 100%; height: 36px; padding: 0 14px 0 14px; border-radius: 18px;
  color: var(--text); text-decoration: none; font-size: 14px; text-align: left;
}
.folder-link:hover { background: var(--surface-3); }
.folder-link.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.folder-link .count { margin-left: auto; font-size: 12px; font-weight: 650; }
.folder-link.has-unread { font-weight: 700; }
.folder-link.small { height: 34px; color: var(--text-2); }
.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.main { margin-left: var(--sidebar-w); padding: 0 16px 16px 0; min-height: calc(100dvh - var(--topbar-h) - var(--safe-top)); }
.panel {
  background: var(--surface); border-radius: var(--radius); min-height: calc(100dvh - var(--topbar-h) - var(--safe-top) - 16px);
  display: flex; flex-direction: column; overflow: clip;
}
.app.collapsed .sidebar { width: 72px; }
.app.collapsed .sidebar .folder-link > span:not(.ic), .app.collapsed .compose-btn > span:last-child, .app.collapsed .folder-link .count { display: none; }
.app.collapsed .compose-btn { padding: 0; width: 56px; justify-content: center; }
.app.collapsed .main { margin-left: 72px; }
.app.collapsed .folder-link { width: 36px; padding: 0; justify-content: center; position: relative; }
.app.collapsed .folder-link.has-unread::after { content: ""; position: absolute; top: 6px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky; top: calc(var(--topbar-h) + var(--safe-top)); z-index: 20; display: flex; align-items: center; gap: 2px;
  min-height: 52px; padding: 4px 10px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .spacer { flex: 1; }
.toolbar-title { font-size: 18px; font-weight: 600; margin: 0 0 0 6px; }
.toolbar .range { color: var(--muted); font-size: 12px; margin-right: 4px; white-space: nowrap; }
.toolbar .sel-count { font-weight: 650; margin: 0 8px 0 4px; }
.check {
  width: 18px; height: 18px; border-radius: 4px; border: 2px solid var(--muted); display: inline-grid; place-items: center; flex: none;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.check.partial { background: var(--accent); border-color: var(--accent); }
.check.partial::after { content: ""; width: 8px; height: 2px; background: #fff; }
.list-heading { display: none; }
.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }

/* ---------- thread list ---------- */
.threads { list-style: none; margin: 0; padding: 0; }
.row {
  position: relative; display: grid; grid-template-columns: auto auto minmax(120px, 200px) 1fr auto; align-items: center; gap: 0 10px;
  height: 44px; padding: 0 16px 0 10px; border-bottom: 1px solid var(--border); background: var(--read-bg); cursor: pointer;
  user-select: none; -webkit-user-select: none; transition: box-shadow 0.1s;
}
.row.unread { background: var(--unread-bg); }
.row.unread .row-from, .row.unread .row-subject, .row.unread .row-date { font-weight: 700; color: var(--text); }
.row:hover { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 1px 3px rgba(20, 24, 40, 0.12); z-index: 1; }
.row.selected { background: var(--select-bg); }
.row.focused::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.row-check { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.row-check:hover { background: var(--surface-3); }
.row-star { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.row-star:hover { background: var(--surface-3); }
.row-star.on { color: #f59f00; }
.row-star.on svg.i { fill: currentColor; }
.row-avatar { display: none; }
.row-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.row-from .n { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.row-from .draft { color: var(--danger); }
.row-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); min-width: 0; }
.row-subject { color: var(--text-2); }
.row-snippet::before { content: " – "; }
.row-meta { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.row-date { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 52px; text-align: right; }
.row-clip { color: var(--muted); }
.row-clip svg.i { width: 16px; height: 16px; }
.row-hover-actions { display: none; gap: 2px; }
.row:hover .row-hover-actions { display: flex; }
.row:hover .row-date { display: none; }
.row-hover-actions .icon-btn { width: 34px; height: 34px; }
.row-hover-actions svg.i { width: 18px; height: 18px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); margin-right: 6px; font-weight: 600; vertical-align: 1px; }
.chip.failed { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.empty { padding: 72px 24px; text-align: center; color: var(--muted); }
.empty .big-ic svg.i { width: 56px; height: 56px; stroke-width: 1.4; color: var(--surface-3); margin-bottom: 10px; }
.empty h3 { margin: 0 0 4px; color: var(--text-2); font-weight: 600; font-size: 16px; }
.list-foot { padding: 16px; text-align: center; color: var(--muted); font-size: 12px; }
.skeleton .row { pointer-events: none; }
.skeleton .bar { height: 10px; border-radius: 5px; background: var(--surface-2); }

/* ---------- thread view ---------- */
.thread { padding: 4px 0 40px; }
.thread-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 20px 10px 64px; }
.thread-head h1 { font-size: 22px; font-weight: 500; margin: 0; flex: 1; line-height: 1.3; word-break: break-word; }
.thread-head .chip { font-size: 12px; vertical-align: 3px; margin-left: 8px; }
.msg { border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px 6px; cursor: pointer; }
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 650; font-size: 16px; }
.msg-who { flex: 1; min-width: 0; }
.msg-from { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.msg-from .name { font-weight: 700; }
.msg-from .addr { color: var(--muted); font-size: 12px; }
.msg-to { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 2px; }
.msg-to button { color: var(--muted); display: inline-grid; place-items: center; border-radius: 4px; }
.msg-to button:hover { background: var(--surface-3); }
.msg-to svg.i { width: 14px; height: 14px; }
.msg-snippet { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-side { display: flex; align-items: center; gap: 2px; flex: none; }
.msg-date { color: var(--muted); font-size: 12px; white-space: nowrap; margin-right: 4px; }
.msg-date .d-short { display: none; }
.msg-from .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.msg-details { margin: 0 16px 8px 68px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 12px; color: var(--text-2); display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.msg-details dt { color: var(--muted); text-align: right; }
.msg-details dd { margin: 0; word-break: break-word; }
.msg-body { padding: 4px 16px 6px 68px; }
.msg-body iframe { display: block; width: 100%; border: 0; min-height: 60px; background: #fff; border-radius: 8px; color-scheme: light; }
.msg.collapsed .msg-head { padding-bottom: 14px; }
.msg-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: 10px; padding: 8px 12px; margin: 0 16px 8px 68px; font-size: 13px; }
.images-banner { margin: 0 16px 8px 68px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.atts { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 16px 12px 68px; }
.att {
  display: flex; align-items: center; gap: 10px; width: 220px; max-width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px;
  text-decoration: none; color: var(--text); background: var(--surface);
}
.att:hover { background: var(--surface-2); }
.att-thumb { width: 40px; height: 40px; border-radius: 8px; flex: none; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-size: 10px; font-weight: 700; overflow: hidden; text-transform: uppercase; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-info { min-width: 0; flex: 1; }
.att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
.att-size { color: var(--muted); font-size: 12px; }
.att .x { margin-left: auto; }
.reply-bar { display: flex; gap: 10px; padding: 14px 16px 6px 68px; flex-wrap: wrap; }
.reply-bar .btn { height: 38px; font-weight: 600; }
.reply-bar svg.i { width: 18px; height: 18px; }

/* ---------- compose ---------- */
.compose-host { position: fixed; right: 16px; bottom: 0; z-index: 60; display: flex; align-items: flex-end; gap: 12px; pointer-events: none; }
.compose {
  pointer-events: auto; width: 560px; height: min(620px, calc(100dvh - 80px)); background: var(--surface); border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-2); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); border-bottom: 0;
}
.compose.min { height: 44px; width: 300px; }
.compose.max {
  position: fixed; inset: 5vh 8vw; width: auto; height: auto; border-radius: 14px; border-bottom: 1px solid var(--border);
}
.compose-head { display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 6px 0 16px; background: var(--surface-2); flex: none; cursor: pointer; }
.compose-head .title { flex: 1; font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-head .icon-btn { width: 32px; height: 32px; }
.compose-head .icon-btn svg.i { width: 17px; height: 17px; }
.compose-head .mobile-only { display: none; }
.compose.min .compose-body, .compose.min .compose-foot { display: none; }
.compose-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.cfield { display: flex; align-items: flex-start; gap: 8px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); min-height: 42px; position: relative; }
.cfield > label { color: var(--muted); padding-top: 11px; flex: none; min-width: 26px; }
.cfield .cc-toggle { color: var(--muted); padding: 11px 4px 0; font-size: 13px; }
.cfield .cc-toggle:hover { color: var(--text); text-decoration: underline; }
.cfield input.subject { flex: 1; border: 0; outline: 0; background: transparent; height: 42px; font-size: 15px; min-width: 0; }
.recips { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px 0; min-width: 0; }
.recips input { flex: 1; min-width: 120px; border: 0; outline: 0; background: transparent; height: 30px; font-size: 15px; }
.rchip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; height: 28px; padding: 0 4px 0 10px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px;
}
.rchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rchip.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.rchip button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.rchip button:hover { background: var(--surface-3); }
.rchip svg.i { width: 13px; height: 13px; }
.suggest {
  position: absolute; left: 40px; right: 12px; top: 100%; z-index: 5; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-2);
  border: 1px solid var(--border); padding: 6px 0; list-style: none; margin: 4px 0 0; max-height: 280px; overflow-y: auto;
}
.suggest li { display: flex; align-items: center; gap: 10px; padding: 7px 14px; cursor: pointer; }
.suggest li.on, .suggest li:hover { background: var(--surface-2); }
.suggest .avatar { width: 30px; height: 30px; font-size: 13px; }
.suggest .s-name { font-weight: 600; }
.suggest .s-email { color: var(--muted); font-size: 12px; }
.editor {
  flex: 1; min-height: 180px; padding: 14px 16px; outline: none; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; cursor: text;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor blockquote { margin: 0 0 0 4px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-2); }
.editor .sig { color: var(--text-2); }
.editor img { max-width: 100%; }
.fwd-box { margin: 0 16px 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 12px; white-space: pre-wrap; }
.compose-atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.compose-atts .att { width: auto; max-width: 100%; padding: 6px 6px 6px 10px; }
.compose-atts .att-thumb { width: 28px; height: 28px; font-size: 9px; }
.compose-atts .progress { font-size: 12px; color: var(--muted); }
.compose-error { margin: 0 16px 10px; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); font-size: 13px; }
.fmt-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 10px; margin: 0 12px 6px; border-radius: 10px; background: var(--surface-2); }
.fmt-bar .icon-btn { width: 34px; height: 34px; border-radius: 8px; }
.fmt-bar svg.i { width: 17px; height: 17px; }
.compose-foot { display: flex; align-items: center; gap: 4px; padding: 10px 12px calc(10px + var(--safe-bottom)); flex: none; }
.compose-foot .btn.primary { height: 40px; padding: 0 22px; }
.compose-foot .status { color: var(--muted); font-size: 12px; margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.compose-foot .spacer { flex: 1; }

/* ---------- popover menu ---------- */
.menu-pop {
  position: fixed; z-index: 80; min-width: 210px; max-width: calc(100vw - 16px); background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow-2); border: 1px solid var(--border); padding: 6px 0;
}
.menu-pop button, .menu-pop a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 16px; text-align: left; color: var(--text); text-decoration: none; font-size: 14px; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--surface-2); }
.menu-pop svg.i { width: 18px; height: 18px; color: var(--text-2); }
.menu-pop .sep { height: 1px; background: var(--border); margin: 6px 0; }
.menu-pop .menu-head { padding: 10px 16px 8px; color: var(--muted); font-size: 12px; }
.menu-pop .menu-head b { display: block; color: var(--text); font-size: 14px; }

/* ---------- toasts ---------- */
.toast-host { position: fixed; left: 16px; bottom: calc(16px + var(--safe-bottom)); z-index: 90; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 8px 8px 8px 18px; border-radius: 10px;
  background: #2b2f38; color: #f1f3f8; box-shadow: var(--shadow-2); max-width: min(560px, calc(100vw - 32px)); animation: toast-in 0.18s ease-out;
}
.toast .msg-text { flex: 1; }
.toast button { color: #ffb48a; font-weight: 700; padding: 8px 10px; border-radius: 8px; }
.toast button:hover { background: rgba(255, 255, 255, 0.08); }
.toast.error { background: #5c1f1f; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------- settings ---------- */
.settings { padding: 8px 24px 48px; max-width: 760px; }
.settings section { padding: 22px 0; border-bottom: 1px solid var(--border); }
.settings h3 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
.settings p.help { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.settings .row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.settings .radio { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.settings .radio input { width: 18px; height: 18px; accent-color: var(--accent); }
.blocked-list { list-style: none; margin: 0; padding: 0; }
.blocked-list li { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 10px; word-break: break-all; }

.fab { display: none; }

/* ---------- tablet ---------- */
@media (max-width: 1100px) {
  .row { grid-template-columns: auto auto minmax(100px, 160px) 1fr auto; }
}

/* ---------- phones ---------- */
@media (max-width: 767px) {
  body { font-size: 15px; }
  :root { --topbar-h: 64px; }
  .topbar { padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) 8px calc(12px + var(--safe-left)); height: auto; }
  .brand, .menu-btn, .topbar-right { display: none; }
  .search { max-width: none; height: 48px; background: var(--surface-2); box-shadow: var(--shadow-1); }
  .search .search-menu, .search .search-avatar { display: grid; }
  .search .search-icon { display: none; }
  .search-avatar { width: 32px; height: 32px; font-size: 14px; margin-right: 4px; }

  .sidebar {
    top: 0; width: min(300px, 84vw); padding: calc(12px + var(--safe-top)) 12px calc(16px + var(--safe-bottom)) calc(12px + var(--safe-left));
    transform: translateX(-102%); transition: transform 0.22s ease; background: var(--surface); box-shadow: var(--shadow-2); z-index: 70;
    border-radius: 0 18px 18px 0;
  }
  .app.drawer-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 65; background: rgba(0, 0, 0, 0.35); }
  .drawer-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px 16px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
  .sidebar .compose-btn { display: none; }
  .folder-link { height: 46px; font-size: 15px; border-radius: 23px; }
  .folder-link.small { height: 44px; }
  .app.collapsed .sidebar { width: min(300px, 84vw); }
  .app.collapsed .main, .main { margin-left: 0; padding: 0; }

  .panel { border-radius: 0; min-height: calc(100dvh - 64px - var(--safe-top)); background: var(--bg); }
  #list-panel .toolbar { display: none; }
  #list-panel.selecting .toolbar { display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 35; padding-top: calc(4px + var(--safe-top)); min-height: calc(64px + var(--safe-top)); }
  .list-heading { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 2px 20px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
  .list-heading .icon-btn { width: 34px; height: 34px; }
  .list-heading svg.i { width: 17px; height: 17px; }

  .row {
    grid-template-columns: 44px 1fr auto; grid-template-rows: auto auto auto; gap: 1px 12px; height: auto; padding: 10px 16px 10px 14px;
    border-bottom: 0; background: var(--bg);
  }
  .row.unread { background: var(--bg); }
  .row.selected { background: var(--select-bg); }
  .row:hover { box-shadow: none; }
  .row-check, .row-hover-actions { display: none !important; }
  .row:hover .row-date { display: block; }
  .row-avatar { display: grid; grid-row: 1 / span 3; align-self: start; margin-top: 2px; position: relative; }
  .row-avatar .avatar { width: 42px; height: 42px; }
  .row.selected .row-avatar .avatar { background: var(--accent) !important; font-size: 0; }
  .row.selected .row-avatar .avatar::after { content: ""; width: 8px; height: 15px; border: solid #fff; border-width: 0 3px 3px 0; transform: translateY(-2px) rotate(45deg); }
  .row-from { grid-column: 2; grid-row: 1; font-size: 15px; }
  .row-meta { grid-column: 3; grid-row: 1; }
  .row-main { grid-column: 2; grid-row: 2 / span 2; display: flex; flex-direction: column; white-space: normal; }
  .row-subject, .row-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  .row-snippet::before { content: none; }
  .row-star { grid-column: 3; grid-row: 2 / span 2; align-self: end; justify-self: end; margin-right: -8px; width: 36px; height: 36px; }
  .row-date { font-size: 12px; }
  .row.unread .row-date { color: var(--text); }

  .fab {
    display: inline-flex; align-items: center; gap: 12px; position: fixed; right: calc(16px + var(--safe-right)); bottom: calc(18px + var(--safe-bottom)); z-index: 50;
    height: 56px; padding: 0 20px 0 18px; border-radius: 18px; background: var(--accent-soft); color: var(--accent-text); font-weight: 650; font-size: 15px;
    box-shadow: var(--shadow-2); transition: padding 0.2s, width 0.2s;
  }
  .fab svg.i { width: 22px; height: 22px; }
  .fab.small { padding: 0 17px; }
  .fab.small .fab-label { display: none; }
  .app.in-thread .fab, .app.in-settings .fab { display: none; }

  /* thread & settings take over the screen */
  .app.in-thread .topbar, .app.in-settings .topbar { display: none; }
  .app.in-thread .panel, .app.in-settings .panel { min-height: 100dvh; background: var(--surface); }
  #thread-panel .toolbar, #settings-panel .toolbar { top: 0; padding-top: calc(4px + var(--safe-top)); min-height: calc(56px + var(--safe-top)); border-bottom: 0; }
  .thread-head { padding: 8px 16px 6px; }
  .thread-head h1 { font-size: 21px; }
  .msg-head { padding: 12px 10px 6px 14px; gap: 10px; }
  .msg-date .d-long { display: none; }
  .msg-date .d-short { display: inline; }
  .msg-from { flex-wrap: nowrap; }
  .msg-from .addr { display: none; }
  .msg-side .icon-btn { width: 36px; height: 36px; }
  .msg-body { padding: 4px 8px 6px; }
  .msg-body iframe { border-radius: 6px; }
  .msg-details, .images-banner, .msg-error { margin-left: 14px; margin-right: 14px; }
  .atts { padding: 8px 14px 12px; }
  .att { width: 100%; }
  .reply-bar { padding: 14px 14px calc(16px + var(--safe-bottom)); }
  .reply-bar .btn { flex: 1; }
  .settings { padding: 0 16px calc(40px + var(--safe-bottom)); }

  /* compose is a full-screen sheet */
  .compose-host { inset: 0; right: 0; display: block; }
  .compose, .compose.max { position: fixed; inset: 0; width: auto; height: 100dvh; border-radius: 0; border: 0; }
  .compose.min { height: 100dvh; width: auto; }
  .compose-head { height: calc(56px + var(--safe-top)); padding: var(--safe-top) 6px 0 6px; background: var(--surface); cursor: default; }
  .compose-head .desk-only { display: none; }
  .compose-head .mobile-only { display: grid; }
  .compose-head .icon-btn { width: 44px; height: 44px; }
  .compose-head .icon-btn svg.i { width: 21px; height: 21px; }
  .compose-head .title { font-size: 17px; font-weight: 600; padding-left: 2px; }
  .compose-foot { border-top: 1px solid var(--border); }
  .toast-host { left: 12px; right: 12px; bottom: calc(86px + var(--safe-bottom)); }
  .app.in-thread ~ .toast-host, .app.in-settings ~ .toast-host { bottom: calc(16px + var(--safe-bottom)); }
  .toast { max-width: none; }
  .menu-pop button, .menu-pop a { padding: 13px 18px; font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .topbar, .sidebar, .toolbar, .fab, .reply-bar, .compose-host, .toast-host { display: none !important; }
  .main { margin: 0; padding: 0; }
}
