/* ---------- Design tokens ---------- */
:root {
  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --panel: #151924;
  --panel-2: #1a1f2c;
  --border: #262c3a;
  --border-soft: #1e2330;
  --text: #eef0f4;
  --text-dim: #9aa4b8;
  --text-faint: #6b7386;
  --accent: #f0a132;
  --accent-strong: #ffb84d;
  --accent-text: #1a1206;
  --accent-soft: rgba(240, 161, 50, 0.12);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f26d6d;
  --danger-soft: rgba(242, 109, 109, 0.14);
  --warn: #f0c96f;
  --warn-soft: rgba(240, 201, 111, 0.14);
  --info: #7fc4f0;
  --info-soft: rgba(127, 196, 240, 0.14);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);

  --sidebar-w: 246px;
  --topbar-h: 60px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --border: #e4e6ec;
  --border-soft: #ebedf1;
  --text: #171a21;
  --text-dim: #5b6373;
  --text-faint: #8891a1;
  --accent-text: #1a1206;
  --accent-soft: rgba(217, 130, 15, 0.1);
  --success-soft: rgba(16, 150, 100, 0.1);
  --danger-soft: rgba(220, 60, 60, 0.1);
  --warn-soft: rgba(180, 130, 10, 0.12);
  --info-soft: rgba(30, 120, 190, 0.1);
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 20, 30, 0.08);
  --shadow-lg: 0 16px 48px rgba(20, 20, 30, 0.14);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: var(--accent); }

svg { display: block; width: 18px; height: 18px; flex-shrink: 0; }

input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
select { cursor: pointer; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
.login-bg-glow {
  position: absolute;
  width: 700px;
  height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  top: -200px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.login-box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 34px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.login-logo svg { width: 24px; height: 24px; }
.login-box h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 18px; }
.login-box label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-top: 10px; }
.login-box input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-top: 5px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.login-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), color 0.15s var(--ease);
  white-space: nowrap;
}
button:active { transform: translateY(1px); }

.btn-primary, .btn-secondary, .btn-danger {
  padding: 8px 16px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-block { width: 100%; margin-top: 18px; padding: 10px 16px; font-size: 14px; }

.btn-secondary {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: var(--border-soft); border-color: var(--text-faint); }
.btn-secondary:disabled, .btn-icon:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-icon:hover { color: var(--text); border-color: var(--text-faint); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
  text-align: left;
}
.link-btn:hover { color: var(--danger); }

.btn-spinner {
  width: 15px; height: 15px;
  animation: spin 0.7s linear infinite;
  stroke: currentColor;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Shell layout ---------- */

.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  transition: transform 0.25s var(--ease);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  width: 100%;
}
.tab-btn svg { opacity: 0.85; }
.tab-btn:hover { background: var(--panel-2); color: var(--text); }
.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.tab-btn.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-toggle {
  align-self: flex-start;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.theme-toggle:hover { color: var(--accent); }

.sidebar-user { display: flex; align-items: center; gap: 9px; padding: 0 2px; }
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}
#whoami { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.mobile-nav-btn {
  display: none;
  background: none; border: none; color: var(--text);
  width: 32px; height: 32px; align-items: center; justify-content: center;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 60px;
}

/* ---------- Panels & cards ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { font-size: 14.5px; margin: 0 0 12px; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.cards { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  min-width: 150px;
  flex: 1;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.card .icon-wrap {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.card .icon-wrap svg { width: 17px; height: 17px; }
.card.forwarded .icon-wrap { background: var(--success-soft); color: var(--success); }
.card.processed .icon-wrap { background: var(--info-soft); color: var(--info); }
.card.blocked .icon-wrap { background: var(--danger-soft); color: var(--danger); }
.card.pending .icon-wrap { background: var(--warn-soft); color: var(--warn); }
.card .n { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.card .l { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* ---------- Tables ---------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border-soft); }
th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--panel-2);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s var(--ease); }
tbody tr:hover td { background: var(--panel-2); }
td { color: var(--text); }
.hint { color: var(--text-faint); font-size: 12px; margin: 4px 0 10px; }

/* ---------- Toolbar / forms ---------- */

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-spacer { flex: 1; }
.toolbar input, .toolbar select,
.modal input, .modal select, .modal textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.toolbar input:focus, .toolbar select:focus,
.modal input:focus, .modal select:focus, .modal textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-input {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 220px;
  flex: 1;
  max-width: 340px;
}
.search-input svg { position: absolute; left: 10px; width: 15px; height: 15px; color: var(--text-faint); }
.search-input input { padding-left: 32px; width: 100%; }

/* ---------- Badges ---------- */

.badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.forwarded { background: var(--success-soft); color: var(--success); }
.badge.processed { background: var(--info-soft); color: var(--info); }
.badge.blocked { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Bar chart ---------- */

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding-top: 10px; }
.bar-chart .bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--text-faint); flex: 1; }
.bar-chart .bar-wrap .n { color: var(--text); font-weight: 600; font-size: 12px; }
.bar-chart .bar {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  width: 100%;
  max-width: 34px;
  border-radius: 6px 6px 2px 2px;
  transition: height 0.3s var(--ease);
}

