/* ═════════════════════════════════════════════════════════════════
   TrackMail — design system (dark, red accent)
   ═════════════════════════════════════════════════════════════════ */

:root {
  --bg: #09090b;
  --bg2: #111114;
  --bg3: #1a1a1f;
  --surface: rgba(220, 38, 38, 0.03);
  --surface-h: rgba(220, 38, 38, 0.08);
  --border: rgba(220, 38, 38, 0.15);
  --border-h: rgba(220, 38, 38, 0.3);
  --border-soft: rgba(255, 255, 255, 0.07);

  --accent: #dc2626;
  --accent-light: #ef4444;
  --accent-dim: rgba(220, 38, 38, 0.15);
  --accent-glow: rgba(220, 38, 38, 0.5);

  --green: #00ff9d;
  --red: #ff0055;
  --yellow: #ffea00;
  --orange: #ff9f43;
  --blue: #4da6ff;

  --text: #e2f1f8;
  --text-2: #94b0c2;
  --text-3: #4a6782;

  --radius: 6px;
  --radius-lg: 10px;

  --sidebar-w: 290px;
  --topbar-h: 60px;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(220, 38, 38, 0.15);

  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(220, 38, 38, 0.07), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, rgba(220, 38, 38, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-h); }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
code { font-family: var(--mono); font-size: 12px; color: var(--text-2); background: var(--bg3); padding: 1px 5px; border-radius: 4px; }

/* ───────────────────────── shared bits ───────────────────────── */

.btn-primary, .btn-secondary, .btn-ghost, .btn-danger, .btn-page {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius); font-size: 13px; font-weight: 600;
  border: 1px solid transparent; transition: all 0.15s ease; padding: 9px 16px;
}
.btn-primary {
  background: var(--accent); color: #fff; letter-spacing: 0.02em;
  box-shadow: 0 0 0 rgba(220, 38, 38, 0);
}
.btn-primary:hover { background: var(--accent-light); box-shadow: var(--shadow-glow); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-h); border-color: var(--border-h); }
.btn-ghost {
  background: transparent; color: var(--text-2); border-color: var(--border-soft);
  width: 100%; justify-content: flex-start; padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-h); background: var(--surface); }
.btn-ghost.subtle { color: var(--text-3); }
.btn-ghost.subtle:hover { color: var(--red); border-color: rgba(255, 0, 85, 0.3); background: rgba(255, 0, 85, 0.05); }
.btn-danger { background: rgba(255, 0, 85, 0.1); color: var(--red); border-color: rgba(255, 0, 85, 0.3); }
.btn-danger:hover { background: rgba(255, 0, 85, 0.2); }
.btn-page {
  background: var(--bg3); color: var(--text-2); border-color: var(--border-soft);
  padding: 6px 12px; font-size: 12px;
}
.btn-page:hover:not(:disabled) { color: var(--text); border-color: var(--border-h); }
.btn-page:disabled { opacity: 0.35; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius);
  background: transparent; color: var(--text-2); border: none;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface-h); color: var(--text); }
.icon-btn.tiny { width: 24px; height: 24px; border-radius: 4px; }

.required { color: var(--red); }

/* inputs */
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 9px 12px; font-size: 13px; outline: none; transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--border-h); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12px; line-height: 1.6; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
option { background: var(--bg2); color: var(--text); }

/* ───────────────────────── login ───────────────────────── */

.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(800px 400px at 50% 0%, rgba(220, 38, 38, 0.08), transparent 60%), var(--bg);
  z-index: 100;
}
.login-card {
  width: min(92vw, 360px); padding: 36px 32px; text-align: center;
  background: rgba(24, 24, 27, 0.85); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--shadow-glow);
}
.login-logo {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 20px; font-weight: 700; letter-spacing: 0.02em; margin-bottom: 6px; color: var(--text);
}
.login-logo svg { color: var(--accent); }
.login-sub { color: var(--text-3); font-size: 12px; margin-bottom: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-error {
  color: var(--red); font-size: 12px; min-height: 16px;
}
.login-card.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}

/* ───────────────────────── app shell ───────────────────────── */

/* iOS Safari: 100vh extends under the URL bar / home indicator — the bottom of
   the sidebar (Admin Panel / Sign out buttons) becomes unreachable. dvh tracks
   the *dynamic* viewport (shrinks when browser chrome is visible). Fallback
   chain: 100dvh → 100svh → 100vh. Safe-area padding keeps the last row clear
   of the home indicator on notch phones. */
