  :root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --ink-primary: #1a1d23;
    --ink-secondary: #4b5563;
    --ink-muted: #8a8f98;
    --border: #d8dbe0;
    --grid: #e5e7eb;
    --input-bg: #ffffff;

    --photo-line: #1f6fd6;      /* blue — phototherapy, clinician convention */
    --exchange-line: #c62828;   /* red — exchange transfusion, clinician convention */
    --band-fill: #f6c945;       /* amber shaded "within 50" band */
    --band-fill-alpha: 0.22;

    --status-normal: #1f8a4c;
    --status-approaching: #b7791a;
    --status-photo: #d2691e;
    --status-exchange: #b3261e;

    --focus-ring: #1f6fd6;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #14161a;
      --surface: #1c1f26;
      --ink-primary: #edeef0;
      --ink-secondary: #b7bcc4;
      --ink-muted: #7d838d;
      --border: #343943;
      --grid: #2a2e36;
      --input-bg: #21252c;

      --photo-line: #5b9bf0;
      --exchange-line: #ef5b53;
      --band-fill: #caa032;
      --band-fill-alpha: 0.28;

      --status-normal: #4cbf7d;
      --status-approaching: #e0a934;
      --status-photo: #e2884f;
      --status-exchange: #ef6259;

      --focus-ring: #5b9bf0;
    }
  }

  * { box-sizing: border-box; }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink-primary);
  }
  .app {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px 20px 64px;
  }
  .layout {
    display: flex;
    flex-direction: column;
    gap: 18px;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .chart-pane {
    min-width: 0;
  }
  @media (min-width: 980px) {
    .app { max-width: none; padding: 24px 28px 64px; }
    .layout {
      flex-direction: row;
      align-items: flex-start;
      gap: 24px;
    }
    .sidebar {
      flex: 0 0 400px;
      max-width: 400px;
    }
    .chart-pane {
      flex: 1 1 auto;
      position: sticky;
      top: 24px;
    }
  }
  h1 {
    font-size: 1.4rem;
    margin: 0 0 4px;
  }
  .subtitle {
    color: var(--ink-secondary);
    font-size: 0.9rem;
    margin: 0 0 20px;
  }
  section.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 18px;
  }
  section.card h2 {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-secondary);
    margin: 0 0 14px;
  }
  .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }
  .section-header h2 { margin-bottom: 0; }
  .field-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: end;
  }
  .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
  }
  .field label {
    font-size: 0.78rem;
    color: var(--ink-secondary);
  }
  input, select {
    font: inherit;
    padding: 7px 9px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--ink-primary);
  }
  input:focus, select:focus, button:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 1px;
  }
  input[type="number"] { width: 88px; }
  button {
    font: inherit;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--photo-line);
    background: var(--photo-line);
    color: #fff;
    cursor: pointer;
  }
  button.secondary {
    background: transparent;
    color: var(--photo-line);
  }
  button.ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--ink-secondary);
    padding: 4px 8px;
    font-size: 0.8rem;
  }
  .pill-toggle {
    display: inline-flex;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    margin-bottom: 10px;
  }
  .pill-toggle label {
    position: relative;
    display: flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.82rem;
    color: var(--ink-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
  }
  .pill-toggle label.active {
    background: var(--photo-line);
    color: #fff;
  }
  .pill-toggle input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
  }
  .pill-toggle label:has(input:focus-visible) {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
  }

  #error-banner {
    display: none;
    background: #fdecea;
    color: #7a1f16;
    border: 1px solid #f3b9b2;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 16px;
  }
  @media (prefers-color-scheme: dark) {
    #error-banner { background: #3a201d; color: #ffb4ab; border-color: #6b352e; }
  }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
  }
  th, td {
    text-align: left;
    padding: 7px 10px;
    border-bottom: 1px solid var(--grid);
  }
  th { color: var(--ink-secondary); font-weight: 600; font-size: 0.78rem; }
  .status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    color: #fff;
  }

  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    font-size: 0.8rem;
    color: var(--ink-secondary);
    margin-top: 8px;
  }
  .legend .swatch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .legend .line { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
  .legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
  .legend .band { width: 18px; height: 10px; display: inline-block; border-radius: 2px; }

  #chart-wrap { overflow-x: auto; position: relative; }
  svg { display: block; width: 100%; height: auto; min-width: 560px; }
  .grid-line { stroke: var(--grid); stroke-width: 1; }
  .grid-line.minor { opacity: 0.5; }
  .axis-label { fill: var(--ink-secondary); font-size: 11px; }
  .axis-title { fill: var(--ink-secondary); font-size: 12px; }

  .tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.78rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    display: none;
    white-space: nowrap;
    color: var(--ink-primary);
  }

  .top-bar { position: relative; }
