/* ════════════════════════════════════════════════════════════════════════
   Microsensor Viewer — main stylesheet (used by / and /sites pages)
   Sections:
     0. Design tokens (vars)
     1. Reset + base
     2. Header + toolbar
     3. Layout (sidebar / middle / main)
     4. Main column (charts + info bar)
     5. Pair cards (mFL)
     6. Header controls (search, norm ref)
   ════════════════════════════════════════════════════════════════════════ */

/* ── 0. Design tokens ───────────────────────────────────────────────── */
:root {
  /* Surfaces — cool stone hierarchy, charts tinted to harmonize */
  --bg:           #dfe2e7;   /* gutter behind cards (chart-area) */
  --bg-soft:      #e8ebf0;   /* chrome rails (header, navrail, info-bar) */
  --panel-alt:    #f0f2f6;   /* raised chrome (search, buttons, navrail-head) */
  --panel:        #f6f8fc;   /* cards, inputs (softened off-white, cool tint) */
  --panel-sunken: #cdd2da;   /* inset chips (coords, code) */

  /* Ink */
  --ink:        #14171d;
  --ink-strong: #08090c;
  --mid:        #4d5563;
  --dim:        #7f8593;
  --faint:      #a8aeb9;

  /* Lines */
  --line:        #c8ccd4;
  --line-strong: #a8aeba;
  --line-soft:   #dde0e7;

  /* Accent — deep teal */
  --accent:        #0f6e6f;
  --accent-strong: #0a5354;
  --accent-soft:   #e0eded;
  --accent-fade:   #f0f5f5;

  /* Status */
  --good:       #2e7d4f;
  --good-bg:    #e6f1ea;
  --warn:       #a47410;
  --warn-bg:    #fbf2dc;
  --bad:        #b13a2a;
  --bad-bg:     #f9e6e1;
  --imu:        #6f42c1;
  --imu-bg:     #efe7f7;

  /* Typography */
  --font-ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --font-display: 'IBM Plex Sans', system-ui, sans-serif;

  /* Radius */
  --r-sm: 3px;
  --r-md: 4px;
  --r-lg: 7px;
  --r-card: 10px;  /* chart cards, QC panel, metrics row, photos card */

  /* Shadows — layered, cool-slate tint for harmonized depth */
  --shadow-xs:   0 1px 1px rgba(30, 40, 60, 0.025), 0 0 1px rgba(30, 40, 60, 0.02);
  --shadow-sm:   0 2px 6px rgba(30, 40, 60, 0.055), 0 1px 2px rgba(30, 40, 60, 0.035);
  --shadow-md:   0 4px 14px rgba(30, 40, 60, 0.085), 0 1px 3px rgba(30, 40, 60, 0.05);
  --shadow-lg:   0 14px 38px rgba(30, 40, 60, 0.16), 0 4px 10px rgba(30, 40, 60, 0.08);
  --inset-hi:    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  --inset-hi-lt: inset 0 1px 0 rgba(255, 255, 255, 0.4);

  /* Motion */
  --t-fast: 80ms;
  --t-base: 140ms;
  --ease:    cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ── 1. Reset + base ──────────────────────────────────────────────────── */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  font-feature-settings: 'cv11', 'ss01', 'ss02';
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
::selection {
  background: rgba(15, 110, 111, 0.38);
  color: var(--ink-strong);
}

/* ── 2. Header + toolbar ──────────────────────────────────────────────── */

header {
  padding: 9px 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(30, 40, 60, 0.025), var(--inset-hi-lt);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
header h1 {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink-strong);
  white-space: nowrap;
  flex-shrink: 0;
}
header span { font-size: 0.72rem; color: var(--dim); }

.header-left, .header-right {
  flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0;
}
.header-right { justify-content: flex-end; }
.header-center {
  display: flex; align-items: center;
  flex: 0 1 auto;
}

.hamburger {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 5px 7px;
  border-radius: var(--r-md);
  color: var(--mid);
  font-size: 1.05rem;
  line-height: 1;
  flex-shrink: 0;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.hamburger:hover {
  background: var(--accent-fade);
  border-color: var(--line);
  color: var(--accent);
}

/* ── 3. Layout ────────────────────────────────────────────────────────── */

.layout { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.chart-area {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg);
}

.mhr-columns   { display: flex; gap: 14px; align-items: stretch; }
.mhr-col-left  { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.mhr-col-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 900px) {
  .mhr-columns { flex-direction: column; }
}

/* Subtle separator between mHR sections */
.mhr-section-divider {
  height: 1px;
  margin: 14px 0;
  background: linear-gradient(
    to right,
    transparent,
    var(--line-strong) 12%,
    var(--line-strong) 88%,
    transparent
  );
  opacity: 0.55;
  flex-shrink: 0;
}

/* Columns whose cards should distribute vertical space — used by section 1
   so the left (smoothing + dark-corrected + normalised) and right (Rrs +
   OWT) columns start and end at the same height.

   Strategy: each chart card stretches (flex-grow: 1) to fill remaining
   space proportionally. Plotly's inner div stretches with it, so the
   chart renders at the new height. The slim control card (smoothing
   slider) stays at its natural height — it doesn't grow. */
.mhr-columns.mhr-section-stretch .mhr-col-left,
.mhr-columns.mhr-section-stretch .mhr-col-right {
  gap: 14px;
}

.mhr-section-stretch .chart-card {
  display: flex;
  flex-direction: column;
}
.mhr-section-stretch .chart-card:not(.mhr-control-card) {
  /* Each chart card grows to share leftover space; per-card floors below
     keep the content readable regardless of column distribution. */
  flex: 1 1 auto;
}
.mhr-section-stretch .chart-card .chart-inner {
  flex: 1;
  display: flex;
}
.mhr-section-stretch .chart-card .chart-inner > div {
  flex: 1;
  height: auto;
}

/* Per-card minimum heights. Plotly graphs need ~240 px to stay legible;
   the OWT card has a chromaticity diagram + 7-row dl + 2 pills, so it
   needs more vertical space than the simple plotting cards. */
.mhr-section-stretch .mhr-corrected-card,
.mhr-section-stretch .mhr-normalized-card,
.mhr-section-stretch .mhr-rrs-card {
  min-height: 300px;
}
.mhr-section-stretch .mhr-corrected-card  .chart-inner > div,
.mhr-section-stretch .mhr-normalized-card .chart-inner > div,
.mhr-section-stretch .mhr-rrs-card        .chart-inner > div {
  min-height: 240px;
}

.mhr-section-stretch .mhr-owt-card { min-height: 380px; }
.mhr-section-stretch .mhr-owt-card .chart-inner { min-height: 320px; }
.mhr-section-stretch .mhr-owt-card .chart-inner > #mhrOwtBody {
  flex: 1;
  height: auto;
  min-height: 320px;
}

/* Slim control card (Section 1 — sits atop dark-corrected to balance column height) */
.mhr-control-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}
.mhr-control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.mhr-control-label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
}
.mhr-control-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  height: 4px;
}
.mhr-control-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-strong);
  font-weight: 600;
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── 4. Charts ────────────────────────────────────────────────────────── */

