:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1f2937;
  --border: #374151;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1e1b4b 0%, var(--bg) 60%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem;
  width: min(420px, 92vw);
  box-shadow: var(--shadow);
  text-align: center;
}
.brand h1 { margin: .75rem 0 .25rem; font-size: 1.5rem; }
.brand p { color: var(--muted); margin: 0 0 1.5rem; }
.brand-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem;
}
.brand-icon.sm { width: 40px; height: 40px; font-size: .85rem; border-radius: 10px; }
.login-hint { color: var(--muted); font-size: .85rem; margin-top: 1rem; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem;
  position: fixed; top: 0; left: 0; bottom: 0;
}
.sidebar-brand {
  display: flex; gap: .75rem; align-items: center;
  padding: .5rem; margin-bottom: 1.5rem;
}
.sidebar-brand small { color: var(--muted); display: block; }
.nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.nav-item {
  background: transparent; border: none; color: var(--muted);
  text-align: left; padding: .7rem .9rem; border-radius: 10px;
  cursor: pointer; font-size: .92rem; transition: .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(99,102,241,.2); color: var(--accent-2); font-weight: 600; }
.logout-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: .6rem; border-radius: 10px; cursor: pointer;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

.main { margin-left: 240px; flex: 1; padding: 1.5rem 2rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.topbar h2 { margin: 0; font-size: 1.4rem; }
.topbar-meta { color: var(--muted); font-size: .85rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
}
.kpi-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.75rem; font-weight: 700; margin-top: .35rem; }
.kpi-sub { color: var(--muted); font-size: .8rem; margin-top: .25rem; }

.charts-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem;
}
@media (max-width: 1100px) { .charts-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.card h3 { margin: 0 0 1rem; font-size: 1rem; font-weight: 600; }

.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
input[type=search], select, textarea {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: .55rem .75rem;
  font-family: inherit; font-size: .9rem;
}
input[type=search] { min-width: 240px; }
textarea { width: 100%; resize: vertical; }
.check { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: .4rem; }

.btn {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: .55rem 1rem; border-radius: 8px;
  cursor: pointer; font-size: .9rem;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: .3rem .6rem; font-size: .8rem; }

.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; }
.table tr:hover td { background: rgba(255,255,255,.02); }
.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
}
.badge.ok { background: rgba(34,197,94,.15); color: var(--success); }
.badge.no { background: rgba(156,163,175,.15); color: var(--muted); }

.pager { display: flex; gap: .5rem; margin-top: 1rem; justify-content: center; }
.pager button { min-width: 36px; }

.section-title { margin: 1.5rem 0 .75rem; font-size: 1rem; }

.broadcast-card label { display: block; margin-bottom: 1rem; color: var(--muted); font-size: .85rem; }
.broadcast-card select, .broadcast-card textarea { margin-top: .4rem; display: block; }

.ret-cell { text-align: center; font-weight: 600; border-radius: 4px; padding: .4rem !important; }
.ret-low { background: rgba(239,68,68,.2); }
.ret-mid { background: rgba(245,158,11,.2); }
.ret-high { background: rgba(34,197,94,.25); }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.5rem; width: min(640px, 94vw);
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-close {
  position: absolute; top: .75rem; right: .75rem;
  background: transparent; border: none; color: var(--muted);
  font-size: 1.5rem; cursor: pointer;
}
.modal h3 { margin: 0 0 1rem; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.modal-stat { background: var(--surface-2); padding: .6rem .8rem; border-radius: 8px; }
.modal-stat label { display: block; color: var(--muted); font-size: .75rem; }
.modal-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .75rem 1.25rem; border-radius: 10px; z-index: 200;
  box-shadow: var(--shadow);
}

canvas { max-height: 260px; }
