:root {
  --bg: #0b0a06;
  --surface: #121108;
  --surface-2: #1a180e;
  --surface-3: #232015;
  --border: #28240f;
  --border-strong: #3b361c;
  --text: #f4f0e0;
  --text-2: #c9c3ac;
  --muted: #a59a72;
  --accent: #e8be10;
  --accent-strong: #c9a60a;
  --accent-soft: rgba(232, 190, 16, 0.14);
  --on-accent: #171202;
  --danger: #f07171;
  --star: #ffd75e;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, monospace;

  /* ── Design tokens ── */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --r-sm: 8px; --r-md: 10px; --r-lg: 16px; --r-full: 999px;
  --fs-xs: 11px; --fs-sm: 13px; --fs-base: 14px; --fs-lg: 16px; --fs-xl: 20px;
}

.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-base { font-size: var(--fs-base); }
.text-lg { font-size: var(--fs-lg); }
.text-xl { font-size: var(--fs-xl); }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  background: radial-gradient(1100px 500px at 18% -8%, rgba(232, 190, 16, 0.08), transparent 55%),
              radial-gradient(900px 500px at 100% 0%, rgba(200, 160, 0, 0.06), transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }
svg { width: 16px; height: 16px; flex-shrink: 0; }

.app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 12px;
  background: rgba(15, 14, 8, 0.72);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center;
  width: 27px; height: 27px;
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--muted); font-weight: 500; }

.menu-btn { display: none; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  flex: 1; max-width: 460px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  height: 34px;
  color: var(--muted);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 13.5px; font-family: inherit;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.sync-status { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }

.profile-tag { font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 999px; white-space: nowrap; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text-2);
  font-size: 13px; font-weight: 500; font-family: inherit;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-3); color: var(--text); border-color: #4a4420; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.btn-primary:hover { background: var(--accent-strong); color: var(--on-accent); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }

.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.active { color: var(--accent); }

.icon-btn.spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; font-family: inherit; margin-top: 8px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Auth gate ---------- */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.auth-card {
  width: 360px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 4px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h2 { font-size: 17px; font-weight: 700; }
.auth-sub { font-size: 13px; color: var(--muted); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Layout ---------- */
.layout {
  flex: 1; display: grid;
  --sbw: 300px;
  grid-template-columns: var(--sbw) minmax(340px, 1fr) minmax(380px, 1.15fr);
  min-height: 0; position: relative;
}

.sidebar-resizer {
  position: absolute; top: 0; bottom: 0; left: calc(var(--sbw) - 4px);
  width: 8px; cursor: col-resize; z-index: 6;
  display: none;
}
.sidebar-resizer.active { display: block; }
.sidebar-resizer:hover, .sidebar-resizer.dragging { background: var(--accent-soft); }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  min-height: 0; overflow-y: auto;
}

.sidebar-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); padding: 10px 8px 5px;
}

.sidebar-label.sec-head { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 4px; }
.sidebar-label.sec-head .sec-caret {
  margin-left: auto; width: 13px; height: 13px; color: var(--muted);
  transition: transform .15s ease; flex-shrink: 0;
}
.sidebar-label.sec-head.collapsed .sec-caret { transform: rotate(-90deg); }
.sidebar-label.sec-head.collapsed + .sec-body { display: none; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 10px;
  border: none; border-radius: var(--radius);
  background: transparent; color: var(--text-2);
  font-size: 13.5px; font-family: inherit; text-align: left; cursor: pointer;
  position: relative;
  transition: background .12s ease, color .12s ease;
}
.nav-item svg { color: var(--muted); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-text.acct { display: flex; flex-direction: column; gap: 1px; }
.nav-text.acct .acct-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 12.5px; }
.nav-text.acct .acct-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; color: var(--muted); }

.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  display: grid; place-items: center;
}

