/* ============================================================
   IOL Calculator — v2 Design System
   Inter + single indigo accent
   ============================================================ */

/* Self-hosted Inter variable font (all weights 100-900 in one 24KB file).
   Eliminates Google Fonts dependency → no IP leak to Google, faster loads. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/inter-variable.woff2') format('woff2');
  unicode-range: U+0000-024F, U+0300-036F, U+0400-04FF, U+1E00-1EFF, U+2000-206F,
    U+2070-209F, U+20A0-20CF, U+2100-214F, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

/* --- DESIGN TOKENS --- */
:root {
  /* Primary — Indigo (single accent, no tab-color split) */
  --primary-50: #E8EAF6;
  --primary-100: #C5CAE9;
  --primary-200: #9FA8DA;
  --primary-300: #7986CB;
  --primary-400: #5C6BC0;
  --primary-500: #3F51B5;
  --primary-600: #3949AB;
  --primary-700: #303F9F;
  --primary-800: #283593;
  --primary-900: #1A237E;

  /* Neutral accent retained for subtle variation (used for info/secondary highlights,
     not for tab differentiation) */
  --secondary-50: #E8EAF6;
  --secondary-100: #C5CAE9;
  --secondary-500: #5C6BC0;
  --secondary-700: #303F9F;

  /* All tab accents collapse to primary — tabs are visually identical */
  --tab-primary: var(--primary-500);
  --tab-secondary: var(--primary-500);
  --tab-bilateral: var(--primary-500);

  /* Semantic */
  --error-main: #D32F2F;
  --error-light: #FFEBEE;
  --error-dark: #B71C1C;
  --warning-main: #ED6C02;
  --warning-light: #FFF3E0;
  --warning-dark: #E65100;
  --success-main: #2E7D32;
  --success-light: #E8F5E9;
  --success-dark: #1B5E20;
  --info-main: #0288D1;
  --info-light: #E1F5FE;
  --info-dark: #01579B;

  /* Surfaces */
  --surface: #FFFFFF;
  --surface-variant: #F5F5F5;
  --surface-container: #FAFAFA;
  --surface-dim: #EEEEEE;
  --outline: #E0E0E0;
  --outline-variant: #BDBDBD;
  --on-surface: #212121;
  --on-surface-variant: #616161;
  --on-surface-muted: #9E9E9E;
  --scrim: rgba(0, 0, 0, 0.5);

  /* Spacing (8px grid) */
  --sp-0: 0;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Elevation */
  --elevation-0: none;
  --elevation-1: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --elevation-2: 0 3px 6px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --elevation-3: 0 8px 16px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
  --elevation-4: 0 16px 32px rgba(0,0,0,0.10), 0 8px 16px rgba(0,0,0,0.06);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-short: 150ms;
  --duration-medium: 250ms;
  --duration-long: 400ms;
}

/* --- RESET & BASE --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--on-surface);
  background: var(--surface-variant);
  line-height: 1.5;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

/* Tabular numerals for all numeric/mono contexts */
.cell-mono, .numeric-display, .numeric-body, .numeric-sm,
input[inputmode="decimal"], input[inputmode="numeric"],
.data-table .cell-mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum', 'cv11';
}

/* --- TYPOGRAPHY --- */
.display {
  font-family: inherit;
  font-weight: 600;
  font-size: 28px;
  line-height: 36px;
  letter-spacing: -0.02em;
}

.headline {
  font-family: inherit;
  font-weight: 600;
  font-size: 22px;
  line-height: 28px;
  letter-spacing: -0.015em;
}

.title-lg {
  font-family: inherit;
  font-weight: 600;
  font-size: 18px;
  line-height: 24px;
  letter-spacing: -0.01em;
}

.title-md {
  font-family: inherit;
  font-weight: 600;
  font-size: 16px;
  line-height: 22px;
}

.body-lg {
  font-family: inherit;
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
}

.body-md {
  font-family: inherit;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
}

.body-sm {
  font-family: inherit;
  font-weight: 400;
  font-size: 12px;
  line-height: 16px;
  color: var(--on-surface-variant);
}

.label-lg {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 20px;
}

.label-md {
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  line-height: 16px;
}

.label-sm {
  font-family: inherit;
  font-weight: 600;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}

.numeric-display {
  font-family: inherit;
  font-weight: 700;
  font-size: 32px;
  line-height: 40px;
  letter-spacing: -0.02em;
}

.numeric-body {
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  line-height: 20px;
}

.numeric-sm {
  font-family: inherit;
  font-weight: 400;
  font-size: 12px;
  line-height: 16px;
}

/* --- LAYOUT --- */
.page-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

.two-col {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: var(--sp-6);
  align-items: start;
}

.two-col-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-6);
  align-items: start;
}

.sticky-form {
  position: sticky;
  top: 108px; /* disclaimer(36) + header(64) + gap(8) */
  max-height: calc(100vh - 116px);
  overflow-y: auto;
}

/* --- DISCLAIMER BAR --- */
.disclaimer-bar {
  background: #1B2332;
  color: #8899AA;
  font-size: 12px;
  line-height: 16px;
  padding: 10px var(--sp-6);
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 200;
  font-family: inherit;
}

.disclaimer-bar strong {
  color: #C5D0DB;
}

