/* ============================================================
   PacketVis - local styles. Pairs with ../iz.css for the ECT
   header. Defines the 3D stage layout, HUD panels, and the
   dark / light / auto + high-visibility themes.
   ============================================================ */

/* ── theme tokens: light (default) ─────────────────────────── */
:root {
  --pv-bg:        #eef0e6;
  --pv-surface:   #ffffff;
  --pv-panel:     rgba(255, 255, 255, 0.88);
  --pv-ink:       #1c211e;
  --pv-ink-muted: #5c6660;
  --pv-line:      #d9d8cf;
  --pv-accent:    #00694e;   /* Cutler Green   */
  --pv-accent-dk: #024230;   /* Under the Elms */
  --pv-err-bg:    #fce6e6;
  --pv-err-fg:    #b81b1b;
  --pv-shadow:    0 4px 14px rgba(0,0,0,0.12);
}

html[data-theme="dark"] {
  --pv-bg:        #12150f;
  --pv-surface:   #1b1f17;
  --pv-panel:     rgba(20, 24, 18, 0.86);
  --pv-ink:       #d8dad2;
  --pv-ink-muted: #a4a89e;
  --pv-line:      #2c3531;
  --pv-accent:    #4fc3a1;
  --pv-accent-dk: #024230;
  --pv-err-bg:    #3a1818;
  --pv-err-fg:    #ff7f7f;
  --pv-shadow:    0 4px 18px rgba(0,0,0,0.55);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --pv-bg:        #12150f;
    --pv-surface:   #1b1f17;
    --pv-panel:     rgba(20, 24, 18, 0.86);
    --pv-ink:       #d8dad2;
    --pv-ink-muted: #a4a89e;
    --pv-line:      #2c3531;
    --pv-accent:    #4fc3a1;
    --pv-accent-dk: #024230;
    --pv-err-bg:    #3a1818;
    --pv-err-fg:    #ff7f7f;
    --pv-shadow:    0 4px 18px rgba(0,0,0,0.55);
  }
}

/* ── high-visibility: bigger fonts, heavier weight, contrast ── */
html.hr-hivis { font-size: 18px; }
html.hr-hivis body { font-weight: 600; }
html.hr-hivis {
  --pv-ink: #000000;
  --pv-line: #444;
  --pv-panel: rgba(255, 255, 255, 0.97);
}
html.hr-hivis[data-theme="dark"] { --pv-ink: #ffffff; --pv-line: #ddd; --pv-panel: rgba(10, 12, 9, 0.97); }
@media (prefers-color-scheme: dark) {
  html.hr-hivis[data-theme="auto"] { --pv-ink: #ffffff; --pv-line: #ddd; --pv-panel: rgba(10, 12, 9, 0.97); }
}
html.hr-hivis .pv-panel { font-size: 1.12rem; border-width: 2px; }

/* ── shell ─────────────────────────────────────────────────── */
html, body { height: 100%; }
body {
  background: var(--pv-bg);
  color: var(--pv-ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── header tweaks (icon 36px, dark-mode header) ───────────── */
.ect-header { padding: 8px 16px; gap: 12px; }
.ect-header img { height: 36px; }
.ect-header-divider { height: 36px; }
.ect-header-title .school { font-size: 1.2rem; }
.ect-header-title { flex: 0 0 auto; }
.pv-tagline { flex: 1; min-width: 0; text-align: left; }
.pv-tagline .app-description { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 720px) { .pv-tagline { display: none; } }

html[data-theme="dark"] .ect-header {
  background: var(--pv-surface);
  border-bottom-color: var(--pv-accent);
}
html[data-theme="dark"] .ect-header-title .school { color: var(--pv-accent); }
html[data-theme="dark"] .ect-header-app-title .app-description { color: var(--pv-ink-muted); }
html[data-theme="dark"] .ect-hamburger-btn { border-color: var(--pv-accent); color: var(--pv-accent); }
html[data-theme="dark"] .ect-hamburger-btn:hover { background: var(--pv-accent); color: var(--pv-surface); }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .ect-header { background: var(--pv-surface); border-bottom-color: var(--pv-accent); }
  html[data-theme="auto"] .ect-header-title .school { color: var(--pv-accent); }
  html[data-theme="auto"] .ect-header-app-title .app-description { color: var(--pv-ink-muted); }
  html[data-theme="auto"] .ect-hamburger-btn { border-color: var(--pv-accent); color: var(--pv-accent); }
}

/* ── hamburger menu - ENE-style light surface ──────────────── */
.ect-nav-menu {
  background: var(--pv-surface);
  border: 2px solid var(--pv-accent);
  border-radius: 8px;
  padding: 6px;
  min-width: 240px;
  box-shadow: var(--pv-shadow);
}
.ect-nav-menu a {
  display: block;
  padding: 8px 10px;
  color: var(--pv-accent-dk);
  font-weight: 600;
  border: none;
  border-radius: 4px;
  text-decoration: none;
}
html[data-theme="dark"] .ect-nav-menu a { color: var(--pv-accent); }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] .ect-nav-menu a { color: var(--pv-accent); } }
.ect-nav-menu a:hover { background: var(--sycamore); color: var(--pv-accent-dk); }

/* flyout submenus (open to the LEFT of the menu, same surface) */
.pv-menu-sub { position: relative; }
.pv-menu-sub > a { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pv-sub-arrow { color: var(--pv-ink-muted); }
.pv-submenu {
  display: none; position: absolute; top: -8px; right: 100%; margin-right: 10px;
  background: var(--pv-surface); border: 2px solid var(--pv-accent);
  border-radius: 8px; padding: 6px; min-width: 230px; box-shadow: var(--pv-shadow);
}
.pv-submenu.open { display: block; }

.ect-nav-menu a.pv-has-state {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.pv-menu-state {
  font-size: 0.78em; font-weight: 700; padding: 1px 8px; border-radius: 10px;
  background: var(--pv-accent); color: var(--pv-surface); letter-spacing: 0.04em;
}
.pv-menu-state.is-off { background: var(--pv-line); color: var(--pv-ink-muted); }

.ect-nav-menu a.hr-menu-danger,
html[data-theme="dark"] .ect-nav-menu a.hr-menu-danger { color: var(--pv-err-fg); }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] .ect-nav-menu a.hr-menu-danger { color: var(--pv-err-fg); } }
.ect-nav-menu a.hr-menu-danger:hover { background: var(--pv-err-bg); color: var(--pv-err-fg); }

/* ── stage: the 3D canvas + floating HUD panels ────────────── */
#pv-stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
#pv-stage > canvas {            /* the 3D renderer canvas only, not HUD canvases */
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
}

