/* ============================================================
   Liquefaction Hazard Engine -- visual design system
   ------------------------------------------------------------
   Editorial / Apple software aesthetic. Whitespace is the
   primary structuring device; color is reserved for meaning.
   ============================================================ */

/* ---------- Design tokens --------------------------------- */
:root {
  --color-bg:           #fafaf7;
  --color-surface:      #ffffff;
  --color-text:         #0a0a0a;
  --color-text-muted:   #6b6b6b;
  --color-text-faint:   #a8a8a8;
  --color-rule:         #e8e8e3;
  --color-rule-strong:  #d6d6d0;
  --color-accent:       #1a3a52;
  --color-accent-hover: #122a3c;
  --color-accent-soft:  #eaf0f5;
  --color-required:     #b00020;
  --color-required-bg:  #fef0f1;
  --color-warning:      #8a6d00;
  --color-warning-bg:   #fff8d6;
  --color-warning-rule: #f0d97a;
  --color-success:      #2e7d4f;
  --color-success-soft: #ecf6ee;

  --font-sans:  "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text",
                "Helvetica Neue", Arial, sans-serif;
  --font-mono:  "JetBrains Mono", "SF Mono", "Menlo", "Consolas", monospace;

  --size-eyebrow:  11px;
  --size-caption:  13px;
  --size-body:     15px;
  --size-input:    16px;
  --size-h3:       18px;
  --size-h2:       24px;
  --size-h1:       40px;
  --size-display:  56px;

  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 600;

  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;
  --space-7:  48px;
  --space-8:  64px;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  --rule-width: 1px;
  --transition-fast: 120ms ease-out;
  --transition-medium: 200ms ease-out;

  --header-height: 76px;
  --sidebar-width: 320px;
}

/* ---------- Reset ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--size-body);
  line-height: 1.55;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
input, button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: var(--rule-width) solid var(--color-rule); margin: 0; }

/* ---------- Focus state (accessibility) -------------------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- Utilities ------------------------------------- */
.hidden { display: none !important; }
.eyebrow {
  display: inline-block;
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Header ---------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: var(--rule-width) solid var(--color-rule);
}
.site-header-inner {
  max-width: 1240px; margin: 0 auto;
  padding: 0 var(--space-5);
  height: var(--header-height);
  display: flex; align-items: center; gap: var(--space-5);
}
.brand-mark {
  display: inline-flex; align-items: center;
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--size-body);
}
.brand-mark:hover { text-decoration: none; opacity: 0.85; }
.brand-mark .brand-accent { color: var(--color-accent); }

/* Two-line title block sitting next to the wordmark.
   The hairline separator is drawn via the left padding/border. */
.header-title {
  display: flex; flex-direction: column;
  justify-content: center;
  margin-left: var(--space-4); padding-left: var(--space-4);
  border-left: var(--rule-width) solid var(--color-rule);
  line-height: 1.2;
  min-width: 0;
}
.header-eyebrow {
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.header-product {
  font-size: var(--size-body);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  letter-spacing: -0.005em;
  margin-top: 2px;
}

/* Legacy class retained for back-compat with any external markup; hidden. */
.product-name { display: none; }

.header-spacer { flex: 1; }

.header-right {
  display: flex; align-items: center; gap: var(--space-4);
}
.health-badge {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}
.health-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-text-faint); flex-shrink: 0;
}
.health-dot.ok      { background: var(--color-success); }
.health-dot.loading { background: var(--color-warning); animation: pulse 1.4s ease-in-out infinite; }
.health-dot.error   { background: var(--color-required); }

.header-link {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}
.header-link:hover { color: var(--color-text); text-decoration: none; }

#clerk-user-btn { display: inline-flex; }

/* ---------- Page container -------------------------------- */
main {
  max-width: 1240px; margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
  display: flex; flex-direction: column; gap: var(--space-7);
}

/* The standalone .page-title-block is intentionally removed.
   The product title now lives in the header bar (.header-title). */

