/* ============================================================
   Elvheim Kraftverk HMI — Stilark
   Visuell stil inspirert av ABB 800xA / Siemens WinCC
   ============================================================ */

:root {
  --bg-app:       #2e2e2e;
  --bg-header:    #18232f;
  --bg-nav:       #1f2a35;
  --bg-nav-hover: #28394a;
  --bg-nav-active:#0a6eb4;
  --bg-panel:     #252525;
  --bg-panel-alt: #1e1e1e;
  --bg-display:   #0c0e10;
  --bg-screen:    #2e2e2e;

  --border:       #444;
  --border-light: #555;
  --border-panel: #383838;

  --text-primary: #d4d4d4;
  --text-dim:     #888;
  --text-label:   #a0a0a0;
  --text-header:  #e8e8e8;
  --text-display: #7dd3fc;

  --green:        #22c55e;
  --green-dim:    #15803d;
  --red:          #ef4444;
  --red-dim:      #991b1b;
  --yellow:       #eab308;
  --yellow-dim:   #854d0e;
  --blue:         #3b82f6;
  --orange:       #f97316;
  --gray:         #6b7280;

  --font-mono: 'Courier New', Courier, monospace;
  --font-ui:   'Segoe UI', Arial, sans-serif;

  --radius: 2px;
  --header-h: 48px;
  --nav-w: 175px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  user-select: none;
}

/* ── Topplinje ─────────────────────────────────────────── */

#topbar {
  height: var(--header-h);
  background: var(--bg-header);
  border-bottom: 2px solid #0a6eb4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

#tb-left {
  display: flex;
  align-items: center;
  gap: 18px;
}

#tb-logo {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

#tb-plant {
  font-size: 12px;
  color: #7dd3fc;
  letter-spacing: 1px;
  border-left: 1px solid #2a4a6a;
  padding-left: 18px;
}

#tb-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

#tb-plant-status {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
}

#tb-total-power {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--text-display);
  background: var(--bg-display);
  padding: 2px 10px;
  border: 1px solid #1a3a5a;
  border-radius: var(--radius);
  letter-spacing: 1px;
}

#tb-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

#tb-alarms {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}
#tb-alarms.alarm-active {
  background: var(--yellow-dim);
  color: var(--yellow);
  border: 1px solid var(--yellow-dim);
  animation: alarmPulse 2s ease-in-out infinite;
}
#tb-alarms.alarm-inactive {
  background: #1a2a1a;
  color: var(--green);
  border: 1px solid var(--green-dim);
}

@keyframes alarmPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

#tb-clock {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: 1px;
  min-width: 75px;
}

#tb-date {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Hovednivå layout ────────────────────────────────────── */

#layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Venstrenavigasjon ────────────────────────────────────── */

#sidenav {
  width: var(--nav-w);
  background: var(--bg-nav);
  border-right: 1px solid #2a3a4a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.nav-section-title {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-dim);
  padding: 12px 14px 6px;
  text-transform: uppercase;
  border-bottom: 1px solid #2a3a4a;
}

#sidenav ul {
  list-style: none;
  padding: 6px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #9ab;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.nav-item:hover {
  background: var(--bg-nav-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: rgba(10, 110, 180, 0.18);
  border-left-color: var(--blue);
  color: #fff;
}

.nav-icon {
  font-size: 14px;
  opacity: 0.7;
  width: 18px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  background: var(--yellow);
  color: #000;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

.nav-footer {
  padding: 12px 14px;
  border-top: 1px solid #2a3a4a;
  font-size: 10px;
  color: var(--text-dim);
  line-height: 1.8;
}

.nav-footer .val-green { color: var(--green); }

/* ── Innholdsområde ──────────────────────────────────────── */

#content {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg-screen);
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
}
.screen.active {
  display: flex;
}

.screen-title {
  background: #1e2b38;
  border-bottom: 1px solid #2a3a4a;
  padding: 6px 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #7dd3fc;
  flex-shrink: 0;
}

.screen-body {
  flex: 1;
  overflow: auto;
  padding: 14px;
}

/* ── Statusdot ───────────────────────────────────────────── */

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.green  { background: var(--green);  box-shadow: 0 0 6px var(--green); }
.status-dot.red    { background: var(--red);    box-shadow: 0 0 6px var(--red); }
.status-dot.yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.status-dot.gray   { background: var(--gray); }

