/* style.css — Transformer Dynamic Loading System */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #0f172a;
  color: #e2e8f0;
  font-family: Inter, system-ui, -apple-system, Arial, sans-serif;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: #1e293b;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #334155;
  flex-shrink: 0;
}

.logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.logo-title { font-weight: 700; font-size: 13px; color: #f1f5f9; line-height: 1.3; }
.logo-title span { color: #3b82f6; }
.logo-sub { font-size: 10px; color: #64748b; margin-top: 4px; }

nav { flex: 1; padding: 10px 8px; }
.nav-btn {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; margin-bottom: 2px;
  background: transparent; border: none; border-radius: 6px;
  color: #94a3b8; font-size: 13px; cursor: pointer; text-align: left;
  position: relative; transition: background 0.15s;
}
.nav-btn:hover { background: #334155; color: #e2e8f0; }
.nav-btn.active { background: #1d4ed8; color: #fff; font-weight: 600; }
.badge {
  margin-left: auto; background: #ef4444; color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700;
}

.ws-status {
  padding: 12px 14px; border-top: 1px solid #334155;
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  color: #94a3b8;
}
.ws-status.connected { color: #22c55e; }
.ws-status.error { color: #ef4444; }
.ws-std { margin-left: auto; font-size: 10px; color: #334155; }

/* ── Main area ───────────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; }

.crit-banner {
  background: #7f1d1d; border-bottom: 1px solid #ef4444;
  padding: 9px 24px; display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: #fecaca; position: sticky; top: 0; z-index: 10;
}
.crit-banner button {
  margin-left: auto; background: #ef4444; color: #fff;
  border: none; border-radius: 4px; padding: 3px 12px;
  font-size: 12px; cursor: pointer; font-weight: 600;
}

/* ── Pages ───────────────────────────────────────────────────────────────── */
.page { display: none; padding: 24px; }
.page.active { display: block; }

.page-header {
  display: flex; align-items: flex-start; gap: 12px; margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; color: #f1f5f9; margin-bottom: 3px; }
.page-header p { font-size: 13px; color: #64748b; }
.page-header > div { flex: 1; }

.back-btn {
  background: #1e293b; border: 1px solid #334155; color: #94a3b8;
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  white-space: nowrap; align-self: center;
}
.back-btn:hover { color: #e2e8f0; }

/* ── Summary grid ────────────────────────────────────────────────────────── */
.summary-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px;
}
.summary-card {
  background: #1e293b; border-radius: 10px; padding: 18px 20px;
  display: flex; justify-content: space-between; align-items: flex-start;
}
.summary-card .label { font-size: 12px; color: #64748b; margin-bottom: 5px; }
.summary-card .value { font-size: 22px; font-weight: 700; margin-bottom: 3px; }
.summary-card .sub { font-size: 11px; color: #475569; }

/* ── Unit cards ──────────────────────────────────────────────────────────── */
.units-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px;
}
.unit-card {
  background: #1e293b; border-radius: 10px; padding: 16px 18px;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid #334155;
}
.unit-card:hover { transform: translateY(-2px); }
.unit-card-header {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;
}
.unit-id { font-weight: 700; font-size: 15px; color: #f1f5f9; }
.unit-sub { font-size: 12px; color: #64748b; }

.mode-badge {
  padding: 3px 11px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.mode-NORMAL         { background: #14532d; color: #4ade80; border: 1px solid #16a34a; }
.mode-PLANNED_OVERLOAD { background: #713f12; color: #fde68a; border: 1px solid #d97706; }
.mode-LT_EMERGENCY   { background: #7c2d12; color: #fdba74; border: 1px solid #ea580c; }
.mode-ST_EMERGENCY   { background: #7f1d1d; color: #fca5a5; border: 1px solid #ef4444; }
.mode-LIMIT_EXCEEDED { background: #450a0a; color: #ff8080; border: 1px solid #dc2626; }
.mode-COOLING_FAILURE{ background: #1e1b4b; color: #c4b5fd; border: 1px solid #7c3aed; }
.mode-UNKNOWN        { background: #1e293b; color: #94a3b8; border: 1px solid #475569; }

.gauges { display: flex; gap: 14px; margin-bottom: 12px; }
.gauge { flex: 1; }
.gauge-row { display: flex; justify-content: space-between; font-size: 11px; color: #94a3b8; margin-bottom: 3px; }
.gauge-track { height: 4px; background: #334155; border-radius: 2px; }
.gauge-fill  { height: 100%; border-radius: 2px; transition: width 1s ease; }

.metrics-mini {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.metric-mini { background: #0f172a; border-radius: 6px; padding: 8px 10px; }
.metric-mini .ml { font-size: 10px; color: #64748b; margin-bottom: 2px; }
.metric-mini .mv { font-weight: 700; font-size: 14px; color: #e2e8f0; }
.metric-mini .ms { font-size: 10px; color: #475569; }

.unit-footer {
  margin-top: 10px; display: flex; align-items: center; gap: 6px; font-size: 11px;
}

/* ── Unit detail ─────────────────────────────────────────────────────────── */
.metrics-row {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px;
}
.stat-box { background: #0f172a; border-radius: 8px; padding: 14px 16px; }
.stat-box .sl { font-size: 11px; color: #64748b; margin-bottom: 4px; }
.stat-box .sv { font-size: 24px; font-weight: 700; }
.stat-box .ss { font-size: 11px; color: #475569; margin-top: 3px; }

.corrections-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.corr-tag {
  padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600;
}
.corr-tag.on  { background: #1d4ed820; color: #60a5fa; border: 1px solid #1d4ed8; }
.corr-tag.off { background: #1e293b;   color: #475569; border: 1px solid #334155; }

.detail-grid {
  display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px;
}

.param-footer {
  margin-top: 8px; padding: 12px 16px; background: #1e293b;
  border-radius: 8px; font-size: 12px; color: #64748b;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: #1e293b; border-radius: 10px; overflow: hidden; margin-bottom: 0; }
.card-header {
  padding: 14px 18px 4px; font-size: 14px; font-weight: 600; color: #f1f5f9;
}
.chart-wrap { padding: 8px 16px 14px; height: 230px; position: relative; }

/* ── Envelope panel ──────────────────────────────────────────────────────── */
#envelope-panel { padding: 10px 16px 0; }
.env-bar { margin-bottom: 11px; }
.env-bar-row { display: flex; justify-content: space-between; font-size: 12px; color: #94a3b8; margin-bottom: 3px; }
.env-track { height: 8px; background: #0f172a; border-radius: 4px; }
.env-fill  { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.env-rec {
  margin: 10px 0 0; padding: 10px 14px; background: #0f172a; border-radius: 6px;
  font-size: 13px; font-weight: 700;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert-item {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 8px;
  display: flex; gap: 12px; align-items: flex-start; border: 1px solid transparent;
}
.alert-CRITICAL { background: #450a0a; border-color: #7f1d1d; }
.alert-WARNING  { background: #1c1305; border-color: #713f12; }
.alert-INFO     { background: #0f172a; border-color: #334155; }
.alert-item.acked { opacity: 0.45; }
.alert-code { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.alert-CRITICAL .alert-code { color: #fca5a5; }
.alert-WARNING  .alert-code { color: #fde68a; }
.alert-INFO     .alert-code { color: #94a3b8; }
.alert-msg  { font-size: 13px; color: #cbd5e1; }
.alert-meta { font-size: 10px; color: #475569; margin-top: 3px; }
.ack-btn {
  margin-left: auto; background: #1e293b; border: 1px solid #334155;
  color: #94a3b8; border-radius: 4px; padding: 4px 10px;
  cursor: pointer; font-size: 11px; flex-shrink: 0;
}

.filter-btn {
  padding: 6px 16px; border-radius: 6px; border: none; cursor: pointer;
  font-size: 12px; font-weight: 600; background: #1e293b; color: #64748b;
}
.filter-btn.active { background: #1d4ed8; color: #fff; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 11px 16px; text-align: left; font-size: 12px;
  color: #64748b; font-weight: 600; background: #0f172a;
}
.data-table td { padding: 11px 16px; font-size: 13px; border-top: 1px solid #334155; }
.data-table tr:nth-child(even) td { background: #172033; }

/* ── Params ──────────────────────────────────────────────────────────────── */
.tier-1 { background: #14532d; color: #4ade80; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tier-2 { background: #713f12; color: #fde68a; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tier-3 { background: #450a0a; color: #fca5a5; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }

.action-btn {
  background: #1e3a5f; border: 1px solid #1d4ed8; color: #60a5fa;
  border-radius: 4px; padding: 4px 9px; cursor: pointer; font-size: 11px;
}
.action-btn:hover { background: #1d4ed8; color: #fff; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field-label { font-size: 12px; color: #94a3b8; display: block; margin-bottom: 4px; }
.field-input {
  width: 100%; background: #0f172a; border: 1px solid #334155;
  color: #e2e8f0; border-radius: 6px; padding: 7px 10px; font-size: 13px;
  margin-bottom: 10px;
}
.field-input:focus { outline: none; border-color: #1d4ed8; }

.primary-btn {
  background: #1d4ed8; color: #fff; border: none; border-radius: 6px;
  padding: 8px 18px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.primary-btn:hover { background: #1e40af; }
.secondary-btn {
  background: #334155; color: #94a3b8; border: none; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-size: 13px;
}
.secondary-btn:hover { background: #475569; color: #e2e8f0; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  background: #1e293b; border-radius: 12px; padding: 28px; width: 380px;
}
.modal h3 { color: #f1f5f9; font-size: 16px; margin-bottom: 6px; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.status-msg {
  background: #14532d; border: 1px solid #16a34a; color: #4ade80;
  padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px;
}
.info-footer {
  margin-top: 14px; padding: 12px 16px; background: #1e293b;
  border-radius: 8px; font-size: 12px; color: #64748b;
}
.info-footer strong { color: #94a3b8; }
.empty-state {
  grid-column: 1/-1; text-align: center; padding: 60px 0; color: #475569;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #1e293b; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
