/* =========================================================
   Interstellar Mail — clean & bright design
   ========================================================= */

:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #edf0f4;
  --line-strong: #e2e6ec;
  --hover: #f4f6f9;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --accent-softer: #f6f7ff;
  --star: #f59e0b;
  --danger: #dc2626;
  --success: #059669;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-panel: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 6px 18px rgba(15, 23, 42, 0.05);
  --shadow-pop: 0 18px 48px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.06);
  --ring: 0 0 0 3px rgba(79, 70, 229, 0.18);
  --sidebar-w: 248px;
  --list-w: 400px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Dark theme: chosen in Settings, or "Automatic" with a dark system */
:root[data-theme="dark"] {
  --bg: #0b0d12;
  --panel: #14171e;
  --panel-2: #191d26;
  --text: #eef1f6;
  --text-2: #cbd3df;
  --muted: #8f9bb0;
  --faint: #626d80;
  --line: #222733;
  --line-strong: #2b3140;
  --hover: #1c212b;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-text: #0b0d12;
  --accent-soft: #232845;
  --accent-softer: #1a1e33;
  --star: #fbbf24;
  --danger: #f87171;
  --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 18px 48px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px rgba(129, 140, 248, 0.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0b0d12;
    --panel: #14171e;
    --panel-2: #191d26;
    --text: #eef1f6;
    --text-2: #cbd3df;
    --muted: #8f9bb0;
    --faint: #626d80;
    --line: #222733;
    --line-strong: #2b3140;
    --hover: #1c212b;
    --accent: #818cf8;
    --accent-strong: #a5b4fc;
    --accent-text: #0b0d12;
    --accent-soft: #232845;
    --accent-softer: #1a1e33;
    --star: #fbbf24;
    --danger: #f87171;
    --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 18px 48px rgba(0, 0, 0, 0.6);
    --ring: 0 0 0 3px rgba(129, 140, 248, 0.25);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; color: var(--text); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); font-size: 13.5px; min-height: 1.1em; }
kbd {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  font: 600 11px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--text-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 3px 5px;
  background: var(--panel);
}
.icon { flex-shrink: 0; display: block; }

::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: 600 14px/1 var(--font);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.08s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn .icon { width: 17px; height: 17px; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25), 0 4px 12px rgba(79, 70, 229, 0.22);
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.big { height: 46px; font-size: 15px; border-radius: 12px; }
.btn.small { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--line); }
.icon-btn.on { color: var(--star); }
.icon-btn.on .icon { fill: currentColor; }

.link-btn { white-space: nowrap; border: 0; background: none; color: var(--accent); font: 600 13px var(--font); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--accent-softer); }

input, textarea, select {
  width: 100%;
  font: 14.5px/1.4 var(--font);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; cursor: pointer; box-shadow: none; }
textarea { resize: vertical; line-height: 1.55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: grid; gap: 7px; font-size: 13.5px; font-weight: 600; color: var(--text-2); }

/* ---------- avatars ---------- */
.avatar {
  --hue: 230;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 13.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: hsl(var(--hue) 45% 32%);
  background: hsl(var(--hue) 70% 93%);
  user-select: none;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
:root[data-theme="dark"] .avatar { color: hsl(var(--hue) 80% 86%); background: hsl(var(--hue) 30% 24%); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .avatar { color: hsl(var(--hue) 80% 86%); background: hsl(var(--hue) 30% 24%); }
}

/* ---------- sign in ---------- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(56, 189, 248, 0.14), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 36px 32px 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-pop);
}
.login-card img { border-radius: 14px; box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25); }
.login-card h1 { font-size: 26px; font-weight: 700; margin-top: 4px; }
.login-card > p.muted { margin-top: -8px; }
.login-card .btn { margin-top: 4px; }

/* ---------- app layout ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  gap: 12px;
  padding: 12px 12px 12px 0;
}

/* sidebar (sits on the grey background) */
.sidebar { display: flex; flex-direction: column; gap: 18px; min-height: 0; padding: 8px 4px 4px 14px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 0; font-size: 16.5px; font-weight: 700; letter-spacing: -0.02em; }
.brand img { border-radius: 9px; box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25); }
.compose-btn { width: 100%; height: 48px; border-radius: 14px; font-size: 15px; gap: 10px; }
.compose-btn .icon { width: 18px; height: 18px; }
.nav { display: grid; gap: 2px; overflow-y: auto; margin: 0 -6px; padding: 0 6px 6px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-2);
  font: 500 14.5px var(--font);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item .icon { width: 18px; height: 18px; color: var(--faint); transition: color 0.15s; }
