:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --line: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #020617; color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: rgba(148,163,184,.12); padding: 0.12rem 0.35rem; border-radius: 0.35rem; }
pre { white-space: pre-wrap; word-break: break-word; }

.layout { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, #0b1220 0%, #111827 100%); border-right: 1px solid rgba(148,163,184,.15); padding: 1.35rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 0.85rem; margin-bottom: 1.5rem; }
.brand-mark { width: 2.35rem; height: 2.35rem; border-radius: 0.8rem; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), #6366f1); color: white; font-weight: 800; }
.brand-title { font-size: 1.1rem; font-weight: 800; }
.brand-subtitle { color: var(--muted); font-size: 0.88rem; }
.nav { display: grid; gap: 0.35rem; }
.nav-link { padding: 0.75rem 0.9rem; border-radius: 0.85rem; color: var(--text); }
.nav-link:hover { background: rgba(148,163,184,.08); text-decoration: none; }
.nav-link.active { background: rgba(56,189,248,.14); color: #e0f2fe; border: 1px solid rgba(56,189,248,.18); }
.sidebar-footer { position: absolute; bottom: 1.25rem; left: 1.25rem; right: 1.25rem; color: var(--muted); }
.content { padding: 1.35rem 1.35rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; }
.page-head h1 { margin: 0 0 0.35rem 0; font-size: 1.85rem; }
.muted { color: var(--muted); }

.card { background: rgba(15, 23, 42, 0.92); border: 1px solid rgba(148,163,184,.16); border-radius: 1rem; padding: 1rem; box-shadow: var(--shadow); }
.card-grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.card-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { background: rgba(15, 23, 42, 0.92); border: 1px solid rgba(148,163,184,.16); border-radius: 1rem; padding: 1rem; box-shadow: var(--shadow); }
.stat-number { font-size: 1.85rem; font-weight: 800; margin-bottom: 0.2rem; }
.stat-label { color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.85rem; }
.card h2 { margin-top: 0; margin-bottom: 0.75rem; }
.definition-list { display: grid; gap: 0.6rem; }
.definition-list > div { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: 0.6rem; border-bottom: 1px solid rgba(148,163,184,.12); }
.definition-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.hint-box, .preview-box { background: rgba(148,163,184,.08); border: 1px solid rgba(148,163,184,.12); padding: 0.85rem; border-radius: 0.85rem; display: grid; gap: 0.35rem; }
.preview-box { overflow: auto; max-height: 320px; }
.dns-summary { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-top: 1rem; }
.dns-summary-note { margin-top: 0.55rem; }
.dns-value { white-space: pre-wrap; word-break: break-word; }
.details-block summary { cursor: pointer; color: var(--primary); margin-bottom: 0.5rem; }

.form-grid { display: grid; gap: 0.9rem 1rem; }
.form-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one-col { grid-template-columns: 1fr; }
label { display: grid; gap: 0.38rem; font-size: 0.94rem; }
label > span { color: #cbd5e1; font-weight: 600; }
input, select, textarea, .editor-surface {
  width: 100%;
  border: 1px solid rgba(148,163,184,.25);
  background: rgba(15,23,42,.8);
  color: var(--text);
  border-radius: 0.8rem;
  padding: 0.78rem 0.88rem;
  font: inherit;
  outline: none;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, .editor-surface:focus { border-color: rgba(56,189,248,.55); box-shadow: 0 0 0 4px rgba(56,189,248,.1); }
.checkbox-row, .inline-actions { display: flex; gap: 0.65rem; flex-wrap: wrap; align-items: center; }
.checkbox { grid-auto-flow: column; justify-content: start; align-items: center; gap: 0.55rem; }
.checkbox input { width: auto; }
.section-title { color: #e2e8f0; font-size: 1rem; font-weight: 700; padding-top: 0.6rem; border-top: 1px solid rgba(148,163,184,.15); margin-top: 0.35rem; }
.span-2 { grid-column: 1 / -1; }

.btn, .link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid rgba(148,163,184,.22);
  background: rgba(148,163,184,.08);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover, .link-button:hover { text-decoration: none; background: rgba(148,163,184,.14); }
.btn-primary { background: linear-gradient(135deg, #0ea5e9, #3b82f6); border-color: transparent; color: white; }
.btn-primary:hover { filter: brightness(1.05); }
.link-button { background: transparent; border: 0; padding: 0; color: var(--primary); }
.link-button.danger { color: var(--danger); }
.ghost-link { color: var(--muted); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.85rem 0.7rem; border-bottom: 1px solid rgba(148,163,184,.12); vertical-align: top; }
.table th { color: #cbd5e1; font-size: 0.88rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: 0; }
.dns-table td code { display: inline-block; max-width: 42rem; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.55rem; border-radius: 999px; font-size: 0.82rem;
  background: rgba(148,163,184,.14); border: 1px solid rgba(148,163,184,.18);
}
.badge-active, .badge-sent { background: rgba(34,197,94,.14); border-color: rgba(34,197,94,.22); color: #bbf7d0; }
.badge-draft, .badge-paused, .badge-pending, .badge-scheduled { background: rgba(59,130,246,.14); border-color: rgba(59,130,246,.22); color: #bfdbfe; }
.badge-failed, .badge-bounced { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.22); color: #fecaca; }
.badge-replied { background: rgba(168,85,247,.14); border-color: rgba(168,85,247,.22); color: #e9d5ff; }
.badge-unsubscribed, .badge-completed, .badge-skipped { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.22); color: #fde68a; }

.flash-stack { display: grid; gap: 0.65rem; margin-bottom: 1rem; }
.flash { padding: 0.9rem 1rem; border-radius: 0.9rem; border: 1px solid rgba(148,163,184,.18); }
.flash-success { background: rgba(34,197,94,.14); color: #dcfce7; border-color: rgba(34,197,94,.22); }
.flash-error { background: rgba(239,68,68,.14); color: #fee2e2; border-color: rgba(239,68,68,.22); }
.flash-warning { background: rgba(245,158,11,.14); color: #fef3c7; border-color: rgba(245,158,11,.22); }

.editor { border: 1px solid rgba(148,163,184,.18); border-radius: 0.95rem; overflow: hidden; background: rgba(2,6,23,.35); }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0.55rem; border-bottom: 1px solid rgba(148,163,184,.16); background: rgba(15,23,42,.92); }
.editor-toolbar button { border: 1px solid rgba(148,163,184,.18); background: rgba(148,163,184,.08); color: var(--text); padding: 0.45rem 0.65rem; border-radius: 0.7rem; cursor: pointer; }
.editor-toolbar button:hover { background: rgba(148,163,184,.15); }
.editor-surface { min-height: 260px; border: 0; border-radius: 0; background: transparent; }
.editor-input { display: none; }

.thread-list { display: grid; gap: 0.85rem; }
.thread-item { border: 1px solid rgba(148,163,184,.16); border-radius: 0.9rem; padding: 0.85rem; }
.thread-outgoing { background: rgba(56,189,248,.08); }
.thread-incoming { background: rgba(168,85,247,.08); }
.thread-meta { display: flex; gap: 0.65rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.35rem; }
.thread-addresses { font-size: 0.92rem; color: var(--muted); margin-bottom: 0.5rem; }
.thread-body { margin: 0; background: rgba(2,6,23,.35); border-radius: 0.75rem; padding: 0.85rem; }
.log-box { background: rgba(2,6,23,.65); min-height: 400px; padding: 1rem; border-radius: 0.9rem; border: 1px solid rgba(148,163,184,.14); overflow: auto; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 460px); background: rgba(15,23,42,.95); border: 1px solid rgba(148,163,184,.18); border-radius: 1.1rem; padding: 1.35rem; box-shadow: var(--shadow); }
.login-card h1 { margin-top: 0; }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .sidebar-footer { position: static; margin-top: 1rem; }
  .card-grid.two-col, .form-grid.two-col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .content { padding: 1rem; }
  .page-head { flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}
