:root {
  color-scheme: dark;
  /* Validated dark-mode dataviz palette (chart chrome + categorical + status). */
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);

  --series-blue:    #3987e5; /* sequential / primary chart hue */
  --series-aqua:    #199e70; /* brand accent, matches the RS Tech mark */
  --series-violet:  #9085e9;
  --series-red:     #e66767;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --brand-glow: 0 0 24px rgba(25, 158, 112, 0.35);
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(25,158,112,0.10), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(57,135,229,0.08), transparent 55%),
    var(--page-plane);
  color: var(--text-primary);
  min-height: 100vh;
}

::selection { background: rgba(25,158,112,0.35); }

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

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)), var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-logo img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 0 12px rgba(25,158,112,0.55));
}
.login-logo .brand {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.login-logo .brand strong { color: var(--text-secondary); }

.login-card h1 {
  font-size: 19px;
  margin: 0 0 24px;
  font-weight: 600;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #0c0e14;
  color: var(--text-primary);
  font-size: 14px;
}
.field input:focus {
  outline: none;
  border-color: var(--series-aqua);
  box-shadow: 0 0 0 3px rgba(25,158,112,0.18);
}

button.primary {
  width: 100%;
  padding: 12px;
  border-radius: 9px;
  border: none;
  background: linear-gradient(135deg, var(--series-aqua), #14b886);
  color: #04140d;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: var(--brand-glow);
  transition: filter 0.15s, transform 0.1s;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: translateY(1px); }

.error-msg {
  color: var(--status-critical);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

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

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(13,13,13,0.85);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-block img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(25,158,112,0.5));
}
.brand-block .titles h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand-block .titles .sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sync-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-good);
  box-shadow: 0 0 8px currentColor;
  display: inline-block;
}
.dot.warn { background: var(--status-warning); }
.dot.err { background: var(--status-critical); }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
button.ghost:hover { color: var(--text-primary); border-color: var(--series-aqua); }

main {
  padding: 24px 28px 60px;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---------- KPI row ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-tile {
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0)), var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}
.kpi-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120px 60px at 100% 0%, rgba(57,135,229,0.12), transparent 70%);
  pointer-events: none;
}
.kpi-tile .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.kpi-tile .value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}
.kpi-tile .delta {
  font-size: 12px;
  margin-top: 6px;
  font-weight: 600;
}
.kpi-tile .delta.up { color: var(--status-good); }
.kpi-tile .delta.down { color: var(--status-critical); }
.kpi-tile.alerts .value { display: flex; align-items: baseline; gap: 10px; }
.kpi-tile .sev-breakdown {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}
.kpi-tile .sev-breakdown span { display: flex; align-items: center; gap: 4px; }

/* ---------- Alerts / diagnostics panel ---------- */

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 28px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.alert-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--sev-color, var(--text-muted));
  border-radius: 10px;
  padding: 12px 14px;
}
.alert-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--sev-color, var(--text-muted));
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #06110b;
  margin-top: 1px;
}
.alert-body { flex: 1; min-width: 0; }
.alert-body .top-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}
.alert-body .title { font-size: 13px; font-weight: 700; }
.alert-body .account-chip {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 8px;
}
.alert-body .detail { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.alert-body .suggestion { font-size: 12px; color: var(--series-aqua); }
.alert-body .suggestion::before { content: "→ "; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Account grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0)), var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: rgba(25,158,112,0.4); transform: translateY(-1px); }
.card.disabled { opacity: 0.4; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 10px;
}

.card-head .name-block { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-head h3 { font-size: 14px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .biz { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.card-controls { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.toggle {
  width: 34px;
  height: 19px;
  border-radius: 10px;
  background: var(--baseline);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle.on { background: var(--series-aqua); }
.toggle .knob {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left 0.15s;
}
.toggle.on .knob { left: 17px; }

.spark-wrap { margin: 6px 0 12px; height: 44px; }
.spark-wrap svg { display: block; width: 100%; height: 100%; overflow: visible; }

.period-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.period-tabs button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.period-tabs button.active { background: var(--series-aqua); color: #04140d; border-color: var(--series-aqua); font-weight: 700; }

.metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.metric {
  background: rgba(0,0,0,0.28);
  border-radius: 9px;
  padding: 10px;
}
.metric .label { font-size: 10.5px; color: var(--text-muted); margin-bottom: 4px; }
.metric .value { font-size: 15px; font-weight: 700; font-variant-numeric: normal; }

.badge-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.badge {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: 20px;
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}

.modal h2 { margin: 0 0 2px; font-size: 18px; }
.modal .sub { color: var(--text-muted); font-size: 12px; margin-bottom: 18px; }

.chart-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.chart-toggle button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.chart-toggle button.active { background: rgba(57,135,229,0.18); color: var(--series-blue); border-color: var(--series-blue); font-weight: 700; }

.detail-chart-wrap {
  position: relative;
  height: 180px;
  margin-bottom: 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0,0,0,0.2);
}
.detail-chart-wrap svg { width: 100%; height: 100%; display: block; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: #0c0e14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.chart-tooltip .val { color: var(--text-primary); font-weight: 700; font-size: 13px; }

.campaign-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: rgba(255,255,255,0.02);
}
.campaign-row .name { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.campaign-row .stats { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.campaign-row .stats b { color: var(--text-primary); font-weight: 600; }

.close-btn {
  float: right;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.close-btn:hover { color: var(--text-primary); }

.toggle-ads-btn {
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--series-aqua);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.toggle-ads-btn:hover { border-color: var(--series-aqua); }

.ads-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.ad-row {
  display: flex;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(0,0,0,0.2);
}
.ad-thumb {
  width: 56px;
  height: 56px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--baseline);
}
.ad-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-info { min-width: 0; flex: 1; }
.ad-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-adset { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.ad-stats { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-muted); flex-wrap: wrap; }
.ad-stats b { color: var(--text-primary); font-weight: 600; }

/* ---------- Reports ---------- */

.report-btn {
  background: transparent;
  border: 1px solid var(--series-aqua);
  color: var(--series-aqua);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
  margin-left: 8px;
}
.report-btn:hover { background: rgba(25,158,112,0.12); }

.report-modal .field { margin-bottom: 14px; }
.report-modal label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.report-modal input, .report-modal select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c0e14;
  color: var(--text-primary);
  font-size: 13px;
}
.report-link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #0c0e14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 12px;
  word-break: break-all;
}
.report-link-box a { color: var(--series-blue); }

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  header.topbar { padding: 12px 14px; }
  .brand-block .titles h1 { font-size: 14px; }
  .topbar-actions { gap: 8px; width: 100%; justify-content: space-between; }
  .sync-status { font-size: 11px; }
  button.ghost { padding: 7px 10px; font-size: 12px; }

  main { padding: 16px 14px 50px; }

  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-tile { padding: 13px 14px; }
  .kpi-tile .value { font-size: 20px; }
  .kpi-tile.alerts { grid-column: span 2; }

  .grid { grid-template-columns: 1fr; }
  .card { padding: 15px; }

  .section-title { flex-wrap: wrap; gap: 8px; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 18px;
  }

  .metrics-row { grid-template-columns: repeat(2, 1fr); }

  .ad-row { flex-direction: row; }
  .ad-thumb { width: 46px; height: 46px; }
  .ad-stats { gap: 10px; }

  .campaign-row .stats { gap: 10px; }

  .alert-row { padding: 10px 12px; }
  .alert-body .top-line { flex-direction: column; align-items: flex-start; gap: 4px; }
}

@media (max-width: 380px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .metrics-row { grid-template-columns: 1fr; }
}