.nav-item:hover { background: rgba(15, 23, 42, 0.045); color: var(--text); }
.nav-item:hover .icon { color: var(--muted); }
.nav-item.active { background: var(--panel); color: var(--accent); font-weight: 650; box-shadow: var(--shadow-card); }
.nav-item.active .icon { color: var(--accent); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.nav-heading { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); padding: 16px 12px 6px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 2px; }
.me-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 6px 10px 10px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-card);
}
.me-text { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.me-text strong { font-size: 13.5px; font-weight: 650; }
.me-text span { color: var(--muted); font-size: 12px; }
.me-text strong, .me-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* panels */
.list-pane, .reader-pane {
  min-height: 0;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}

/* ---------- conversation list ---------- */
.list-pane { display: flex; flex-direction: column; }
.list-head { display: flex; align-items: center; gap: 6px; padding: 18px 14px 12px 20px; }
.list-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.list-title h2 { font-size: 21px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-count { color: var(--faint); font-size: 13px; font-weight: 600; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 0 10px 0 13px;
  height: 42px;
  border-radius: 12px;
  background: var(--hover);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.search:focus-within { background: var(--panel); border-color: var(--accent); box-shadow: var(--ring); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; padding: 0; background: transparent; box-shadow: none; }
.search input:focus { box-shadow: none; }
.search-icon { color: var(--faint); }
.search-scope {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.search-scope input { width: 14px; height: 14px; }

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px 10px 30px;
  border-bottom: 1px solid var(--line);
}
.check-all { display: flex; }
.toolbar-title { flex: 1; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: 600 12.5px var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--faint); color: var(--text); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.bulk { flex: 1; display: flex; align-items: center; gap: 2px; }
.bulk-count { font-weight: 650; font-size: 13.5px; margin-right: auto; }
.bulk .icon-btn { width: 34px; height: 34px; }

.email-list { list-style: none; margin: 0; padding: 6px 8px 16px; overflow-y: auto; flex: 1; }
.row {
  position: relative;
  display: flex;
  gap: 13px;
  padding: 13px 14px 13px 22px;
  border-radius: 14px;
  cursor: pointer;
  outline: none;
  transition: background 0.12s;
}
.row + .row { margin-top: 2px; }
.row:hover { background: var(--hover); }
.row.open { background: var(--accent-soft); }
.row.selected { background: var(--accent-softer); box-shadow: inset 0 0 0 1px var(--accent-soft); }
.row-lead { position: relative; width: 38px; height: 38px; flex-shrink: 0; }
.row-check {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  border: 1.5px solid var(--line-strong);
  cursor: pointer;
}
.row:hover .row-check, .row.selected .row-check, .selecting .row-check { display: grid; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-from { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 550; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-count {
  flex-shrink: 0;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.row.open .row-count { background: var(--panel); }
.row-date { flex-shrink: 0; font-size: 12px; color: var(--faint); font-weight: 500; }
.row-subject { font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-preview { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .row-bottom > .icon { color: var(--faint); }
.row.unread .row-from, .row.unread .row-subject { color: var(--text); font-weight: 700; }
.row.unread .row-date { color: var(--accent); font-weight: 700; }
.row.unread::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: var(--accent);
}
.star-btn {
  display: grid;
  padding: 3px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s;
}
.row:hover .star-btn, .star-btn.on { opacity: 1; }
.star-btn:hover { color: var(--star); }
.star-btn.on { color: var(--star); }
.star-btn.on .icon { fill: currentColor; }
.draft-tag { color: var(--danger); font-weight: 700; }
.list-note { display: grid; justify-items: center; gap: 12px; padding: 64px 24px; color: var(--muted); text-align: center; }
.list-note .icon { color: var(--faint); }
.list-sentinel { display: none; }

.skeleton { pointer-events: none; }
.skeleton .bar { height: 10px; border-radius: 6px; background: var(--hover); animation: pulse 1.3s ease-in-out infinite; }
.skeleton .avatar { background: var(--hover); }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---------- reading pane ---------- */
.reader-pane { display: flex; flex-direction: column; min-width: 0; }
.empty-reader { margin: auto; display: grid; justify-items: center; gap: 8px; padding: 32px; text-align: center; }
.empty-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-reader h3 { font-size: 17px; font-weight: 650; }
.empty-reader .small { margin-top: 10px; }

.thread { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.thread-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.toolbar-gap { flex: 1; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 26px 32px 40px; }
.thread-subject { font-size: 25px; font-weight: 700; line-height: 1.25; margin: 0 0 20px; overflow-wrap: anywhere; }
.messages { display: grid; gap: 12px; }
.msg {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.msg.expanded { box-shadow: var(--shadow-card); border-color: var(--line-strong); }
.msg:not(.expanded) { background: var(--panel-2); }
.msg:not(.expanded):hover { background: var(--hover); }
.msg-head { display: flex; align-items: flex-start; gap: 13px; padding: 16px 16px 14px 18px; cursor: pointer; }
.msg:not(.expanded) .msg-head { padding-top: 12px; padding-bottom: 12px; align-items: center; }
.msg-who { flex: 1; min-width: 0; display: grid; gap: 2px; line-height: 1.35; }
.msg-who .name { font-weight: 650; font-size: 14.5px; }
.msg-who .addr { color: var(--faint); font-size: 12.5px; font-weight: 400; }
.msg-to, .msg-snippet { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-meta { display: flex; align-items: center; gap: 2px; color: var(--faint); font-size: 12.5px; flex-shrink: 0; }
.msg-meta time { margin: 0 6px 0 4px; font-weight: 500; }
.msg:not(.expanded) .msg-to, .msg:not(.expanded) .msg-actions { display: none; }
.msg.expanded .msg-snippet { display: none; }
.msg:not(.expanded) .msg-body { display: none; }
.msg-body { display: grid; gap: 12px; padding: 0 22px 20px 69px; }
.msg-actions { display: flex; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.images-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-softer);
  border: 1px solid var(--accent-soft);
  color: var(--text-2);
  font-size: 12.5px;
}
.images-bar .icon { color: var(--accent); }
.body-frame { display: block; width: 100%; height: 120px; border: 0; background: #fff; border-radius: 8px; }
.show-quote {
  justify-self: start;
  height: 20px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: 700 13px/18px var(--font);
  letter-spacing: 1px;
  cursor: pointer;
}
.show-quote:hover { background: var(--hover); }

/* attachments */
.attachments { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 280px;
  padding: 7px 12px 7px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
a.attachment:hover { border-color: var(--accent); box-shadow: var(--ring); }
.attachment .thumb {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  object-fit: cover;
  background: var(--accent-softer);
  color: var(--accent);
}
.attachment .att-text { display: grid; min-width: 0; line-height: 1.3; }
.attachment .att-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-size { color: var(--faint); font-size: 12px; }
.attachment button { display: grid; padding: 3px; border: 0; border-radius: 6px; background: none; color: var(--faint); cursor: pointer; }
.attachment button:hover { background: var(--hover); color: var(--danger); }

/* quick reply */
.quick-reply { margin-top: 16px; }
.qr-prompt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  color: var(--muted);
  font: 500 14.5px var(--font);
  text-align: left;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.qr-prompt .icon { color: var(--faint); }
.qr-prompt:hover { border-color: var(--accent); box-shadow: var(--ring); }
.qr-form {
  display: grid;
  gap: 10px;
  padding: 14px 14px 12px 18px;
  border: 1px solid var(--accent);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--ring), var(--shadow-card);
}
.qr-form textarea { min-height: 120px; padding: 2px 0; border: 0; box-shadow: none; resize: vertical; }
.qr-form textarea:focus { box-shadow: none; }
.qr-to { font-size: 12.5px; }
.qr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--line); }
.qr-all { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-2); cursor: pointer; }

/* ---------- compose ---------- */
.compose {
  position: fixed;
  inset: auto 28px 0 auto;
  z-index: 30;
  width: min(640px, calc(100vw - 56px));
  height: min(660px, calc(100vh - 40px));
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 18px 18px 0 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.compose[open] { display: flex; animation: rise 0.18s ease-out; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.compose.large { inset: 4vh 0 auto 0; margin: 0 auto; width: min(980px, calc(100vw - 48px)); height: 92vh; border-radius: 18px; }
.compose-form { position: relative; display: flex; flex-direction: column; width: 100%; min-height: 0; }
.compose-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 20px; border-bottom: 1px solid var(--line); }
.compose-head h2 { flex: 1; font-size: 15.5px; font-weight: 650; }
.draft-status { font-size: 12px; margin-right: 6px; color: var(--faint); }
.field { display: flex; align-items: center; gap: 10px; margin: 0 20px; border-bottom: 1px solid var(--line); }
.field input { height: 44px; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.field input:focus { box-shadow: none; }
.field-label { width: 38px; flex-shrink: 0; color: var(--faint); font-size: 13.5px; font-weight: 500; }
.field-static { padding: 12px 0; font-size: 13.5px; color: var(--muted); }
.field input[name="subject"] { font-weight: 600; }
.editor-toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: 600 14px var(--font);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.tool:hover { background: var(--hover); color: var(--text); }
.tool .icon { width: 17px; height: 17px; }
.tool.wide { font-size: 13px; padding: 0 10px; }
.tool-sep { width: 1px; height: 20px; margin: 0 6px; background: var(--line-strong); }
.editor { flex: 1; overflow-y: auto; padding: 16px 20px; font-size: 15px; line-height: 1.6; outline: none; overflow-wrap: anywhere; }
.editor:empty::before { content: "Write your message…"; color: var(--faint); }
.editor blockquote { margin: 8px 0 8px 2px; padding-left: 14px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.editor .quote-head { color: var(--muted); font-size: 13.5px; }
.editor .signature { color: var(--muted); }
.editor a { color: var(--accent); }
.editor ul, .editor ol { padding-left: 24px; }
.compose-attachments { padding: 0 20px 6px; }
.compose-attachments:empty { display: none; }
.compose .error { padding: 0 20px; }
.compose .error:empty { display: none; }
.compose-foot { display: flex; align-items: center; gap: 12px; padding: 12px 14px 14px 20px; border-top: 1px solid var(--line); }
.compose-foot .btn.primary { padding: 0 22px; }
.drop-hint {
  position: absolute;
  inset: 8px;
  z-index: 5;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent-soft) 94%, transparent);
  color: var(--accent);
  font-weight: 700;
}
.compose.dragging .drop-hint { display: grid; }

/* ---------- popovers & suggestions ---------- */
.popover, .suggest {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  max-width: 340px;
  max-height: 360px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  animation: pop 0.12s ease-out;
}
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } }
.pop-item, .suggest li {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: 500 14px var(--font);
  text-align: left;
  cursor: pointer;
}
.pop-item:hover, .suggest li:hover, .suggest li.active { background: var(--hover); }
.pop-item .icon { color: var(--muted); }
.pop-heading { padding: 8px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--faint); }
.pop-empty { padding: 10px; color: var(--muted); font-size: 13px; }
.suggest li { display: grid; gap: 0; }
.suggest .s-name { font-weight: 600; }
.suggest .s-email { color: var(--muted); font-size: 12.5px; }

/* ---------- dialogs ---------- */
.modal {
  width: min(780px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.modal[open] { animation: rise 0.18s ease-out; }
.modal::backdrop { background: rgba(15, 23, 42, 0.38); backdrop-filter: blur(2px); }
.small-modal { width: min(440px, calc(100vw - 24px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 14px 24px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 19px; font-weight: 700; }
.settings-body { display: grid; grid-template-columns: 200px 1fr; min-height: 460px; }
.tabs { display: grid; align-content: start; gap: 2px; padding: 14px 12px; background: var(--panel-2); border-right: 1px solid var(--line); }
.tabs button {
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  font: 500 14px var(--font);
  text-align: left;
  cursor: pointer;
}
.tabs button:hover { background: var(--hover); }
.tabs button.active { background: var(--panel); color: var(--accent); font-weight: 650; box-shadow: var(--shadow-card); }
.tab-panels { padding: 22px 24px 26px; overflow-y: auto; max-height: calc(100vh - 150px); }
.stack { display: grid; gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.card-inset { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.settings-list { display: grid; gap: 8px; margin: 10px 0; padding: 0; list-style: none; }
.settings-list li { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border: 1px solid var(--line-strong); border-radius: 12px; }
.settings-list li > span:first-child { color: var(--accent); }
.settings-list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-list .empty { justify-content: center; color: var(--muted); border-style: dashed; }
.inline-form { display: flex; gap: 8px; }
.segmented { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; border: 0; }
.segmented legend { margin-bottom: 8px; font-size: 13.5px; font-weight: 650; color: var(--text-2); }
.segmented label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--accent-softer); color: var(--accent); }
.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 12px 18px; margin: 0; padding: 20px 26px 26px; }
.shortcut-list dt { text-align: right; white-space: nowrap; }
.shortcut-list dd { margin: 0; color: var(--text-2); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-panel); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 32px);
  padding: 12px 12px 12px 18px;
  border-radius: 14px;
  background: #0f172a;
  color: #f1f5f9;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translate(-50%, 14px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-action { padding: 4px 8px; border: 0; border-radius: 8px; background: none; color: #a5b4fc; font: 700 14px var(--font); cursor: pointer; }
.toast-action:hover { background: rgba(255, 255, 255, 0.08); }

.mobile-only { display: none !important; }
.scrim { display: none; }
.fab { display: none; }

/* ---------- smaller laptops ---------- */
@media (max-width: 1240px) {
  :root { --sidebar-w: 220px; --list-w: 340px; }
  .thread-scroll { padding: 22px 24px 36px; }
}

/* ---------- tablets & phones ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; gap: 0; padding: 0; }
  .mobile-only { display: inline-grid !important; }
  .list-pane, .reader-pane { border-radius: 0; box-shadow: none; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 290px;
    padding: max(16px, env(safe-area-inset-top)) 12px 12px 16px;
    background: var(--bg);
    transform: translateX(-102%);
    transition: transform 0.24s ease;
  }
  .app.menu-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .app.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, 0.35); }
  .list-head { padding: max(12px, env(safe-area-inset-top)) 10px 10px 10px; }
  .search { margin: 0 12px 10px; }
  .search-scope { display: none; }
  .list-toolbar { padding: 0 12px 10px 24px; }
  .email-list { padding: 4px 6px 96px; }
  .row-check { display: grid; opacity: 0; }
  .selecting .row-check { opacity: 1; }
  .star-btn { opacity: 1; }
  .reader-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .reader-pane { display: flex; height: 100%; }
  .thread-toolbar { padding: max(8px, env(safe-area-inset-top)) 8px 8px; }
  .thread-scroll { padding: 18px 12px 96px; }
  .thread-subject { font-size: 20px; margin-bottom: 14px; }
  .msg-head { padding: 14px 12px 12px; }
  .msg-body { padding: 0 12px 14px; }
  .fab {
    position: fixed;
    right: 18px;
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 20;
    display: grid !important;
    place-items: center;
    width: 58px;
    height: 58px;
    border: 0;
    border-radius: 18px;
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.4);
    cursor: pointer;
  }
  .app.reading .fab { display: none !important; }
  .compose, .compose.large { inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; }
  #compose-size { display: none; }
  .settings-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; min-height: 0; }
  .tab-panels { max-height: none; }
  .tabs { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tabs button { white-space: nowrap; }
  .row-2 { grid-template-columns: 1fr; }
  .toast { bottom: 96px; }
}

/* ---------- printing a conversation ---------- */
@media print {
  body { background: #fff; color: #000; }
  .sidebar, .list-pane, .thread-toolbar, .quick-reply, .fab, .toast, .msg-actions, .images-bar, .show-quote { display: none !important; }
  .app { display: block; height: auto; padding: 0; }
  .reader-pane, .thread, .thread-scroll { display: block !important; height: auto; overflow: visible; box-shadow: none; }
  .msg { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  .msg:not(.expanded) .msg-body { display: grid; }
}