.account-list { display: flex; flex-direction: column; gap: 2px; }
.account-item { display: flex; align-items: center; min-width: 0; position: relative; }
.account-item .nav-item { flex: 1; min-width: 0; }
.account-item.dragging { opacity: 0.45; }

.logout-btn {
  display: grid; place-items: center;
  width: 26px; height: 26px; margin-right: 2px;
  border: none; border-radius: 7px; flex-shrink: 0;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.logout-btn:hover { background: var(--surface-3); color: var(--danger); }
.copy-btn:hover { color: var(--accent); }
.token-warn { color: var(--danger); font-weight: 800; font-size: 13px; }
.token-warn:hover { color: #fff; background: var(--danger); }
.logout-btn svg { width: 14px; height: 14px; }
.move-btn { width: 18px; height: 24px; }
.move-btn:disabled { opacity: 0.25; cursor: default; }
.move-btn:disabled:hover { background: transparent; color: var(--muted); }

/* ── Account overflow menu ── */
.acct-menu-btn {
  display: grid; place-items: center;
  width: 26px; height: 26px; margin-right: 2px;
  border: none; border-radius: var(--r-sm); flex-shrink: 0;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.acct-menu-btn:hover { background: var(--surface-3); color: var(--text); }
.acct-menu-btn svg { width: 16px; height: 16px; }
.acct-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow);
  min-width: 160px; padding: 4px; display: none;
}
.acct-menu.open { display: block; }
.acct-menu button {
  width: 100%; text-align: left; background: none; border: none;
  color: var(--text); font-size: var(--fs-sm); font-family: inherit;
  padding: 8px 12px; border-radius: var(--r-sm); cursor: pointer;
}
.acct-menu button:hover { background: var(--surface-3); color: var(--accent); }
.acct-menu button.danger:hover { color: var(--danger); }

.avatar {
  display: grid; place-items: center; position: relative;
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, hsl(var(--hue, 40) 85% 52%), hsl(calc(var(--hue, 40) + 18) 68% 34%));
  color: #fff;
  font-size: 9.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }

.scrim { display: none; }

/* ---------- Inbox ---------- */
.inbox { display: flex; flex-direction: column; background: var(--bg); min-width: 0; min-height: 0; }
.inbox-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.inbox-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
.inbox-head .icon-btn { margin-left: auto; }

.bulk-bar { display: flex; align-items: center; gap: 4px; }
.bulk-bar .icon-btn { margin-left: 0; }
.bulk-bar .icon-btn:hover { color: var(--accent); }

.inbox-tools {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.tool-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); cursor: pointer; user-select: none; }
.tool-toggle input { accent-color: var(--accent); cursor: pointer; }
.inbox-tools select, .inbox-tools .btn { margin-left: 0; }
#markReadAll { margin-left: auto; }

.thread-list { list-style: none; overflow-y: auto; min-height: 0; flex: 1; }