/* ---------- Section eyebrow + content --------------------- */
.section { display: flex; flex-direction: column; gap: var(--space-4); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.section-head .eyebrow { color: var(--color-accent); }
.section-head .controls { display: flex; align-items: center; gap: var(--space-3); }
.section-head .control-label {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}

.section-rule { height: 1px; background: var(--color-rule); }

/* ---------- Form card ------------------------------------- */
.form-card {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
}

/* ---------- Loading / param groups ------------------------ */
.params-loading {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-6) 0;
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
}
/* Top-level form sections are spaced tighter than before to keep all
   three groups visible on a 1080p laptop without scrolling. */
.param-groups { display: flex; flex-direction: column; gap: var(--space-4); }

.param-group-label {
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  padding-bottom: var(--space-2);
  border-bottom: var(--rule-width) solid var(--color-rule);
  margin-bottom: var(--space-3);
}
.param-subgroup-label {
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  margin-top: 0;
  margin-bottom: var(--space-2);
}
.param-subgroup-label:first-child { margin-top: 0; }

/* Two-column subgroup layout for the Layer Information group:
   wide subgroups (>= 4 fields) span both columns, narrow ones share a row.
   This keeps SPT (4 fields) and Vs (2 fields) on a single row below the
   wider CPT subgroup. */
.param-subgroups-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-5);
}
.param-subgroup { min-width: 0; display: flex; flex-direction: column; }
.param-subgroup-wide { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .param-subgroups-layout { grid-template-columns: 1fr; gap: var(--space-3); }
  .param-subgroup-wide { grid-column: auto; }
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
}
@media (max-width: 720px) {
  .param-grid { grid-template-columns: 1fr; gap: var(--space-2); }
}

.param-field { display: flex; flex-direction: column; gap: 2px; }
.param-label {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  letter-spacing: 0;
}
.param-label .required-mark {
  color: var(--color-required);
  font-weight: var(--weight-medium);
  font-size: 0.85em;
  margin-left: 1px;
}
.param-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: var(--weight-regular);
  letter-spacing: 0.01em;
  margin-left: auto;
}

/* ---------- Tooltip (CSS-only, hover + focus) ------------- */
.param-tooltip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: var(--rule-width) solid var(--color-rule-strong);
  background: var(--color-bg);
  font-size: 10px;
  color: var(--color-text-muted);
  cursor: help;
  flex-shrink: 0;
}
.param-tooltip:hover, .param-tooltip:focus-visible {
  color: var(--color-text);
  border-color: var(--color-accent);
  outline: none;
}
.param-tooltip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%; transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: var(--size-caption);
  font-weight: var(--weight-regular);
  letter-spacing: 0;
  line-height: 1.55;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  width: 280px;
  text-align: left;
  /* Render above the sticky header (z-index 100) so the topmost
     fields' tooltips are not clipped behind the header bar. */
  z-index: 1000;
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
  pointer-events: none;
  white-space: normal;
}
.param-tooltip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%; transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--color-text);
  z-index: 1001;
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition-fast), visibility var(--transition-fast);
  pointer-events: none;
}
.param-tooltip:hover::after,
.param-tooltip:hover::before,
.param-tooltip:focus-visible::after,
.param-tooltip:focus-visible::before {
  opacity: 1; visibility: visible;
}

/* ---------- Inputs ---------------------------------------- */
input[type="number"] {
  width: 100%;
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-md);
  padding: 6px var(--space-3);
  font-size: var(--size-body);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast),
              background var(--transition-fast);
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"]::placeholder { color: var(--color-text-faint); }
input[type="number"]:hover { border-color: var(--color-text-muted); }
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

select {
  appearance: none; -webkit-appearance: none;
  background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%236b6b6b' d='M5 6L0 0h10z'/%3E%3C/svg%3E") no-repeat right var(--space-3) center;
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-md);
  padding: var(--space-2) 28px var(--space-2) var(--space-3);
  font-size: var(--size-caption);
  color: var(--color-text);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast);
}
select:hover { border-color: var(--color-text-muted); }
select:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }

/* ---------- Inline field warning -------------------------- */
.field-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: var(--rule-width) solid var(--color-warning-rule);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--size-caption);
  line-height: 1.45;
  margin-top: var(--space-2);
}