.dev-banner {
  background: #FFFBEB;
  border-bottom: 1px solid #F59E0B44;
  color: #78350F;
  font-size: 14px;
  line-height: 22px;
  padding: 12px var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.dev-banner svg { width: 20px; height: 20px; }
.dev-banner a {
  color: #92400E;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.dev-banner a:hover { color: #78350F; }

/* --- HEADER --- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
  position: sticky;
  top: 36px;
  z-index: 100;
  box-shadow: var(--elevation-1);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 var(--sp-6);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-8);
}

/* --- LOGO --- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-mark {
  width: 36px;
  height: 36px;
  position: relative;
}

.logo-mark svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  font-family: inherit;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.03em;
  color: var(--on-surface);
}

.logo-text span {
  color: var(--primary-500);
}

.logo-subtitle {
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  color: var(--on-surface-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: -2px;
}

/* --- NAV --- */
.nav {
  display: flex;
  gap: var(--sp-1);
}

.nav-item {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--duration-short) var(--ease-standard);
  cursor: pointer;
}

.nav-item:hover {
  color: var(--on-surface);
  background: var(--surface-variant);
}

.nav-item.active {
  color: var(--primary-500);
  background: var(--primary-50);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.header-contact {
  font-size: 13px;
  color: var(--on-surface-variant);
  text-decoration: none;
}

.header-contact:hover {
  color: var(--primary-500);
}

/* --- TAB BAR (minimal underline tabs) --- */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
  position: sticky;
  top: 100px; /* disclaimer + header */
  z-index: 90;
  overscroll-behavior: none;
}

.tab-bar-inner {
  max-width: 1360px;
  margin: 0 auto;
  touch-action: pan-x;
  overscroll-behavior-y: none;
  padding: 0 var(--sp-6);
  display: flex;
  gap: var(--sp-1);
}

/* Reset browser <button> defaults so button-based tabs look like links */
.tab-item {
  /* reset */
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  border-radius: 0;
  font-family: inherit;
  margin: 0;

  /* tab styling */
  padding: 16px var(--sp-5) 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  text-decoration: none;
  position: relative;
  cursor: pointer;
  transition: color var(--duration-short) var(--ease-standard);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  white-space: nowrap;
  letter-spacing: -0.005em;
}

/* Underline: applied via ::after so it doesn't shift layout on active toggle */
.tab-item::after {
  content: '';
  position: absolute;
  left: var(--sp-5);
  right: var(--sp-5);
  bottom: -1px;
  height: 2px;
  background: transparent;
  border-radius: 2px 2px 0 0;
  transition: background var(--duration-short) var(--ease-standard);
  pointer-events: none;
}

.tab-item:hover {
  color: var(--on-surface);
}

.tab-item:hover::after {
  background: var(--outline-variant);
}

.tab-item.active,
.tab-item.active-secondary,
.tab-item.active-bilateral {
  color: var(--primary-600);
  font-weight: 500;
}

.tab-item.active::after,
.tab-item.active-secondary::after,
.tab-item.active-bilateral::after {
  background: var(--primary-500);
}

.tab-item:focus-visible {
  outline: 2px solid var(--primary-300);
  outline-offset: -4px;
  border-radius: var(--radius-xs);
}

.tab-icon {
  width: 18px;
  height: 18px;
  opacity: 0.6;
  transition: opacity var(--duration-short) var(--ease-standard);
  flex-shrink: 0;
}

.tab-item:hover .tab-icon,
.tab-item.active .tab-icon,
.tab-item.active-secondary .tab-icon,
.tab-item.active-bilateral .tab-icon {
  opacity: 1;
}

/* --- CARD --- */
.card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  box-shadow: var(--elevation-1);
  overflow: hidden;
}

.card-header {
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
  border-bottom: 1px solid var(--surface-dim);
}

.card-header .title-md {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.card-header .body-sm {
  margin-top: var(--sp-1);
}

.card-body {
  padding: var(--sp-5);
}

.card-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--surface-dim);
  background: var(--surface-container);
}

.card--toric {
  border-left: 4px solid var(--primary-500);
}

.card--toric .card-header {
  background: var(--primary-50);
}

.card--warning {
  border-left: 4px solid var(--warning-main);
}

.card--error {
  border-left: 4px solid var(--error-main);
}

.card--success {
  border-left: 4px solid var(--success-main);
}

.card--info {
  border-left: 4px solid var(--info-main);
}

/* --- FORM SECTION --- */
.form-section {
  margin-bottom: var(--sp-5);
}

.form-section-title {
  font-family: inherit;
  font-weight: 600;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--outline);
  margin-bottom: var(--sp-4);
}

.form-grid {
  display: grid;
  gap: var(--sp-5) var(--sp-3);
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Top-level form column layouts */
.form-3col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-5);
  align-items: stretch;
}

.form-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
  align-items: stretch;
}

.form-3col > .card,
.form-2col > .card {
  display: flex;
  flex-direction: column;
}

.form-3col > .card > .card-body,
.form-2col > .card > .card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

@media (max-width: 960px) {
  .form-3col,
  .form-2col { grid-template-columns: 1fr; }
}

/* --- UNIFIED FORM CARD (single big card with 2 sections side-by-side) --- */
.form-card {
  /* full-width card containing two sections separated by a vertical divider */
}

.form-card .card-body {
  padding: 0; /* sections handle their own padding */
}

.form-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.form-card-grid > .form-section {
  padding: var(--sp-6);
  margin: 0;
  min-width: 0;
}

.form-card-grid > .form-section + .form-section {
  border-left: 1px solid var(--surface-dim);
}

.form-section-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-bottom: var(--sp-4);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--surface-dim);
}

