/* ===========================================================================
   base.css — design tokens, page shell (two independently scrolling panes),
   cards, buttons, header, presets & KPI telemetry cards.
   Mineral colours are NOT here: they live in js/data.js (MINERALS).
   =========================================================================== */

/* ---- Design tokens & reset ---- */
:root {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;


  /* Alert & Status Colors */
  --alarm: #dc2626;
  --alarm-dark: #991b1b;
  --alarm-bg: #fef2f2;
  --alarm-border: #fecaca;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sticky: 0 10px 25px -5px rgba(15, 23, 42, 0.14), 0 4px 10px -4px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
  overflow-x: hidden;
}

/* Only the two panes scroll — never the page itself */
body {
  overflow: hidden;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
}

/* ---- Page shell, cards, header, buttons & presets ---- */
/* Tab rail | left column (selection over foliar suggestion) | diagrams — every pane scrolls separately */
.app-shell {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 68px clamp(360px, 32vw, 440px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

/* ---- Far-left vertical tab rail (js/nav.js) ---- */
.nav-rail {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 12px 6px;
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 3px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-tab svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

.nav-tab.active {
  background: #0f766e;
  color: #ffffff;
}

.nav-tab.active svg circle {
  fill: #0f766e;
}

/* ---- Phone-only right-edge rail (Inputs ⇄ Diagram + stage jumps) ---- */
.view-rail {
  display: none;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  background: #0f172a;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 12px 5px;
}

.vr-sep {
  height: 1px;
  margin: 4px 6px;
  background: #334155;
}

.vr-num {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.nav-tab:focus-visible {
  outline: 2px solid #5eead4;
  outline-offset: 2px;
}

/* Left column: selection pane (top 60%) over foliar suggestion pane (bottom 40%) */
.left-col {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 60fr) minmax(0, 40fr);
  border-right: 1px solid var(--border-strong);
}

.side-pane,
.spray-pane,
.main-pane {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding: 14px 12px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-pane > *,
.spray-pane > *,
.main-pane > * {
  flex-shrink: 0;
}

.side-pane {
  background: #eef2f6;
  container-type: inline-size;
  container-name: side;
}

.spray-pane {
  padding: 10px 12px 20px;
  background: #e2e8f0;
  border-top: 2px solid #94a3b8;
}

.main-pane {
  container-type: inline-size;
  container-name: main;
}

/* Narrow / portrait screens: controls on top, diagrams below, still scrolling separately */
@media (max-width: 899px) {
  .app-shell {
    grid-template-columns: 64px minmax(0, 1fr);
    grid-template-rows: minmax(0, 55fr) minmax(0, 45fr);
  }
  .nav-rail {
    grid-row: 1;
    grid-column: 1;
  }
  .left-col {
    grid-row: 1;
    grid-column: 2;
    border-right: none;
    border-bottom: 2px solid var(--border-strong);
  }
  .main-pane {
    grid-row: 2;
    grid-column: 1 / -1;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.header-card {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.eyebrow-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.eyebrow-sub {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}

.app-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.app-title .accent {
  color: #0f766e;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.btn:hover {
  background: var(--bg-subtle);
}

.btn:active {
  transform: scale(0.98);
}

.btn-dark {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.btn-dark:hover {
  background: #1e293b;
}

/* Presets Bar */
.presets-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--bg-subtle);
}

.presets-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-right: 4px;
}

.preset-btn {
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.preset-btn.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.18);
}

/* ---- KPI telemetry cards (stacked) ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.kpi-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.kpi-card.is-alarm {
  background: var(--alarm-bg);
  border-color: var(--alarm-border);
}

.kpi-card.is-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.kpi-card.is-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
}

.kpi-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}

.kpi-badge.alarm { background: #fee2e2; color: #b91c1c; }
.kpi-badge.warn  { background: #fef3c7; color: #b45309; }
.kpi-badge.ok    { background: #d1fae5; color: #047857; }

.kpi-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.kpi-value.sm { font-size: 16px; line-height: 1.25; }
.kpi-value.alarm { color: #b91c1c; }
.kpi-value.warn  { color: #b45309; }
.kpi-value.ok    { color: #047857; }

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 0;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: #0d9488;
  transition: width 0.14s ease, background-color 0.2s ease;
}

/* ===========================================================================
   PHONE (narrow, or short landscape): one view at a time.
   Left rail = sections of the Inputs view; right rail = Inputs ⇄ Diagram.
   =========================================================================== */
@media (max-width: 699px), (max-height: 500px) {
  .app-shell {
    grid-template-columns: 56px minmax(0, 1fr) 56px;
    grid-template-rows: minmax(0, 1fr);
  }
  .nav-rail {
    grid-row: 1;
    grid-column: 1;
    padding: 10px 4px;
  }
  .left-col,
  .main-pane {
    grid-row: 1;
    grid-column: 2;
  }
  .left-col {
    border-right: none;
    border-bottom: none;
  }
  .view-rail {
    display: flex;
    grid-row: 1;
    grid-column: 3;
  }
  .nav-tab {
    font-size: 10px;
  }

  /* Inputs view: hide the diagram + the stage jumps */
  .app-shell[data-view="inputs"] .main-pane,
  .app-shell[data-view="inputs"] .vr-sep,
  .app-shell[data-view="inputs"] .vr-stage {
    display: none;
  }

  /* Diagram view: hide the inputs and their section rail; diagram gets the width */
  .app-shell[data-view="diagram"] .left-col,
  .app-shell[data-view="diagram"] .nav-rail {
    display: none;
  }
  .app-shell[data-view="diagram"] .main-pane {
    grid-column: 1 / 3;
  }
}