/* ---------- Buttons --------------------------------------- */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  background: var(--color-accent);
  color: var(--color-surface);
  font-size: var(--size-body);
  font-weight: var(--weight-medium);
  letter-spacing: 0.005em;
  padding: 12px var(--space-6);
  border: var(--rule-width) solid var(--color-accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.btn-secondary:hover { color: var(--color-text); border-color: var(--color-text-muted); }
/* Backwards-compat alias (existing markup still uses .btn-reset). */
.btn-reset {
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.btn-reset:hover { color: var(--color-text); border-color: var(--color-text-muted); }

/* ---------- Two-pane form layout -------------------------- */
.form-section { width: 100%; }
.form-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  gap: var(--space-7);
  align-items: start;
}
.form-main { min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.form-sidebar { min-width: 0; }
.sidebar-sticky {
  position: sticky;
  top: calc(var(--header-height) + var(--space-5));
  display: flex; flex-direction: column;
  /* keep the unified panel inside the viewport when scrolling */
  max-height: calc(100vh - var(--header-height) - var(--space-5) * 2);
  overflow-y: auto;
  padding-right: 2px;
}

/* ---------- Unified sidebar panel ------------------------ */
.sidebar-panel {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden; /* hairline dividers reach the edges */
}
.sidebar-section {
  padding: var(--space-5);
}
/* Inner Derived block needs no card chrome of its own; it is just a
   section inside the unified panel. */
#derived-panel.sidebar-section,
.derived-panel.sidebar-section {
  background: transparent;
  border: 0;
  border-radius: 0;
}
.sidebar-divider {
  border: 0;
  border-top: var(--rule-width) solid var(--color-rule);
  margin: 0;
}
.sidebar-actions {
  display: flex; flex-direction: column; gap: var(--space-3);
}
.sidebar-footnote {
  padding-top: var(--space-4);
  padding-bottom: var(--space-4);
}
.sidebar-footnote a {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  text-decoration: none;
  line-height: 1.5;
}
.sidebar-footnote a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

.top-n-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
}
.top-n-row .control-label {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}
.top-n-row select { min-width: 110px; }

.btn-block { width: 100%; }
.btn-primary.btn-block { padding: 11px var(--space-5); }
.btn-secondary.btn-block, .btn-reset.btn-block { padding: 9px var(--space-4); }

/* Inline error banner inside the sidebar (compact, no icon). */
.error-banner {
  font-size: var(--size-caption);
  line-height: 1.45;
  color: var(--color-required);
  background: var(--color-required-bg);
  border: var(--rule-width) solid #f4c5cb;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
}

/* Backwards-compat alias: some markup may still emit .form-actions. */
.form-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  margin-top: var(--space-4);
}
.form-actions .secondary-link {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}
.form-actions .secondary-link:hover { color: var(--color-text); }

/* ---------- Spinner --------------------------------------- */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
  display: inline-block;
}

/* ---------- Banners --------------------------------------- */
.banner {
  display: flex; align-items: flex-start; gap: var(--space-2);
  font-size: var(--size-caption);
  line-height: 1.5;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: var(--rule-width) solid transparent;
}
.banner-error {
  background: var(--color-required-bg);
  color: var(--color-required);
  border-color: #f4c5cb;
}
.banner-icon { flex-shrink: 0; margin-top: 1px; }

/* ---------- Derived parameters panel ---------------------- */
/* Derived panel is rendered as one section inside the unified
   .sidebar-panel; it inherits the panel's surface and border. The
   .sidebar-section rule supplies the padding. The standalone card
   chrome below is retained only as a fallback if the panel ever
   needs to render outside the unified sidebar. */
.derived-panel:not(.sidebar-section) {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.derived-panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: var(--space-3);
  gap: var(--space-2);
}
.derived-panel-head .eyebrow { color: var(--color-accent); }
.derived-panel-head .caption {
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}
/* In the sticky sidebar (320px) a 2x2 grid reads more cleanly than a
   four-up row. The two-up keeps the value type size large enough to
   feel like a real readout. */
.derived-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-3);
}

