/* Family Health Hub — dedicated responsive chart and mobile navigation corrections. */
#panel-charts .charts-grid { align-items: start; }
#panel-charts .chart-card { min-width: 0; overflow: hidden; }
#panel-charts .cc-chart-wrap {
  width: 100%;
  height: 205px;
  min-width: 0;
  position: relative;
  margin-top: 12px;
}
#panel-charts .cc-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: none !important;
}
#panel-charts .cc-labels { min-width: 0; flex: 1; overflow-wrap: anywhere; }
#panel-charts .cc-val { min-width: 0; }
#panel-charts .cc-unit { font-size: .7rem; opacity: .75; overflow-wrap: anywhere; }
#panel-charts .cc-name { overflow-wrap: anywhere; white-space: normal; color: var(--text2); }
#panel-charts .cc-top { gap: 12px; align-items: flex-start; }

@media (max-width: 768px) {
  html, body { max-width: 100%; overflow-x: clip; }
  #global-header { padding: 8px 10px; gap: 0; height: auto; min-height: 0; }
  #global-header > .header-brand { display: none; }
  #global-header > div:nth-child(2) {
    width: 100%;
    min-width: 0;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    align-items: stretch;
    justify-items: stretch;
  }
  #global-header .patient-pill {
    order: 1; grid-column: 1 / span 2;
    width: 100%; max-width: 100%; min-width: 0;
    margin: 0; padding: 7px 8px;
    justify-content: center; overflow: hidden;
  }
  #global-header .patient-pill-name {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0; font-size: .76rem;
  }
  #global-header .lang-switcher {
    order: 2; grid-column: 3; min-width: 0;
    display: flex; justify-content: center; padding: 2px;
  }
  #global-header .lang-switcher .lang-btn {
    min-width: 0; flex: 1; padding: 6px 2px; font-size: .7rem;
  }
  #global-header .theme-toggle {
    order: 3; grid-column: 4; width: 100%; margin: 0;
    min-height: 38px;
  }
  #global-header .mode-switcher {
    order: 4; grid-column: 1 / -1;
    width: 100%; display: flex; flex-wrap: nowrap !important;
    min-width: 0; margin: 0; gap: 4px;
  }
  #global-header .mode-switcher .mode-btn {
    min-width: 0; flex: 1 1 0; padding: 8px 5px;
    font-size: .75rem; white-space: normal; line-height: 1.35;
  }
  #global-header .notif-wrap {
    order: 5; grid-column: 1;
    width: 100%; display: flex; justify-content: center; align-items: center;
  }
  #global-header .notif-bell { width: 100%; min-height: 37px; }
  #global-header > div:nth-child(2) > .btn-sm:not(:last-child) {
    order: 6; grid-column: 2; white-space: nowrap; padding: 5px 3px; font-size: .74rem;
  }
  #global-header > div:nth-child(2) > .btn-sm:last-child {
    order: 7; grid-column: 3 / span 2; white-space: nowrap; padding: 5px 3px; font-size: .74rem;
  }

  /* Keep the 22 medical sections discoverable without consuming six rows. */
  #dashboard > .tabs {
    display: flex !important;
    flex-flow: row nowrap !important;
    gap: 5px; align-items: center;
    min-width: 0; width: 100%;
    overflow-x: auto !important; overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding: 8px 10px 6px !important;
    scroll-margin-top: 12px;
  }
  #dashboard > .tabs .tab {
    flex: 0 0 auto; min-width: 0;
    padding: 10px 12px; border-radius: 10px;
    white-space: nowrap; scroll-snap-align: start;
    font-size: .8rem; line-height: 1.4;
  }
  /* The fixed More action expands the full section list on demand. */
  #dashboard > .tabs.pui-tabs-expanded {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    max-height: min(55dvh, 440px);
    overflow-x: hidden !important; overflow-y: auto !important;
    scroll-snap-type: none;
  }
  #dashboard > .tabs.pui-tabs-expanded .tab {
    white-space: normal; text-align: center;
    overflow-wrap: anywhere; padding: 11px 5px;
    border: 1px solid var(--border);
  }
  #dashboard .stats-bar {
    width: 100%; max-width: 100%; overflow-x: auto;
    padding: 9px 10px; gap: 7px;
  }
  #dashboard .stats-bar .stat-pill { padding: 8px 12px; min-width: 76px; }
  #dashboard .panel {
    min-width: 0;
    padding: 12px 12px calc(86px + env(safe-area-inset-bottom, 0px));
  }
  #panel-charts .charts-grid {
    width: 100%; grid-template-columns: minmax(0, 1fr) !important; gap: 14px;
  }
  #panel-charts .chart-card { padding: 16px; border-radius: 17px; }
  #panel-charts .cc-chart-wrap { height: 225px; margin-top: 12px; }
  #panel-charts .cc-name { font-size: .72rem; line-height: 1.45; }
  #panel-charts .cc-ar { font-size: .96rem; line-height: 1.6; }
  #panel-charts .cc-num { font-size: 1.3rem; }
  #panel-charts .cc-val { flex: 0 0 auto; max-width: 44%; }
  #panel-charts .cc-trend { font-size: .8rem; }
  #panel-charts .cc-ref { line-height: 1.45; overflow-wrap: anywhere; }
  #pui-bottom-nav.pui-bottom-nav {
    height: calc(62px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
@media (max-width: 360px) {
  #global-header .mode-switcher .mode-btn { font-size: .68rem; }
  #panel-charts .cc-top { gap: 6px; }
  #panel-charts .cc-chart-wrap { height: 205px; }
}

/* v101: focused clinical chart workspace; respects light and dark palettes. */
#panel-charts .lab-chart-toolbar {
  margin-bottom: 16px;
  padding: clamp(16px, 2vw, 24px);
  background: linear-gradient(130deg, rgba(59,130,246,.12), rgba(14,165,164,.06) 52%, var(--bg2));
  border: 1px solid var(--border2);
  border-radius: 21px;
  box-shadow: 0 12px 34px rgba(0,0,0,.10);
}
#panel-charts .lab-chart-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 17px;
}
#panel-charts .lab-chart-title-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
#panel-charts .lab-chart-symbol {
  width: 45px;
  height: 45px;
  flex: none;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(59,130,246,.17);
  border: 1px solid rgba(96,165,250,.24);
  color: var(--accent2);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
}
#panel-charts #lab-chart-title { font-size: 1.22rem; font-weight: 800; color: var(--text); line-height: 1.35; }
#panel-charts #lab-chart-subtitle { margin-top: 3px; font-size: .79rem; color: var(--text2); line-height: 1.6; }
#panel-charts .lab-chart-count {
  white-space: nowrap;
  color: var(--accent2);
  border: 1px solid rgba(96,165,250,.24);
  background: rgba(59,130,246,.085);
  border-radius: 100px;
  padding: 6px 12px;
  font: 700 .81rem var(--mono);
  direction: ltr;
}
#panel-charts .lab-chart-controls { display: grid; grid-template-columns: minmax(0,1fr) minmax(178px,235px); gap: 10px; align-items: stretch; }
#panel-charts .lab-chart-search-field, #panel-charts .lab-chart-sort-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  min-width: 0;
  border: 1px solid var(--border2);
  background: var(--bg2);
  border-radius: 13px;
  padding: 0 12px;
  color: var(--text2);
  transition: border-color .2s, box-shadow .2s;
}
#panel-charts .lab-chart-search-field:focus-within,
#panel-charts .lab-chart-sort-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
#panel-charts .lab-chart-search-field > span { font-size: 1.4rem; line-height: 1; }
#panel-charts #lab-chart-search {
  min-width: 0;
  flex: 1;
  width: 100%;
  padding: 4px 0;
  background: transparent;
  color: var(--text);
  border: 0;
  outline: 0;
  font: 500 .88rem var(--sans);
}
#panel-charts #lab-chart-search::placeholder { color: var(--text2); opacity: .8; }
#panel-charts #lab-chart-search-clear {
  font-size: 1.4rem;
  min-width: 30px;
  min-height: 30px;
  cursor: pointer;
  color: var(--text2);
  border: 0;
  background: var(--bg3);
  border-radius: 8px;
}
#panel-charts .lab-chart-sort-field > span { font-size: .75rem; white-space: nowrap; }
#panel-charts #lab-chart-sort {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  min-width: 0;
  flex: 1;
  font: 700 .82rem var(--sans);
}
#panel-charts #lab-chart-sort option { background: var(--bg2); color: var(--text); }
#panel-charts .lab-chart-note {
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  font-size: .76rem;
  line-height: 1.75;
  color: var(--text2);
}
#panel-charts .lab-chart-empty {
  border: 1px dashed var(--border2);
  border-radius: 17px;
  padding: 35px 20px;
  text-align: center;
  color: var(--text2);
  background: var(--bg2);
  line-height: 1.8;
}
#panel-charts [hidden] { display: none !important; }
#panel-charts .chart-card {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(150deg, var(--bg2), var(--bg3));
  box-shadow: 0 5px 22px rgba(0,0,0,.1);
}
#panel-charts .chart-card:hover { border-color: var(--border2); }
#panel-charts .cc-top { align-items: flex-start; }
#panel-charts .cc-ar { font-size: 1rem; line-height: 1.5; }
#panel-charts .cc-num { font-size: 1.57rem; line-height: 1.3; color: var(--text); }
#panel-charts .cc-num.ok { color: var(--green); }
#panel-charts .cc-num.warn { color: var(--yellow); }
#panel-charts .cc-num.na { color: var(--text); }
#panel-charts .cc-trend .up, #panel-charts .cc-trend .dn {
  color: var(--text2); /* An upward trend is not necessarily adverse. */
}
#panel-charts .cc-footer {
  border-top: 1px solid var(--border);
  margin-top: 13px;
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  color: var(--text2);
  font-size: .76rem;
}
#panel-charts .cc-sample-count {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
}
#panel-charts .cc-last { font-family: var(--mono); font-size: .7rem; direction: ltr; }

