:root {
  --navy:  #003057;
  --blue:  #006DAE;
  --teal:  #00877A;
  --sky:   #E8F4FA;
  --gold:  #F5A800;
  --amber: #E87722;
  --red:   #C0392B;
  --green: #27AE60;
  --purple:#7B2D8B;
  --bg:    #F2F5F8;
  --card:  #FFFFFF;
  --border:#D5DFE8;
  --text:  #1A2535;
  --muted: #5A6A7E;
  --ease:  cubic-bezier(0.4,0,0.2,1);
  --t:     0.22s;
}

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

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

/* ─── HEADER ─────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: 52px;
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-m {
  width: 32px; height: 32px; border-radius: 7px;
  background: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px; color: var(--navy); flex-shrink: 0;
}
.logo-text { min-width: 0; }
.logo-text strong { font-size: 13px; color: #fff; display: block; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-text span   { display: none; }
.header-spacer    { flex: 1; }
.header-tag       { display: none; }
.barben-btn       { display: none; }

/* Install button — shown via JS when installable */
.install-btn {
  display: none;
  align-items: center; gap: 5px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  color: #fff;
  padding: 5px 11px; border-radius: 6px;
  cursor: pointer; font-size: 12px; font-weight: 600;
  white-space: nowrap;
  transition: background var(--t) var(--ease);
  flex-shrink: 0;
}
.install-btn:hover { background: rgba(255,255,255,0.22); }


/* ─── MOBILE LAYOUT ──────────────────────────────────────────── */
.app { display: flex; flex-direction: column; }

.flowchart-col {
  width: 100%;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.flowchart-header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 52px;
  z-index: 10;
}
.flowchart-header h2 { font-size: 13px; font-weight: 700; color: var(--navy); }
.flowchart-header p  { font-size: 11px; color: var(--muted); margin-top: 2px; }
.fc-hint { font-size: 11px; color: var(--blue); margin-top: 5px; display: flex; align-items: center; gap: 4px; }

#svgWrap { padding: 8px; }
#svgWrap svg { width: 100%; height: auto; display: block; }

/* hide detail + evidence columns on mobile */
.detail-col   { display: none; }
.evidence-col { display: none; }

/* ─── BOTTOM DRAWER ──────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t) var(--ease);
}
.drawer-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 65vh;
  max-height: 90vh;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  z-index: 301;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  will-change: transform;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
}
.drawer.open    { transform: translateY(0); }
.drawer.no-anim { transition: none; }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-backdrop, #scrollPill, .ios-sheet { transition: none; }
}

.drawer-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.drawer-inner {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.drawer-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-back {
  background: none; border: none; color: var(--blue);
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 4px 0; display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.drawer-nav-title {
  flex: 1; font-size: 13px; font-weight: 700; color: var(--navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.drawer-section  { padding: 12px 16px 96px; }
.drawer-evidence { padding: 16px 16px 96px; }

/* ─── iOS INSTALL SHEET ──────────────────────────────────────── */
#iosSheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 400;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
}
#iosSheet.visible { transform: translateY(0); }

.ios-sheet-inner {
  background: var(--navy);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px 40px;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.3);
}
.ios-sheet-title {
  font-size: 16px; font-weight: 800; color: #fff; margin-bottom: 16px;
}
.ios-sheet-steps {
  list-style: none;
  display: flex; flex-direction: column; gap: 12px;
  counter-reset: steps;
}
.ios-sheet-steps li {
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 13px; line-height: 1.5; color: #8BAFC8;
  counter-increment: steps;
}
.ios-sheet-steps li::before {
  content: counter(steps);
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff; font-size: 11px; font-weight: 700;
  flex-shrink: 0; margin-top: 1px;
}
.ios-sheet-steps strong { color: var(--gold); }
.ios-sheet-close {
  margin-top: 24px; width: 100%;
  background: var(--gold); color: var(--navy);
  border: none; border-radius: 10px;
  padding: 13px; font-size: 14px; font-weight: 800;
  cursor: pointer;
  transition: opacity var(--t) var(--ease);
}
.ios-sheet-close:hover { opacity: 0.9; }

/* ─── SHARED CONTENT STYLES ──────────────────────────────────── */
.section-badge {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 700; color: var(--blue);
  background: var(--sky); padding: 4px 12px; border-radius: 20px;
  border: 1px solid rgba(0,109,174,0.2); margin-bottom: 6px;
}
.section-title { font-size: 20px; font-weight: 800; color: var(--navy); line-height: 1.2; }
.section-sub   { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

.card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.06); margin: 12px 0; }
.card-hd { padding: 10px 14px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); background: #FAFBFC; }
.card-hd h3     { font-size: 13px; font-weight: 700; color: var(--navy); flex: 1; }
.card-hd .hicon { font-size: 15px; }
.card-bd { padding: 12px 14px; }

.ev-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; margin: 0 -10px; cursor: pointer; transition: background var(--t) var(--ease); border-radius: 6px; border-bottom: 1px solid #F0F3F6; }
.ev-item:last-child { border-bottom: none; }
.ev-item:hover      { background: rgba(0,109,174,0.05); }

