/* notifications-service admin UI — single shared stylesheet
   Palette: dataviz reference instance (validated light+dark), surfaces #fcfcfb / #1a1a19 */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --status-sent: #2a78d6;
  --status-deferred: #eda100;
  --status-bounced: #d03b3b;
  --status-expired: #4a3aa7;
  --status-failed: #d03b3b;
  --status-dryrun: #898781;
  --good: #006300;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --status-sent: #3987e5;
    --status-deferred: #c98500;
    --status-bounced: #d03b3b;
    --status-expired: #9085e9;
    --status-failed: #e66767;
    --status-dryrun: #898781;
    --good: #0ca30c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; letter-spacing: 0.2px; }
.topbar .brand span { color: var(--text-muted); font-weight: 400; }
.topbar nav { display: flex; gap: 14px; flex: 1; }
.topbar nav a { color: var(--text-secondary); padding: 4px 8px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text-primary); background: color-mix(in srgb, var(--accent) 12%, transparent); text-decoration: none; }
.user-badge { color: var(--text-secondary); font-size: 13px; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.6px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat .label { color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.stat.accent-sent .value { color: var(--status-sent); }
.stat.accent-bounced .value { color: var(--status-bounced); }
.stat.accent-deferred .value { color: var(--status-deferred); }
.stat.accent-expired .value { color: var(--status-expired); }
a.stat-link { display: block; color: inherit; border-radius: 12px; }
a.stat-link:hover { text-decoration: none; }
a.stat-link:hover .stat { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.row > .card { flex: 1 1 380px; margin-bottom: 0; }
.mb16 { margin-bottom: 16px; }

/* ---------- controls ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
select, input[type="text"], input[type="email"], input[type="search"] {
  background: var(--page);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); color: #fff; }
button.danger { color: var(--status-bounced); }
button:disabled { opacity: 0.5; cursor: default; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.table-scroll { overflow-x: auto; }
.muted { color: var(--text-muted); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- status chips (icon glyph + label: never color alone) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-secondary);
  white-space: nowrap;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.chip.s-sent::before, .chip.s-dry-run::before { background: var(--status-sent); }
.chip.s-bounced::before, .chip.s-failed::before { background: var(--status-bounced); }
.chip.s-deferred::before { background: var(--status-deferred); }
.chip.s-expired::before { background: var(--status-expired); }
.chip.s-rejected::before { background: #b3622b; }
.chip.s-suppressed::before { background: var(--text-muted); }
.chip.s-delivered::before { background: #1c9e6e; }
.chip.s-complaint::before { background: #8a2be2; }
.chip.s-spam_block::before { background: #8a2be2; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.badge.ok { color: var(--good); }
.badge.ok::before { background: var(--good); }
.badge.down { color: var(--status-bounced); }
.badge.down::before { background: var(--status-bounced); }

/* ---------- chart ---------- */
.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }
#tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--text-primary);
  box-shadow: 0 6px 24px rgba(0,0,0,0.18); display: none; min-width: 150px;
}
#tooltip .t { color: var(--text-muted); margin-bottom: 4px; }
#tooltip .rowline { display: flex; justify-content: space-between; gap: 14px; }
#tooltip .rowline i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* ---------- reasons ---------- */
.reasons { list-style: none; margin: 0; padding: 0; }
.reasons li { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.reasons .bar-track { flex: 1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.reasons .bar-fill { display: block; height: 100%; background: var(--status-bounced); border-radius: 3px; }
.reasons .count { font-variant-numeric: tabular-nums; color: var(--text-secondary); min-width: 34px; text-align: right; }
.reasons .text { min-width: 0; flex: 0 0 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reasons li.clickable { cursor: pointer; border-radius: 6px; }
.reasons li.clickable:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.reasons li.clickable:hover .text { color: var(--accent); }
.reasons li.clickable:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); }

/* ---------- summary + filter chips (bounces page) ---------- */
.summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; font-size: 13px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip-btn {
  font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-secondary);
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip-btn.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px;
}
.login-card h1 { font-size: 18px; margin: 0 0 6px; }
.login-card p.hint { color: var(--text-secondary); margin: 0 0 18px; font-size: 13px; }
.login-card label { display: block; margin: 14px 0 6px; color: var(--text-secondary); font-size: 13px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 16px; padding: 10px; }
.login-card .error { color: var(--status-bounced); font-size: 13px; min-height: 18px; margin-top: 10px; }
.steps { display: flex; gap: 8px; margin-bottom: 8px; }
.steps .dot { height: 4px; flex: 1; background: var(--grid); border-radius: 2px; }
.steps .dot.active { background: var(--accent); }

.empty { color: var(--text-muted); padding: 18px 0; text-align: center; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------- chart-segment drill-down (click a bar → that bucket) ---------- */
.chart-wrap svg path[data-tip-status] { cursor: pointer; }
.chart-wrap svg path[data-tip-status]:hover { opacity: 0.8; }

.interval-row { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.interval-row[hidden] { display: none; }
.interval-chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 3px 6px 3px 12px; font-size: 12px; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.interval-chip b { font-variant-numeric: tabular-nums; font-weight: 600; }
.interval-chip .chip-x {
  border: 0; background: none; color: inherit; cursor: pointer;
  font-size: 12px; line-height: 1; padding: 3px 6px; border-radius: 50%;
}
.interval-chip .chip-x:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- clickable rows ---------- */
.row-click { cursor: pointer; }
tr.row-click:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- message detail modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px 16px; overflow-y: auto;
  background: rgba(0, 0, 0, 0.45);
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative;
  width: 100%; max-width: 760px; max-height: 85vh; overflow: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}
.modal h3 {
  margin: 0 24px 12px 0; font-size: 14px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.6px; overflow-wrap: anywhere;
}
.modal h4 {
  margin: 16px 0 8px; font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
}
.modal-close {
  position: absolute; top: 10px; right: 10px;
  border: 1px solid var(--border); background: var(--page); color: var(--text-secondary);
  border-radius: 8px; padding: 2px 9px; font-size: 14px; line-height: 1.4;
}
.modal-close:hover { color: var(--status-bounced); border-color: var(--status-bounced); }

.msg-meta { font-size: 13px; }
.msg-meta th, .msg-meta td { border-bottom: 1px solid var(--grid); }
.msg-meta tr:last-child th, .msg-meta tr:last-child td { border-bottom: 0; }
.msg-meta th {
  width: 140px; color: var(--text-muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px; vertical-align: top; white-space: nowrap;
}
.msg-meta td { overflow-wrap: anywhere; }

.msg-error { color: var(--status-bounced); }

.msg-outcomes { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.msg-outcomes li { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.msg-outcomes li:last-child { border-bottom: 0; }
.msg-outcome-ts { white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-outcomes .reason { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--text-secondary); }

.msg-tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.msg-pre {
  margin: 0; padding: 10px 12px; overflow: auto; max-height: 420px;
  background: var(--page); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
