:root {
  --bg: #0a1210;
  --panel: #0f1c18;
  --panel2: #12241d;
  --border: #1e3d32;
  --border2: #2a5343;
  --accent: #3dd68c;
  --accent2: #66d49a;
  --warn: #f0b429;
  --risk: #f04438;
  --text: #e2f0ea;
  --muted: #7a9e8e;
  --font: system-ui, "Segoe UI", Roboto, -apple-system, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; margin: 0; }
html, body { height: 100%; }
.hidden { display: none !important; }
.screen { min-height: 100vh; }

#login-screen {
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-top: 3px solid var(--accent);
  border-radius: 10px; padding: 34px 30px; width: min(440px, 94vw); text-align: center;
}
.logo { letter-spacing: 0.16em; color: var(--accent); font-weight: 800; font-size: 0.82rem; }
.subtitle { letter-spacing: 0.2em; color: var(--text); font-weight: 800; font-size: 1.15rem; margin: 4px 0 12px; }
.login-meta { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.08em; margin: 0 0 18px; text-transform: uppercase; }
.login-card label { display: block; text-align: center; font-size: 0.75rem; color: var(--muted); margin: 12px 0 4px; letter-spacing: 0.08em; }
.login-card input {
  width: 100%; text-align: center; padding: 0.6rem 0.7rem; margin-bottom: 0.2rem;
  background: var(--bg); border: 1px solid var(--border2); border-radius: 6px; color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  min-width: 160px; margin-top: 16px; padding: 0.7rem 1.1rem; background: var(--accent); color: #04121f;
  border: none; border-radius: 6px; font-weight: 700; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.error { color: var(--risk); font-size: 0.78rem; margin-top: 0.6rem; min-height: 16px; }
.login-foot { font-size: 0.7rem; color: var(--muted); margin-top: 16px; line-height: 1.5; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 1.4rem; background: var(--panel); border-bottom: 1px solid var(--border);
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name { font-weight: 700; letter-spacing: 0.06em; color: var(--accent); }
.badge {
  background: #152922; color: var(--accent); font-size: 0.72rem;
  padding: 0.18rem 0.55rem; border-radius: 4px; border: 1px solid var(--border);
}
.badge.warn { color: var(--warn); border-color: #5c4a1a; background: #2a2210; }
.session-info { display: flex; align-items: center; gap: 0.9rem; font-size: 0.85rem; color: var(--muted); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 0.3rem 0.7rem; border-radius: 4px; cursor: pointer; font-size: 0.8rem;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

#console-screen {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
}
.scada-strip {
  grid-column: 1 / -1;
  grid-row: 2;
}
.sidenav {
  grid-column: 1;
  grid-row: 3;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 0.6rem 0 1rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.nav-item {
  background: transparent; border: none; color: var(--muted); text-align: left;
  padding: 0.55rem 1.1rem; cursor: pointer; font-size: 0.86rem;
  border-left: 3px solid transparent;
  flex-shrink: 0;
}
.nav-item:hover { color: var(--text); background: rgba(61,214,140,0.05); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(61,214,140,0.08); }

.content {
  grid-column: 2;
  grid-row: 3;
  padding: 1.2rem 1.4rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}
.content .view { max-width: none; width: 100%; }
.view h2 { font-size: 1.2rem; margin-bottom: 1rem; }
.view h3 { font-size: 0.95rem; margin: 1.2rem 0 0.5rem; color: var(--accent); }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem 1.2rem; margin-bottom: 0.7rem;
}
.card.risk { border-left: 3px solid var(--risk); }
.card.warn { border-left: 3px solid var(--warn); }
.card.ok { border-left: 3px solid var(--accent); }
.card-title { font-weight: 600; margin-bottom: 0.3rem; }
.card-meta { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.7rem; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 480px; }
th, td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.78rem; }
tr:hover td { background: rgba(61,214,140,0.04); }

.form-row { margin-bottom: 0.9rem; }
.form-row label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.form-row input, .form-row textarea, .form-row select {
  width: 100%; max-width: 480px; padding: 0.55rem 0.75rem;
  background: #0a1210; border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.btn-primary {
  background: var(--accent); color: #0a1210; border: none;
  padding: 0.55rem 1.1rem; border-radius: 6px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

pre, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
}
pre {
  background: #0a1210; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.9rem; overflow-x: auto; color: var(--muted); white-space: pre-wrap;
}

.status-pill {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
}
.status-pill.offline { background: rgba(240,68,56,0.15); color: var(--risk); }
.status-pill.online { background: rgba(61,214,140,0.15); color: var(--accent); }

.progress-bar { height: 6px; background: #152922; border-radius: 3px; margin: 0.5rem 0 1.3rem; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width 0.3s; }

.msg { padding: 0.55rem 0.85rem; border-radius: 6px; margin-top: 0.5rem; font-size: 0.85rem; }
.msg.ok { background: rgba(61,214,140,0.12); color: var(--accent); }
.msg.err { background: rgba(240,68,56,0.12); color: var(--risk); }

.mission-card.solved { border-left: 3px solid var(--accent); }

.map-layout {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 0.9rem;
  width: 100%;
}
@media (max-width: 980px) {
  .map-layout { grid-template-columns: 1fr; }
}
.map-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #050808;
}
.map-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.35) contrast(1.05) brightness(0.85);
  display: block;
}
.map-overlay { position: absolute; inset: 0; }
.map-zone {
  position: absolute;
  border: 1px solid rgba(240,68,56,0.55);
  background: rgba(240,68,56,0.18);
  border-radius: 6px;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4px 6px;
}
.map-zone span { font-size: 0.65rem; color: #fff; text-shadow: 0 1px 2px #000; }
.map-zone.power-on { border-color: rgba(61,214,140,0.5); background: rgba(61,214,140,0.12); }
.map-zone.power-degraded { border-color: rgba(240,180,41,0.55); background: rgba(240,180,41,0.16); }
.map-zone.power-off { border-color: rgba(240,68,56,0.6); background: rgba(240,68,56,0.2); animation: pulseOff 2.4s ease-in-out infinite; }
@keyframes pulseOff {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}
.map-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 18px; height: 18px;
  border-radius: 3px;
  border: 1px solid #fff;
  background: #f04438;
  color: transparent;
  cursor: pointer;
  font-size: 8px;
  padding: 0;
}
.map-pin.power-on { background: #3dd68c; }
.map-pin.power-degraded { background: #f0b429; }
.map-pin.power-off { background: #f04438; box-shadow: 0 0 10px rgba(240,68,56,0.7); }
.map-legend { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 0.6rem; font-size: 0.78rem; color: var(--muted); }
.map-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.map-legend .dot.off { background: #f04438; }
.map-legend .dot.deg { background: #f0b429; }
.map-legend .dot.on { background: #3dd68c; }
.map-legend .dot.inc { background: #42a5ff; }
.district-row {
  display: flex; justify-content: space-between; gap: 0.6rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border);
}
.history-list { max-height: 320px; overflow-y: auto; }
.history-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.history-item .history-ts { font-size: 0.72rem; color: var(--muted); }
.history-item .history-title { font-size: 0.88rem; font-weight: 600; }
.history-item .history-detail { font-size: 0.78rem; color: var(--muted); }
.history-item.sev-critical .history-title { color: var(--risk); }
.history-item.sev-high .history-title { color: #ff8a7a; }
.history-item.sev-medium .history-title { color: var(--warn); }
.cam-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  width: 100%;
}
@media (max-width: 1200px) {
  .cam-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .cam-grid { grid-template-columns: 1fr; }
}
.cam-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.cam-video {
  width: 100%;
  margin-top: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #000;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  min-height: 220px;
  max-height: 42vh;
  flex: 1;
}

.map-street {
  position: absolute;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.85;
}
.map-street.power-off {
  background: linear-gradient(90deg, rgba(240,68,56,0.85), rgba(240,68,56,0.35));
  box-shadow: 0 0 8px rgba(240,68,56,0.5);
  animation: pulseOff 2.2s ease-in-out infinite;
}
.map-street.power-degraded {
  background: linear-gradient(90deg, rgba(240,180,41,0.8), rgba(240,180,41,0.3));
}
.map-street.power-on {
  background: linear-gradient(90deg, rgba(61,214,140,0.55), rgba(61,214,140,0.2));
}
.map-legend .dot.street {
  background: linear-gradient(90deg, #f04438, #7a2020);
  width: 16px;
  border-radius: 2px;
}

/* SCADA top strip */
.scada-strip {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.4rem 1rem;
  background: #07140f;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-x: auto;
}
.scada-unit {
  background: #0d1f18;
  border: 1px solid #1e3d32;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  min-width: 110px;
}
.scada-unit.wide { min-width: 160px; }
.scada-unit .su-id { color: #7a9e8e; font-size: 0.7rem; display: block; }
.scada-unit .su-v { color: #3dd68c; font-size: 0.95rem; font-weight: 700; display: block; }
.scada-unit .su-s { color: #9bb5a8; font-size: 0.72rem; }
.scada-unit.warn .su-v { color: #f0b429; }
.scada-unit.risk .su-v, .scada-unit.risk .su-s { color: #f04438; }

/* HQ-Link */
.hq-thread { display: flex; flex-direction: column; gap: 0.65rem; }
.hq-bubble {
  max-width: 720px;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0d1a16;
}
.hq-bubble.from-V { border-left: 3px solid #42a5ff; }
.hq-bubble.from-Thomas { border-left: 3px solid #f0b429; }
.hq-bubble.from-Mayor { border-left: 3px solid #f04438; }
.hq-bubble.from-OP { border-left: 3px solid #3dd68c; }
.hq-from { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; font-weight: 600; }

/* Case history forms */
.case-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
@media (max-width: 900px) { .case-grid { grid-template-columns: 1fr; } }
.case-list { max-height: 220px; overflow-y: auto; }
.case-item { padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }

/* Findings */
.mission-card { margin-bottom: 0.65rem; }
.mission-card.verified { border-color: rgba(61,214,140,0.45); }
.mission-card input[type="text"] { width: 100%; }

/* Schematic */
.schematic-wrap {
  background: #070f0c;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  overflow-x: auto;
}
.schematic-wrap svg { width: 100%; min-width: 720px; height: auto; }


.btn, .btn-primary {
  background: var(--accent);
  color: #0a1210;
  border: none;
  padding: 0.5rem 0.95rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover, .btn-primary:hover { filter: brightness(1.08); }
.btn:disabled, .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* Harden SCADA unit sizing */
.scada-unit {
  background: #0d1f18;
  border: 1px solid #1e3d32;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  min-width: 100px;
  flex: 0 0 auto;
}
.scada-unit.wide { min-width: 150px; }
.scada-unit .su-id { color: #7a9e8e; font-size: 0.7rem; display: block; }
.scada-unit .su-v { color: #3dd68c; font-size: 0.95rem; font-weight: 700; display: block; }
.scada-unit .su-s { color: #9bb5a8; font-size: 0.72rem; }

/* Login vs console screens stacking */
#login-screen.hidden, #console-screen.hidden { display: none !important; }
#console-screen:not(.hidden) {
  display: grid;
}

.cam-head { margin-bottom: 0.35rem; }
.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: #f04438;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.live-dot::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #f04438;
  box-shadow: 0 0 8px #f04438;
  animation: livePulse 1.2s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.cam-frame {
  position: relative;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}
.cam-frame .cam-video {
  margin-top: 0;
  border: none;
  border-radius: 0;
  min-height: 240px;
  max-height: 46vh;
  width: 100%;
  display: block;
}
.cam-scan {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.45;
  animation: scanDrift 6s linear infinite;
}
@keyframes scanDrift {
  0% { background-position: 0 0; }
  100% { background-position: 0 40px; }
}

/* Use full main panel width for cams / map / schematic */
.content { padding: 1rem 1.1rem; }
.content .view { width: 100%; max-width: none; }
