:root {
  /* Backgrounds & Surfaces */
  --bg: #101820; /* Shade Black - Main Page Background */
  --s1: #18222d; /* Slightly lighter Shade Black for cards */
  --s2: #22326e; /* TRI Blue - Hover states & inner panels */
  --s3: #7c7fab; /* Bowtie Blue - Lighter accents */
  --bd: #3c0064; /* Prism Purple - Deep borders & outlines */

  /* Typography */
  --tx: #f6f2f4; /* Official Off-White for primary text */
  --mu: #c7c9c7; /* Gamma Gray for muted/secondary text */
  --di: #7c7fab; /* Bowtie Blue for dividers */

  /* Brand Accents & Chart Colors */
  --bl: #c5b4e3; /* Photon Periwinkle (Primary bright accent for dark mode) */
  --pu: #3c0064; /* Prism Purple */
  --cy: #22326e; /* TRI Blue */
  --pk: #7c7fab; /* Bowtie Blue */

  /* Standard Status Colors (Kept standard so warnings still look like warnings) */
  --re: #ef4444; /* Critical Alerts */
  --or: #f59e0b; /* Warnings */
  --ye: #fbbf24; /* Caution */
  --gr: #10b981; /* Success / OK */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}
#shell { display: flex; flex-direction: column; height: 100vh; }

/* TOP BAR */
#top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--s1);
  border-bottom: 1px solid var(--bd);
  flex-shrink: 0;
  flex-wrap: wrap;
}
#top .logo {
  font-size: 1.05rem;
  font-weight: 800;
  background: linear-gradient(90deg, #c5b4e3, #7c7fab);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.02em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sp { flex: 1; }
.last-upd {
  font-size: 0.65rem;
  color: var(--mu);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-decoration: none;
  padding: 2px 7px;
  border: 1px solid var(--bd);
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0.75;
  transition: opacity 0.15s, border-color 0.15s;
}
.last-upd:hover { opacity: 1; border-color: var(--mu); }
.last-upd .sha { color: #c5b4e3; }
.tb {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid;
  transition: all 0.15s;
  white-space: nowrap;
  background: transparent;
}
#ib { color: var(--gr); border-color: #22c55e44; }
#ib:hover { background: #0a2010; }
#pb { color: var(--bl); border-color: #3b82f644; }
#pb:hover { background: #050f20; }
#nb { color: var(--pu); border-color: #a855f744; }
#nb:hover { background: #100620; }
.tb:disabled { opacity: 0.3; cursor: not-allowed; }

/* FILE TABS */
#ftab {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 10px;
  background: var(--s1);
  border-bottom: 1px solid var(--bd);
  flex-shrink: 0;
  overflow-x: auto;
  min-height: 36px;
  -webkit-overflow-scrolling: touch;
}
.ft {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px 0;
  font-size: 0.74rem;
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  color: var(--mu);
  background: transparent;
  margin-bottom: -1px;
  min-height: 32px;
  white-space: nowrap;
}
.ft:hover { background: var(--s2); color: var(--tx); }
.ft.act { background: var(--bg); border-color: var(--bd); color: var(--tx); }
.ft .x {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; color: var(--mu);
}
.ft .x:hover { background: var(--re); color: #fff; }
.nof { padding: 8px 12px; font-size: 0.72rem; color: var(--mu); font-style: italic; }

/* CONTENT */
#ca { flex: 1; overflow: hidden; position: relative; }
.tc { display: none; height: 100%; overflow-y: auto; padding: 14px; }
.tc.act { display: block; }
.tc::-webkit-scrollbar { width: 5px; }
.tc::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 3px; }

/* WELCOME */
#wlc {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--mu); padding: 20px;
}
#wlc h2 { font-size: 1.1rem; font-weight: 600; color: var(--tx); text-align: center; }
#wlc p { font-size: 0.78rem; text-align: center; max-width: 420px; line-height: 1.6; }
#wlc .hint {
  font-size: 0.72rem;
  background: var(--s2);
  border: 1px solid var(--bd);
  border-radius: 8px;
  padding: 10px 16px;
  line-height: 1.9;
  text-align: center;
}

