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

:root {
  --bg:        #0d0f14;
  --surface:   #161922;
  --surface2:  #1e2230;
  --border:    #272c3e;
  --text:      #dde1f0;
  --muted:     #606880;
  --green:     #22c55e;
  --red:       #ef4444;
  --amber:     #f59e0b;
  --blue:      #3b82f6;
  --purple:    #a855f7;
  --radius:    8px;
  --hdr-h:     52px;
  --ctrl-h:    40px;
  --sig-h:     88px;
  --bot-h:     calc(var(--ctrl-h) + var(--sig-h));
}

html, body { height: 100%; background: var(--bg); color: var(--text);
  font-family: 'Inter', system-ui, sans-serif; overflow: hidden; }

/* ── HEADER ──────────────────────────────────────────────────────────────── */
#header {
  height: var(--hdr-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
}
#header h1 { font-size: 1rem; font-weight: 800; color: var(--blue); letter-spacing:.05em; flex-shrink:0; }
.hdr-divider { width: 1px; height: 24px; background: var(--border); flex-shrink:0; }
.hdr-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hdr-label { font-size: .6rem; text-transform: uppercase; letter-spacing:.1em; color: var(--muted); }

/* Node-status i header */
.node-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px; font-size: .7rem; font-weight: 600;
  background: var(--surface2); border: 1px solid var(--border);
}
.node-badge .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink:0; }
.node-badge.online  .dot { background: var(--green); box-shadow: 0 0 5px var(--green); }
.node-badge.offline .dot { background: var(--red); }
.node-badge.unknown .dot { background: var(--muted); }

/* FSM-status */
#hdr-fsm {
  margin-left: auto; font-size: .75rem; font-weight: 600;
  padding: 4px 12px; border-radius: 20px;
  background: rgba(59,130,246,.15); color: var(--blue);
}
#hdr-conn {
  font-size: .7rem; padding: 3px 9px; border-radius: 20px; font-weight:600;
}
#hdr-conn.connected    { background:rgba(34,197,94,.15); color:var(--green); }
#hdr-conn.disconnected { background:rgba(239,68,68,.15); color:var(--red); }
#hdr-conn.connecting   { background:rgba(245,158,11,.15); color:var(--amber); }

/* ── SCROLL-CONTAINER ─────────────────────────────────────────────────────── */
#scroll {
  margin-top: var(--hdr-h);
  margin-bottom: var(--bot-h);
  height: calc(100vh - var(--hdr-h) - var(--bot-h));
  overflow-y: auto;
}

/* ── KAI + FERGE (side om side) ──────────────────────────────────────────── */
#quay-ferry {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 12px;
}
.qf-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.qf-header {
  padding: 8px 12px; background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: .65rem; text-transform: uppercase; letter-spacing:.12em; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}
/* Felt-grid: høyre → venstre, så høyre er fremst (field 1 = rightmost) */
.fields-rtl {
  display: flex; flex-direction: row-reverse;   /* field 1 vises til høyre */
  gap: 1px; min-height: 120px;
}
.field-col {
  flex: 1; display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
}
.field-col:last-child { border-left: none; }
.field-col-hdr {
  padding: 5px 8px; background: var(--surface2);
  font-size: .65rem; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}
.field-col-hdr.active { background: rgba(34,197,94,.1); color: var(--green); }
.field-light {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red); flex-shrink:0;
}
.field-light.green { background: var(--green); box-shadow: 0 0 6px var(--green); }

.vehicle-stack { display: flex; flex-direction: column; gap: 4px; padding: 6px; flex:1; }