.form-section-header .col-section-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-50);
  color: var(--primary-700);
  font-weight: 700;
  font-size: 14px;
  margin: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.form-section-header .title {
  font-size: 17px;
  font-weight: 600;
  color: var(--on-surface);
  letter-spacing: -0.01em;
}

.form-section-header .subtitle {
  font-size: 12px;
  color: var(--on-surface-muted);
  margin-left: auto;
}

/* Tooltip trigger — small inline indicator (ⓘ) with custom hover tooltip.
   pointer-events: auto overrides parent label's pointer-events: none. */
.tooltip-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 12px;
  color: var(--on-surface-muted);
  cursor: help;
  vertical-align: middle;
  margin-left: 4px;
  pointer-events: auto;
  border-radius: 50%;
  transition: color 150ms var(--ease-standard), background 150ms var(--ease-standard);
}

.tooltip-trigger:hover {
  color: var(--primary-600);
  background: var(--primary-50);
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--on-surface);
  color: var(--surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 400;
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms var(--ease-standard);
  z-index: 100;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.tooltip-trigger::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--on-surface);
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms var(--ease-standard);
  z-index: 100;
}

/* Smart positioning: tooltip stays inside its closest text-field by default.
   For triggers near the right edge use .tooltip-trigger--left,
   near the left edge use .tooltip-trigger--right (default behavior covers both via flex containers). */
.tooltip-trigger--left::after {
  left: auto;
  right: 0;
  transform: none;
}
.tooltip-trigger--left::before {
  left: auto;
  right: 4px;
  transform: none;
}
.tooltip-trigger--right::after {
  left: 0;
  right: auto;
  transform: none;
}
.tooltip-trigger--right::before {
  left: 4px;
  right: auto;
  transform: none;
}

.tooltip-trigger:hover::after,
.tooltip-trigger:hover::before,
.tooltip-trigger:focus-visible::after,
.tooltip-trigger:focus-visible::before {
  opacity: 1;
}

/* Subgroup label inside a section — uppercase label with thin top-divider */
.subgroup-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--on-surface-muted);
  margin-top: var(--sp-5);
  margin-bottom: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--surface-dim);
}

/* No top divider for the very first subgroup right after section header */
.form-section-header + .subgroup-label,
.subgroup-label:first-of-type {
  /* keep top border — it visually separates header from group */
}

@media (max-width: 960px) {
  .form-card-grid { grid-template-columns: 1fr; }
  .form-card-grid > .form-section + .form-section {
    border-left: none;
    border-top: 1px solid var(--surface-dim);
  }
}

/* Footer of the unified form-card — full consent text + submit button on one row,
   right-aligned. Multi-line consent wraps inside its own bounded box. */
.form-card-footer {
  padding: var(--sp-3) var(--sp-6);
  border-top: 1px solid var(--surface-dim);
  background: var(--surface-container);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}

.form-card-footer .consent-inline {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  max-width: 580px;
  text-align: center;
  font-size: 12px;
  line-height: 1.45;
  color: var(--on-surface-muted);
}

.form-card-footer .consent-inline input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  flex-shrink: 0;
  accent-color: var(--primary-500);
  cursor: pointer;
}

.form-card-footer .consent-inline label {
  cursor: pointer;
}

.form-card-footer .consent-inline label a {
  color: var(--primary-500);
  text-decoration: underline;
}

.form-card-footer .btn {
  flex-shrink: 0;
  min-width: 280px;
}

.form-card-footer .spinner-row {
  flex-basis: 100%;
  text-align: right;
  font-size: 13px;
  color: var(--on-surface-muted);
  margin-top: var(--sp-1);
}

@media (max-width: 768px) {
  .form-card-footer { padding: var(--sp-4); }
  .form-card-footer .consent-inline { max-width: none; text-align: left; }
  .form-card-footer .btn { width: 100%; min-width: 0; }
}

/* Section-number badge inside card title (used for numbered columns 1/2/3) */
.col-section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-100);
  color: var(--primary-700);
  font-weight: 700;
  font-size: 13px;
  margin-right: var(--sp-2);
  flex-shrink: 0;
}

/* --- TEXT FIELD (MUI Outlined) --- */
.text-field {
  position: relative;
  display: flex;
  align-items: center;
}

.text-field input,
.text-field select {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--on-surface);
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--duration-short) var(--ease-standard),
              box-shadow var(--duration-short) var(--ease-standard);
}

.text-field input::placeholder {
  color: var(--on-surface-muted);
}

.text-field input:focus,
.text-field select:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(63, 81, 181, 0.12);
}

.text-field.has-value input {
  color: var(--on-surface);
}

.text-field.error input,
.text-field.error select {
  border-color: var(--error-main);
  box-shadow: 0 0 0 2px rgba(211, 47, 47, 0.12);
}

/* Prevent layout jump: use box-shadow for error border instead of changing border-width */

.text-field.disabled input {
  background: var(--surface-dim);
  color: var(--on-surface-muted);
  cursor: not-allowed;
}

.text-field label {
  position: absolute;
  top: -7px;
  left: 10px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 14px;
  color: var(--on-surface-variant);
  background: var(--surface);
  pointer-events: none;
  transition: color var(--duration-short) var(--ease-standard);
  z-index: 1;
}

.text-field.focused label {
  color: var(--primary-500);
}

.text-field.error label {
  color: var(--error-main) !important;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 8px);
}

.text-field .required {
  color: var(--error-main);
  margin-left: 2px;
}