.ev-item-check {
  width: 18px; height: 18px;
  border: 2px solid var(--border); border-radius: 4px;
  flex-shrink: 0; margin-top: 1px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.ev-item-check.done { background: var(--blue); border-color: var(--blue); }
.ev-item-check.done::after { content: '✓'; color: #fff; font-size: 11px; font-weight: 700; }

.ev-item-text                  { flex: 1; min-width: 0; }
.ev-item-text .label           { font-size: 13px; color: var(--text); line-height: 1.5; }
.ev-item-text .label.optional  { color: var(--muted); }
.ev-item-text .label.optional::after { content: ' — if clinically indicated'; font-size: 11px; }

/* ─── COMBINED EVIDENCE PILL ─────────────────────────────────── */
.ev-combined-pill {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
  cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.ev-combined-pill.barben {
  background: #F0E8FF; color: #6B21A8; border: 1px solid #D8B4FE;
}
.ev-combined-pill.barben:hover {
  background: #E4D4FF; transform: translateY(-1px);
}
.ev-combined-pill.mch {
  background: #E8F4FA; color: var(--blue); border: 1px solid rgba(0,109,174,0.2);
}
.ev-combined-pill.diff {
  background: #FFF0E8; color: var(--amber); border: 1px solid rgba(232,119,34,0.3);
}

/* ─── LEGEND ─────────────────────────────────────────────────── */
.legend-strip {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px; padding-top: 8px;
}
.legend-label { font-size: 11px; color: var(--muted); }
.legend-item {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted); white-space: nowrap;
}

/* ─── INFO STRIPS ────────────────────────────────────────────── */
.info-strip {
  padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.6;
  display: flex; gap: 10px; align-items: flex-start;
  cursor: pointer; transition: filter var(--t) var(--ease); margin: 6px 0;
}
.info-strip:hover    { filter: brightness(0.96); }
.info-strip.blue   { background: rgba(0,109,174,0.07);  border: 1px solid rgba(0,109,174,0.15);  color: #004A7C; }
.info-strip.amber  { background: rgba(232,119,34,0.08); border: 1px solid rgba(232,119,34,0.2);  color: #7A3A00; }
.info-strip.red    { background: rgba(192,57,43,0.07);  border: 1px solid rgba(192,57,43,0.2);   color: #7A1A0A; }
.info-strip.green  { background: rgba(39,174,96,0.07);  border: 1px solid rgba(39,174,96,0.2);   color: #0A5A28; }
.info-strip.purple { background: rgba(123,45,139,0.07); border: 1px solid rgba(123,45,139,0.2);  color: #4A1060; }
.info-strip .si-icon { font-size: 17px; flex-shrink: 0; margin-top: 1px; }

.print-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--blue); color: #fff; border: none;
  padding: 6px 13px; border-radius: 7px; cursor: pointer;
  font-size: 12px; font-weight: 600;
  transition: background var(--t) var(--ease);
}
.print-btn:hover { background: var(--navy); }

/* ─── EVIDENCE CONTENT ───────────────────────────────────────── */
.ev-age-badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 700; color: var(--navy);
  background: var(--gold); padding: 3px 10px; border-radius: 20px;
  margin-bottom: 10px;
}
.ev-blockquote {
  background: rgba(0,48,87,0.04);
  border-left: 3px solid var(--navy);
  border-radius: 0 8px 8px 0;
  padding: 12px 14px; margin: 10px 0;
  font-style: italic; font-size: 13px; line-height: 1.7; color: var(--text);
}
.ev-blockquote cite {
  display: block; margin-top: 8px;
  font-style: normal; font-size: 11px; font-weight: 700; color: var(--blue);
}
.ev-context-box {
  background: var(--sky); border: 1px solid rgba(0,109,174,0.15);
  border-radius: 8px; padding: 12px 14px; margin: 10px 0;
  font-size: 12px; line-height: 1.65; color: #004A7C;
}
.ev-context-box strong {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 5px; color: var(--navy);
}
.ev-section-ref {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: var(--blue);
  background: rgba(0,109,174,0.08); border: 1px solid rgba(0,109,174,0.2);
  padding: 4px 10px; border-radius: 6px; margin: 6px 0;
}
.ev-download-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--navy); color: #fff; text-decoration: none;
  padding: 12px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 700; margin-top: 16px;
  transition: background var(--t) var(--ease);
}
.ev-download-btn:hover { background: var(--blue); }

/* ─── WELCOME ────────────────────────────────────────────────── */
.welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center; gap: 16px;
}
.welcome-ring {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; box-shadow: 0 8px 24px rgba(0,109,174,0.3);
}
.welcome h2 { font-size: 20px; font-weight: 800; color: var(--navy); }
.welcome p  { font-size: 13px; color: var(--muted); max-width: 360px; line-height: 1.6; }
.welcome-pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.welcome-pill {
  padding: 5px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  background: var(--sky); color: var(--blue);
  border: 1px solid rgba(0,109,174,0.2);
  cursor: pointer; transition: all 0.15s;
}
.welcome-pill:hover, .welcome-pill:focus { background: var(--blue); color: #fff; outline: none; }

/* ─── SCROLLBAR ──────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── DESKTOP ≥ 900px ────────────────────────────────────────── */
@media (min-width: 900px) {
  html, body { height: 100%; overflow: hidden; }
  body { display: flex; flex-direction: column; }

  .logo-text span { display: block; font-size: 10px; color: #8BAFC8; }
  .header-tag {
    display: block; font-size: 11px; padding: 3px 8px; border-radius: 20px;
    background: rgba(255,255,255,0.1); color: #8BAFC8;
    border: 1px solid rgba(255,255,255,0.12);
  }
  .barben-btn {
    display: flex; align-items: center; gap: 6px;
    background: rgba(245,168,0,0.15); border: 1px solid rgba(245,168,0,0.35);
    color: var(--gold); padding: 5px 13px; border-radius: 6px;
    cursor: pointer; font-size: 12px; font-weight: 600;
    transition: background var(--t) var(--ease);
  }
  .barben-btn:hover { background: rgba(245,168,0,0.25); }
  .barben-btn .dot  { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }

  #scrollPill { display: none; }

  .app {
    display: flex; flex-direction: row;
    flex: 1; overflow: hidden;
    height: calc(100vh - 52px);
  }

  .flowchart-col {
    width: 380px; flex-shrink: 0;
    overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column;
    background: var(--card);
    border-right: 1px solid var(--border); border-bottom: none;
  }
  .flowchart-header { position: sticky; top: 0; z-index: 10; }
  #svgWrap { padding: 12px; flex: 1; }

  .detail-col {
    display: flex; flex: 1; overflow-y: auto;
    flex-direction: column; background: var(--bg); min-width: 0;
  }
  .detail-inner { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

  .evidence-col {
    display: flex; width: 440px; flex-shrink: 0;
    background: var(--navy); flex-direction: column;
    border-left: 1px solid rgba(255,255,255,0.08); overflow: hidden;
    transition: width var(--t) var(--ease), opacity var(--t) var(--ease);
  }
  .evidence-col.collapsed { width: 0; opacity: 0; pointer-events: none; }

  #evContent { display: flex; flex-direction: column; height: 100%; }

  .ev-panel-header {
    padding: 14px 16px; background: rgba(255,255,255,0.05);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex; align-items: flex-start; gap: 12px; flex-shrink: 0;
  }
  .ev-panel-header-text { flex: 1; min-width: 0; }
  .ev-panel-header-text h3 { font-size: 13px; font-weight: 700; color: #fff; line-height: 1.4; }
  .ev-panel-header-text .ev-section-label { font-size: 11px; color: var(--gold); margin-top: 3px; font-weight: 600; }
  .ev-panel-header-text .ev-context-label { font-size: 11px; color: #8BAFC8; margin-top: 5px; line-height: 1.5; }

  .ev-panel-close {
    background: rgba(255,255,255,0.1); border: none; color: #fff;
    width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
    font-size: 14px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background var(--t) var(--ease);
  }
  .ev-panel-close:hover { background: rgba(255,255,255,0.2); }

  .ev-panel-body {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
  }

  /* Dark-theme overrides for evidence inside desktop panel */
  .ev-panel-body .ev-blockquote {
    background: rgba(245,168,0,0.08); border-left-color: var(--gold); color: #F0D080;
  }
  .ev-panel-body .ev-blockquote cite { color: var(--gold); }
  .ev-panel-body .ev-context-box {
    background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.1); color: #8BAFC8;
  }
  .ev-panel-body .ev-context-box strong { color: #fff; }
  .ev-panel-body .ev-section-ref {
    color: var(--gold); background: rgba(245,168,0,0.1); border-color: rgba(245,168,0,0.25);
  }
  .ev-panel-body .ev-age-badge { color: var(--navy); }
  .ev-panel-body .ev-download-btn {
    background: rgba(245,168,0,0.15); border: 1px solid rgba(245,168,0,0.35); color: var(--gold);
  }
  .ev-panel-body .ev-download-btn:hover { background: rgba(245,168,0,0.28); }

  .ev-empty {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 32px; text-align: center; gap: 16px;
  }
  .ev-empty .ev-icon { font-size: 40px; opacity: 0.4; }
  .ev-empty h3 { font-size: 14px; color: #8BAFC8; font-weight: 600; }
  .ev-empty p  { font-size: 12px; color: #4A6070; line-height: 1.6; }

  .drawer, .drawer-backdrop { display: none !important; }
}

/* ─── PRINT ──────────────────────────────────────────────────── */
@media print {
  .evidence-col, .flowchart-col, header, .drawer, .drawer-backdrop, #iosSheet { display: none !important; }
  .detail-col { overflow: visible; display: block !important; }
  .app { display: block; }
  html, body { height: auto; overflow: visible; }
}