.app-shell { display: flex; height: 100vh; height: 100dvh; width: 100%; }

.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); height: 100vh; height: 100dvh;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: relative; z-index: 40;
  transition: margin-left 0.25s ease;
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft); min-height: var(--topbar-h);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.logo-icon {
  width: 32px; height: 32px; border-radius: var(--radius);
  background: var(--accent-dim); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.sidebar-search {
  display: flex; align-items: center; gap: 8px; margin: 12px 14px 8px;
  padding: 6px 10px; background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius);
  color: var(--text-3);
}
.sidebar-search input { border: none; background: transparent; padding: 0; font-size: 12px; }
.sidebar-search input:focus { border: none; }

.sidebar-stats { display: flex; gap: 6px; padding: 0 14px 10px; }
.stat-chip {
  flex: 1; text-align: center; font-size: 10px; color: var(--text-3);
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 4px; padding: 4px 0;
  letter-spacing: 0.03em;
}
.stat-chip b { display: block; font-size: 14px; color: var(--text); }
.stat-chip.green b { color: var(--green); }
.stat-chip.red b { color: var(--red); }

.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px 6px 16px; margin-top: 2px;
}
.sidebar-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.12em; color: var(--text-3);
}
.count-badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
  background: var(--bg3); border-radius: 8px; font-size: 10px; color: var(--text-2);
  text-align: center; letter-spacing: 0;
}

.platform-chips {
  display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 14px 10px;
}
/* active filter status line under the chips (tap hint / NOT-filter explainer) */
.platform-filter-status {
  font-size: 10px; color: var(--text-3); padding: 0 14px 8px; display: none;
}
.platform-filter-status.show { display: block; }
.platform-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; color: var(--text-2); background: var(--bg);
  border: 1px solid var(--border-soft); border-radius: 20px; padding: 3px 9px;
  cursor: pointer; transition: all 0.15s; user-select: none;
}
.platform-chip .dot { width: 7px; height: 7px; border-radius: 50%; }
.platform-chip:hover { border-color: var(--border-h); color: var(--text); }
.platform-chip.active {
  background: var(--accent-dim); border-color: var(--accent); color: var(--text);
  box-shadow: 0 0 8px rgba(220, 38, 38, 0.25);
}
.platform-chip .chip-count { color: var(--text-3); font-size: 9px; }

.account-list {
  list-style: none; flex: 1; overflow-y: auto; padding: 4px 10px;
  display: flex; flex-direction: column; gap: 3px;
}
.account-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px;
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: all 0.12s; position: relative;
}
.account-item:hover { background: var(--surface); border-color: var(--border-soft); }
.account-item.active {
  background: var(--accent-dim); border-color: var(--border);
  box-shadow: inset 0 0 12px rgba(220, 38, 38, 0.06);
}
.account-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--bg3); border: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--text-2);
}
.account-item.active .account-avatar { border-color: var(--border-h); color: var(--accent-light); }
.account-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.account-line1 { display: flex; align-items: center; gap: 6px; }
.account-email {
  flex: 1; font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--text-3);
}
.status-dot.alive { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.dead { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-dot.disabled { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.account-platform-dots { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.pdot { width: 6px; height: 6px; border-radius: 50%; opacity: 0.9; }
.account-item .account-del {
  display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: var(--bg3); border: none; border-radius: 4px; width: 22px; height: 22px;
  align-items: center; justify-content: center; color: var(--text-3);
}
.account-item:hover .account-del { display: inline-flex; }
.account-item .account-del:hover { color: var(--red); }
.account-empty {
  padding: 28px 16px; text-align: center; color: var(--text-3); font-size: 12px;
}

.sidebar-actions {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-soft);
}

/* ───────────────────────── main / topbar ───────────────────────── */

.main-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; height: 100dvh; }

.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  border-bottom: 1px solid var(--border);
  /* solid, NOT backdrop-filter: iOS WebKit renders backdrop-filter elements
     above their absolutely-positioned children (the folder dropdown) — the
     menu then shows through with no background ("transparent cards") */
  background: var(--bg2);
}
.topbar-title-col { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.topbar-title {
  font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-sub { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-only { display: none; }

.conn-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px;
  padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border-soft); color: var(--text-2);
}
.conn-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.conn-badge.ok::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.conn-badge.err::before { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* dropdown */
.cyber-dropdown { position: relative; }
.cyber-dropdown-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg2); border: 1px solid var(--border-soft); border-radius: var(--radius);
  color: var(--text-2); font-size: 12px; font-weight: 500; padding: 7px 12px;
}
.cyber-dropdown-btn:hover { border-color: var(--border-h); color: var(--text); }
.cyber-dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 5px; z-index: 160;
}
.cyber-dropdown.open .cyber-dropdown-menu { display: block; }
.cyber-dropdown-item {
  padding: 8px 10px; border-radius: 4px; font-size: 12px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.cyber-dropdown-item:hover { background: var(--surface-h); color: var(--text); }
.cyber-dropdown-item.active { color: var(--accent-light); background: var(--accent-dim); }

/* NOT-registered filter mode on platform chips */
.platform-chip.not-mode { border-color: var(--red); background: rgba(239, 68, 68, 0.08); }
.platform-chip .chip-not {
  font-size: 8px; font-weight: 700; letter-spacing: 0.5px; color: var(--red);
  border: 1px solid var(--red); border-radius: 3px; padding: 0 3px; margin-right: 1px;
}
.platform-chip .chip-clear {
  margin-left: 5px; color: var(--text-3); font-weight: 700; padding: 0 2px;
  border-radius: 3px; font-size: 11px; line-height: 1;
}
.platform-chip .chip-clear:hover { color: var(--text); background: var(--surface-h); }

/* per-platform metadata pickers in the edit modal */
.reg-meta-edit { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border-soft); }
.reg-meta-edit select {
  width: 100%; background: var(--bg); border: 1px solid var(--border-soft); color: var(--text);
  border-radius: var(--radius); padding: 7px 10px; font-size: 12px; margin-bottom: 8px;
}
.platform-toggle.selected { border-color: var(--accent); }
.platform-toggle-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───────────────────────── content area ───────────────────────── */