.chart-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-base) var(--ease),
              box-shadow var(--t-base) var(--ease),
              transform var(--t-base) var(--ease);
}
.chart-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.chart-title {
  padding: 9px 14px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-alt);
  display: flex; align-items: baseline; gap: 8px;
}
.chart-note,
.chart-meta {
  font-size: 0.66rem;
  font-weight: 400;
  color: var(--dim);
  letter-spacing: 0;
  font-family: var(--font-mono);
}
.chart-title-text { flex-shrink: 0; }
.chart-title .chart-meta { margin-left: auto; text-align: right; }

.chart-info-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--mid);
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--inset-hi-lt);
  transition: all var(--t-fast) var(--ease);
  flex-shrink: 0;
}
.chart-info-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.06);
}
/* When .chart-info-btn follows .chart-meta, keep meta left of it */
.chart-title .chart-meta + .chart-info-btn { margin-left: 8px; }
.chart-inner { padding: 6px; }
.chart-inner > div { min-height: 240px; height: 240px; }
/* OWT card hosts a grid (chart + dl), let it size to content */
.chart-inner > #mhrOwtBody { height: auto; min-height: 0; }

.placeholder {
  flex: 1; display: flex; align-items: center;
  justify-content: center; color: var(--dim);
  font-size: 0.82rem; text-align: center; line-height: 1.8;
  padding: 40px 20px;
  font-style: italic;
}

