/* ── Reset & base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-page:    #f4f5f7;
  --bg-surface: #ffffff;
  --bg-muted:   #f9fafb;
  --text-primary:   #1a1a1a;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --border:         rgba(0,0,0,0.09);
  --border-strong:  rgba(0,0,0,0.18);
  --teal:       #1D9E75;
  --teal-light: #E1F5EE;
  --teal-dark:  #0F6E56;
  --amber:      #BA7517;
  --amber-light:#FAEEDA;
  --red:        #E24B4A;
  --red-light:  #FCEBEB;
  --blue:       #378ADD;
  --blue-light: #E6F1FB;
  --orange:     #D85A30;
  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
}

body {
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ───────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 216px 1fr;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ──────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 0.5px solid var(--border);
  z-index: 10;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.logo-dot     { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }
.logo-text    { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; }
.divider      { color: var(--border-strong); }
.station-label{ font-size: 12px; color: var(--text-secondary); font-family: monospace; }
.clock        { font-size: 12px; color: var(--text-muted); font-family: monospace; }

.live-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--teal);
  background: var(--teal-light);
  padding: 3px 9px; border-radius: 20px;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--teal);
  animation: pulse 1.4s infinite;
}
.live-badge.disconnected { color: var(--text-muted); background: var(--bg-muted); }
.live-badge.disconnected .live-dot { background: var(--text-muted); animation: none; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-surface);
  border-right: 0.5px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}
.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--text-muted);
  padding: 14px 20px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 2px solid transparent;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover   { background: var(--bg-muted); color: var(--text-primary); }
.nav-item.active  { background: var(--teal-light); color: var(--teal-dark); border-left-color: var(--teal); font-weight: 600; }
.nav-icon         { font-size: 13px; width: 16px; text-align: center; }
.badge            {
  margin-left: auto;
  background: var(--red-light); color: var(--red);
  font-size: 10px; padding: 1px 6px; border-radius: 8px;
}

/* ── Main content ─────────────────────────────────────────────────── */
.main { overflow-y: auto; padding: 24px; }
.page { display: none; flex-direction: column; gap: 16px; }
.page.active { display: flex; }

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Metric cards ─────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.metric-card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  position: relative;
  transition: border-color 0.2s;
}
.metric-card.breached { border-color: var(--red); }
.metric-label  { font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 5px; }
.metric-value  { font-size: 30px; font-weight: 600; letter-spacing: -1px; line-height: 1; }
.metric-unit   { font-size: 14px; font-weight: 400; color: var(--text-secondary); margin-left: 2px; }
.metric-trend  { font-size: 11px; color: var(--text-muted); margin-top: 5px; display: flex; align-items: center; gap: 6px; }
.alert-dot     {
  position: absolute; top: 12px; right: 12px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
  animation: pulse 1s infinite;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 13px; font-weight: 600; }
.card-meta  { font-size: 11px; color: var(--text-muted); }
.card-footer { display: flex; align-items: center; gap: 10px; margin-top: 16px; }

/* ── Charts ───────────────────────────────────────────────────────── */
.chart-block { margin-bottom: 20px; }
.chart-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.chart-wrap  { position: relative; height: 120px; }
.chart-wrap.tall { height: 150px; }

.live-chart-card {
  background: var(--bg-surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin-bottom: 12px;
}
.live-chart-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.live-chart-title { font-size: 13px; font-weight: 500; }
.live-chart-val   { font-size: 13px; color: var(--text-secondary); font-family: monospace; }

/* ── Threshold table ──────────────────────────────────────────────── */
.thresh-table { width: 100%; }
.thresh-row {
  display: grid;
  grid-template-columns: 1fr 130px 130px 110px 60px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
}
.thresh-row:last-child { border-bottom: none; }
.thresh-header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding-bottom: 6px;
}
.thresh-input {
  width: 100%;
  padding: 5px 8px;
  font-size: 13px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text-primary);
  font-family: monospace;
}
.thresh-input:focus { outline: none; border-color: var(--teal); }

/* ── Toggle ───────────────────────────────────────────────────────── */
.toggle {
  width: 34px; height: 19px;
  border-radius: 10px;
  background: #d1d5db;
  position: relative; cursor: pointer;
  border: none; transition: background 0.2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--teal); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2.5px; left: 2.5px;
  width: 14px; height: 14px;
  border-radius: 50%; background: #fff;
  transition: left 0.2s;
}
.toggle.on::after { left: 17.5px; }

/* ── Status chips ─────────────────────────────────────────────────── */
.chip {
  display: inline-block;
  font-size: 11px; padding: 2px 8px;
  border-radius: 10px; font-weight: 500;
}
.chip.ok     { background: var(--teal-light);  color: var(--teal-dark); }
.chip.warn   { background: var(--amber-light); color: var(--amber); }
.chip.danger { background: var(--red-light);   color: var(--red); }

/* ── Alert log ────────────────────────────────────────────────────── */
.alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }
.alert-icon {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0; margin-top: 1px;
}
.alert-icon.warn   { background: var(--amber-light); color: var(--amber); }
.alert-icon.danger { background: var(--red-light);   color: var(--red); }
.alert-icon.ok     { background: var(--teal-light);  color: var(--teal); }
.alert-msg  { font-size: 13px; line-height: 1.5; }
.alert-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.empty-msg  { font-size: 13px; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  padding: 7px 16px;
  font-size: 13px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn:hover { background: var(--bg-muted); }
.btn.primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn.primary:hover { background: var(--teal-dark); }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-group { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.form-group label { font-size: 13px; color: var(--text-secondary); min-width: 120px; }
.form-group input,
.form-group select {
  flex: 1; padding: 7px 10px; font-size: 13px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  color: var(--text-primary);
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--teal); }

.save-confirm { font-size: 12px; color: var(--teal); display: none; }
.status-msg   { font-size: 12px; margin-top: 10px; min-height: 18px; }

/* ── Guide list ───────────────────────────────────────────────────── */
.guide-list { padding-left: 20px; font-size: 13px; line-height: 2; color: var(--text-secondary); }
.guide-list code { background: var(--bg-muted); padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 12px; }
.info-box { margin-top: 14px; background: var(--bg-muted); border-radius: var(--radius-md); padding: 10px 14px; font-size: 13px; }

/* ── Overlay ──────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.overlay-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  text-align: center;
  min-width: 260px;
}
.spinner {
  width: 30px; height: 30px;
  border: 2.5px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-title { font-size: 14px; font-weight: 600; }
.overlay-sub   { font-size: 12px; color: var(--text-secondary); margin-top: 5px; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .thresh-row  { grid-template-columns: 1fr 100px 100px 80px 50px; gap: 8px; }
}
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 52px auto 1fr; }
  .sidebar { grid-row: 2; display: flex; flex-wrap: wrap; padding: 8px; border-right: none; border-bottom: 0.5px solid var(--border); }
  .nav-section { display: none; }
  .metric-grid { grid-template-columns: 1fr; }
}