.derived-item { display: flex; flex-direction: column; gap: 2px; }
.derived-label {
  font-size: var(--size-eyebrow);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: var(--weight-semibold);
}
.derived-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--size-h3);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  letter-spacing: -0.005em;
  line-height: 1.15;
}
.derived-note {
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
  margin-top: var(--space-3);
  line-height: 1.45;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* Legacy class names kept for compatibility (these are also touched by CSS) */
.derived-panel-title { display: none; } /* replaced by .derived-panel-head */

/* ---------- Results header ------------------------------- */
.results-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
}
.results-title {
  font-size: var(--size-h2);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--color-text);
}
.results-meta {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- AI memo card --------------------------------- */
.ai-card {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-7);
}
.ai-card-top {
  display: flex; align-items: center; gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.ai-eyebrow {
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
}
.ai-memo {
  font-size: var(--size-body);
  line-height: 1.7;
  color: var(--color-text);
}
.ai-memo p { margin-bottom: var(--space-4); }
.ai-memo p:last-child { margin-bottom: 0; }
.ai-memo strong { font-weight: var(--weight-semibold); color: var(--color-text); }
.ai-memo em { font-style: italic; }
.ai-recommendation {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-accent-soft);
  border-left: 2px solid var(--color-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--size-caption);
  color: var(--color-text);
  line-height: 1.6;
}

/* ---------- Risk badge ----------------------------------- */
.risk-badge {
  display: inline-flex; align-items: center;
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px var(--space-3);
  border-radius: var(--radius-pill);
  border: var(--rule-width) solid transparent;
}
.risk-low      { background: var(--color-success-soft); color: var(--color-success); border-color: #c4e0cc; }
.risk-moderate { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-rule); }
.risk-high     { background: var(--color-required-bg); color: var(--color-required); border-color: #f4c5cb; }

/* ---------- CSR plot card -------------------------------- */
.csr-plot-wrap {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
}
.csr-plot-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3); flex-wrap: wrap;
}
.csr-plot-head .eyebrow { color: var(--color-accent); }
#csr-canvas { width: 100%; display: block; }
#csr-plot-placeholder {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  padding: var(--space-5) 0;
  text-align: center;
}
.csr-legend {
  display: flex; gap: var(--space-5); flex-wrap: wrap;
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
  margin-top: var(--space-3);
  align-items: center;
  letter-spacing: 0.04em;
}
.csr-legend > span { display: inline-flex; align-items: center; gap: 5px; }
.legend-circle { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.legend-diamond { display: inline-block; width: 8px; height: 8px; transform: rotate(45deg); }
.legend-rule { display: inline-block; width: 18px; height: 1px; background: var(--color-text-faint); }
.legend-liq { background: var(--color-required); opacity: 0.55; border: 1px solid var(--color-required); }
.legend-nonliq { background: var(--color-surface); border: 1px solid var(--color-text-muted); }
.legend-star { color: var(--color-accent); font-size: 12px; line-height: 1; }
.legend-hollow {
  background: var(--color-surface);
  border: 1px dashed var(--color-text-muted);
}
.csr-legend > span.hidden { display: none; }

/* ---------- Results table -------------------------------- */
.results-table-wrap {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: var(--size-caption); }
thead { background: transparent; }
th {
  padding: var(--space-4) var(--space-4);
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: left;
  white-space: nowrap;
  border-bottom: var(--rule-width) solid var(--color-rule);
}
td {
  padding: var(--space-5) var(--space-4);
  color: var(--color-text);
  border-bottom: var(--rule-width) solid var(--color-rule);
  vertical-align: top;
  font-size: var(--size-caption);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.data-row { transition: background var(--transition-fast); cursor: pointer; }
tbody tr.data-row:hover { background: var(--color-bg); }

.rank-badge {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--size-caption);
  font-weight: var(--weight-semibold);
  font-family: var(--font-mono);
  border: var(--rule-width) solid var(--color-rule-strong);
  color: var(--color-text-muted);
  background: var(--color-surface);
}
.rank-1 { color: var(--color-accent); border-color: var(--color-accent); }
.rank-2 { color: var(--color-text); }
.rank-3 { color: var(--color-text-muted); }
.rank-n { color: var(--color-text-faint); }

.site-cell { min-width: 150px; }
.site-name {
  font-weight: var(--weight-medium);
  font-size: var(--size-caption);
  color: var(--color-text);
  margin-bottom: 2px;
}
.event-name {
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.meas-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  margin-top: 4px;
  border: var(--rule-width) solid transparent;
}
.meas-cpt { background: var(--color-surface); color: var(--color-accent); border-color: var(--color-rule-strong); }
.meas-spt { background: var(--color-surface); color: var(--color-warning); border-color: var(--color-warning-rule); }

.stack-cell { display: flex; flex-direction: column; gap: 3px; }
.stack-top {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--size-caption);
  color: var(--color-text);
}
.stack-bot {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
}
.stack-lbl {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-left: 2px;
  font-weight: var(--weight-medium);
}