.load-more-wrap { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- Thread rows ---------- */
.thread {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 16px; border-bottom: 1px solid rgba(40, 36, 15, 0.45);
  cursor: pointer; transition: background .1s ease;
}
.thread:hover { background: var(--surface); }
.thread.selected { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.thread.bulk-checked { background: var(--surface-3); box-shadow: inset 3px 0 0 var(--accent); }
.thread .avatar { margin-top: 2px; }
.thread-check { width: 15px; height: 15px; margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.thread-main { flex: 1; min-width: 0; }

.thread-top { display: flex; align-items: baseline; gap: 8px; }
.thread-from { font-size: 13.5px; font-weight: 500; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.thread-count { font-family: var(--mono); font-size: 10.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; flex-shrink: 0; }
.thread-account { font-family: var(--mono); font-size: 10.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; flex-shrink: 0; }
.thread-date { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.thread-subject { font-size: 13.5px; color: var(--text); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-snippet { font-size: 12.5px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread-meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12px; color: var(--muted); }
.thread-meta .thread-count { font-family: var(--mono); font-size: 10.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; }
.thread-meta .thread-acct { display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .02em; color: var(--muted); background: var(--surface-3); border-radius: var(--r-full); padding: 1px 7px; }
.thread-meta .thread-snippet { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread.starred .thread-star { color: var(--star); }
.thread-star { color: var(--muted); }

.thread.unread .thread-from { color: var(--text); font-weight: 700; }
.thread.unread .thread-subject { font-weight: 600; }
.thread.unread .avatar::after {
  content: ""; position: absolute; top: -1px; right: -1px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}

.thread-att { display: inline-block; vertical-align: -2px; color: var(--muted); }
.thread-att svg { width: 13px; height: 13px; }

.row-actions {
  display: flex; align-items: center; gap: 2px;
  opacity: 0; transition: opacity .12s ease;
  align-self: center; flex-shrink: 0;
}
.thread:hover .row-actions { opacity: 1; }
.row-actions .icon-btn { width: 26px; height: 26px; color: var(--muted); }
.row-actions .icon-btn:hover { color: var(--accent); background: var(--surface-2); }
@media (hover: none) { .row-actions { display: none; } }

.thread { position: relative; }
.snooze-menu {
  position: absolute; right: 8px; top: 38px; z-index: 20;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 150px; padding: 4px;
}
.snooze-menu button {
  background: none; border: none; color: var(--text); font-size: 12.5px;
  text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.snooze-menu button:hover { background: var(--surface-2); color: var(--accent); }

/* ---------- Detail ---------- */
.detail { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; min-height: 0; min-width: 0; }
.detail-content { padding: 22px 26px; }

.detail-back { display: none; margin-bottom: 12px; }

.detail-head { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 18px; }
.detail-head h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.35; }

.detail-actions { display: flex; gap: 6px; margin: 14px 0 18px; flex-wrap: wrap; }

.msg-block { border-bottom: 1px solid var(--border); padding: 16px 0; }
.msg-block:last-child { border-bottom: none; }
.msg-head { margin-bottom: 10px; }
.msg-from { font-weight: 600; font-size: 14px; }
.msg-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.email-frame {
  display: block; width: 100%; min-height: 120px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: #fff; overflow: hidden;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border), 0 4px 16px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,0.3);
}

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attachment {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text-2); font-size: 13px;
  text-decoration: none; cursor: pointer;
}
.attachment:hover { border-color: var(--accent); color: var(--text); }
.attachment svg { color: var(--muted); }
.attachment .att-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-size { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ---------- Empty & loading ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 48px 24px; color: var(--muted); gap: 12px;
}
.empty-state .glyph {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-3));
  border: 1px solid var(--border); color: var(--muted);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.03);
}
.empty-state .glyph svg { width: 24px; height: 24px; color: var(--accent); }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 36ch; }

.skeleton { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.skeleton .s-avatar { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); }
.skeleton .s-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.skeleton .s-line { height: 10px; border-radius: 4px; background: var(--surface-3); }
.skeleton .s-line.short { width: 40%; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.skeleton .s-avatar, .skeleton .s-line { animation: pulse 1.4s ease-in-out infinite; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.compose-card, .settings-card {
  position: relative; display: flex; flex-direction: column; gap: 14px;
  width: 520px; max-width: 100%; max-height: 100%; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow);
}
.settings-card { width: 480px; }
.compose-head { display: flex; align-items: center; justify-content: space-between; }
.compose-head h3 { font-size: 16px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; font-weight: 500; color: var(--muted); }
.field.grow { flex: 1; min-height: 0; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border-strong);
  color: var(--text); border-radius: var(--radius); padding: 9px 12px;
  font-size: 14px; font-family: inherit; transition: border-color .15s ease;
}
.field textarea { min-height: 160px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.compose-actions { display: flex; justify-content: flex-end; gap: 8px; }
.compose-att-list { display: flex; flex-wrap: wrap; gap: 8px; }
.compose-att {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 4px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); font-size: 12.5px;
}
.compose-att .att-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-att .icon-btn { width: 22px; height: 22px; }
.compose-att .icon-btn:hover { color: var(--danger); }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; }
.setting-row span { display: flex; flex-direction: column; gap: 4px; }
.setting-row strong { font-size: 14px; }
.setting-row small { font-size: 12px; color: var(--muted); }
.setting-row input[type="checkbox"] { width: 40px; height: 22px; accent-color: var(--accent); }
.setting-section { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.setting-section h4 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 2px; }
.setting-note { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.forward-row { display: flex; gap: 8px; margin-bottom: 4px; }
.forward-row input { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius); padding: 9px 12px; font-size: 14px; font-family: inherit; transition: border-color .15s ease; }
.forward-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.forward-row input::placeholder { color: var(--muted); }
.forward-row select { flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius); padding: 9px 10px; font-size: 14px; font-family: inherit; max-width: 40%; }
.setting-status { font-size: 12px; margin: 8px 0 0; min-height: 16px; line-height: 1.4; }
.setting-status.ok { color: var(--accent); }
.setting-status.err { color: #f87171; }
.setting-status.pending { color: #fbbf24; }

.unsub-card { width: min(560px, 100%); height: min(70vh, 560px); padding: 16px; gap: 10px; }

.switch-card { width: min(400px, 100%); padding: 16px; gap: 10px; }
.switch-card .setting-section { display: flex; flex-direction: column; gap: 8px; }
.switch-card .setting-section + .setting-section { border-top: 1px solid var(--border); padding-top: 12px; }
.unsub-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.unsub-toolbar .setting-status { margin: 0; flex: 1; }
.unsub-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.unsub-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius); }
.unsub-row:hover { background: var(--surface-2); }
.unsub-row.unsubscribed { opacity: 0.5; }
.unsub-row.unsubscribed .btn { pointer-events: none; }
.unsub-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.unsub-info strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unsub-info small { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unsub-count { font-size: 10.5px; color: var(--accent); }
.unsub-row .btn { flex-shrink: 0; }
.unsub-row .btn.done { background: var(--surface-3); color: var(--muted); border-color: transparent; cursor: default; }

/* ---------- Settings: rules / templates / important ---------- */
.chips-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 12px; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  width: 18px; height: 18px; border: none; border-radius: 50%; cursor: pointer;
  background: var(--surface-3); color: var(--muted); font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chip button:hover { color: var(--danger); }
#sigText { width: 100%; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius); padding: 9px 12px; font-size: 14px; font-family: inherit; resize: vertical; margin-bottom: 8px; }

/* ---------- Stats modal ---------- */
.stats-card { width: min(480px, 100%); }
.stats-body { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.stats-body h5 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.stat-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; padding: 2px 0; }
.stat-row .stat-label { flex: 0 0 42%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row .stat-count { flex: 0 0 auto; min-width: 28px; text-align: right; color: var(--muted); }
.stat-bar { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.stat-fill { height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- Manage modal ---------- */
.manage-card { width: min(560px, 100%); max-height: 80vh; overflow-y: auto; }
.manage-tabs { display: flex; gap: 2px; padding: 4px; background: var(--surface-2); border-radius: var(--radius); margin-bottom: 8px; }
.manage-tab { flex: 1; text-align: center; padding: 8px 12px; font-size: 12.5px; font-weight: 600; color: var(--muted); background: transparent; border: none; border-radius: var(--radius-sm, 8px); cursor: pointer; transition: all .15s ease; }
.manage-tab:hover { color: var(--text); background: var(--surface-3); }
.manage-tab.active { color: var(--on-accent); background: var(--accent); }
.manage-tab-panel { display: none; }
.manage-tab-panel.active { display: block; }
.manage-tab-panel .setting-section { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }
.manage-tab-panel .setting-section:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ---------- Shortcut sheet ---------- */
.shortcut-list { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.shortcut-list > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shortcut-list kbd {
  font-family: inherit; font-size: 11.5px; color: var(--text);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px;
}

/* ---------- Account pill on unified threads ---------- */
.thread-acct {
  display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: .02em;
  color: var(--muted); background: var(--surface-3); border-radius: 999px;
  padding: 1px 7px; margin-left: 6px; vertical-align: 1px; flex-shrink: 0;
}

/* ---------- Light theme ---------- */
html.theme-light {
  --bg: #faf8f0; --surface: #ffffff; --surface-2: #f5f1e5; --surface-3: #ece6d2;
  --border: #e6ddc0; --border-strong: #d6cb9f;
  --text: #262009; --text-2: #4a432a; --muted: #8f8556;
  --accent: #b89407; --accent-strong: #9a7d05; --accent-soft: rgba(184,148,7,0.14);
  --on-accent: #1a1402;
  --shadow: 0 10px 40px rgba(120,100,20,.12); --shadow-sm: 0 2px 8px rgba(120,100,20,.10);
}

.declutter-card { width: min(560px, 100%); height: min(76vh, 640px); padding: 16px; gap: 12px; overflow-y: auto; }
.declutter-card .setting-section + .setting-section { border-top: 1px solid var(--border); padding-top: 12px; }
.declutter-card .declutter-check { width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.declutter-card .forward-row input { flex: 1; }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
#declutterCleanSel { margin-top: 8px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; z-index: 60;
  transform: translateX(-50%) translateY(8px);
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 10px 18px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--danger); }
.toast-action {
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: transparent; color: var(--accent); font-size: 12.5px; font-weight: 700;
  font-family: inherit; padding: 3px 10px; cursor: pointer; flex-shrink: 0;
}
.toast-action:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

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

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sbw, 280px) minmax(320px, 1fr) minmax(340px, 1fr); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 260px 1fr; }
  .sidebar-resizer { display: none !important; }
  #resizeRow { display: none !important; }
  .detail {
    position: fixed; inset: 56px 0 0 0; z-index: 30;
    transform: translateX(100%); transition: transform .22s ease;
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.detail-open .detail { transform: translateX(0); }
  .detail-back { display: inline-flex; }
}

@media (max-width: 680px) {
  .layout { grid-template-columns: 1fr; }
  .menu-btn { display: grid; }
  .brand { display: none; }
  .topbar { gap: 8px; padding: 0 8px; }
  .search-box { max-width: none; height: 36px; }
  .sync-status { display: none; }
  .profile-tag { display: none; }
  .add-acct { display: none; }
  #composeBtn .btn-label { display: none; }
  #composeBtn { width: 34px; padding: 0; justify-content: center; }

  .auth-gate { padding: 16px; }
  .auth-card { width: 100%; max-width: 400px; padding: 24px 20px; gap: 14px; }
  .auth-card .field input { height: 46px; font-size: 15px; }
  .auth-card .btn { height: 46px; font-size: 15px; }

  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; z-index: 40;
    width: 280px; transform: translateX(-100%); transition: transform .22s ease;
    border-right: 1px solid var(--border-strong);
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .scrim { display: block; position: fixed; inset: 56px 0 0 0; z-index: 35; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }

  .detail-content { padding: 16px; }
  .thread { padding: 12px 12px; }
  .inbox-head { padding: 12px; }

  .modal { padding: 0; align-items: flex-end; }
  .compose-card, .settings-card {
    width: 100%; max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .field textarea { min-height: 140px; }
  .compose-actions { flex-wrap: wrap; }
  .compose-actions .btn, .compose-actions select { flex: 1 1 auto; }
  .declutter-card, .stats-card { height: 86dvh; }
  .snooze-menu { position: fixed; right: 12px; }
  .stat-label { flex-basis: 34%; }
}

/* base touch tweaks for small screens */
@media (hover: none) {
  * { -webkit-tap-highlight-color: transparent; }
}