/* Redirect Platform — operator console.
 *
 * Design intent: an instrument panel for one technical operator, not a
 * marketing SaaS dashboard. Dense, legible, calm. A single cool accent marks
 * "live / active / primary action"; danger is a separate warm signal. Numeric
 * identifiers (email_id, list_id, ASN) are set in a monospace face because they
 * ARE data the operator reads and compares — justified, not decorative.
 *
 * Theming: default dark; light theme via [data-theme="light"].
 */

:root {
  /* Core palette — cool slate console */
  --bg: #0d1117;
  --bg-raised: #151b24;
  --bg-inset: #0a0e14;
  --panel: #161d27;
  --border: #232d3b;
  --border-strong: #324155;
  --text: #e6edf3;
  --text-dim: #9aa7b5;
  --text-faint: #64717f;

  /* Accent (live/active/primary) — a signalling cyan, used sparingly */
  --accent: #39b7c9;
  --accent-strong: #2a97a8;
  --accent-wash: rgba(57, 183, 201, 0.12);

  /* Status signals */
  --ok: #3fb950;
  --ok-wash: rgba(63, 185, 80, 0.12);
  --warn: #d29922;
  --warn-wash: rgba(210, 153, 34, 0.12);
  --danger: #e5534b;
  --danger-wash: rgba(229, 83, 75, 0.12);
  --automated: #a371f7;
  --automated-wash: rgba(163, 113, 247, 0.12);

  --radius: 6px;
  --radius-sm: 4px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --sidebar-w: 236px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] {
  --bg: #f6f8fa;
  --bg-raised: #ffffff;
  --bg-inset: #eef1f4;
  --panel: #ffffff;
  --border: #d8dee4;
  --border-strong: #c2cad3;
  --text: #1c2330;
  --text-dim: #5a6575;
  --text-faint: #8a94a2;
  --accent: #1a8697;
  --accent-strong: #146b79;
  --accent-wash: rgba(26, 134, 151, 0.1);
  --ok: #1a7f37;
  --ok-wash: rgba(26, 127, 55, 0.1);
  --warn: #9a6700;
  --warn-wash: rgba(154, 103, 0, 0.1);
  --danger: #cf222e;
  --danger-wash: rgba(207, 34, 46, 0.1);
  --automated: #8250df;
  --automated-wash: rgba(130, 80, 223, 0.1);
  --shadow: 0 1px 2px rgba(27, 35, 48, 0.08), 0 2px 8px rgba(27, 35, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono, .id { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-inset);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 8px 16px;
  font-weight: 600; letter-spacing: -0.01em;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.nav-group-label {
  font-size: 11px; color: var(--text-faint);
  padding: 14px 8px 4px; letter-spacing: 0.02em;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-size: 13px;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--bg-raised); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-wash); color: var(--text);
  border-color: var(--border);
}
.nav-item.active .nav-ico { color: var(--accent); }
.nav-ico { width: 16px; text-align: center; color: var(--text-faint); font-size: 13px; }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }
.content { padding: 24px; max-width: 1280px; width: 100%; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 13px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-raised);
  color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--text-faint); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04171a; font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-wash); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-raised); border-color: var(--border); }

/* ---------- Panels & cards ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-body { padding: 16px; }

/* Metric tiles — numbers lead, labels follow */
.metric-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.metric {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.metric .val { font-family: var(--mono); font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.metric .lbl { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.metric .sub { color: var(--text-faint); font-size: 11px; margin-top: 2px; }
.metric.accent .val { color: var(--accent); }
.metric.ok .val { color: var(--ok); }
.metric.warn .val { color: var(--warn); }
.metric.danger .val { color: var(--danger); }
.metric.automated .val { color: var(--automated); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 9px 12px; color: var(--text-dim);
  font-weight: 500; border-bottom: 1px solid var(--border); white-space: nowrap;
  cursor: default; font-size: 12px;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg-raised); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Badges & pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px;
  border: 1px solid var(--border-strong); color: var(--text-dim);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); border-color: transparent; background: var(--ok-wash); }
.badge.warn { color: var(--warn); border-color: transparent; background: var(--warn-wash); }
.badge.danger { color: var(--danger); border-color: transparent; background: var(--danger-wash); }
.badge.accent { color: var(--accent); border-color: transparent; background: var(--accent-wash); }
.badge.automated { color: var(--automated); border-color: transparent; background: var(--automated-wash); }
.badge.neutral::before { background: var(--text-faint); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field .hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
input, select, textarea {
  font: inherit; font-size: 13px; width: 100%;
  padding: 8px 10px; background: var(--bg-inset);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input[type="checkbox"] { width: auto; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 160px; margin-bottom: 0; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin-bottom: 0; min-width: 130px; }

/* ---------- States ---------- */
.empty, .loading, .err-state {
  padding: 40px 20px; text-align: center; color: var(--text-dim);
}
.empty .big { font-size: 15px; color: var(--text); margin-bottom: 4px; }
.err-state { color: var(--danger); }
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius); width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent); padding: 11px 15px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); max-width: 340px; font-size: 13px;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }

/* ---------- Charts (inline SVG/CSS) ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; background: var(--accent-wash); border-top: 2px solid var(--accent); min-height: 2px; border-radius: 1px 1px 0 0; position: relative; }
.bars .bar:hover { background: var(--accent); }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 12px; }
.hbar-label { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 8px; background: var(--bg-inset); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar:hover .hbar-fill { background: var(--accent-strong); }
.hbar-val { font-family: var(--mono); color: var(--text); white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-wash); }
.spark { display: flex; align-items: flex-end; gap: 1px; height: 32px; }
.spark .b { flex: 1; background: var(--accent); opacity: 0.6; min-height: 1px; }

/* ---------- Pagination & misc ---------- */
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-dim); }
.pager .spacer { flex: 1; }
.pill-group { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.pill-group button { border: 0; background: var(--bg-raised); color: var(--text-dim); padding: 6px 11px; cursor: pointer; font: inherit; font-size: 12px; border-right: 1px solid var(--border); }
.pill-group button:last-child { border-right: 0; }
.pill-group button.active { background: var(--accent-wash); color: var(--accent); }
.inline-note { font-size: 12px; color: var(--text-faint); display: flex; gap: 6px; align-items: baseline; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-family: var(--mono); }

.section-title { font-size: 13px; color: var(--text-dim); margin: 24px 0 10px; font-weight: 500; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -100%; z-index: 50; width: var(--sidebar-w); transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }

/* Login screen */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { justify-content: center; font-size: 18px; padding-bottom: 20px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