/* ── Oversiktsskjerm (SVG) ───────────────────────────────── */

#oversikt-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  padding: 8px;
  gap: 8px;
}

#prosess-svg {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#oversikt-sidebar {
  width: 190px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Aggregatskjerm ──────────────────────────────────────── */

#agg-tabs {
  display: flex;
  background: #1a1a1a;
  border-bottom: 1px solid var(--border);
  padding: 8px 14px 0;
  gap: 4px;
  flex-shrink: 0;
}

.agg-tab {
  background: #252525;
  border: 1px solid var(--border);
  border-bottom: none;
  color: var(--text-dim);
  padding: 6px 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 2px 2px 0 0;
  transition: background 0.12s, color 0.12s;
}
.agg-tab:hover  { background: #2e2e2e; color: var(--text-primary); }
.agg-tab.active { background: var(--bg-panel); color: #fff; border-color: #0a6eb4; border-bottom: 1px solid var(--bg-panel); }

#agg-panel-wrap {
  flex: 1;
  overflow: auto;
  padding: 14px;
}

.agg-status-banner {
  padding: 10px 16px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  border: 1px solid;
}
.agg-status-banner.drift  { background: rgba(34,197,94,0.12); border-color: var(--green-dim); color: var(--green); }
.agg-status-banner.stopp  { background: rgba(107,114,128,0.12); border-color: #555; color: var(--gray); }
.agg-status-banner.alarm  { background: rgba(239,68,68,0.12); border-color: var(--red-dim); color: var(--red); }

.agg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Paneler / Kort ──────────────────────────────────────── */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  background: #1a1a1a;
  border-bottom: 1px solid var(--border-panel);
  padding: 6px 12px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.panel-body {
  padding: 10px 12px;
}

/* ── Verdirader ──────────────────────────────────────────── */

.val-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid #1e1e1e;
}
.val-row:last-child { border-bottom: none; }

.val-label {
  font-size: 11px;
  color: var(--text-label);
  flex: 1;
}

.val-num {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-display);
  text-align: right;
  min-width: 75px;
}

.val-unit {
  font-size: 10px;
  color: var(--text-dim);
  width: 42px;
  text-align: right;
}

.val-status {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 2px;
  letter-spacing: 0.5px;
}
.val-status.ok     { background: var(--green-dim); color: var(--green); }
.val-status.warn   { background: var(--yellow-dim); color: var(--yellow); }
.val-status.fault  { background: var(--red-dim); color: var(--red); }

/* ── Temperaturlinje med gradientstatus ──────────────────── */

.temp-row {
  display: grid;
  grid-template-columns: 1fr 70px 36px 52px;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #1e1e1e;
}
.temp-row:last-child { border-bottom: none; }

.temp-bar-track {
  height: 5px;
  background: #1a1a1a;
  border-radius: 2px;
  overflow: hidden;
}
.temp-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s, background 0.4s;
}

/* ── Vannveiskjerm ───────────────────────────────────────── */

#vannvei-grid {
  display: grid;
  grid-template-columns: 220px 1fr 1fr;
  gap: 10px;
  height: 100%;
}

.gauge-vertical {
  height: 260px;
  background: #0c0e10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.gauge-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, #1a5a9a, #2a8acd);
  transition: height 0.8s ease;
}
.gauge-label-top, .gauge-label-bot {
  position: absolute;
  left: 8px;
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
.gauge-label-top { top: 4px; }
.gauge-label-bot { bottom: 4px; }
.gauge-level-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: #4aafdf;
  box-shadow: 0 0 6px #4aafdf;
  pointer-events: none;
  transition: bottom 0.8s ease;
}

.lukestatus-bar {
  height: 18px;
  background: #0c0e10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.lukestatus-fill {
  height: 100%;
  transition: width 0.6s;
}
.lukestatus-fill.open   { background: var(--green); }
.lukestatus-fill.closed { background: var(--gray); }
.lukestatus-fill.partial { background: var(--yellow); }

/* ── Elektrisk skjerm ────────────────────────────────────── */

#elektrisk-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#el-svg-wrap {
  flex: 1;
  overflow: hidden;
  padding: 8px;
}

#el-svg {
  width: 100%;
  height: 100%;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#el-bottom {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 8px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: #1e1e1e;
}

