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

:root {
  --navy:   #1B3A5C;
  --blue:   #2471A3;
  --green:  #1E8449;
  --red:    #C0392B;
  --orange: #D35400;
  --grey:   #566573;
  --lgrey:  #F2F3F4;
  --border: #DDE1E7;
  --text:   #1A202C;
  --muted:  #718096;
  --bg:     #F7F8FA;
  --card:   #FFFFFF;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.07);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--navy);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  letter-spacing: 0.02em;
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-link {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover  { background: rgba(255,255,255,0.12); color: white; }
.nav-link.active { background: rgba(255,255,255,0.18); color: white; }

/* ── Main layout ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 2rem 2rem;
}

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title    { font-size: 1.6rem; font-weight: 700; color: var(--navy); line-height: 1.2; }
.page-subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }

.date-picker-wrap { flex-shrink: 0; }
.date-picker {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.date-picker:focus { outline: 2px solid var(--blue); }

/* ── Stat cards ────────────────────────────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--grey);
}
.stat-card.accent-green  { border-top-color: var(--green); }
.stat-card.accent-blue   { border-top-color: var(--blue);  }
.stat-card.accent-orange { border-top-color: var(--orange);}
.stat-card.accent-red    { border-top-color: var(--red);   }
.stat-card.accent-navy   { border-top-color: var(--navy);  }
.stat-card.accent-grey   { border-top-color: var(--grey);  }

.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 0.3rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stat-sub   { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card-header {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.card-title { font-size: 1rem; font-weight: 600; color: var(--navy); }
.card-meta  { font-size: 0.8rem; color: var(--muted); }

/* ── Charts ────────────────────────────────────────────────────────────────── */
.chart-wrap    { padding: 1rem 1.25rem 1.25rem; height: 320px; }
.chart-wrap-sm { height: 220px; }

/* ── Legend ────────────────────────────────────────────────────────────────── */
.legend-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.legend-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.data-table th {
  background: var(--navy);
  color: white;
  font-weight: 600;
  padding: 0.6rem 0.85rem;
  text-align: left;
  white-space: nowrap;
  /* Sticky header — works when .table-scroll has overflow-y:auto + max-height */
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table td {
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) { background: var(--lgrey); }

.row-charge    { background: rgba(30,132,73,0.06)  !important; }
.row-discharge { background: rgba(192,57,43,0.06)  !important; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.18em 0.6em;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-charge    { background: #D5F5E3; color: var(--green);  }
.badge-discharge { background: #FADBD8; color: var(--red);    }
.badge-idle      { background: #EAECEE; color: var(--grey);   }
.badge-warn      { background: #FDEBD0; color: var(--orange); }
.badge-get       { background: #D5F5E3; color: var(--green);  font-family: monospace; }
.badge-post      { background: #D6EAF8; color: var(--blue);   font-family: monospace; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  line-height: 1.55;
}
.alert a { color: inherit; font-weight: 600; }
.alert-warn { background: #FEF9E7; border-left: 4px solid var(--orange); color: #7D6608; }
.alert-info { background: #EBF5FB; border-left: 4px solid var(--blue);   color: #1A5276; }

/* ── EMS status ────────────────────────────────────────────────────────────── */
.ems-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}
.ems-status-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.status-indicator {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-ok   { background: var(--green);  box-shadow: 0 0 0 3px rgba(30,132,73,0.2); }
.status-warn { background: var(--orange); box-shadow: 0 0 0 3px rgba(211,84,0,0.2);  }
.status-off  { background: #BDC3C7; }

.status-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.status-value { font-size: 0.92rem; font-weight: 600; color: var(--navy); }

/* ── Code block ────────────────────────────────────────────────────────────── */
.code-block {
  background: #1E2A3A;
  color: #A8D8A8;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.82rem;
  padding: 1.25rem;
  overflow-x: auto;
  line-height: 1.7;
  border-radius: 0;
}
code {
  background: var(--lgrey);
  color: var(--navy);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.82em;
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
.footer {
  background: var(--navy);
  color: rgba(255,255,255,0.55);
  text-align: center;
  font-size: 0.78rem;
  padding: 0.7rem;
}

/* ── Cycle counter row ─────────────────────────────────────────────────────── */
.stat-row-cycles { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.cycle-card .stat-value { font-size: 1.7rem; font-variant-numeric: tabular-nums; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main-content { padding: 1rem; }
  .navbar       { padding: 0 1rem; }
  .nav-brand    { font-size: 0.95rem; }
  .nav-link     { padding: 0.35rem 0.55rem; font-size: 0.8rem; }
  .stat-value   { font-size: 1.25rem; }
  .chart-wrap   { height: 240px; }
}