.text-field .unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--on-surface-muted);
  pointer-events: none;
}

.text-field.has-unit input {
  padding-right: 40px;
}

/* Error helper text — MUI pattern: display below the entire text-field */
.field-error-text {
  display: block;
  font-size: 11px;
  color: var(--error-main);
  line-height: 14px;
  margin-top: 4px;
  padding-left: 2px;
}

.text-field .check-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--success-main);
  font-size: 14px;
  font-weight: 700;
}

.text-field.has-unit .check-icon {
  right: 38px;
}

/* When both unit and check-icon are present, shift input padding */
.text-field.has-unit.has-value input {
  padding-right: 54px;
}

/* Select with chevron */
.text-field select {
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
}

.text-field .select-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--on-surface-variant);
}

/* Plus/Minus toggle */
.text-field .sign-toggle {
  position: absolute;
  left: 1px;
  top: 1px;
  bottom: 1px;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-variant);
  border-right: 1px solid var(--outline);
  border-radius: 7px 0 0 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--on-surface-variant);
  user-select: none;
}

.text-field.has-sign input {
  padding-left: 40px;
}

/* --- BUTTON --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: inherit;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-standard);
  white-space: nowrap;
}

.btn-lg {
  height: 48px;
  padding: 0 var(--sp-6);
  font-size: 15px;
  border-radius: var(--radius-sm);
}

.btn-md {
  height: 40px;
  padding: 0 var(--sp-5);
  font-size: 14px;
  border-radius: var(--radius-sm);
}

.btn-sm {
  height: 32px;
  padding: 0 var(--sp-4);
  font-size: 13px;
  border-radius: var(--radius-xs);
}

.btn-full { width: 100%; }

.btn-primary {
  background: var(--primary-500);
  color: white;
  box-shadow: var(--elevation-1);
}

.btn-primary:hover {
  background: var(--primary-600);
  box-shadow: var(--elevation-2);
}

.btn-primary:active {
  background: var(--primary-700);
  box-shadow: none;
}

.btn-primary.disabled, .btn-primary:disabled {
  background: var(--surface-dim);
  color: var(--on-surface-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-primary.loading {
  background: var(--primary-400);
  pointer-events: none;
}

/* Legacy tab-coloured buttons collapsed to primary */
.btn-orange, .btn-green {
  background: var(--primary-500);
  color: white;
  box-shadow: var(--elevation-1);
}
.btn-orange:hover, .btn-green:hover { background: var(--primary-700); }

.btn-outlined {
  background: transparent;
  color: var(--primary-500);
  border: 1px solid var(--primary-500);
}

.btn-outlined:hover {
  background: var(--primary-50);
}

.btn-text {
  background: transparent;
  color: var(--primary-500);
  padding: 0 var(--sp-3);
}

.btn-text:hover {
  background: var(--primary-50);
}

.btn-ghost {
  background: transparent;
  color: var(--on-surface-variant);
}

.btn-ghost:hover {
  background: var(--surface-variant);
  color: var(--on-surface);
}

/* Loading spinner inside button */
.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- CHIP / BADGE --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip-success {
  background: var(--success-light);
  color: var(--success-main);
  border: 1px solid #A5D6A7;
}

.chip-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
  border: 1px solid #FFE0B2;
}

.chip-error {
  background: var(--error-light);
  color: var(--error-main);
  border: 1px solid #FFCDD2;
}

.chip-info {
  background: var(--info-light);
  color: var(--info-dark);
  border: 1px solid #B3E5FC;
}

.chip-primary {
  background: var(--primary-50);
  color: var(--primary-700);
  border: 1px solid var(--primary-200);
}

.chip-neutral {
  background: var(--surface-variant);
  color: var(--on-surface-variant);
  border: 1px solid var(--outline);
}

/* chip-toric aliased to primary — no purple accent */
.chip-toric {
  background: var(--primary-50);
  color: var(--primary-700);
  border: 1px solid var(--primary-100);
}

.chip-eye {
  background: var(--surface-container);
  color: var(--on-surface);
  border: 1px solid var(--outline);
  font-family: inherit;
  font-weight: 700;
  font-size: 11px;
  padding: 0 8px;
  height: 22px;
}

/* --- ALERT --- */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  font-size: 13px;
  line-height: 20px;
}

.alert-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.alert-critical {
  background: var(--error-light);
  border-color: var(--error-main);
  color: var(--error-dark);
}

.alert-warning {
  background: var(--warning-light);
  border-color: var(--warning-main);
  color: var(--warning-dark);
}

.alert-info {
  background: var(--info-light);
  border-color: var(--info-main);
  color: var(--info-dark);
}

.alert-success {
  background: var(--success-light);
  border-color: var(--success-main);
  color: var(--success-dark);
}

/* --- TOGGLE GROUP (OD/OS) --- */
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-group-item {
  padding: 6px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface);
  color: var(--on-surface-variant);
  border: none;
  cursor: pointer;
  transition: all var(--duration-short) var(--ease-standard);
}

.toggle-group-item + .toggle-group-item {
  border-left: 1px solid var(--outline-variant);
}

.toggle-group-item.active {
  background: var(--primary-100);
  color: var(--primary-700);
}

/* --- CHECKBOX --- */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: 14px;
}

.checkbox-field .check-box {
  width: 18px;
  height: 18px;
  border: 2px solid var(--outline-variant);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--duration-short) var(--ease-standard);
}

.checkbox-field.checked .check-box {
  background: var(--primary-500);
  border-color: var(--primary-500);
  color: white;
}