.content-area { flex: 1; overflow: hidden; position: relative; }

.welcome-screen {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center; padding: 24px;
}
.welcome-icon { color: var(--text-3); margin-bottom: 8px; }
.welcome-screen h1 { font-size: 22px; font-weight: 700; }
.welcome-screen p { color: var(--text-3); font-size: 13px; max-width: 420px; }
.welcome-actions { display: flex; gap: 10px; margin-top: 12px; }

/* inbox */
.inbox-view { display: flex; height: 100%; }
.email-list-panel {
  width: 380px; min-width: 300px; border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; background: rgba(9, 9, 11, 0.35);
}
.email-list { flex: 1; overflow-y: auto; padding: 6px; }
.email-item {
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: background 0.1s; margin-bottom: 2px;
}
.email-item:hover { background: var(--surface); }
.email-item.active { background: var(--accent-dim); border-color: var(--border); }
.email-item.unread { border-left: 2px solid var(--accent); }
.email-item-row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 2px; }
.email-item-sender { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-item.unread .email-item-sender { color: var(--accent-light); }
.email-item-date { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.email-item-subject {
  font-size: 12px; color: var(--text-2); margin: 2px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.email-item-preview {
  font-size: 11px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge-attach { font-size: 11px; }
.empty-state {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--text-3); font-size: 12px; padding: 24px; text-align: center;
}

.skeleton-item { padding: 12px; }
.skeleton-line {
  height: 8px; border-radius: 4px; margin-bottom: 7px;
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg2) 50%, var(--bg3) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px; border-top: 1px solid var(--border-soft);
}
.page-info { font-size: 11px; color: var(--text-3); }

.email-detail-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.detail-placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--text-3); font-size: 13px;
}
.detail-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.detail-header { padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.back-btn {
  display: none; align-items: center; gap: 6px; background: none; border: none;
  color: var(--text-3); font-size: 12px; margin-bottom: 10px; padding: 0;
}
.back-btn:hover { color: var(--text); }
.detail-subject { font-size: 17px; font-weight: 700; margin-bottom: 12px; line-height: 1.35; }
.detail-meta { display: flex; flex-direction: column; gap: 4px; }
.meta-row { display: flex; gap: 10px; font-size: 12px; }
.meta-label { color: var(--text-3); min-width: 36px; }
.meta-value { color: var(--text-2); word-break: break-all; }
.detail-attachments { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-chip {
  font-size: 11px; padding: 4px 10px; background: var(--bg3); border: 1px solid var(--border-soft);
  border-radius: 20px; color: var(--text-2);
}
.detail-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.detail-body.html { white-space: normal; }
.detail-body.plain { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); }
.detail-body img { max-width: 100%; }
.detail-body a { color: var(--accent-light); }
.detail-body table { max-width: 100%; }
.detail-body.sandbox iframe { width: 100%; min-height: 480px; border: none; background: #fff; border-radius: 4px; }

/* error card */
.ms-error-card {
  margin: 16px; padding: 18px; border-radius: var(--radius-lg);
  display: flex; gap: 14px; align-items: flex-start;
  background: rgba(255, 0, 85, 0.04); border: 1px solid rgba(255, 0, 85, 0.2);
}
.ms-error-card.err-warn { background: rgba(255, 234, 0, 0.03); border-color: rgba(255, 234, 0, 0.2); color: var(--yellow); }
.ms-error-icon { color: var(--red); }
.ms-error-card.err-warn .ms-error-icon { color: var(--yellow); }
.ms-error-code { font-family: var(--mono); font-size: 12px; color: var(--red); font-weight: 700; margin-bottom: 4px; }
.ms-error-friendly { font-size: 13px; color: var(--text); margin-bottom: 4px; }
.ms-error-desc { font-size: 12px; color: var(--text-3); word-break: break-word; }
.ms-error-sources { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.src-row { display: flex; gap: 8px; font-size: 11px; align-items: baseline; }
.src-label { font-size: 9px; font-weight: 700; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 3px; }
.src-label.graph { background: var(--accent-dim); color: var(--accent-light); }
.src-label.imap { background: rgba(77, 166, 255, 0.12); color: var(--blue); }

/* ───────────────────────── matrix view ───────────────────────── */

.matrix-view { height: 100%; overflow-y: auto; padding: 26px 30px; }
.matrix-header { margin-bottom: 18px; }
.matrix-header h2 { font-size: 18px; margin-bottom: 4px; }
.matrix-header p { color: var(--text-3); font-size: 12px; }
.matrix-table-wrap { border: 1px solid var(--border-soft); border-radius: var(--radius-lg); overflow: hidden; max-width: 760px; }
.matrix-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix-table th {
  text-align: left; font-size: 10px; letter-spacing: 0.1em; color: var(--text-3);
  padding: 10px 14px; border-bottom: 1px solid var(--border-soft); background: var(--bg2);
  font-weight: 600;
}
.matrix-table td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); color: var(--text-2); }
.matrix-table tr:last-child td { border-bottom: none; }
.matrix-table tbody tr { cursor: pointer; transition: background 0.1s; }
.matrix-table tbody tr:hover { background: var(--surface); }
.mbar { height: 5px; border-radius: 3px; background: var(--bg3); overflow: hidden; width: 120px; }
.mbar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-light)); border-radius: 3px; }