.sim-cell { min-width: 100px; }
.sim-bar-wrap {
  height: 3px;
  background: var(--color-rule);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 5px;
}
.sim-bar {
  height: 100%;
  background: var(--color-accent);
  transition: width 0.6s cubic-bezier(.22, 1, .36, 1);
}
.sim-pct {
  font-family: var(--font-mono);
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-accent);
}

.liq-yes, .liq-no, .liq-unk {
  display: inline-block;
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: var(--rule-width) solid transparent;
}
.liq-yes { background: var(--color-success-soft); color: var(--color-success); border-color: #c4e0cc; }
.liq-no  { background: var(--color-required-bg); color: var(--color-required); border-color: #f4c5cb; }
.liq-unk { background: var(--color-bg); color: var(--color-text-muted); border-color: var(--color-rule-strong); }

.consequence-flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cflag {
  font-size: 10px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: var(--rule-width) solid var(--color-warning-rule);
  white-space: nowrap;
}
.cflag-slope { background: var(--color-required-bg); color: var(--color-required); border-color: #f4c5cb; }

.remarks-cell { min-width: 180px; max-width: 240px; }
.remarks-text {
  font-size: var(--size-caption);
  line-height: 1.55;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.remarks-text.expanded {
  display: block; -webkit-line-clamp: unset;
}
.remarks-toggle {
  font-size: var(--size-eyebrow);
  color: var(--color-accent);
  background: none; border: none; padding: 2px 0;
  margin-top: 2px;
  font-family: var(--font-sans);
  font-weight: var(--weight-medium);
  letter-spacing: 0.04em;
  cursor: pointer;
}
.remarks-toggle:hover { text-decoration: underline; }

.expand-btn {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.expand-btn:hover { color: var(--color-accent); border-color: var(--color-accent); }
.expand-btn.open { color: var(--color-accent); border-color: var(--color-accent); transform: rotate(180deg); }

.dp-refs { display: flex; flex-direction: column; gap: var(--space-2); }
.ngl-link {
  font-size: var(--size-caption);
  color: var(--color-accent);
}
.refs-loading {
  font-size: var(--size-eyebrow);
  color: var(--color-text-muted);
  font-style: italic;
}
.refs-group { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.refs-group-title {
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.refs-item {
  font-size: var(--size-caption);
  color: var(--color-text);
  line-height: 1.55;
}
.refs-item a { color: var(--color-accent); }

/* Detail row inside the table (expanded match details) */
.detail-row { background: var(--color-bg); }
.detail-row > td { padding: 0 !important; border-bottom: var(--rule-width) solid var(--color-rule) !important; }
.detail-row.hidden { display: none; }
.detail-panel {
  display: flex; flex-wrap: wrap; gap: var(--space-5);
  padding: var(--space-5) var(--space-5);
  border-top: var(--rule-width) solid var(--color-rule);
}
.dp-section { min-width: 140px; }
.dp-section.dp-full { width: 100%; flex-basis: 100%; }
.dp-title {
  font-size: var(--size-eyebrow);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-accent);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: var(--rule-width) solid var(--color-rule);
}
.dp-grid { display: flex; flex-direction: column; gap: 5px; }
.dp-item { display: flex; align-items: baseline; gap: var(--space-2); }
.dp-label {
  color: var(--color-text-muted);
  min-width: 90px;
  flex-shrink: 0;
  font-size: var(--size-caption);
}
.dp-val {
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}
.dp-unit {
  color: var(--color-text-muted);
  font-size: var(--size-eyebrow);
  margin-left: 1px;
}
.dp-remarks {
  font-size: var(--size-caption);
  color: var(--color-text);
  line-height: 1.6;
  max-width: 860px;
}

/* ---------- Loading skeleton ----------------------------- */
.skel {
  height: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-rule) 25%, var(--color-bg) 50%, var(--color-rule) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* ---------- Footer --------------------------------------- */
.site-footer {
  border-top: var(--rule-width) solid var(--color-rule);
  background: var(--color-bg);
  padding: var(--space-7) 0;
  margin-top: var(--space-8);
}
.site-footer-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 0 var(--space-5);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: var(--space-4);
  font-size: var(--size-caption);
  color: var(--color-text-muted);
}
.site-footer-inner a { color: var(--color-text-muted); }
.site-footer-inner a:hover { color: var(--color-text); text-decoration: none; }
.site-footer-brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--color-text);
  font-weight: var(--weight-medium);
}
.site-footer-brand .copyright { color: var(--color-text-muted); font-weight: var(--weight-regular); }
.site-footer-links {
  display: flex; align-items: center; gap: var(--space-5);
}

/* ---------- Animations ----------------------------------- */
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes pulse  { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fadeUp .35s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Clerk auth wall ------------------------------ */
#clerk-auth-wall {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg);
  padding: var(--space-5);
}

/* ---------- Tablet: collapse two-pane to single column ---- */
@media (max-width: 1024px) {
  .form-layout { grid-template-columns: 1fr; gap: var(--space-5); }
  .sidebar-sticky {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
  /* On collapse the derived panel can breathe back into a four-up. */
  .derived-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .derived-value { font-size: var(--size-h2); }
}

/* ---------- Mobile / responsive -------------------------- */
@media (max-width: 768px) {
  main { padding: var(--space-5) var(--space-4) var(--space-7); gap: var(--space-6); }
  .form-card { padding: var(--space-4); }
  .ai-card { padding: var(--space-5) var(--space-5); }
  .csr-plot-wrap { padding: var(--space-4); }
  .results-title { font-size: 20px; }
  .derived-grid { grid-template-columns: 1fr 1fr; }
  .derived-value { font-size: var(--size-h3); }
  th, td { padding: var(--space-3); }
  .site-cell { max-width: 110px; }
  /* Header collapses to the wordmark + product name only on narrow viewports. */
  .header-eyebrow { display: none; }
  .header-product { font-size: var(--size-caption); }
}
@media (max-width: 480px) {
  .derived-grid { grid-template-columns: 1fr; }
  .header-title { display: none; }
}

/* ============================================================
   Export buttons + modal
   ============================================================ */

.export-actions {
  display: flex; align-items: center; gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
}
.export-actions-label {
  font-size: var(--size-caption);
  color: var(--color-text-muted);
  margin-right: auto;
}

/* Body lock while modal is open */
body.body-locked { overflow: hidden; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  padding: var(--space-4);
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 100%; max-width: 480px;
  max-height: calc(100vh - var(--space-7));
  overflow-y: auto;
}
.modal-card .eyebrow { display: block; margin-bottom: var(--space-2); }

.modal-title {
  font-size: var(--size-h2);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  color: var(--color-text);
  margin-bottom: var(--space-5);
}

.modal-form {
  display: flex; flex-direction: column; gap: var(--space-3);
}
.modal-field {
  display: flex; flex-direction: column; gap: 4px;
}
.modal-field label {
  font-size: var(--size-caption);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.modal-field input[type="text"],
.modal-field input[type="date"] {
  width: 100%;
  background: var(--color-surface);
  border: var(--rule-width) solid var(--color-rule-strong);
  border-radius: var(--radius-md);
  padding: 7px var(--space-3);
  font-size: var(--size-body);
  font-family: var(--font-sans);
  color: var(--color-text);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}
.modal-field input[type="text"]:focus,
.modal-field input[type="date"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.modal-actions {
  display: flex; align-items: center; justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: var(--rule-width) solid var(--color-rule);
}

@media (max-width: 480px) {
  .modal-card { padding: var(--space-5); }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; }
  .modal-actions button { width: 100%; }
}