/* ── Alarmskjerm ─────────────────────────────────────────── */

#alarm-filterbar {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: #1e1e1e;
}

.alarm-filter-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-label);
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  cursor: pointer;
  border-radius: var(--radius);
}
.alarm-filter-btn.active { background: #0a6eb4; color: #fff; border-color: #0a6eb4; }

#alarm-body {
  flex: 1;
  overflow: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.alarm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.alarm-table th {
  background: #1a1a1a;
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.alarm-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #1e1e1e;
  vertical-align: middle;
}
.alarm-table tr:hover td { background: rgba(255,255,255,0.03); }
.alarm-table tr.kvittert td { opacity: 0.45; }

.alarm-prio {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.alarm-prio.ROD { background: var(--red); box-shadow: 0 0 4px var(--red); }
.alarm-prio.GUL { background: var(--yellow); box-shadow: 0 0 4px var(--yellow); }
.alarm-prio.GRN { background: var(--green); }

.btn-kvitter {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 10px;
  font-size: 10px;
  cursor: pointer;
  border-radius: var(--radius);
  letter-spacing: 0.5px;
  transition: background 0.12s;
}
.btn-kvitter:hover { background: #333; color: var(--text-primary); }
.btn-kvitter:disabled { opacity: 0.3; cursor: default; }

/* ── Trendskjerm ─────────────────────────────────────────── */

#trend-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: #1e1e1e;
  flex-shrink: 0;
}

.trend-range-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-label);
  padding: 3px 12px;
  font-size: 11px;
  cursor: pointer;
  border-radius: var(--radius);
}
.trend-range-btn.active { background: #0a4a7a; color: #7dd3fc; border-color: #0a6eb4; }

#trend-charts {
  flex: 1;
  overflow: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius);
  overflow: hidden;
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
}

.chart-panel-header {
  background: #1a1a1a;
  border-bottom: 1px solid var(--border-panel);
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.chart-panel canvas {
  flex: 1;
}

/* ── Oversiktspanel (sidebar) ────────────────────────────── */

.mini-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-panel);
  border-radius: var(--radius);
  overflow: hidden;
}

.mini-panel-title {
  background: #1a1a1a;
  border-bottom: 1px solid var(--border-panel);
  padding: 5px 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.mini-val-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  border-bottom: 1px solid #1e1e1e;
  font-size: 11px;
}
.mini-val-row:last-child { border-bottom: none; }
.mini-val-row .lbl { color: var(--text-label); font-size: 10px; }
.mini-val-row .num { font-family: var(--font-mono); font-size: 13px; color: var(--text-display); }
.mini-val-row .unt { color: var(--text-dim); font-size: 10px; }

/* ── SVG-felles stiler ───────────────────────────────────── */

.svg-label {
  font-family: var(--font-ui);
  font-size: 10px;
  fill: #aaa;
}

.svg-val {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: #7dd3fc;
}

.svg-title {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  fill: #ccc;
  letter-spacing: 1px;
}

/* ── SVG flow-animasjoner ────────────────────────────────── */

.water-flow {
  stroke-dasharray: 18 9;
  animation: flowWater 1.2s linear infinite;
}

.power-flow {
  stroke-dasharray: 12 6;
  animation: flowPower 0.8s linear infinite;
}

@keyframes flowWater {
  to { stroke-dashoffset: -27; }
}

@keyframes flowPower {
  to { stroke-dashoffset: -18; }
}

/* ── Diverse hjelpeklasser ──────────────────────────────── */

.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-dim    { color: var(--text-dim); }
.text-mono   { font-family: var(--font-mono); }

/* ── Temavelger ─────────────────────────────────────────── */

#theme-switcher {
  display: flex;
  border: 1px solid #2a3a4a;
  border-radius: 2px;
  overflow: hidden;
  width: 100%;
}

.theme-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 4px;
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 0.8px;
  font-weight: 700;
  font-family: var(--font-ui);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.theme-btn:hover:not(.active) {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}
.theme-btn.active {
  background: var(--bg-nav-active);
  color: #fff;
}

/* ── Ignition-tema ──────────────────────────────────────────
   Bruker BEGGE: data-attributt og CSS-klasse for maksimal
   nettleserkompatibilitet.
   ──────────────────────────────────────────────────────── */