@media (max-width: 768px) {
  #panel-charts .lab-chart-toolbar { padding: 15px; border-radius: 18px; margin-bottom: 12px; }
  #panel-charts .lab-chart-intro { align-items: flex-start; }
  #panel-charts .lab-chart-title-row { gap: 9px; }
  #panel-charts .lab-chart-symbol { width: 38px; height: 38px; border-radius: 12px; font-size: 1.5rem; }
  #panel-charts #lab-chart-title { font-size: 1.03rem; }
  #panel-charts #lab-chart-subtitle { font-size: .72rem; }
  #panel-charts .lab-chart-count { padding: 4px 8px; font-size: .7rem; }
  #panel-charts .lab-chart-controls { grid-template-columns: minmax(0,1fr); gap: 9px; }
  #panel-charts .lab-chart-search-field, #panel-charts .lab-chart-sort-field { height: 46px; }
  #panel-charts .lab-chart-note { font-size: .72rem; }
  #panel-charts .chart-card { padding: 16px; border-radius: 19px; }
  #panel-charts .cc-chart-wrap { height: 235px; }
  #panel-charts .cc-num { font-size: 1.4rem; }
  #panel-charts .cc-ar { font-size: .94rem; }
  #panel-charts .cc-last { font-size: .68rem; }
  #dashboard > .tabs .tab.active { box-shadow: inset 0 0 0 1px rgba(59,130,246,.25); }
}
@media (prefers-reduced-motion:reduce) {
  #panel-charts .lab-chart-search-field, #panel-charts .lab-chart-sort-field { transition:none; }
}

/* V102 — restrained luminous tracer. Keeps the existing live clinical cards. */
#panel-charts .cc-chart-wrap { isolation: isolate; }
#panel-charts .cc-chart-wrap .cc-light-tracer {
  position: absolute !important;
  inset: 0 auto auto 0;
  z-index: 2;
  display: block;
  max-width: 100% !important;
  pointer-events: none !important;
  user-select: none;
  transform: translateZ(0);
  opacity: .94;
}
@media (prefers-reduced-motion: reduce), print {
  #panel-charts .cc-chart-wrap .cc-light-tracer {
    animation: none !important;
    transition: none !important;
  }
}
@media print {
  #panel-charts .cc-chart-wrap .cc-light-tracer { display: none !important; }
}