/* Loading / empty / error states share a centered vertical stack. */
.placeholder-state {
  flex-direction: column;
  gap: 12px;
  font-style: normal;
}
.placeholder-icon {
  color: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  line-height: 1;
}
.placeholder-msg {
  max-width: 340px;
  line-height: 1.5;
}
.placeholder-error .placeholder-icon { color: var(--bad); }
.placeholder-retry {
  margin-top: 4px;
  padding: 6px 16px;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  color: var(--accent-strong);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.placeholder-retry:hover { border-color: var(--accent); color: var(--accent); }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.info-bar {
  padding: 8px 18px;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  box-shadow: 0 -1px 0 rgba(30, 40, 60, 0.025), var(--inset-hi-lt);
  font-size: 0.7rem;
  color: var(--mid);
  display: flex;
  gap: 14px;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}
.info-bar-left,
.info-bar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-width: 0;
}
.info-bar-right { justify-content: flex-end; }

.exp-info-pill {
  display: none; align-items: center; gap: 10px;
  font-size: 0.7rem; color: var(--ink);
  padding: 4px 10px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs), var(--inset-hi-lt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
  min-width: 0;
  max-width: 100%;
}
.exp-info-pill.visible { display: flex; }
.exp-info-pill strong { color: var(--accent-strong); font-weight: 600; }

/* Hide header search + norm controls until a device is picked */
body.state-no-device .header-center,
body.state-no-device .norm-wrap { display: none; }

.info-exp-id {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-strong);
}

/* ── 5. Pair cards (mFL) ──────────────────────────────────────────────── */

.pair-card-header {
  padding: 9px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-alt);
  display: flex; align-items: center; gap: 9px;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast) var(--ease);
}
.pair-card-header:hover { background: var(--accent-fade); }
.pair-card-exp { margin-left: auto; }
.pair-toggle {
  width: 14px; height: 14px; border-radius: 2px;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem;
  line-height: 1;
  font-weight: 700;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.pair-card.inactive .pair-toggle {
  background: var(--panel);
  border-color: var(--line-strong);
  color: transparent;
}
.pair-card.inactive .chart-inner      { opacity: 0.25; pointer-events: none; }
.pair-card.inactive .pair-card-header { color: var(--faint); }

.pair-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (max-width: 900px) { .pair-grid { grid-template-columns: 1fr; } }

/* ── 6. Header controls ───────────────────────────────────────────────── */

.search-wrap { display: flex; align-items: center; }
.search-wrap input {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 0.74rem;
  color: var(--ink);
  background: var(--panel-alt);
  width: 200px;
  font-family: var(--font-mono);
  box-shadow: var(--inset-hi-lt);
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.search-wrap input::placeholder { color: var(--dim); font-family: var(--font-ui); }
.search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 3px var(--accent-fade), var(--shadow-xs);
}
.search-wrap input.search-error {
  border-color: var(--bad);
  background: var(--bad-bg);
  color: var(--bad);
}
.search-wrap input:disabled { opacity: 0.6; cursor: wait; }

.norm-wrap {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.7rem; color: var(--dim);
}
.norm-wrap input {
  width: 80px; padding: 4px 7px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: 0.74rem; color: var(--ink);
  background: var(--panel-alt);
  font-family: var(--font-mono);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.norm-wrap input:focus {
  outline: none; border-color: var(--accent); background: var(--panel);
}
.norm-wrap button {
  padding: 4px 9px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--panel-alt);
  font-size: 0.7rem;
  cursor: pointer;
  color: var(--mid);
  box-shadow: var(--inset-hi-lt);
  transition: all var(--t-fast) var(--ease);
}
.norm-wrap button:active { box-shadow: none; transform: translateY(0.5px); }
.norm-wrap button:hover {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent-strong);
}

/* Legacy header toolbar buttons (still used on /sites etc.) */
.toolbar-btn {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-alt);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--mid);
  flex-shrink: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all var(--t-fast) var(--ease);
}
.toolbar-btn:hover {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong);
}
.toolbar-btn:disabled { opacity: 0.5; cursor: default; }

/* Empty-state chart card (mHR raw angles when measurements are missing).
   The card itself renders normally; the title gets a red "Missing
   measurements" tag and the body shows an italic placeholder. */
.chart-warn-note {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--bad);
  font-family: var(--font-mono);
  margin-left: auto;
}
.chart-empty-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 240px;
  color: var(--dim);
  font-style: italic;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}