.theme-ignition {
  background: #0a0e14;
  color: #e8eef8;
}
html:has(body.theme-ignition) {
  background: #0a0e14;
}

.theme-ignition #app      { background: #0a0e14; }
.theme-ignition #layout   { background: #0a0e14; }
.theme-ignition #content  { background: #0a0e14; }
.theme-ignition .screen   { background: #0a0e14; }
.theme-ignition .screen-body { background: #0a0e14; }
.theme-ignition #oversikt-wrap { background: #0a0e14; }
.theme-ignition #agg-panel-wrap { background: #0a0e14; }

.theme-ignition #topbar {
  background: linear-gradient(to right, #020810, #060f20);
  border-bottom: 2px solid #2563eb;
  box-shadow: 0 2px 20px rgba(37,99,235,0.4);
}
.theme-ignition #tb-logo { color: #60a5fa; letter-spacing: 2px; }
.theme-ignition #tb-plant { color: #93c5fd; border-left-color: #1e3a6a; }
.theme-ignition #tb-total-power {
  border-color: #1e4a9a;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(147,197,253,0.6);
}

.theme-ignition #sidenav {
  background: #070f1e;
  border-right-color: #1e3558;
}
.theme-ignition .nav-section-title {
  color: #3a5a8a;
  border-bottom-color: #1e3558;
}
.theme-ignition .nav-item { color: #6a90c0; }
.theme-ignition .nav-item.active {
  background: rgba(29,78,216,0.18);
  border-left-color: #3b82f6;
  color: #93c5fd;
}
.theme-ignition .nav-footer { border-top-color: #1e3558; }

.theme-ignition .screen-title {
  background: #060e1c;
  border-bottom-color: #1e3558;
  color: #60a5fa;
}
.theme-ignition .panel { background: #0d1420; border-color: #1a2e48; }
.theme-ignition .panel-header {
  background: #080f1e;
  border-bottom-color: #1a2e48;
  color: #60a5fa;
}
.theme-ignition .mini-panel { background: #0d1420; border-color: #1a2e48; }
.theme-ignition .mini-panel-title {
  background: #080f1e;
  border-bottom-color: #1a2e48;
  color: #60a5fa;
}
.theme-ignition .val-row { border-bottom-color: #0e1a28; }
.theme-ignition .mini-val-row { border-bottom-color: #0e1a28; }
.theme-ignition .val-num { color: #ffffff; font-weight: 600; }
.theme-ignition .mini-val-row .num { color: #ffffff; }

.theme-ignition #agg-tabs {
  background: #080f1a;
  border-bottom-color: #1e3558;
}
.theme-ignition .agg-tab {
  background: #111927;
  border-color: #1e3558;
  color: #4a6a8a;
}
.theme-ignition .agg-tab.active {
  background: var(--bg-panel);
  color: #93c5fd;
  border-color: #1d4ed8;
  border-bottom-color: var(--bg-panel);
}

.theme-ignition #prosess-svg,
.theme-ignition #el-svg {
  background: #080f1a;
  border-color: #1e3558;
}
.theme-ignition #el-bottom {
  background: #0a1020;
  border-top-color: #1e3558;
}
.theme-ignition #alarm-filterbar {
  background: #0a1020;
  border-bottom-color: #1e3558;
}
.theme-ignition .alarm-table th {
  background: #080f1a;
  border-bottom-color: #1e3558;
}
.theme-ignition #trend-controls {
  background: #0a1020;
  border-bottom-color: #1e3558;
}
.theme-ignition .chart-panel { border-color: #1a2e48; }
.theme-ignition .chart-panel-header {
  background: #080f1a;
  border-bottom-color: #1a2e48;
  color: #60a5fa;
}

.theme-ignition #theme-switcher { border-color: #1e3a5a; }
.theme-ignition .theme-btn.active { background: #1d4ed8; }
.theme-ignition .nav-section-title { color: #1e4a8a; border-bottom-color: #1e3a5a; }
.theme-ignition .screen-title { letter-spacing: 2.5px; }
.theme-ignition .panel-header { letter-spacing: 2px; font-size: 10px; }
.theme-ignition #prosess-svg,
.theme-ignition #el-svg { background: #050a12; border-color: #1e3a5a; }

/* ── Scrollbar-styling ──────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