/* ───────────────────────── admin view ───────────────────────── */

.admin-view { height: 100%; overflow-y: auto; padding: 26px 30px; }
.admin-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px; max-width: 1200px;
}
.admin-card {
  background: var(--bg2); border: 1px solid var(--border-soft); border-radius: var(--radius-lg);
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.admin-card h3 { font-size: 14px; }
.admin-card label { display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--text-3); letter-spacing: 0.04em; }
.admin-card .hint { font-size: 11px; color: var(--text-3); }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.admin-row { display: flex; gap: 10px; }
.stat-box {
  flex: 1; background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
}
.stat-label { font-size: 10px; color: var(--text-3); letter-spacing: 0.06em; }
.stat-box b { font-size: 16px; color: var(--text); }
.file-btn { position: relative; overflow: hidden; }
.admin-card .matrix-table-wrap { max-width: none; max-height: 260px; overflow-y: auto; }
.admin-card .matrix-table tbody tr { cursor: default; }

/* ───────────────────────── modals ───────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  width: min(94vw, 480px); max-height: 88vh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--shadow-glow); padding: 22px;
}
.modal.wide { width: min(94vw, 680px); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 15px; }
.modal form, .modal .form-body { display: flex; flex-direction: column; gap: 12px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--text-3); letter-spacing: 0.04em; }
.modal .check-row { flex-direction: row; align-items: center; gap: 9px; color: var(--text-2); font-size: 12px; cursor: pointer; }
.modal .check-row input { width: 15px; height: 15px; accent-color: var(--accent); }
.format-hint { font-size: 11px; color: var(--text-3); line-height: 1.6; margin-top: -4px; }
.bulk-counter { font-size: 11px; color: var(--text-3); }
.modal-error {
  font-size: 12px; color: var(--red); background: rgba(255, 0, 85, 0.06);
  border: 1px solid rgba(255, 0, 85, 0.25); border-radius: var(--radius); padding: 9px 12px;
}
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.buy-estimate {
  font-size: 12px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 10px 12px; line-height: 1.7;
}
.buy-estimate b { color: var(--accent-light); }

/* edit account modal */
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.edit-col { display: flex; flex-direction: column; gap: 12px; }
.edit-col label { display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--text-3); letter-spacing: 0.04em; }
.status-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.status-opt {
  flex: 1; padding: 8px 4px; font-size: 11px; font-weight: 600; border-radius: var(--radius);
  background: var(--bg); color: var(--text-3); border: 1px solid var(--border-soft); transition: all 0.12s;
}
.status-opt:hover { color: var(--text); border-color: var(--border-h); }
.status-opt.active[data-status="alive"] { background: rgba(0, 255, 157, 0.1); border-color: var(--green); color: var(--green); }
.status-opt.active[data-status="dead"] { background: rgba(255, 0, 85, 0.1); border-color: var(--red); color: var(--red); }
.status-opt.active[data-status="disabled"] { background: rgba(255, 159, 67, 0.1); border-color: var(--orange); color: var(--orange); }
.status-opt.active[data-status="unknown"] { background: var(--surface-h); border-color: var(--border-h); color: var(--text); }
.edit-meta { font-size: 11px; color: var(--text-3); line-height: 1.8; border-top: 1px solid var(--border-soft); padding-top: 10px; }
.platform-toggle-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.platform-toggle {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
  border-radius: 20px; background: var(--bg); border: 1px solid var(--border-soft);
  font-size: 12px; color: var(--text-2); transition: all 0.12s;
}
.platform-toggle .dot { width: 8px; height: 8px; border-radius: 50%; }
.platform-toggle:hover { border-color: var(--border-h); color: var(--text); }
.platform-toggle.on {
  background: var(--accent-dim); border-color: var(--accent); color: var(--text);
  box-shadow: 0 0 10px rgba(220, 38, 38, 0.2);
}

