/* ==========================================================================
   3D MI Reports — shared visual system
   Aura "Blueprint" background (dark lattice) + glass UI + brand bar.
   Loaded by the portal, both 3D viewers and the statistics dashboards.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Backdrop — blend modes composite against the BODY colour (see .aura) */
  --bg: #100e0b;

  /* Brand (sampled from the i2 / Fisabio lock-up) */
  --brand-indigo: #180040;
  --brand-blue: #3870e0;
  --brand-blue-hi: #6a95ff;
  --brand-cyan: #06b6d4;

  /* Text */
  --fg: #ecebe7;
  --fg-muted: rgba(236, 235, 231, 0.64);
  --fg-faint: rgba(236, 235, 231, 0.4);

  /* Surfaces */
  --glass: rgba(16, 14, 11, 0.72);
  --glass-strong: rgba(16, 14, 11, 0.88);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --hover: rgba(255, 255, 255, 0.05);
  --selected: rgba(56, 112, 224, 0.18);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.7);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html, body {
  margin: 0;
  background-color: var(--bg);   /* required: aura layers blend against this */
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   Aura background — three decorative layers, no background on the container
   -------------------------------------------------------------------------- */
.aura {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.aura > div {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transform: translateZ(0);
  will-change: transform;
}
.aura-layer-1 {
  background:
    linear-gradient(rgba(14, 165, 233, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14, 165, 233, 0.12) 1px, transparent 1px);
  background-size: 50px 50px;
  mix-blend-mode: normal;
}
.aura-layer-2 {
  background:
    linear-gradient(rgba(14, 165, 233, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14, 165, 233, 0.06) 1px, transparent 1px);
  background-size: 10px 10px;
  mix-blend-mode: normal;
}
.aura-layer-3 {
  background: radial-gradient(circle at 60% 40%, rgba(6, 182, 212, 0.35) 0%, transparent 45%);
  mix-blend-mode: screen;
  filter: blur(175px);
}
@media (min-width: 900px) {
  .aura-layer-3 { filter: blur(252px); }
}

/* Everything real sits above the aura */
.above { position: relative; z-index: 1; }

[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Brand bar (logo lock-up). Kept intact, never recoloured: white version on
   the dark backdrop, minimum clear space = logo height / 4.
   -------------------------------------------------------------------------- */
.brand-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-bar img {
  display: block;
  height: 40px;
  width: auto;
  max-width: 100%;
  opacity: 0.92;
}
@media (max-width: 640px) {
  .brand-bar img { height: 28px; }
}

/* --------------------------------------------------------------------------
   Generic controls
   -------------------------------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font: 500 12px/1 var(--font);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); border-color: var(--line-strong); }
.btn:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 1px; }
.btn.is-active { background: var(--selected); border-color: var(--brand-blue); color: #fff; }
.btn.primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn.primary:hover { background: var(--brand-blue-hi); }
.btn.icon { padding: 7px; width: 30px; height: 30px; justify-content: center; }
.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-muted);
  font: 500 11px/1 var(--font);
  padding: 6px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--fg); border-color: var(--line-strong); }
.chip.is-active { color: #fff; background: var(--selected); border-color: var(--brand-blue); }
.chip:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 1px; }

/* Range slider */
input[type="range"].slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}
input[type="range"].slider::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brand-blue) 0 var(--fill, 50%), rgba(255, 255, 255, 0.18) var(--fill, 50%) 100%);
}
input[type="range"].slider::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); }
input[type="range"].slider::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--brand-blue); }
input[type="range"].slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand-blue);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
input[type="range"].slider::-moz-range-thumb {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand-blue);
}
input[type="range"].slider:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 2px; border-radius: 4px; }

/* Checkbox */
input[type="checkbox"].check {
  -webkit-appearance: none;
  appearance: none;
  width: 15px; height: 15px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex: none;
  transition: background 0.12s, border-color 0.12s;
}
input[type="checkbox"].check:checked { background: var(--brand-blue); border-color: var(--brand-blue); }
input[type="checkbox"].check:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"].check:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 1px; }

/* Colour swatch = the native colour input, restyled as a dot */
input[type="color"].swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  padding: 0; margin: 0;
  border: 1px solid rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  flex: none;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}
input[type="color"].swatch::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].swatch::-webkit-color-swatch { border: none; border-radius: 50%; }
input[type="color"].swatch::-moz-color-swatch { border: none; border-radius: 50%; }

select.select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%23ecebe7' stroke-width='1.5'/></svg>") no-repeat right 8px center;
  color: var(--fg);
  font: 500 12px/1 var(--font);
  padding: 7px 24px 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
select.select:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 1px; }

/* --------------------------------------------------------------------------
   Viewer chrome (shared by brain + spine)
   -------------------------------------------------------------------------- */
.viewer-body { overflow: hidden; height: 100vh; }

#viewer {
  position: fixed;
  inset: 0;
  z-index: 1;
}
#viewer canvas { display: block; touch-action: none; }

.viewer-header {
  position: fixed;
  top: 14px; left: 16px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}
.viewer-header > * { pointer-events: auto; }
.viewer-header .home {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: color 0.15s, border-color 0.15s;
}
.viewer-header .home:hover { color: var(--fg); border-color: var(--line-strong); }
.viewer-header .home svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
.viewer-title { display: flex; flex-direction: column; line-height: 1.15; }
.viewer-title .eyebrow { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-faint); }
.viewer-title h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }

.viewer-footer {
  position: fixed;
  left: 16px; bottom: 14px;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  gap: 16px;
  pointer-events: none;
}
.viewer-footer > * { pointer-events: auto; }
.viewer-footer .brand-bar img { height: 34px; }

.hint {
  position: fixed;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  z-index: 3;
  font-size: 11px;
  color: var(--fg-faint);
  white-space: nowrap;
  pointer-events: none;
}

/* Floating toolbar (bottom-right) */
.toolbar {
  position: fixed;
  right: 16px; bottom: 14px;
  z-index: 3;
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}
.toolbar .btn { border-radius: 999px; background: transparent; border-color: transparent; }
.toolbar .btn:hover { background: var(--hover); }
.toolbar .btn.is-active { background: var(--selected); }

/* Control panel (right) */
.panel-toggle {
  position: fixed;
  top: 14px; right: 16px;
  z-index: 4;
}
.panel {
  position: fixed;
  top: 14px; right: 16px;
  z-index: 3;
  width: 300px;
  max-height: calc(100vh - 92px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  transition: transform 0.28s ease, opacity 0.22s ease;
}
.panel.collapsed { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; }
.panel-head .btn { padding: 5px 8px; font-size: 11px; }
.panel-scroll { overflow: auto; overscroll-behavior: contain; padding: 6px 8px 10px; }
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }

.section { padding: 8px 6px 6px; }
.section + .section { border-top: 1px solid var(--line); }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin: 0 0 8px;
}
.section-title .btn { padding: 4px 7px; font-size: 10px; text-transform: none; letter-spacing: 0; }
.section-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 12px; }
.section-row label { color: var(--fg-muted); flex: none; min-width: 54px; }
.section-row .grow { flex: 1; min-width: 0; }
.section-row .value { font-family: var(--mono); font-size: 11px; color: var(--fg-muted); min-width: 52px; text-align: right; }

/* Segment rows */
.seg-row {
  display: grid;
  grid-template-columns: 15px 16px minmax(0, 1fr) 76px 22px;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: background 0.12s;
  cursor: pointer;
  border: 1px solid transparent;
}
.seg-row:hover { background: var(--hover); }
.seg-row.is-selected { background: var(--selected); border-color: rgba(56, 112, 224, 0.5); }
.seg-row.is-hidden .seg-name { color: var(--fg-faint); text-decoration: line-through; }
.seg-name { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.seg-name .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-name .v { font-family: var(--mono); font-size: 10px; color: var(--fg-faint); }
.seg-row .focus-btn {
  width: 22px; height: 22px;
  border: none; background: transparent;
  color: var(--fg-faint);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.seg-row:hover .focus-btn, .seg-row.is-selected .focus-btn { opacity: 1; }
.seg-row .focus-btn:hover { color: var(--fg); background: var(--hover); }
.seg-row .focus-btn svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* Loading overlay */
.loading {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 14, 11, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.35s;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-card {
  width: min(320px, 84vw);
  padding: 20px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  text-align: center;
}
.loading-card .spinner {
  width: 28px; height: 28px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--brand-blue-hi);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card .title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.loading-card .status { font-size: 11px; color: var(--fg-muted); font-family: var(--mono); min-height: 14px; }
.loading-card .bar { height: 3px; margin-top: 12px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.loading-card .bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand-blue), var(--brand-cyan)); transition: width 0.2s; }
.loading-card .error { color: #ff8a80; font-size: 12px; margin-top: 8px; display: none; }

/* Pick tooltip */
.pick-tip {
  position: fixed;
  z-index: 4;
  pointer-events: none;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--glass-strong);
  font-size: 11px;
  color: var(--fg);
  transform: translate(12px, 12px);
  opacity: 0;
  transition: opacity 0.12s;
  white-space: nowrap;
}
.pick-tip.show { opacity: 1; }
.pick-tip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* Language switch (ES | EN) */
.lang-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 2px;
}
.lang-btn {
  appearance: none; border: none; background: transparent;
  color: var(--fg-faint); font: 600 11px/1 var(--font); letter-spacing: .06em;
  padding: 5px 9px; border-radius: 999px; cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-btn:hover { color: var(--fg); }
.lang-btn.is-active { background: var(--brand-blue); color: #fff; }
.lang-btn:focus-visible { outline: 2px solid var(--brand-blue-hi); outline-offset: 1px; }
.viewer-header .lang-switch { margin-left: 4px; }

/* Keyboard help */
kbd {
  font: 10px/1 var(--mono);
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg-muted);
}

/* --------------------------------------------------------------------------
   Responsive: the panel becomes a bottom sheet on narrow screens
   -------------------------------------------------------------------------- */
@media (max-width: 820px) {
  .panel {
    top: auto;
    right: 12px; left: 12px; bottom: 64px;
    width: auto;
    max-height: 46vh;
  }
  .panel.collapsed { transform: translateY(calc(100% + 80px)); }
  .viewer-footer { bottom: 12px; left: 12px; }
  .viewer-footer .brand-bar img { height: 24px; }
  .toolbar { right: 12px; bottom: 12px; padding: 4px; }
  .hint { display: none; }
  .viewer-header { left: 12px; top: 12px; }
  .viewer-title h1 { font-size: 13px; }
  .panel-toggle { right: 12px; top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .loading, .btn, .chip { transition: none; }
  .loading-card .spinner { animation-duration: 2s; }
}