/* DASHBOARD */
.dash { max-width: 1400px; margin: 0 auto; }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 7px;
  margin-bottom: 11px;
}
.tile {
  background: var(--s1);
  border: 1px solid var(--bd);
  border-radius: 7px;
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
}
.tile::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.tile.c::before  { background: var(--re); }
.tile.w::before  { background: var(--or); }
.tile.ok::before { background: var(--gr); }
.tile.b::before  { background: var(--bl); }
.tile .lb { font-size: 0.6rem; color: var(--mu); text-transform: uppercase; letter-spacing: 0.06em; }
.tile .vl { font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.tile .dt { font-size: 0.61rem; color: var(--mu); margin-top: 1px; }
.re { color: var(--re); }
.or { color: var(--or); }
.gr { color: var(--gr); }
.bl { color: var(--bl); }

/* ALERTS */
.als { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.al { padding: 7px 11px; border-radius: 6px; font-size: 0.73rem; border-left: 3px solid; line-height: 1.5; }
.al.cr { background: #180606; border-color: var(--re); color: #ffb0b0; }
.al.wa { background: #170d00; border-color: var(--or); color: #ffd080; }
.al.in { background: #050f1a; border-color: var(--bl); color: #88bbff; }
.al.ok { background: #05150a; border-color: var(--gr); color: #80e0a0; }

/* SECTION HEADER */
.sh {
  font-size: 0.63rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--di);
  display: flex; align-items: center; gap: 8px;
  margin: 14px 0 8px;
}
.sh::after { content: ""; flex: 1; height: 1px; background: var(--bd); }

/* INNER TABS */
.itb { display: flex; gap: 3px; margin-bottom: 9px; border-bottom: 1px solid var(--bd); flex-wrap: wrap; }
.it {
  padding: 5px 11px; font-size: 0.73rem; font-weight: 600;
  border: none; background: transparent; color: var(--mu);
  cursor: pointer; border-radius: 5px 5px 0 0;
  border-bottom: 2px solid transparent;
}
.it.act { color: var(--bl); border-bottom-color: var(--bl); background: var(--s2); }
.it:hover:not(.act) { color: var(--tx); background: var(--s2); }
.itp { display: none; }
.itp.act { display: block; }

/* GRID */
.gr2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.card { background: var(--s1); border: 1px solid var(--bd); border-radius: 8px; padding: 12px; }
.card.fl { grid-column: 1/-1; }
.card h3 {
  font-size: 0.71rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--mu); margin-bottom: 8px;
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
}
.bdg { font-size: 0.59rem; padding: 1px 6px; border-radius: 9px; font-weight: 700; }
.bdg.r { background: #1f0606; color: var(--re); border: 1px solid #ff3d3d30; }
.bdg.o { background: #170900; color: var(--or); border: 1px solid #ff7a0030; }
.bdg.g { background: #061509; color: var(--gr); border: 1px solid #22c55e30; }
.bdg.b { background: #040e1f; color: var(--bl); border: 1px solid #3b82f630; }

/* CHARTS */
.cw { position: relative; overflow: hidden; }
.cw.h140 { height: 140px; }
.cw.h180 { height: 180px; }
.cw.h200 { height: 200px; }
.cw.h220 { height: 220px; }
.cw.h240 { height: 240px; }
.cw.h280 { height: 280px; }
.cw.h320 { height: 320px; }
.cw canvas { cursor: crosshair; display: block; }

/* SUBSYSTEM STATS */
.sts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.ss { background: var(--s2); border-radius: 5px; padding: 5px 9px; font-size: 0.68rem; text-align: center; flex: 1; min-width: 62px; }
.ss .sv { font-size: 0.95rem; font-weight: 700; }

/* BREAKER INFO BOX */
.bkb { background: var(--s2); border: 1px solid var(--bd); border-radius: 6px; padding: 8px 11px; font-size: 0.71rem; margin-bottom: 8px; line-height: 1.7; }
.zs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 7px; }
.zc { padding: 2px 6px; border-radius: 3px; font-size: 0.63rem; font-weight: 600; }

/* HOVER STATUS BAR */
.td { font-size: 0.67rem; color: var(--mu); background: var(--s2); border-radius: 4px; padding: 4px 8px; margin-top: 4px; }

/* DRAG-TO-ZOOM */
.zoom-overlay {
  background: rgba(197, 180, 227, 0.15);
  border: 1px solid rgba(197, 180, 227, 0.55);
  border-radius: 2px;
  box-sizing: border-box;
}
.zoom-header { display: none; }
.zoom-time-label {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--bl);
  background: rgba(7, 9, 13, 0.75);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}
.zh-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bl);
  margin: 8px 0 6px;
}
.zh-bar::before { content: "⬛"; font-size: 0.55rem; opacity: 0.6; }
.zh-dur { font-weight: 400; color: var(--mu); text-transform: none; letter-spacing: 0; }
#zoom-clear-btn { display: none; color: var(--bl); border-color: #c5b4e344; }
#zoom-clear-btn:hover { background: #050f20; }

/* TAB DRAG-TO-REORDER */
.ft[draggable] { cursor: grab; }
.ft[draggable]:active { cursor: grabbing; }
.ft.dragging { opacity: 0.35; }
.ft.drag-before { box-shadow: -3px 0 0 var(--bl); }
.ft.drag-after  { box-shadow:  3px 0 0 var(--bl); }

/* COMPARE TAB */
.ft-cmp { color: var(--bl); border-color: #c5b4e344; }
.ft-cmp.act { background: var(--bg); border-color: var(--bl); color: var(--bl); }
.ft-cmp:hover { background: var(--s2); }
.ft-sep { width: 1px; background: var(--bd); margin: 6px 2px 0; flex-shrink: 0; }

/* COMPARE TABLE */
.cmp-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.cmp-table th { color: var(--mu); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.6rem; border-bottom: 1px solid var(--bd); padding: 5px 8px; text-align: left; }
.cmp-table td { padding: 5px 8px; border-bottom: 1px solid #1e2840; }
.cmp-table tr:last-child td { border-bottom: none; }

/* READ-ONLY BADGE */
.ro-badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ye);
  border: 1px solid #f59e0b55; border-radius: 4px;
  padding: 2px 7px; white-space: nowrap;
}

/* INFO NOTE */
.nb { font-size: 0.67rem; color: var(--ye); background: #170d00; border-left: 3px solid var(--ye); padding: 4px 8px; border-radius: 0 4px 4px 0; margin-bottom: 6px; }

/* TRIP PREDICTION BOX */
.trip-pred { background: #1f0606; border: 1px solid #ff3d3d55; border-radius: 6px; padding: 8px 11px; font-size: 0.71rem; color: #ffb0b0; margin-bottom: 8px; line-height: 1.7; }
.trip-pred strong { color: var(--re); }

/* LOADING SPINNER */
.ld { position: absolute; inset: 0; background: #07090dcc; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; z-index: 200; }
.sp2 { width: 36px; height: 36px; border: 3px solid var(--bd); border-top-color: var(--bl); border-radius: 50%; animation: sp2 0.8s linear infinite; }
@keyframes sp2 { to { transform: rotate(360deg); } }

/* TIMELINE BAR */
#tl-bar {
  height: 48px;
  background: #090d12;
  border-bottom: 1px solid var(--bd);
  flex-shrink: 0;
  display: none;
  position: relative;
  cursor: crosshair;
  overflow: hidden;
}
#tl-cv {
  display: block;
  width: 100%;
  height: 100%;
}

/* PRINT */
@media print {
  #top, #ftab { display: none !important; }
  #ca { overflow: visible !important; height: auto !important; }
  .tc { display: none !important; height: auto !important; }
  .tc.act { display: block !important; overflow: visible !important; height: auto !important; }
  body, html { overflow: auto !important; height: auto !important; }
  .card { break-inside: avoid; page-break-inside: avoid; }
  .sh { page-break-before: auto; }
}
