/*
 * hud.css — the console as an OPERATIONAL HUD (Platform Space redesign).
 *
 * The 3D world IS the screen; everything else is instrumentation floating over it. The
 * reference is the user's OSINT HUD — corner instrument blocks, mono type, live readouts —
 * deliberately dialled back: no scanlines, no glitch, nothing that moves without data. The
 * world provides the theatre; the chrome stays legible.
 *
 * Layer model:
 *   #space-canvas   the WebGL world, fixed, z0
 *   .hud            fixed corner instruments + rail, z1 (pointer-events only on themselves)
 *   .hud-overlay    pages (Users, Audit, …) as a floating glass panel, z2
 */

.hud { position: fixed; inset: 0; z-index: 1; pointer-events: none; font-family: var(--mono); }
.hud > * { pointer-events: auto; }

/* ── instrument block: the corner panel with bracket corners ──────────────── */
.ib {
  position: absolute;
  background: rgba(8, 10, 18, .72);
  border: 1px solid rgba(139, 123, 255, .28);
  border-radius: 4px;
  padding: 12px 15px;
  backdrop-filter: blur(6px);
  min-width: 200px;
}
.ib::before, .ib::after {
  content: ""; position: absolute; width: 10px; height: 10px; pointer-events: none;
  border-color: var(--accent); border-style: solid;
}
.ib::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.ib::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.ib .ib-h {
  font-size: 10.5px; letter-spacing: .22em; color: var(--accent);
  margin-bottom: 8px; display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.ib .ib-h .live { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: hud-live 2s infinite; }
@keyframes hud-live { 0%,100%{opacity:1} 50%{opacity:.35} }
.ib .ln { display: flex; justify-content: space-between; gap: 18px; font-size: 11.5px; padding: 1.5px 0; }
.ib .ln .k { color: var(--muted); letter-spacing: .06em; }
.ib .ln .v { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ib .ln .v.ok { color: var(--green); } .ib .ln .v.warn { color: var(--amber); } .ib .ln .v.bad { color: var(--red); }

/* placement */
.ib.tl { top: 16px; left: 76px; }
.ib.tr { top: 16px; right: 16px; text-align: right; }
.ib.tr .ln { justify-content: flex-end; }
.ib.bl { bottom: 16px; left: 76px; }
.ib.br { bottom: 16px; right: 16px; width: 360px; max-width: 44vw; }

/* the big clock */
.hud-clock { font-size: 20px; letter-spacing: .12em; color: var(--text-primary); }
.hud-clock small { display: block; font-size: 10px; color: var(--faint); letter-spacing: .2em; margin-top: 2px; }

/* ── event log (bottom right) ─────────────────────────────────────────────── */
.ib.br .feed { max-height: 170px; overflow-y: auto; display: flex; flex-direction: column-reverse; }
.ib.br .ev { font-size: 10.8px; padding: 1.5px 0; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib.br .ev .t { color: var(--faint); margin-right: 8px; }
.ib.br .ev.warn { color: var(--amber); } .ib.br .ev.bad { color: var(--red); }

/* ── the nav rail (left edge, icons only) ─────────────────────────────────── */
.hud-rail {
  position: absolute; top: 16px; bottom: 16px; left: 16px; width: 46px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: rgba(8, 10, 18, .72); border: 1px solid rgba(139, 123, 255, .28);
  border-radius: 6px; padding: 10px 0; backdrop-filter: blur(6px);
}
.hud-rail .logo { font-size: 18px; margin-bottom: 8px; }
.hud-rail a {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px;
  font-size: 16px; color: var(--muted); border: 1px solid transparent; position: relative;
}
.hud-rail a:hover { color: var(--text-primary); background: rgba(255,255,255,.05); }
.hud-rail a.active { color: var(--accent); background: var(--accent-soft); border-color: rgba(139,123,255,.3); }
.hud-rail a .tip {
  position: absolute; left: 46px; top: 50%; transform: translateY(-50%);
  background: rgba(8,10,18,.92); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 10px; font-size: 11px; letter-spacing: .08em; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s; color: var(--text-primary);
}
.hud-rail a:hover .tip { opacity: 1; }
.hud-rail .gap { flex: 1; }

/* ── page overlay: a glass instrument, not a separate screen ──────────────── */
.hud-overlay {
  position: fixed; z-index: 2; top: 70px; left: 50%; transform: translateX(-50%);
  width: min(1040px, calc(100vw - 140px)); max-height: calc(100vh - 120px);
  overflow: auto; background: rgba(10, 12, 20, .88);
  border: 1px solid rgba(139, 123, 255, .35); border-radius: 10px;
  padding: 20px 24px; backdrop-filter: blur(14px);
  font-family: "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}
.hud-overlay .mc-head h1 { font-family: var(--mono); letter-spacing: .1em; font-size: 17px; text-transform: uppercase; }
.hud-overlay-close {
  position: sticky; top: 0; float: right; margin: -6px -8px 0 12px;
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 7px; padding: 3px 11px; cursor: pointer; font-family: var(--mono); font-size: 12px;
}
.hud-overlay-close:hover { color: var(--red); border-color: var(--red); }

/* ── selection panel (world picking) — right side instrument ──────────────── */
.ib.sel { top: 90px; right: 16px; width: 320px; max-width: 40vw; max-height: 60vh; overflow: auto; text-align: left; }
.ib.sel .ln { justify-content: space-between; }
.ib.sel h4 { margin: 0 0 6px; font-size: 12.5px; letter-spacing: .12em; color: var(--text-primary); }

/* world hint (bottom center) */
.hud-hint {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  font-size: 10.5px; letter-spacing: .18em; color: var(--faint); white-space: nowrap;
}

/*
 * SCROLL, ALWAYS. "The modals that open are not scrollable" — overflow:auto alone is not enough
 * on touch: iOS wants momentum scrolling opted into, and without overscroll containment the
 * world behind the panel eats the gesture the moment the panel hits its edge. Both fixed here,
 * for every scrolling surface the HUD has.
 */
.hud-overlay, .ib.sel, .ib.br .feed, .hud-overlay .tblwrap {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.hud-overlay .tblwrap { touch-action: pan-x pan-y; }

@media (max-width: 900px) {
  .ib.br { display: none; }
  .ib.tl { left: 70px; right: 12px; min-width: 0; }
  .ib.tl .ln { font-size: 10.5px; }
  .ib.tr { display: none; }                        /* the clock yields; the world does not */
  .hud-hint { display: none; }                     /* gestures replace the keyboard legend */
  .hud-rail { top: 12px; bottom: auto; left: 8px; width: 40px; padding: 8px 0; }
  .hud-rail a { width: 30px; height: 30px; font-size: 14px; }
  /* the selection panel becomes a bottom sheet — thumb range, not corner range */
  .ib.sel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; max-width: none;
    max-height: 42vh; border-radius: 12px 12px 0 0;
  }
  /* pages fill the phone, minus a sliver so the world stays visibly behind */
  .hud-overlay {
    top: 10px; width: calc(100vw - 16px); max-height: calc(100dvh - 20px);
    padding: 14px;
  }
}

/*
 * SCROLLBARS BELONG TO THE INSTRUMENT, NOT THE OS. The default white bars sat on the glass
 * panels like stickers on a cockpit. Thin, dark, borderless — visible on hover, invisible in
 * the corner of the eye.
 */
.hud-overlay, .ib.sel, .ib.br .feed, .hud-overlay .tblwrap, .hud-overlay pre {
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 123, 255, .35) transparent;
}
.hud-overlay::-webkit-scrollbar, .ib.sel::-webkit-scrollbar,
.ib.br .feed::-webkit-scrollbar, .hud-overlay .tblwrap::-webkit-scrollbar,
.hud-overlay pre::-webkit-scrollbar { width: 7px; height: 7px; }
.hud-overlay::-webkit-scrollbar-thumb, .ib.sel::-webkit-scrollbar-thumb,
.ib.br .feed::-webkit-scrollbar-thumb, .hud-overlay .tblwrap::-webkit-scrollbar-thumb,
.hud-overlay pre::-webkit-scrollbar-thumb {
  background: rgba(139, 123, 255, .3); border-radius: 8px;
}
.hud-overlay::-webkit-scrollbar-track, .ib.sel::-webkit-scrollbar-track,
.ib.br .feed::-webkit-scrollbar-track, .hud-overlay .tblwrap::-webkit-scrollbar-track,
.hud-overlay pre::-webkit-scrollbar-track { background: transparent; }

/* The rail (and its tooltips) must ride ABOVE the page overlay — a hover hint that renders
   BEHIND the panel it is meant to explain is worse than none. */
.hud-rail { z-index: 3; }

/* ── draggable / minimisable / resizable panel chrome (enhancePanel in boot.js) ── */
.ib .ib-h { position: relative; padding-right: 24px; }
.mc-drag { cursor: move; }
.mc-panel-btn {
  position: absolute; top: -3px; right: -2px; width: 19px; height: 19px; padding: 0;
  line-height: 15px; text-align: center; font-size: 15px; font-family: var(--mono);
  color: var(--muted); background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.14); border-radius: 5px; cursor: pointer;
}
.mc-panel-btn:hover { color: var(--text-primary); border-color: var(--accent, #8b7bff); background: var(--accent-soft, rgba(139,123,255,.15)); }
.mc-grip {
  position: absolute; right: 2px; bottom: 2px; width: 15px; height: 15px; cursor: nwse-resize; opacity: .55;
  background: linear-gradient(135deg, transparent 45%, var(--muted) 45%, var(--muted) 55%, transparent 55%, transparent 68%, var(--muted) 68%, var(--muted) 78%, transparent 78%);
}
.mc-grip:hover { opacity: 1; }

/* ── security alarm overlay (buildAlarmUI in boot.js) ── */
#mc-alarm {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 40;
  min-width: 320px; max-width: min(92vw, 560px); display: none;
  background: rgba(26, 10, 14, .93); border: 1px solid rgba(242, 100, 122, .6); border-radius: 12px;
  padding: 11px 14px; backdrop-filter: blur(8px); font-family: var(--mono);
  animation: mc-alarm-pulse 1.8s ease-in-out infinite;
}
@keyframes mc-alarm-pulse {
  0%, 100% { box-shadow: 0 0 22px rgba(242, 100, 122, .30); }
  50%      { box-shadow: 0 0 42px rgba(242, 100, 122, .60); }
}
.mc-alarm-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.mc-alarm-head > span { color: #f2647a; font-size: 12px; letter-spacing: .12em; }
.mc-alarm-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; }
.mc-alarm-acts { display: flex; gap: 6px; flex-shrink: 0; }
.mc-alarm-yes, .mc-alarm-no, .mc-alarm-dismissall {
  font-family: var(--mono); font-size: 10.5px; padding: 3px 10px; border-radius: 6px; cursor: pointer;
  background: transparent; border: 1px solid var(--faint, #5b6178); color: var(--muted, #8189a0);
}
.mc-alarm-yes { border-color: rgba(242, 100, 122, .7); color: #f2647a; }
.mc-alarm-yes:hover { background: rgba(242, 100, 122, .18); }
.mc-alarm-no:hover, .mc-alarm-dismissall:hover { color: var(--text-primary); border-color: var(--accent, #8b7bff); }

/* ── confirm-gated action panel (rent/stop node) — violet, mirrors the alarm ── */
#mc-confirm {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 41;
  min-width: 340px; max-width: min(92vw, 600px); display: none;
  background: rgba(18, 14, 30, .94); border: 1px solid rgba(139, 123, 255, .6); border-radius: 12px;
  padding: 11px 14px; backdrop-filter: blur(8px); font-family: var(--mono);
  box-shadow: 0 0 28px rgba(139, 123, 255, .4);
}
#mc-confirm .mc-alarm-head > span { color: #b1a6ff; }
#mc-confirm .mc-alarm-yes { border-color: rgba(56, 208, 232, .7); color: #38d0e8; }
#mc-confirm .mc-alarm-yes:hover { background: rgba(56, 208, 232, .16); }