/* platforms admin modal */
.platform-admin-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 300px; overflow-y: auto; }
.platform-admin-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius);
}
.platform-admin-row .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.platform-admin-row .name { flex: 1; font-size: 12px; color: var(--text); }
.platform-admin-row .cnt { font-size: 11px; color: var(--text-3); }

/* ───────────────────────── toast + loader ───────────────────────── */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: var(--bg3); border: 1px solid var(--border-h); color: var(--text);
  padding: 10px 18px; border-radius: var(--radius); font-size: 13px;
  opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 500;
  box-shadow: var(--shadow), var(--shadow-glow); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { border-color: rgba(0, 255, 157, 0.4); }
.toast.error { border-color: rgba(255, 0, 85, 0.5); color: #ffb4c8; }

.loader-overlay {
  position: fixed; inset: 0; background: rgba(9, 9, 11, 0.75); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 400;
}
.loader-box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 26px 40px; box-shadow: var(--shadow);
}
.loader-ring {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--bg3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-box span { font-size: 12px; color: var(--text-2); }

/* ───────────────────────── responsive ───────────────────────── */

/* scrim behind the mobile drawer — a real element (not body::after): iOS Safari
   renders ::after stacking unreliably against fixed siblings. Hidden by default
   on all widths, only participates below 900px. */
.drawer-scrim {
  display: none;
}

@media (max-width: 900px) {
  .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 298;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .drawer-scrim.show { opacity: 1; pointer-events: auto; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 300;
    margin-left: calc(-1 * var(--sidebar-w) - 20px); box-shadow: var(--shadow);
  }
  /* .mobile-open must beat BOTH the off-canvas margin and any desktop-collapse
     state — order + !important so nothing overrides it later */
  .sidebar.mobile-open {
    margin-left: 0 !important;
  }
  .sidebar.collapsed:not(.mobile-open) { margin-left: calc(-1 * var(--sidebar-w) - 20px); }
  .mobile-only { display: inline-flex; }
  .email-list-panel { width: 100%; min-width: 0; }
  .email-detail-panel {
    position: fixed; inset: 0; top: var(--topbar-h); background: var(--bg); z-index: 100;
    display: none;
  }
  .email-detail-panel.mobile-open { display: flex; }
  .back-btn { display: inline-flex; }
  .edit-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .inbox-view { position: relative; }
}
