:root {
  --bg-primary:     #ffffff;
  --bg-secondary:   #f4f6f9;
  --bg-card:        #ffffff;
  --bg-deep:        #eef1f6;
  --border:         #e2e8f0;
  --text-primary:   #0f1923;
  --text-secondary: #2d3748;
  --text-muted:     #4a5568;
  --accent:         #1ec99e;
  --accent-dim:     #e6faf5;
  --blue:           #4a9ee8;
  --blue-dim:       #eaf4fd;
  --amber:          #f5a623;
  --amber-dim:      #fef6e6;
  --green:          #3bb37a;
  --green-dim:      #e8f7ef;
  --red:            #e85555;
  --red-dim:        #fdeaea;
  --shadow:         0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.08);
  --radius:         10px;
  --radius-lg:      14px;
  --radius-sm:      6px;
  --font:           'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg-primary:     #0f1923;
  --bg-secondary:   #141d2b;
  --bg-card:        #1a2535;
  --bg-deep:        #141d2b;
  --border:         #1e2d42;
  --text-primary:   #ffffff;
  --text-secondary: #8a9bb0;
  --text-muted:     #4a5568;
  --accent-dim:     #1ec99e22;
  --blue-dim:       #4a9ee822;
  --amber-dim:      #f5a62322;
  --green-dim:      #3bb37a22;
  --red-dim:        #e8555522;
  --shadow:         0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:      0 4px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Typography ── */
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; }

/* ── Layout ── */
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* ── Navbar ── */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}
.navbar-brand .logo-icon {
  width: 32px; height: 32px;
  background: var(--accent-dim);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 16px;
}
.navbar-brand small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
  line-height: 1;
}
.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-link.active { background: var(--accent-dim); color: var(--accent); }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-body { padding: 20px; }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}
.kpi-unit {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 3px;
  font-weight: 400;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.badge-online  { background: var(--green-dim); color: var(--green); }
.badge-offline { background: var(--red-dim);   color: var(--red); }
.badge-warning { background: var(--amber-dim); color: var(--amber); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover { opacity: 0.9; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { background: var(--bg-secondary); }
.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid var(--red);
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
}
select.form-control { cursor: pointer; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  font-family: var(--font);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Progress bar ── */
.progress {
  height: 6px;
  background: var(--bg-deep);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── Alert/feedback ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: var(--green-dim); color: var(--green); }
.alert-error   { background: var(--red-dim);   color: var(--red); }
.alert-warning { background: var(--amber-dim); color: var(--amber); }
.alert-info    { background: var(--blue-dim);  color: var(--blue); }

/* ── Offline banner ── */
.offline-banner {
  background: var(--red);
  color: #fff;
  padding: 8px 24px;
  font-size: 12px;
  display: none;
  align-items: center;
  gap: 10px;
}
.offline-banner.show { display: flex; }

/* ── Theme toggle ── */
.theme-toggle {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.15s;
}
.theme-toggle:hover { background: var(--bg-deep); }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading skeleton ── */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-deep) 25%,
    var(--border) 50%,
    var(--bg-deep) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Utility ── */
.text-accent   { color: var(--accent); }
.text-muted    { color: var(--text-muted); }
.text-green    { color: var(--green); }
.text-red      { color: var(--red); }
.text-amber    { color: var(--amber); }
.text-blue     { color: var(--blue); }
.d-flex        { display: flex; }
.align-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8         { gap: 8px; }
.gap-12        { gap: 12px; }
.gap-16        { gap: 16px; }
.mt-8          { margin-top: 8px; }
.mt-12         { margin-top: 12px; }
.mt-16         { margin-top: 16px; }
.mt-24         { margin-top: 24px; }
.mb-8          { margin-bottom: 8px; }
.mb-12         { margin-bottom: 12px; }
.mb-16         { margin-bottom: 16px; }
.mb-24         { margin-bottom: 24px; }
.w-100         { width: 100%; }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.font-mono     { font-family: monospace; }
.hidden        { display: none !important; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .kpi-grid  { grid-template-columns: repeat(2, 1fr); }
  .navbar-nav { display: none; }
}

/* ── Mobile fixes ── */
@media (max-width: 600px) {
  .counts-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .count-card {
    padding: 12px;
    gap: 8px;
    flex-direction: column;
    align-items: flex-start;
  }
  .count-num { font-size: 22px; }
  .sites-grid {
    grid-template-columns: 1fr;
  }
  .site-card-body {
    grid-template-columns: repeat(3, 1fr);
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .live-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .mode-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .date-row {
    grid-template-columns: 1fr;
  }
  .navbar-nav { display: none; }
  .navbar-right span { display: none; }
}