.pv-panel {
  position: absolute;
  background: var(--pv-panel);
  color: var(--pv-ink);
  border: 1px solid var(--pv-line);
  border-radius: 8px;
  box-shadow: var(--pv-shadow);
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  max-width: 300px;
  z-index: 10;
}

/* stats - top left */
#pv-stats { top: 12px; left: 12px; min-width: 220px; }
#pv-stats h2 { margin: 0 0 6px; font-size: 1rem; color: var(--pv-accent); }
html[data-theme="dark"] #pv-stats h2 { color: var(--pv-accent); }
.pv-stat-row { display: flex; justify-content: space-between; gap: 12px; }
.pv-stat-row b { font-variant-numeric: tabular-nums; }
.pv-proto-rows { margin-top: 8px; border-top: 1px solid var(--pv-line); padding-top: 6px; }
.pv-proto-row { display: flex; align-items: center; gap: 7px; }
.pv-proto-row em { font-style: normal; color: var(--pv-ink-muted); font-size: 0.85em; }
html.hr-hivis .pv-proto-row em { color: var(--pv-ink); }
.pv-proto-row .pv-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.pv-chip {
  width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.25);
}
/* drag-to-resize grips on each resizable HUD window's free top + bottom corners */
.pv-resize-grip {
  position: absolute; width: 16px; height: 16px; z-index: 2;
  font-size: 11px; line-height: 16px; text-align: center;
  color: var(--pv-ink-muted); opacity: 0.6;
  user-select: none; touch-action: none;
}
.pv-resize-grip:hover { color: var(--pv-accent); opacity: 1; }
.pv-resize-tr { top: 2px; right: 2px; cursor: nesw-resize; }
.pv-resize-tl { top: 2px; left: 2px; cursor: nwse-resize; }
.pv-resize-br { bottom: 2px; right: 2px; cursor: nwse-resize; }
.pv-resize-bl { bottom: 2px; left: 2px; cursor: nesw-resize; }
html.hr-hivis .pv-resize-grip { color: var(--pv-ink); opacity: 0.9; font-size: 14px; }