.checkbox-field .check-box svg {
  width: 12px;
  height: 12px;
}

/* --- DATA TABLE --- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  background: var(--surface-container);
  border-bottom: 2px solid var(--outline);
}

.data-table th {
  padding: 10px var(--sp-4);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table td {
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--surface-dim);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--primary-50);
}

.data-table .cell-mono {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}

.data-table .cell-formula {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 500;
}

.data-table .row-expanded {
  background: var(--surface-container);
}

.data-table .expand-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
}

.data-table .expand-btn:hover {
  background: var(--surface-variant);
}

/* --- POWER TABLE (expanded sub-row) --- */
.power-table {
  background: var(--surface-container);
  padding: var(--sp-3) var(--sp-4) var(--sp-3) var(--sp-12);
  max-height: 240px;
  overflow-y: auto;
}

.power-table table {
  width: 200px;
  border-collapse: collapse;
}

.power-table th,
.power-table td {
  padding: 4px var(--sp-3);
  font-family: inherit;
  font-size: 12px;
}

.power-table th {
  font-weight: 600;
  color: var(--on-surface-variant);
  text-align: left;
}

.power-table .best-row {
  background: var(--primary-100);
  font-weight: 700;
  border-radius: 4px;
}

/* --- COLLAPSIBLE --- */
.collapsible-trigger {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-500);
  cursor: pointer;
  border: none;
  background: none;
}

.collapsible-trigger .chevron {
  width: 16px;
  height: 16px;
  transition: transform var(--duration-short) var(--ease-standard);
}

.collapsible-trigger.open .chevron {
  transform: rotate(90deg);
}

.collapsible-content {
  padding: var(--sp-3) 0 var(--sp-3) var(--sp-5);
  border-left: 2px solid var(--primary-100);
  margin-left: var(--sp-2);
}

/* --- CONSENSUS BLOCK --- */
.consensus-block {
  display: grid;
  grid-template-columns: 1fr 1fr auto 1fr;
  gap: var(--sp-5);
  align-items: center;
  padding: var(--sp-5);
}

.consensus-metric {
  text-align: center;
}

.consensus-metric .label-sm {
  margin-bottom: var(--sp-1);
}

.consensus-metric .numeric-display {
  color: var(--primary-900);
}

.consensus-metric .chip {
  margin-top: var(--sp-1);
}

/* --- DEFOCUS CHART --- */
.defocus-chart-area {
  height: 320px;
  background: var(--surface-container);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-surface-muted);
  font-size: 14px;
  position: relative;
  overflow: hidden;
}

/* Decorative axes for mockup */
.defocus-chart-area::before {
  content: '';
  position: absolute;
  left: 60px;
  top: 20px;
  right: 20px;
  bottom: 40px;
  border-left: 1px solid var(--outline);
  border-bottom: 1px solid var(--outline);
}

/* --- SKELETON LOADING --- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-dim) 25%, var(--surface-variant) 50%, var(--surface-dim) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 24px; width: 60%; margin-bottom: 12px; }
.skeleton-block { height: 80px; margin-bottom: 12px; }
.skeleton-chart { height: 320px; }

/* --- EMPTY STATE --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
}

.empty-state-icon {
  width: 120px;
  height: 120px;
  margin-bottom: var(--sp-6);
  opacity: 0.5;
}

.empty-state .headline {
  color: var(--on-surface-variant);
  margin-bottom: var(--sp-2);
}

.empty-state .body-md {
  color: var(--on-surface-muted);
  max-width: 360px;
  margin-bottom: var(--sp-6);
}

.hint-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
  width: 100%;
  max-width: 480px;
}

.hint-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  text-align: left;
}

.hint-card .label-sm {
  margin-bottom: 4px;
}

.hint-card .body-sm {
  font-size: 11px;
}

/* --- CONSENT MODAL --- */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px;
  z-index: 500;
  padding: var(--sp-4);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 50px rgba(17, 24, 39, 0.22);
  max-width: 480px;
  width: 100%;
  padding: 40px 44px 36px;
  margin: auto;
  flex-shrink: 0;
}

.modal-card .modal-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: #111827;
  margin-bottom: 8px;
}

.modal-card .modal-subtitle {
  font-size: 13px;
  color: #6B7280;
  margin-bottom: 28px;
}

.modal-point {
  display: block;
  font-size: 14px;
  line-height: 1.65;
  color: #374151;
  margin-bottom: 14px;
  padding-left: 0;
}

.modal-point:last-of-type { margin-bottom: 0; }

.modal-point strong {
  color: #111827;
  font-weight: 600;
}

.modal-links {
  font-size: 12px;
  color: #6B7280;
  margin: 24px 0 28px;
  padding-top: 20px;
  border-top: 1px solid #F3F4F6;
}

.modal-links a {
  color: #374151;
  text-decoration: underline;
  text-decoration-color: #9CA3AF;
  text-underline-offset: 2px;
}

.modal-links a:hover {
  text-decoration-color: #374151;
}

/* --- RECOMMENDATIONS --- */
.recommendations-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

/* --- TORIC SECTION (single primary accent, no purple) --- */
.toric-card .card-header {
  background: var(--primary-50);
  border-bottom-color: var(--primary-100);
}

.toric-card .title-md {
  color: var(--primary-700);
}

.toric-metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  text-align: center;
}

.toric-metric .numeric-body {
  color: var(--primary-700);
  font-size: 18px;
  font-weight: 700;
}

