:root {
  /* surfaces & lines */
  --bg: #f4f6fb; --panel: #ffffff; --panel-2: #fbfcfe;
  --line: #e9edf3; --line2: #d7dee8;
  /* ink */
  --ink: #0d1526; --muted: #5a6675; --faint: #97a2b2;
  /* brand */
  --brand: #4f46e5; --brand-600: #4338ca; --brand-ink: #ffffff;
  --brand-tint: #eef1fe; --brand-tint-2: #e5e9fd;
  /* semantic */
  --ok: #15a34a; --good: #15a34a; --warn: #d97706; --bad: #e02424;
  /* states */
  --sel: #eef1fe; --hover: #f3f5fa;
  /* shape & depth */
  --radius-sm: 8px; --radius: 11px; --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(13, 21, 38, .06), 0 1px 1px rgba(13, 21, 38, .04);
  --shadow: 0 6px 24px -8px rgba(13, 21, 38, .14), 0 2px 6px -2px rgba(13, 21, 38, .06);
  --shadow-lg: 0 24px 60px -18px rgba(13, 21, 38, .28), 0 8px 20px -8px rgba(13, 21, 38, .12);
  --ring: 0 0 0 3px rgba(79, 70, 229, .28);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }
a { color: var(--brand); text-decoration: none; }
b, strong { font-weight: 650; }
h1, h2, h3, h4 { letter-spacing: -.011em; }

/* thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: #c8d0dc transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd5e1; border: 3px solid transparent; background-clip: content-box; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #b3bdcc; background-clip: content-box; }

/* ── buttons / inputs ─────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line2); background: var(--panel); color: var(--ink);
  padding: 6px 13px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: 13px;
  font-weight: 550; box-shadow: var(--shadow-sm); white-space: nowrap;
  transition: background .14s, border-color .14s, box-shadow .14s, transform .06s;
}
.btn:hover { background: var(--hover); border-color: var(--faint); }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--brand); }
.btn.primary {
  background: linear-gradient(180deg, #5b52e8, var(--brand)); border-color: var(--brand-600);
  color: var(--brand-ink); box-shadow: 0 1px 2px rgba(67, 56, 202, .35), 0 2px 8px -2px rgba(67, 56, 202, .4);
}
.btn.primary:hover { filter: brightness(1.06); border-color: var(--brand-600); }
.btn.danger { color: var(--bad); border-color: #f6cccc; background: var(--panel); }
.btn.danger:hover { background: #fdf1f1; border-color: #efb0b0; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { padding: 3px 9px; font-size: 12px; box-shadow: none; }
.btn.wide { width: 100%; padding: 9px 13px; }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; transform: none; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line2); border-radius: var(--radius-sm); padding: 8px 11px;
  transition: border-color .14s, box-shadow .14s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 550; color: var(--muted); margin-bottom: 5px; }
label.field > input, label.field > select, label.field > textarea { width: 100%; }

/* ── login ────────────────────────────────────── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 100;
  background: radial-gradient(1200px 600px at 50% -10%, #e9ecfb 0%, var(--bg) 55%);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 40px 40px 34px; width: 360px; text-align: center;
}
.login-logo {
  font-size: 30px; width: 62px; height: 62px; margin: 0 auto 14px; display: grid; place-items: center;
  border-radius: 16px; background: linear-gradient(180deg, #5b52e8, var(--brand));
  box-shadow: 0 8px 20px -6px rgba(67, 56, 202, .5); color: #fff;
}
.login-card h1 { margin: 4px 0 3px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
.login-card input { width: 100%; margin-bottom: 12px; text-align: center; padding: 10px; }

/* ── topbar ───────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px;
  background: rgba(255, 255, 255, .82); backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 15px; font-weight: 650; white-space: nowrap; letter-spacing: -.01em; display: flex; align-items: center; gap: 7px; padding-right: 14px; border-right: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs::-webkit-scrollbar { height: 0; }
.tabs a {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 550; white-space: nowrap;
  transition: background .14s, color .14s;
}
.tabs a:hover { background: var(--hover); color: var(--ink); }
.tabs a.active { background: var(--brand-tint); color: var(--brand-600); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
#sync-status { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px;
  font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
  box-shadow: 0 0 0 2px var(--panel);
}
.tabs a.active .badge { box-shadow: 0 0 0 2px var(--brand-tint); }
.badge.subtle { background: var(--line2); color: var(--muted); }

main { height: calc(100vh - 56px); overflow: hidden; }

/* ── mail 3-pane ──────────────────────────────── */
/* grid-template-rows: minmax(0,1fr) + min-height:0 on the panes BOUNDS each column to the
   viewport height, so the message list scrolls INTERNALLY (Outlook-style). Keep this. */