.pv-bar-track { height: 6px; border-radius: 3px; background: var(--pv-line); overflow: hidden; margin-top: 6px; display: flex; }
.pv-bar-seg { height: 100%; }
.pv-stats-file { margin-top: 6px; color: var(--pv-ink-muted); font-size: 0.8rem; word-break: break-all; }

/* legend - bottom right (left side is the stats panel) */
#pv-legend {
  bottom: 12px; right: 12px; max-width: 340px; max-height: calc(100% - 24px);
  padding-bottom: 20px;                  /* clear strip for the bottom-left resize grip */
  display: flex; flex-direction: column; overflow: hidden;
}
#pv-legend h2 { padding-left: 16px; }    /* clear the top-left resize grip */
.pv-legend-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.pv-legend-sub {
  margin: 8px 0 3px; border-top: 1px solid var(--pv-line); padding-top: 6px;
  font-weight: 700; font-size: 0.82rem; color: var(--pv-ink-muted);
}
html.hr-hivis .pv-legend-sub { color: var(--pv-ink); }
#pv-legend h2 { margin: 0 0 6px; font-size: 1rem; color: var(--pv-accent); display: flex; align-items: center; gap: 8px; }
#pv-legend-close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--pv-ink-muted); font-size: 1.1rem; line-height: 1; padding: 0 2px;
}
#pv-legend-close:hover { color: var(--pv-err-fg); }
.pv-legend-row { display: flex; align-items: baseline; gap: 7px; margin: 2px 0; }
.pv-legend-row .pv-chip { align-self: center; }
.pv-legend-row b { white-space: nowrap; }
.pv-legend-row span { color: var(--pv-ink-muted); font-size: 0.82rem; }
.pv-legend-note { margin-top: 6px; border-top: 1px solid var(--pv-line); padding-top: 6px; color: var(--pv-ink-muted); font-size: 0.82rem; }
.pv-legend-more {
  display: block; width: 100%; margin-top: 8px; padding: 7px 0 0;
  border: none; border-top: 1px solid var(--pv-line); background: none;
  text-align: left; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--pv-accent);
}
html[data-theme="dark"] .pv-legend-more { color: var(--pv-accent); }
.pv-legend-more:hover { text-decoration: underline; }
html.hr-hivis .pv-chip { width: 16px; height: 16px; }
html.hr-hivis .pv-legend-row span, html.hr-hivis .pv-legend-note { color: var(--pv-ink); }

/* traffic-over-time graph - bottom left */
#pv-graph { bottom: 12px; left: 12px; min-width: 248px; max-width: none; padding-bottom: 20px; }
#pv-graph h2 {
  margin: 0 0 6px; padding-right: 16px;   /* clear the top-right resize grip */
  font-size: 1rem; color: var(--pv-accent);
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
html[data-theme="dark"] #pv-graph h2 { color: var(--pv-accent); }
.pv-graph-max { font-size: 0.78rem; font-weight: 700; color: var(--pv-ink-muted); font-variant-numeric: tabular-nums; }
html.hr-hivis .pv-graph-max { color: var(--pv-ink); }
#pv-graph-cv { display: block; }   /* pixel size set inline by hud.js (drag-resizable) */
.pv-graph-toggle {
  display: flex; align-items: center; gap: 6px; margin-top: 6px; cursor: pointer;
  font-size: 0.78rem; color: var(--pv-ink-muted);
}
.pv-graph-toggle input { margin: 0; cursor: pointer; accent-color: var(--pv-accent); }
html.hr-hivis .pv-graph-toggle { color: var(--pv-ink); font-size: 0.95rem; }
.pv-graph-cap { margin-top: 5px; color: var(--pv-ink-muted); font-size: 0.74rem; line-height: 1.3; }
html.hr-hivis .pv-graph-cap { color: var(--pv-ink); }

