:root {
  --navy-900: #0a1d3a;
  --navy-800: #0f2850;
  --navy-700: #173466;
  --navy-600: #1f4285;
  --cyan-500: #00c6ff;
  --cyan-400: #33d6ff;
  --cyan-600: #0098cc;
  --ink-900: #0b1220;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-300: #cbd5e1;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 40, 80, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 40, 80, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink-900);
  background: var(--bg);
  min-height: 100vh;
}

body {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar ------------------------------------------------------------- */
.sidebar {
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-800) 100%);
  color: #e2ecff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }

.logo-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cyan-500), var(--cyan-600));
  color: var(--navy-900);
  box-shadow: 0 0 0 2px rgba(0, 198, 255, 0.15);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; letter-spacing: 0.08em; }
.brand-sub { font-size: 11px; color: var(--ink-300); letter-spacing: 0.05em; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  padding: 10px 12px;
  color: #cbd8ef;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active {
  background: rgba(0, 198, 255, 0.12);
  color: #fff;
  border-left: 3px solid var(--cyan-500);
  padding-left: 9px;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  font-size: 12px;
  color: var(--ink-300);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.user-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-email {
  color: #e2ecff;
  font-weight: 500;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form { margin: 0; }

.logout-btn {
  background: transparent;
  color: #cbd8ef;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.logout-btn:hover {
  background: rgba(0, 198, 255, 0.1);
  color: #fff;
  border-color: rgba(0, 198, 255, 0.4);
}

.status-row { display: flex; align-items: center; gap: 8px; }

.status-dot { font-size: 14px; color: var(--ink-500); }
.status-dot.ok { color: var(--success); }
.status-dot.err { color: var(--danger); }

/* Main ---------------------------------------------------------------- */
.main {
  padding: 28px 32px 40px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 24px;
  margin: 0 0 4px;
  color: var(--navy-900);
  letter-spacing: -0.01em;
}

.subtitle { margin: 0; color: var(--ink-500); font-size: 13px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.filters label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px;
  color: var(--ink-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filters input,
.filters select {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink-900);
  background: #fff;
  min-width: 140px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filters .campaign-field select { min-width: 260px; max-width: 320px; }
.scope-badge strong { color: var(--navy-900); margin-left: 2px; }
.scope-badge .muted { color: var(--ink-500); font-weight: 400; }
.filters input:focus,
.filters select:focus {
  border-color: var(--cyan-500);
  box-shadow: 0 0 0 3px rgba(0, 198, 255, 0.18);
}

.btn-primary {
  background: var(--navy-800);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  height: 36px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--navy-700); }
.btn-primary:active { transform: translateY(1px); }

/* Scope badge --------------------------------------------------------- */
.scope-badge {
  display: inline-block;
  margin-bottom: 14px;
  padding: 6px 12px;
  background: rgba(0, 198, 255, 0.1);
  color: var(--navy-800);
  border: 1px solid rgba(0, 198, 255, 0.3);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.scope-badge.all { background: #eef2f7; color: var(--ink-700); border-color: var(--border); }

/* Hint icons (tooltips on KPI labels) ---------------------------------- */
.hint {
  display: inline-grid;
  place-items: center;
  width: 14px; height: 14px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--ink-300);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  vertical-align: 1px;
}
.hint:hover { background: var(--cyan-500); }

/* KPIs ---------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--cyan-500), var(--cyan-600));
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-500);
  font-weight: 600;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--navy-900);
  letter-spacing: -0.02em;
}

/* Panels -------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.panel-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  color: var(--navy-900);
  font-weight: 600;
}

.muted { color: var(--ink-500); font-size: 12px; }

.chart-wrap {
  position: relative;
  height: 300px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1024px) {
  .two-col { grid-template-columns: 1fr; }
}

/* Table --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table th,
table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-500);
  background: #f8fafc;
  font-weight: 600;
}

table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #f8fbff; }

/* Channel summary ----------------------------------------------------- */
.channel-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--ink-700);
}
.channel-summary .row { display: flex; justify-content: space-between; }
.channel-summary .row strong { color: var(--navy-900); font-weight: 600; }

/* User stats ---------------------------------------------------------- */
.stats-grid {
  display: flex;
  flex-direction: column;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }

.stat-label {
  font-size: 13px;
  color: var(--ink-700);
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--navy-900);
  letter-spacing: -0.01em;
}

/* Campaign stats table ------------------------------------------------ */
.campaign-table th.num,
.campaign-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.campaign-table td.campaign-name {
  max-width: 280px;
}

.campaign-table .cn-name {
  font-weight: 500;
  color: var(--navy-900);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.campaign-table .cn-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--ink-500);
  cursor: help;
  margin-top: 2px;
}

.campaign-table tr.highlight td {
  background: rgba(0, 198, 255, 0.08);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status-pill.active { background: rgba(16, 185, 129, 0.12); color: #047857; }
.status-pill.inactive { background: #eef2f7; color: var(--ink-500); }

/* Modal --------------------------------------------------------------- */
.campaign-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.campaign-table tbody tr:hover td {
  background: #eff6fc;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 29, 58, 0.55);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  width: min(900px, 96vw);
  max-height: 92vh;
  border-radius: 14px;
  box-shadow: 0 30px 60px rgba(6, 20, 46, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.18s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  color: var(--navy-900);
}
.modal-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-500);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--ink-500);
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--navy-900); background: #eef2f7; }

.modal-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.modal-kpis .mk {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.modal-kpis .mk-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-500);
  font-weight: 600;
}
.modal-kpis .mk-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy-900);
  letter-spacing: -0.01em;
}

.modal-chart {
  height: 260px;
  padding: 16px 22px 0;
}

.modal-table {
  padding: 16px 22px 22px;
  overflow-y: auto;
}

/* Footer -------------------------------------------------------------- */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 4px 0;
  font-size: 12px;
  color: var(--ink-500);
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* Toast --------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy-900);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

/* Responsive ---------------------------------------------------------- */
@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin-left: auto; border-top: none; padding-top: 0; }
  .main { padding: 20px 18px 32px; }
}
