/* Theme matched to NEP Fleet Manager:
   near-black header, light warm-gray body, white cards, brick-red accent,
   green positives, uppercase letter-spaced labels, monospaced numerals. */
:root {
  --bg: #f4f3f1;          /* light warm-gray main area */
  --panel: #ffffff;        /* white cards */
  --panel-2: #ecebe8;
  --dark: #161513;         /* near-black header / dark surfaces */
  --dark-2: #211f1c;
  --text: #1a1a1a;         /* near-black text on light */
  --text-inv: #f5f4f2;     /* light text on dark */
  --muted: #8a847c;        /* warm gray */
  --border: #e2e0dc;
  --accent: #e0433f;       /* NEP brick red */
  --accent-dark: #c5362f;
  --ok: #1f9d55;           /* green (positive) */
  --warn: #e0433f;         /* red (was amber) */
  --crit: #e0433f;         /* critical == accent red */
  --offline: #a8a29a;
  --radius: 10px;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* --- Header (dark bar, like the NEP nav) --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--dark);
  color: var(--text-inv);
  position: sticky;
  top: 0;
  z-index: 5;
}
header h1 {
  font-size: 1.1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.logo-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.05em;
}
.conn { display: flex; gap: 8px; }
.badge {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--dark-2);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.link-up { background: rgba(31,157,85,0.2); color: #4ade80; }
.link-down { background: rgba(224,67,63,0.2); color: #ff7b76; }

main { padding: 28px; max-width: 1200px; margin: 0 auto; }
.grid { display: grid; gap: 20px; margin-bottom: 24px; }
.grid-temps { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-cams { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* --- Temperature cards --- */
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  border-top: 4px solid var(--offline);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}
.card.ok { border-top-color: var(--ok); }
.card.warn { border-top-color: var(--warn); }
/* Critical: fill the card red with white text, echoing NEP's red stat tiles. */
.card.critical {
  background: var(--accent);
  border-color: var(--accent);
  border-top-color: var(--accent-dark);
  color: #fff;
  animation: pulse 1.2s infinite;
}
.card.critical .name,
.card.critical .meta,
.card.critical .temp .unit { color: rgba(255,255,255,0.85); }
.card.offline { border-top-color: var(--offline); opacity: 0.75; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(224,67,63,0.25); } }

.card .name {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.card .temp { font-family: var(--mono); font-size: 3rem; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.card .temp .unit { font-size: 1.1rem; color: var(--muted); font-weight: 500; }
.card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 0.8rem; color: var(--muted); }
.card .setpoint { font-family: var(--mono); }
.card .status-pill { font-weight: 700; text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.06em; }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-critical { color: #fff; }
.status-offline { color: var(--offline); }

/* --- Camera tiles --- */
.cam {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
}
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .label {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 8px 12px; font-size: 0.72rem; color: #fff;
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
}
.cam-overlay { position: absolute; inset: 0; pointer-events: none; }
.det {
  position: absolute;
  border: 2px solid #3366cc;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
}
.det-tag {
  position: absolute; top: -18px; left: -2px;
  background: #3366cc; color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 3px; white-space: nowrap;
  font-family: var(--mono); text-transform: uppercase;
}
.det-alert { border-color: var(--accent); }
.det-alert .det-tag { background: var(--accent); }
.cam-ai {
  position: absolute; top: 8px; right: 8px;
  background: rgba(31,157,85,0.9); color: #fff;
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 5px;
}
.cam .offline-msg {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: #9a938a; font-size: 0.85rem; text-align: center; padding: 12px;
}

/* --- Panels (history, alerts) --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 {
  margin: 0; font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); font-weight: 700;
}
.panel-head { gap: 12px; }
.chart-legend { display: flex; gap: 14px; margin-right: auto; }
.chart-legend .lg { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text); font-weight: 600; }
.chart-legend .sw { width: 12px; height: 3px; border-radius: 2px; }
.range-tabs { display: flex; gap: 4px; }
.range-tabs button {
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 4px 12px; border-radius: 6px; cursor: pointer;
}
.range-tabs button.active { background: var(--dark); color: #fff; border-color: var(--dark); }

/* Chart */
#chart { width: 100%; }
#chart svg { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.chart-thresh { stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart-thresh-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.chart-line { fill: none; stroke-width: 2; }
.chart-line-label { font-size: 11px; font-weight: 700; font-family: var(--mono); }
.chart-empty { fill: var(--muted); font-size: 12px; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: var(--dark); color: #fff;
  font-size: 11px; font-family: var(--mono); padding: 6px 9px; border-radius: 6px;
  white-space: nowrap; transform: translate(-50%, -120%); opacity: 0; transition: opacity 0.08s;
}
.chart-wrap { position: relative; }

/* Alerts feed */
#alerts-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
#alerts-list li {
  display: flex; gap: 12px; align-items: baseline;
  padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
#alerts-list li:last-child { border-bottom: none; }
.alert-empty { color: var(--muted); }
.alert-time { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.alert-sev {
  font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap;
}
.sev-critical { background: rgba(224,67,63,0.15); color: var(--crit); }
.sev-warning { background: rgba(217,131,36,0.16); color: #b5670f; }
.sev-info { background: var(--panel-2); color: var(--muted); }
.alert-msg { flex: 1; }

/* --- Reset --- */
.reset-bar { display: flex; align-items: center; gap: 16px; }
button.reset {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 28px;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: var(--radius);
  cursor: pointer;
}
button.reset:hover { background: var(--accent-dark); }
button.reset:disabled { background: var(--offline); cursor: not-allowed; }
.reset-status { color: var(--muted); font-size: 0.85rem; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 420px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h2 { margin-top: 0; text-transform: uppercase; letter-spacing: 0.05em; font-size: 1.1rem; }
dialog menu { display: flex; gap: 12px; justify-content: flex-end; padding: 0; margin: 20px 0 0; }
dialog button { padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); cursor: pointer; font-weight: 600; }