/* playback bar - bottom center */
#pv-playbar {
  bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  max-width: none; white-space: nowrap;
}
#pv-playbar button {
  background: var(--pv-accent); color: var(--pv-surface);
  border: none; border-radius: 6px; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 7px 12px; font-weight: 700;
}
#pv-playbar button:hover { background: var(--pv-accent-dk); color: #fff; }
#pv-playbar select {
  background: var(--pv-surface); color: var(--pv-ink);
  border: 1px solid var(--pv-line); border-radius: 6px; padding: 5px 6px;
  font: inherit;
}
#pv-playbar input[type="range"] { width: 200px; accent-color: var(--pv-accent); }
#pv-playbar.pv-has-timeline {
  flex-direction: column; align-items: stretch; gap: 8px;
  width: 600px; max-width: calc(100vw - 24px);
}
.pv-playrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#pv-timeline {
  display: block; width: 100%; height: 44px;
  background: var(--pv-bg); border: 1px solid var(--pv-line);
  border-radius: 6px; cursor: pointer; touch-action: none;
}
.pv-play-time { font-variant-numeric: tabular-nums; color: var(--pv-ink-muted); }
.pv-play-src { color: var(--pv-ink-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.pv-local-pick { display: inline-flex; align-items: center; gap: 5px; color: var(--pv-ink-muted); font-size: 0.85rem; }

/* detail popover - top right */
#pv-detail { top: 12px; right: 12px; min-width: 250px; }
#pv-detail h2 { margin: 0 0 6px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
#pv-detail h2 .pv-chip { width: 13px; height: 13px; }
#pv-detail-close {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--pv-ink-muted); font-size: 1.1rem; line-height: 1; padding: 0 2px;
}
#pv-detail-close:hover { color: var(--pv-err-fg); }
.pv-detail-row { display: flex; gap: 10px; }
.pv-detail-row .k { color: var(--pv-ink-muted); min-width: 64px; flex-shrink: 0; }
.pv-detail-row .v { word-break: break-all; }
.pv-flag-pill {
  display: inline-block; font-size: 0.74em; font-weight: 700; padding: 0 7px;
  border-radius: 9px; background: var(--pv-accent); color: var(--pv-surface);
  margin-right: 4px; letter-spacing: 0.04em;
}
.pv-detail-info { margin-top: 6px; border-top: 1px solid var(--pv-line); padding-top: 6px; color: var(--pv-ink-muted); }

/* hover tooltip near cursor */
#pv-tip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--pv-panel); color: var(--pv-ink);
  border: 1px solid var(--pv-line); border-radius: 6px;
  padding: 3px 8px; font-size: 0.8rem; box-shadow: var(--pv-shadow);
  max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
html.hr-hivis #pv-tip { font-size: 1rem; }

/* ── modal: ENE-style standalone window ────────────────────── */
.pv-modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.pv-modal[hidden] { display: none; }
.pv-modal-card {
  background: var(--pv-surface); color: var(--pv-ink);
  border: 2px solid var(--pv-accent); border-radius: 10px;
  width: min(560px, calc(100vw - 40px));
  max-height: min(80vh, 700px);
  display: flex; flex-direction: column;
  box-shadow: var(--pv-shadow);
  overflow: hidden;
}
.pv-win-title {
  display: flex; align-items: center; gap: 10px;
  background: var(--pv-accent); color: #fff;
  padding: 8px 14px; font-weight: 700; cursor: move; user-select: none;
}
.pv-win-close {
  margin-left: auto; background: none; border: none; color: #fff;
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 2px;
}
.pv-win-close:hover { color: var(--sycamore); }
#pv-modal-body { padding: 14px 18px; overflow-y: auto; }
#pv-modal-body h3 { color: var(--pv-accent); margin: 14px 0 6px; font-size: 1rem; }
html[data-theme="dark"] #pv-modal-body h3 { color: var(--pv-accent); }
#pv-modal-body code {
  background: var(--pv-bg); border: 1px solid var(--pv-line);
  border-radius: 4px; padding: 0 4px;
}
#pv-modal-body a { color: var(--pv-accent); }
.pv-modal-actions { margin-top: 14px; text-align: right; }
.pv-modal-actions button {
  background: var(--pv-accent); color: var(--pv-surface);
  border: none; border-radius: 6px; cursor: pointer;
  font: inherit; font-weight: 700; padding: 8px 18px;
}
.pv-modal-actions button:hover { background: var(--pv-accent-dk); color: #fff; }
.pv-about { text-align: left; }
.pv-about-logo { width: 64px; float: right; margin: 0 0 8px 12px; }
.pv-about-list { margin: 4px 0; padding-left: 0; list-style: none; }
#pv-modal-body h3.pv-about-school { font-size: 0.8rem; white-space: nowrap; }
.pv-about-cr { color: var(--pv-ink-muted); font-size: 0.85rem; }
.pv-err-detail { color: var(--pv-err-fg); font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* panels collapse politely on small screens */
@media (max-width: 900px) {
  #pv-legend, #pv-graph { display: none; }
  .pv-panel { font-size: 0.8rem; }
}