/* ---------- Empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--text-faint);
  text-align: center;
}
.empty-state svg { width: 34px; height: 34px; opacity: 0.5; }
.empty-state p { margin: 0; font-size: 13px; max-width: 320px; }

/* ---------- Pager ---------- */

.pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--text-dim); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(5, 6, 10, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fade-in 0.15s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 560px;
  max-width: 100%;
  max-height: 85vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s var(--ease);
  position: relative;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.confirm-modal { width: 380px; }
.confirm-modal p { margin: 4px 0 4px; font-size: 14px; }
.modal h2 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin: 12px 0 5px; }
.modal input, .modal select, .modal textarea { width: 100%; }
.modal textarea { font-family: ui-monospace, monospace; font-size: 12px; min-height: 200px; white-space: pre; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 50%;
  font-size: 13px;
  padding: 0;
}
.modal-close:hover { color: var(--text); }

/* ---------- Toasts ---------- */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  max-width: 340px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s var(--ease);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
.toast.leaving { animation: toast-out 0.15s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-nav-btn { display: flex; }
  main { padding: 18px 16px 60px; }
  .topbar { padding: 0 14px; }
}

/* ---------- Bounce-Hub ---------- */
.hub-subnav { gap: 6px; }
.hub-pill { background: transparent; border: 1px solid var(--border); color: var(--text-dim); padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px; }
.hub-pill:hover { color: var(--text); border-color: var(--text-faint); }
.hub-pill.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
.hubcard { min-width: 150px; flex: 1; }
.hubcard.complaint .icon-wrap { background: rgba(192, 132, 252, 0.15); color: #c084fc; }
.hub-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }
.hub-svg { width: 100%; height: auto; display: block; }
.hub-grid { stroke: var(--border-soft); stroke-width: 1; }
.hub-axis { fill: var(--text-faint); font-size: 10.5px; }
.hub-donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hub-donut { width: 150px; height: 150px; flex: none; }
.hub-donut-n { fill: var(--text); font-size: 20px; font-weight: 700; }
.hub-legend { flex: 1; min-width: 190px; }
.hub-legend-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.hub-legend-label { flex: 1; color: var(--text-dim); }
.hub-pct { color: var(--text-faint); width: 38px; text-align: right; font-size: 12px; }
.hub-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.hub-hbar { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 12.5px; }
.hub-hbar-label { width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.hub-hbar-track { flex: 1; display: flex; height: 12px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.hub-hbar-track i { display: block; height: 100%; }
.hub-hbar b { width: 48px; text-align: right; }
.hub-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); }
.hub-detail { max-width: 380px; }
.hub-bad { color: var(--danger); }
.hub-switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; margin-right: 8px; }
.hub-switch input { opacity: 0; width: 0; height: 0; }
.hub-switch span { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: background .15s; }
.hub-switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.hub-switch input:checked + span { background: var(--success); }
.hub-switch input:checked + span::before { transform: translateX(16px); }
.toolbar label { color: var(--text-dim); font-size: 13px; }
.hub-token-box { margin: 10px 0 16px; padding: 12px 14px; background: var(--warn-soft); border: 1px solid var(--warn); border-radius: var(--radius); font-size: 13px; }
.hub-token-box code { display: block; margin-top: 6px; word-break: break-all; user-select: all; font-size: 13px; }

/* Bounce-Hub Analytics */
.an-rate { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.an-rate-track { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; position: relative; }
.an-rate-track i { display: block; height: 100%; border-radius: 4px; }
.an-rate b { font-size: 12.5px; width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.an-risk-ok { color: var(--success); }
.an-risk-warn { color: var(--warn); }
.an-risk-critical { color: var(--danger); }
.an-risk-dead { color: var(--text-faint); }
.an-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.an-split { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--panel-2); }
.an-split i { display: block; height: 100%; }

.an-insights { display: grid; gap: 8px; margin-bottom: 16px; }
.an-ins { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel); border-left: 4px solid var(--c); }
.an-ins.critical { --c: var(--danger); background: color-mix(in srgb, var(--danger) 7%, var(--panel)); }
.an-ins.warn { --c: var(--warn); background: color-mix(in srgb, var(--warn) 7%, var(--panel)); }
.an-ins.info { --c: var(--info); }
.an-ins.good { --c: var(--success); background: color-mix(in srgb, var(--success) 7%, var(--panel)); }
.an-ins-body { flex: 1; min-width: 0; }
.an-ins-title { font-weight: 600; font-size: 13.5px; }
.an-ins-text { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.an-ins button { flex: none; align-self: center; }

#hub-view-analytics .grid-2 > * { min-width: 0; }
#hub-view-analytics h3 { font-size: 13px; margin: 6px 0; color: var(--text-dim); }
#hub-view-analytics svg { max-width: 100%; }
@media (max-width: 900px) { #hub-view-analytics .grid-2 { grid-template-columns: 1fr; } }