.mail-layout { display: grid; grid-template-columns: 240px 400px 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; }
.mail-layout > * { min-height: 0; }
.rail {
  background: var(--panel-2); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 10px;
}
.rail h4 { margin: 16px 8px 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 650; }
.rail-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--ink); position: relative; transition: background .12s;
}
.rail-item:hover { background: var(--hover); }
.rail-item.active { background: var(--brand-tint); color: var(--brand-600); font-weight: 600; }
.rail-item.active::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 3px; background: var(--brand); }
.rail-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.04) inset; }
.rail-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .err-dot { color: var(--bad); font-size: 11px; }

.msglist { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.msglist-tools { padding: 11px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.msglist-tools input[type=search] { flex: 1; min-width: 0; }
.msglist-scroll { flex: 1; overflow-y: auto; }
.msgrow {
  padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: grid; grid-template-columns: 10px 1fr auto; gap: 3px 10px; align-items: baseline;
  transition: background .1s;
}
.msgrow:hover { background: var(--hover); }
.msgrow.selected { background: var(--brand-tint); box-shadow: inset 3px 0 0 var(--brand); }
.msgrow .dot { width: 8px; height: 8px; border-radius: 50%; align-self: center; background: transparent; }
.msgrow .from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgrow .time { color: var(--faint); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msgrow .subj {
  grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink);
}
.msgrow .snip { grid-column: 2 / 4; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msgrow.unread .dot { background: var(--brand); }
.msgrow.unread .from, .msgrow.unread .subj { font-weight: 700; }
.msgrow.unread .time { color: var(--brand); font-weight: 600; }
.msgrow .flags { font-size: 11px; color: var(--faint); }
.list-empty { padding: 48px 24px; text-align: center; color: var(--faint); font-size: 13.5px; }
.msglist-foot { padding: 9px 12px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.msglist-foot .spacer { flex: 1; }

.reader { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.reader-empty { display: grid; place-items: center; height: 100%; color: var(--faint); font-size: 15px; }
.reader-card { background: var(--panel); margin: 16px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.reader-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 9px; font-size: 19px; }
.reader-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.acct-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff;
}
.reader-actions { padding: 10px 22px; display: flex; gap: 7px; flex-wrap: wrap; border-bottom: 1px solid var(--line); align-items: center; }
.reader-body iframe, .tm-body iframe { width: 100%; border: none; display: block; background: #fff; }
.att-strip { padding: 12px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.att-chip {
  display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line2);
  padding: 5px 11px; border-radius: var(--radius-sm); font-size: 12px; color: var(--ink); background: var(--panel-2);
  transition: background .12s, border-color .12s;
}
.att-chip:hover { background: var(--hover); border-color: var(--faint); }
.thread-msg { border-bottom: 1px solid var(--line); }
.thread-msg-head { padding: 11px 22px; display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.thread-msg-head:hover { background: var(--hover); }
.thread-msg-head .who { font-weight: 600; }
.thread-msg-head .when { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .01em; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.open { background: #fef3c7; color: #a15c07; }
.pill.answered { background: #d6f5e3; color: #067647; }
.pill.closed { background: #eef1f6; color: #64748b; }
.pill.draft { background: #eef1f6; color: #64748b; }
.pill.sending { background: #dbe7fe; color: #1d4ed8; }
.pill.paused { background: #fef3c7; color: #a15c07; }
.pill.done { background: #d6f5e3; color: #067647; }
.pill.sent { background: #d6f5e3; color: #067647; }
.pill.failed { background: #fde3e3; color: #b42318; }
.pill.pending { background: #eef1f6; color: #64748b; }
.pill.skipped { background: #fef3c7; color: #a15c07; }

/* ── generic page (helpdesk/tickets/signups/campaigns/contacts/settings) ── */
.page { height: 100%; overflow-y: auto; padding: 22px; }
.page-inner { max-width: 1120px; margin: 0 auto; }
.page h2 { margin: 2px 0 16px; font-size: 21px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h2 { margin: 0; }
.toolbar .spacer { flex: 1; }
.chip {
  border: 1px solid var(--line2); background: var(--panel); color: var(--muted); border-radius: 999px;
  padding: 5px 13px; cursor: pointer; font-size: 12.5px; font-weight: 550; box-shadow: var(--shadow-sm);
  font-variant-numeric: tabular-nums; transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--hover); color: var(--ink); border-color: var(--faint); }
.chip.active { background: linear-gradient(180deg, #5b52e8, var(--brand)); border-color: var(--brand-600); color: #fff; box-shadow: 0 1px 3px rgba(67,56,202,.35); }

/* cards that hold a table/list flush */
.card:has(> table.grid), .card:has(> .thread-row) { padding: 0; overflow: hidden; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--faint); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr { transition: background .1s; }
table.grid tr:hover td { background: var(--hover); }

.thread-row {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 12px; align-items: center;
  padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--panel);
  transition: background .1s;
}
.thread-row:last-child { border-bottom: none; }
.thread-row:hover { background: var(--hover); }
.thread-row .subj { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-row .sub { grid-column: 2/5; color: var(--muted); font-size: 12px; }

/* progress bar */
.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, #6a61ee, var(--brand)); border-radius: 999px; transition: width .4s; }

.stat-tiles { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.stat-tile { background: linear-gradient(180deg, var(--panel), var(--panel-2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 18px; min-width: 104px; box-shadow: var(--shadow-sm); }
.stat-tile b { display: block; font-size: 23px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-tile span { font-size: 12px; color: var(--muted); }

/* ── modal ────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(13, 21, 38, .5); z-index: 50;
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .16s ease-out;
}
.modal {
  background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(760px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  animation: rise .2s cubic-bezier(.2, .8, .2, 1);
}
.modal.wide { width: min(980px, 96vw); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; flex: 1; font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 13px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.modal-foot .spacer { flex: 1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(10px) scale(.99); opacity: 0; } }

.editor {
  border: 1px solid var(--line2); border-radius: var(--radius-sm); min-height: 180px; max-height: 44vh;
  overflow-y: auto; padding: 11px 13px; background: #fff; transition: border-color .14s, box-shadow .14s;
}
.editor:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.editor blockquote { border-left: 3px solid var(--line2); margin: 8px 0 8px 4px; padding-left: 10px; color: var(--muted); }

/* toast */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; border-radius: var(--radius); padding: 11px 18px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: pop .2s ease-out;
}
.toast.bad { background: var(--bad); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

/* deliverability */
.dns-check { display: flex; gap: 6px; align-items: center; margin: 3px 0; font-size: 13px; }
.dns-check .ok { color: var(--ok); }
.dns-check .bad { color: var(--bad); }

/* ── dark theme ───────────────────────────────── */
:root { --toast: #101828; }             /* toast bg (was hardcoded var(--ink) which inverts in dark) */
.toast { background: var(--toast); }

:root[data-theme="dark"] {
  --bg: #0b1120; --panel: #141c2e; --panel-2: #101828;
  --line: #263148; --line2: #35425f;
  --ink: #e9eef7; --muted: #a2b2ca; --faint: #6f819e;
  --brand: #7c74f2; --brand-600: #6a61ee; --brand-ink: #ffffff;
  --brand-tint: #20283f; --brand-tint-2: #283158;
  --ok: #35d07f; --good: #35d07f; --warn: #f0ad4a; --bad: #f4595d;
  --sel: #1b2338; --hover: #1a2236;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, .7), 0 3px 10px -4px rgba(0, 0, 0, .55);
  --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, .75);
  --ring: 0 0 0 3px rgba(124, 116, 242, .4);
  --toast: #26314c;
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="dark"] .topbar { background: rgba(17, 24, 40, .72); }
:root[data-theme="dark"] .login { background: radial-gradient(1200px 600px at 50% -10%, #1a2142 0%, var(--bg) 55%); }
:root[data-theme="dark"] * { scrollbar-color: #3a4864 transparent; }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #37455f; background-clip: content-box; }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #47587a; background-clip: content-box; }
:root[data-theme="dark"] .editor { background: var(--panel); }
:root[data-theme="dark"] .btn.danger { border-color: #5b2b2e; }
:root[data-theme="dark"] .btn.danger:hover { background: #2a1719; border-color: #7a3a3e; }
/* status pills — muted, legible variants on dark */
:root[data-theme="dark"] .pill.open,
:root[data-theme="dark"] .pill.paused,
:root[data-theme="dark"] .pill.skipped { background: #382a0f; color: #f2c879; }
:root[data-theme="dark"] .pill.answered,
:root[data-theme="dark"] .pill.sent,
:root[data-theme="dark"] .pill.done { background: #113020; color: #5fd992; }
:root[data-theme="dark"] .pill.closed,
:root[data-theme="dark"] .pill.draft,
:root[data-theme="dark"] .pill.pending { background: #1e2a44; color: #a6b6ce; }
:root[data-theme="dark"] .pill.sending { background: #16233f; color: #8fb4ff; }
:root[data-theme="dark"] .pill.failed { background: #3a1a1d; color: #f39098; }

/* ── responsive ───────────────────────────────── */
@media (max-width: 1000px) {
  .mail-layout { grid-template-columns: 64px 1fr; }
  .rail .label, .rail h4, .rail .badge { display: none; }
  .reader { position: fixed; inset: 56px 0 0 0; z-index: 30; display: none; }
  .reader.open { display: flex; }
  .tabs a { padding: 7px 9px; }
  .brand { border-right: none; padding-right: 0; }
}