/* --- VECTOR BREAKDOWN TABLE --- */
.vector-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.vector-table td, .vector-table th {
  padding: 8px var(--sp-3);
  border-bottom: 1px solid var(--surface-dim);
}

.vector-table th {
  font-weight: 600;
  color: var(--on-surface-variant);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.vector-table .target-row {
  background: var(--primary-50);
  font-weight: 600;
}

/* --- ROTATION PENALTY TABLE --- */
.rotation-table .row-severe {
  background: var(--error-light);
  color: var(--error-dark);
}

.rotation-table .row-moderate {
  background: var(--warning-light);
  color: var(--warning-dark);
}

/* --- FOOTER --- */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding: var(--sp-6) 0;
  margin-top: var(--sp-10);
}

.footer-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

.footer-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-5);
}

.footer-nav {
  display: flex;
  gap: var(--sp-6);
}

.footer-nav a {
  font-size: 13px;
  color: var(--on-surface-variant);
  text-decoration: none;
}

.footer-nav a:hover {
  color: var(--primary-500);
}

.footer-disclaimer {
  font-size: 11px;
  line-height: 18px;
  color: var(--on-surface-muted);
  max-width: 900px;
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--outline);
  margin-top: var(--sp-4);
  font-size: 12px;
  color: var(--on-surface-muted);
}

/* --- GRADIENT ACCENT (top of page — single-tone primary) --- */
.gradient-accent {
  height: 3px;
  background: var(--primary-500);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
}

/* --- BILATERAL RESULTS LAYOUT --- */
.bilateral-eyes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}

@media (max-width: 768px) {
  .bilateral-eyes-grid { grid-template-columns: 1fr; gap: var(--sp-4); }
}

/* Wide data-tables with many columns overflow on mobile — allow horizontal
   scroll within the card instead of clipping or stretching the page. */
@media (max-width: 768px) {
  .card > .data-table,
  .card .bilateral-eyes-grid .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
}

/* --- TORIC RESULTS LAYOUT --- */
.toric-methods-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
  align-items: stretch;
}