/* ── Kjøretøy-kort ────────────────────────────────────────────────────────── */
.vcard {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 7px;
  display: flex; align-items: center; gap: 6px; font-size: .72rem;
}
.vcard.ambulanse { border-color: rgba(239,68,68,.6); }
.vcard.buss      { border-color: rgba(59,130,246,.5); }
.vcard.tankbil   { border-color: rgba(245,158,11,.5); }
.vcard-icon { font-size: 1rem; line-height:1; flex-shrink:0; }
.vcard-info { display:flex; flex-direction:column; gap:1px; min-width:0; }
.vcard-class { font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.vcard-meta  { font-size:.6rem; color:var(--muted); display:flex; gap:5px; align-items:center; }
.vcard-plan  { font-size:.6rem; color:var(--amber); }
.color-dot   { width:8px; height:8px; border-radius:50%; border:1px solid rgba(255,255,255,.15); flex-shrink:0; }

.color-dot[data-color="blå"]   { background:#3b82f6; }
.color-dot[data-color="rød"]   { background:#ef4444; }
.color-dot[data-color="grønn"] { background:#22c55e; }
.color-dot[data-color="hvit"]  { background:#f1f5f9; }
.color-dot[data-color="sort"]  { background:#1e293b; border-color:#475569; }
.color-dot[data-color="grå"]   { background:#94a3b8; }
.color-dot[data-color="gul"]   { background:#fbbf24; }

.empty-slot { padding: 6px; font-size: .65rem; color: var(--muted); text-align:center; }

/* ── KAMERAFEED-SEKSJON ──────────────────────────────────────────────────── */
#cam-feeds { padding: 0 12px 12px; display:flex; flex-direction:column; gap:8px; }
.cam-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.cam-row-header {
  padding: 6px 12px; background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: .65rem; text-transform:uppercase; letter-spacing:.1em; color:var(--muted);
  display:flex; align-items:center; gap:8px;
}
/* Deteksjonsbokser: nyligste til VENSTRE */
.detections {
  display: flex; flex-direction: row;
  gap: 8px; padding: 8px 10px;
  overflow-x: auto;
  min-height: 70px;
}
.det-box {
  flex-shrink: 0;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px;
  display: flex; flex-direction:column; gap:3px;
  min-width: 100px;
}
.det-box.new { border-color: rgba(59,130,246,.5); animation: flash .4s ease; }
.det-icon  { font-size: 1.4rem; text-align:center; }
.det-class { font-size: .7rem; font-weight:600; text-align:center; }
.det-meta  { font-size: .6rem; color:var(--muted); text-align:center; display:flex; justify-content:center; gap:4px; align-items:center; }
.det-time  { font-size: .58rem; color:var(--muted); text-align:center; }

.no-detections { font-size:.7rem; color:var(--muted); padding:8px 12px; }

@keyframes flash {
  0%   { background: rgba(59,130,246,.2); }
  100% { background: var(--bg); }
}

/* ── SIGNALSTASJONER (bunnen, fixed) ─────────────────────────────────────── */
#signal-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--sig-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: stretch; overflow-x: auto;
}
.sig-station {
  flex: 1; min-width: 180px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction:column; padding: 8px 12px; gap:6px;
}
.sig-station:last-child { border-right: none; }
.sig-stn-label { font-size:.62rem; text-transform:uppercase; letter-spacing:.1em; color:var(--muted); }
.sig-fields { display:flex; gap:8px; }
.sig-field {
  display:flex; flex-direction:column; align-items:center; gap:4px;
  min-width: 44px;
}
.sig-led {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.1);
}
.sig-led.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.sig-led.red   { background: var(--red);   box-shadow: 0 0 8px var(--red); }
.sig-led.off   { background: #1e2230; }
.sig-field-label { font-size:.58rem; color:var(--muted); }
.sig-display { font-size:.58rem; color:var(--text); text-align:center; white-space:nowrap; overflow:hidden; max-width:44px; text-overflow:ellipsis; }

.no-stations { padding:12px 16px; font-size:.75rem; color:var(--muted); align-self:center; }

/* Kontrollknapper */
#ctrl-bar {
  position:fixed; bottom: var(--sig-h); left:0; right:0;
  display:flex; gap:6px; padding:6px 12px;
  background: rgba(13,15,20,.9); border-top:1px solid var(--border);
  backdrop-filter: blur(6px);
}
.ctrl-btn {
  padding: 4px 12px; border-radius:5px; border:1px solid var(--border);
  background: var(--surface2); color: var(--text);
  cursor:pointer; font-size:.72rem; font-weight:600;
  transition: background .15s;
}
.ctrl-btn:hover { background: var(--border); }
.ctrl-btn.danger { color: var(--red); border-color: rgba(239,68,68,.4); }

/* ── Offline LED (viser bestemt status, men dempet) ─────────────────────────── */
.sig-led.offline-led { opacity: .28; box-shadow: none !important; }
.sig-station.offline .sig-stn-label { opacity: .65; }

/* Simuler-knapp i kamera-header */
.sim-btn {
  margin-left: auto; font-size: .65rem;
  padding: 3px 10px; color: var(--blue);
  border-color: rgba(59,130,246,.3);
}
.sim-btn:hover { background: rgba(59,130,246,.12); }
.sim-global-btn { color: var(--blue); border-color: rgba(59,130,246,.35); font-weight: 700; }
.sim-global-btn:hover { background: rgba(59,130,246,.12); }

/* Kamera-ID-felt i modal */
.sim-cam-input {
  width: 100%; padding: 7px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: .8rem;
  outline: none;
}
.sim-cam-input:focus { border-color: var(--blue); }
#sim-cam-row.hidden { display: none; }

/* ── MODAL ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; width: 360px; max-width: 95vw;
  display: flex; flex-direction: column; gap: 14px;
}

.modal-title {
  font-size: .85rem; font-weight: 700; color: var(--text);
}

.modal-section-label {
  font-size: .6rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); margin-bottom: -8px;
}

.sim-vbtn-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}

.sim-vbtn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 6px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); cursor: pointer; font-size: .65rem; font-weight: 600;
  transition: border-color .12s, background .12s;
}
.sim-vbtn .icon { font-size: 1.25rem; line-height: 1; }
.sim-vbtn.selected {
  border-color: var(--blue);
  background: rgba(59,130,246,.12);
  color: var(--blue);
}
.sim-vbtn:hover:not(.selected) { border-color: var(--muted); }

.sim-color-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.sim-cbtn {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.12);
  cursor: pointer; flex-shrink: 0;
  transition: transform .1s, border-color .12s;
}
.sim-cbtn.selected { border-color: white; transform: scale(1.2); }
.sim-cbtn:hover:not(.selected) { transform: scale(1.1); }
.sim-cbtn-none {
  background: transparent;
  border: 2px dashed var(--muted);
  position: relative;
}
.sim-cbtn-none::after {
  content: "–"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; color: var(--muted);
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-confirm { color: var(--green); border-color: rgba(34,197,94,.4); }
.modal-confirm:hover { background: rgba(34,197,94,.1); }

/* ── scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width:5px; height:5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius:3px; }