.toric-methods-grid .toric-method-code {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.toric-methods-grid .toric-method-axis {
  font-size: 18px;
  font-weight: 600;
}

@media (max-width: 960px) {
  /* Two cards side-by-side, axis diagram full-width below */
  .toric-methods-grid { grid-template-columns: 1fr 1fr; }
  .toric-methods-grid > :nth-child(3) { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  /* Stack everything on phone */
  .toric-methods-grid { grid-template-columns: 1fr; }
  .toric-methods-grid > :nth-child(3) { grid-column: auto; }
  .toric-methods-grid .toric-method-code { font-size: 22px; }
  .toric-methods-grid .toric-method-axis { font-size: 16px; }
}

/* --- Toric model comparison table (per-model breakdown) --- */
.toric-row-best {
  background: var(--primary-50, #eef2ff);
}
.toric-row-best td {
  border-top: 2px solid var(--primary-200, #c7d2fe) !important;
  border-bottom: 2px solid var(--primary-200, #c7d2fe) !important;
}

.toric-direction-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.toric-direction-under {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}
.toric-direction-over {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

/* Toric model comparison — over-correction row + axis flip icon */
.toric-row-over td {
  background: #fef3c7;
}
/* Best model that's also over-correction: keep yellow (warning takes priority),
   ★ marker still visible in first cell, bold left border indicates "best". */
.toric-row-over.toric-row-best td {
  background: #fef3c7;
}
.toric-row-over.toric-row-best td:first-child {
  border-left: 3px solid var(--primary-500, #6366f1);
}
.toric-overcorrection-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 22px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 50%;
  cursor: help;
}

/* Toric step-by-step calculation breakdown */
.toric-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.toric-step {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--surface, #ffffff);
  border: 1px solid var(--outline-variant, #e5e7eb);
  border-radius: var(--radius-md, 8px);
}
.toric-step-num {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-100, #c5cae9);
  color: var(--primary-700, #303f9f);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toric-step-body {
  flex: 1;
  min-width: 0;
}
.toric-step-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--on-surface, #1f2937);
  margin-bottom: 2px;
}
.toric-step-value {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 13px;
  color: var(--on-surface-variant, #6b7280);
}
.toric-step-value strong {
  color: var(--on-surface, #1f2937);
  font-weight: 600;
}

/* Mobile: scrollable table for narrow screens */
@media (max-width: 720px) {
  .toric-models-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .toric-direction-badge {
    font-size: 11px;
    padding: 2px 8px;
  }
}

@media (max-width: 480px) {
  .toric-step { padding: var(--sp-2); gap: var(--sp-2); }
  .toric-step-num { width: 24px; height: 24px; font-size: 12px; }
  .toric-step-title { font-size: 13px; }
  .toric-step-value { font-size: 12px; }
}

/* =====================================================================
   MOBILE & TABLET RESPONSIVE
   Breakpoints:
     ≤1024 — tablet landscape (minor tweaks, content already 1-col at 960)
     ≤768  — tablet portrait (header condenses, tab-bar scrollable)
     ≤480  — phone (typography shrinks, button+consent stack)
   ===================================================================== */

/* Tablet portrait and below: shrink header, allow tab-bar horizontal scroll */
@media (max-width: 768px) {
  .page-container { padding: 0 var(--sp-4); }

  /* Disclaimer bar: smaller padding, keep centered */
  .disclaimer-bar { padding: 8px var(--sp-4); font-size: 11px; line-height: 14px; }

  /* Header: hide email, tighten gaps, make nav compact */
  .header-inner { height: 56px; padding: 0 var(--sp-4); gap: var(--sp-3); }
  .header-left { gap: var(--sp-4); min-width: 0; }
  .header-right { display: none; }
  .logo-mark { width: 30px; height: 30px; }
  .logo-text { font-size: 17px; }
  .logo-subtitle { display: none; }
  .nav { gap: 2px; }
  .nav-item { padding: 6px 10px; font-size: 13px; }
  /* Hide the currently-active nav item on mobile — user is already on that page,
     so the remaining item always offers the alternative destination. */
  .nav-item.active { display: none; }

  /* Header is sticky at top:36 (disclaimer-bar). On mobile, disclaimer height
     shrinks to ~28px, so align sticky offsets accordingly. */
  .header { top: 30px; }
  .tab-bar { top: 86px; }

  /* Tab-bar: horizontally scrollable so all three tabs remain reachable */
  .tab-bar-inner {
    padding: 0 var(--sp-4);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-bar-inner::-webkit-scrollbar { display: none; }
  .tab-item { padding: 14px var(--sp-3) 12px; font-size: 13px; }
  .tab-item::after { left: var(--sp-3); right: var(--sp-3); }
  .tab-icon { width: 16px; height: 16px; }

  /* Footer: stack everything */
  .footer-inner { padding: 0 var(--sp-4); }
  .footer-top { flex-direction: column; gap: var(--sp-4); align-items: flex-start; margin-bottom: var(--sp-4); }
  .footer-nav { flex-direction: column; gap: var(--sp-2); width: 100%; }
  .footer-nav a { font-size: 14px; }
  .footer-bottom { flex-direction: column; gap: var(--sp-1); align-items: flex-start; }

  /* Form-card: already 1-col at 960px; reduce section padding on phone-width */
  .form-card-grid > .form-section { padding: var(--sp-5) var(--sp-4); }
  .form-section-header { padding-bottom: var(--sp-3); margin-bottom: var(--sp-4); }
  .form-section-header .title { font-size: 16px; }

  /* Card headers and bodies: slightly tighter */
  .card-header { padding: var(--sp-4) var(--sp-4) var(--sp-2); }
  .card-body { padding: var(--sp-4); }
  .card-footer { padding: var(--sp-3) var(--sp-4); }
}

/* Phone-width: single column for 2-col form grids, larger touch targets */
@media (max-width: 480px) {
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr; }

  /* Text fields: slightly taller for easier tapping */
  .text-field input,
  .text-field select { height: 44px; font-size: 15px; }

  /* Disable sticky header on narrow phones to reclaim vertical space */
  .disclaimer-bar,
  .header,
  .tab-bar { position: static; top: auto; }

  /* Hero on formulas page */
  .hero { padding: 32px 0 24px; }
}

/* --- PRINT STYLES --- */
/* =====================================================================
   PRINT STYLES — optimized for A4 paper handed to a surgeon for planning
   ===================================================================== */
@media print {
  /* Page geometry */
  @page {
    size: A4;
    margin: 12mm 14mm;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 9pt;
    line-height: 1.35;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    orphans: 3;
    widows: 3;
  }

  /* Hide all chrome: disclaimer, header, tab-bar, footer, gradient accent,
     consent modal, and the entire input form (keep only the #results area).
     Also hide everything marked .no-print and any interactive controls. */
  .disclaimer-bar,
  .header,
  .tab-bar,
  .footer,
  .gradient-accent,
  .modal-scrim,
  .no-print,
  .btn,
  .form-card,
  .form-card-footer,
  form,
  #panel_secondary > form,
  #panel_bilateral > form,
  .tooltip-trigger,
  .expand-btn,
  .collapsible-trigger .chevron,
  .power-table button {
    display: none !important;
  }

  /* Expand all details so their content prints */
  details[open],
  details {
    display: block !important;
  }
  details > summary {
    display: none !important;
  }
  details > .collapsible-content {
    display: block !important;
    padding: 0 !important;
    margin-top: 6pt !important;
  }

  /* Panel visibility: hidden panels stay hidden, visible panels show results only */
  #panel_primary.hidden,
  #panel_secondary.hidden,
  #panel_bilateral.hidden {
    display: none !important;
  }

  /* Results area flows naturally */
  #results,
  #results_secondary,
  #results_bilateral {
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Page container: full width, no side padding eats paper */
  .page-container,
  main.page-container {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Cards on paper: thin border, no shadow, tight spacing, avoid breaks mid-card */
  .card {
    box-shadow: none !important;
    border: 1px solid #bbb !important;
    border-radius: 3px !important;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 5pt !important;
    background: #fff !important;
  }

  .card-header {
    padding: 4pt 8pt 3pt !important;
    border-bottom: 1px solid #e0e0e0 !important;
    background: #fafafa !important;
  }

  .card-header .title-md {
    font-size: 10pt;
    font-weight: 700;
    color: #000;
  }

  .card-body {
    padding: 5pt 8pt !important;
  }

  .card-footer {
    display: none !important;
  }

  /* Print-only elements become visible */
  .print-only {
    display: block !important;
  }

  /* Print header: logo + patient info, top of every result page */
  .print-header {
    font-size: 8.5pt;
    margin-bottom: 6pt;
    padding-bottom: 4pt;
    border-bottom: 1.5px solid #000;
  }

  .print-header .print-logo {
    display: inline-flex !important;
    align-items: center;
    gap: 6pt;
    font-weight: 700;
    font-size: 12pt;
    color: #1A237E;
  }

  .print-header .print-logo svg {
    width: 24pt;
    height: 24pt;
  }

  .print-header .print-meta {
    color: #444;
    font-size: 9pt;
  }

  /* Data tables: compact, readable */
  .data-table {
    font-size: 8.5pt !important;
    width: 100%;
  }

  .data-table th {
    background: #f0f0f0 !important;
    color: #000 !important;
    font-weight: 700;
    padding: 3pt 6pt !important;
    border-bottom: 1px solid #000 !important;
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .data-table td {
    padding: 3pt 6pt !important;
    border-bottom: 0.5px solid #d0d0d0 !important;
    color: #000 !important;
  }

  .data-table tbody tr:hover {
    background: transparent !important;
  }

  /* Inline power tables (per-formula) — hide in print; use dedicated ESCRS matrix instead */
  [id^="ptr-"],
  [id^="chev-"] {
    display: none !important;
  }

  .power-table {
    display: none !important;
  }

  /* ESCRS power matrix (.print-only) — primary planning tool on paper */
  .print-power-matrix,
  .print-only {
    display: block !important;
  }

  .print-power-matrix table,
  .print-only table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
    margin-top: 6pt;
  }

  .print-power-matrix th,
  .print-only table th {
    background: #f0f0f0 !important;
    padding: 3pt 5pt !important;
    border: 0.5px solid #999 !important;
    text-align: center;
    font-weight: 700;
  }

  .print-power-matrix td,
  .print-only table td {
    padding: 3pt 5pt !important;
    border: 0.5px solid #ddd !important;
    text-align: center;
    font-size: 8pt;
  }

  /* Alerts on paper: thin-bordered boxes, no filled backgrounds except accents */
  .alert {
    padding: 3pt 6pt !important;
    border: 1px solid #999 !important;
    border-radius: 3px !important;
    font-size: 8.5pt;
    background: #fff !important;
    color: #000 !important;
    break-inside: avoid;
    margin-bottom: 3pt !important;
  }

  .alert-critical { border-left: 3px solid #b71c1c !important; background: #fff5f5 !important; }
  .alert-warning  { border-left: 3px solid #e65100 !important; background: #fff8f0 !important; }
  .alert-info     { border-left: 3px solid #01579b !important; background: #f0f8ff !important; }
  .alert-success  { border-left: 3px solid #1b5e20 !important; background: #f5fff5 !important; }

  .alert-icon { width: 10pt; height: 10pt; flex-shrink: 0; }

  /* Chips on paper: plain outlined pills */
  .chip {
    border: 1px solid #999 !important;
    background: #fff !important;
    color: #000 !important;
    padding: 1pt 6pt !important;
    height: auto !important;
    font-size: 8pt !important;
  }
  .chip-success { border-color: #1b5e20 !important; color: #1b5e20 !important; }
  .chip-error   { border-color: #b71c1c !important; color: #b71c1c !important; }
  .chip-warning { border-color: #e65100 !important; color: #e65100 !important; }

  /* Section headings (form-section-header) — hide (data comes from print-header instead) */
  .form-section-header { display: none !important; }

  /* Toric section: keep but compact */
  .card--toric .card-header {
    background: #f5f5ff !important;
  }

  /* SVG axis diagram — keep, but smaller in print to save space */
  svg[viewBox="0 0 200 200"] {
    max-width: 110pt !important;
    height: auto !important;
  }

  /* Signature line at the bottom of print — MUST stay with preceding content,
     never orphan on a new page alone. */
  .print-signature {
    display: block !important;
    margin-top: 8pt;
    padding-top: 5pt;
    border-top: 1px solid #bbb;
    font-size: 7.5pt;
    color: #555;
    break-before: avoid !important;
    page-break-before: avoid !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .print-signature .sig-row {
    display: flex;
    gap: 30pt;
    margin-top: 6pt;
  }
  .print-signature .sig-line {
    flex: 1;
    border-bottom: 1px solid #000;
    height: 18pt;
    position: relative;
  }
  .print-signature .sig-line::after {
    content: attr(data-label);
    position: absolute;
    bottom: -12pt;
    left: 0;
    font-size: 7pt;
    color: #555;
  }

  /* Keep elements together: tables, cards, alert blocks */
  table, thead, tbody, tr, td, th { page-break-inside: avoid; }
  h1, h2, h3, h4, .title-md, .title-lg, .headline { page-break-after: avoid; }

  /* Last card before signature: never break after it (signature glues to it) */
  .card:last-of-type {
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  /* Power matrix compact — should fit alongside results table on single A4 */
  .print-only .data-table,
  .print-power-matrix {
    font-size: 7pt !important;
    margin-top: 3pt !important;
  }
  .print-only .data-table th,
  .print-only .data-table td,
  .print-power-matrix th,
  .print-power-matrix td {
    padding: 2pt 4pt !important;
  }

  /* Hide design-only labels and tabs that leaked */
  .tab-icon,
  .select-chevron,
  .sign-toggle { display: none !important; }
}

.print-only { display: none; }

/* --- UTILITIES --- */
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.color-primary { color: var(--primary-500); }
.color-error { color: var(--error-main); }
.color-success { color: var(--success-main); }
.color-muted { color: var(--on-surface-muted); }
.color-secondary-text { color: var(--on-surface-variant); }
.hidden { display: none; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
