/* Patient Profile layout v2.31.0 — layout/responsive only */
#profile{
  width:100%;
  min-width:0;
}

#profile .patient-profile-header{
  width:100%;
  min-width:0;
  margin:0 0 10px;
  padding:8px 12px;
}

#profile .patient-header-row{
  display:flex;
  align-items:center;
  gap:10px;
  width:100%;
  min-width:0;
}

#profile .profile-back-compact{
  flex:0 0 auto;
  min-height:28px;
  height:28px;
  padding:0 9px;
  border:1px solid var(--line);
  border-radius:8px;
  background:var(--surface-soft);
  color:var(--text);
  font-size:11px;
  font-weight:800;
  line-height:1;
  white-space:nowrap;
}

#profile .patient-avatar-large{
  flex:0 0 44px;
  width:44px;
  height:44px;
  display:grid;
  place-items:center;
  border-radius:13px;
  font-size:16px;
}

#profile .patient-header-name{
  flex:0 0 auto;
  min-width:0;
  max-width:240px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:18px;
  line-height:1.2;
}

#profile .patient-header-meta-inline{
  display:flex;
  align-items:center;
  gap:0;
  min-width:0;
  flex:1 1 auto;
  overflow:hidden;
  white-space:nowrap;
  font-size:11px;
  line-height:1.25;
}

#profile .patient-header-meta-inline span{
  display:inline-flex;
  align-items:center;
  min-width:0;
  white-space:nowrap;
}

#profile .patient-header-meta-inline span + span::before{
  content:"|";
  margin:0 9px;
  color:var(--muted);
  font-weight:400;
}

#profile .patient-header-disease-inline{
  overflow:hidden;
  text-overflow:ellipsis;
}

#profile .patient-profile-layout,
#profile .patient-profile-workspace-only{
  display:block;
  width:100%;
  min-width:0;
  min-height:0;
}

#profile .patient-profile-workspace{
  width:100%;
  min-width:0;
  min-height:0;
  display:grid;
  grid-template-rows:48px minmax(0,1fr);
  gap:8px;
  padding:12px 14px;
  overflow:hidden;
}

#profile .patient-main-tabs{
  position:sticky;
  top:0;
  z-index:4;
  display:flex;
  align-items:center;
  width:100%;
  min-width:0;
  height:48px;
  min-height:48px;
  gap:4px;
  padding:4px;
  overflow-x:auto;
  overflow-y:hidden;
  scrollbar-width:thin;
}

#profile .patient-main-tabs button{
  flex:1 1 0;
  min-width:0;
  height:40px;
  min-height:40px;
  padding:0 8px;
  white-space:nowrap;
  line-height:1.2;
}

#profile .patient-tab-panel{
  width:100%;
  min-width:0;
  min-height:0;
}

#profile .patient-tab-panel:not([hidden]){
  display:grid;
  align-content:start;
  gap:10px;
}

#profile .patient-tab-panel > *{
  min-width:0;
  max-width:100%;
}

#profile .patient-context-tab-panel{
  padding:0 2px 2px 0;
}

#profile .patient-context-tab-head{
  margin-bottom:0;
}

#profile .patient-context-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:0 18px;
  width:100%;
  min-width:0;
}

#profile .patient-context-section{
  min-width:0;
  padding:10px 0 12px;
  border-top:1px solid var(--line);
}

#profile .patient-context-section h4{
  margin:0 0 8px;
  font-size:13px;
  line-height:1.3;
}

#profile .patient-context-rows{
  display:grid;
  gap:6px;
}

#profile .patient-context-row{
  display:grid;
  grid-template-columns:minmax(92px,38%) minmax(0,1fr);
  gap:8px;
  align-items:start;
}

#profile .patient-context-row span{
  color:var(--muted);
  font-size:11px;
  line-height:1.4;
}

#profile .patient-context-row strong{
  min-width:0;
  color:var(--text);
  font-size:12px;
  line-height:1.4;
  font-weight:700;
  overflow-wrap:anywhere;
}

#profile .patient-profile-workspace .profile-table-wrap,
#profile .patient-profile-workspace .table-wrap{
  width:100%;
  max-width:100%;
  min-width:0;
  overflow-x:auto;
}

#profile .patient-chart-panel,
#profile .patient-lab-history,
#profile .patient-lab-grid{
  width:100%;
  max-width:100%;
  min-width:0;
}

/* Desktop/Laptop viewport fit */
@media (min-width:1200px) and (min-height:650px){
  html:has(#profile.active),
  body:has(#profile.active){
    height:100%;
    overflow:hidden;
  }

  .main:has(> #profile.active){
    --profile-system-header-height:82px;
    height:100vh;
    height:100dvh;
    min-height:0;
    padding-top:calc(var(--profile-system-header-height) + 8px)!important;
    padding-bottom:calc(var(--fixed-footer-height) + 6px)!important;
    overflow:hidden!important;
  }

  .main:has(> #profile.active) > .topbar{
    min-height:var(--profile-system-header-height)!important;
    height:var(--profile-system-header-height);
    margin-bottom:0!important;
    padding-top:8px!important;
    padding-bottom:8px!important;
  }

  #profile.active{
    height:100%;
    min-height:0;
    display:grid;
    grid-template-rows:auto minmax(0,1fr);
    gap:8px;
    overflow:hidden;
    max-width:none!important;
  }

  #profile.active .patient-profile-header{
    min-height:60px;
    max-height:66px;
    margin:0;
    padding:8px 12px;
    overflow:hidden;
  }

  #profile.active .patient-profile-layout{
    height:100%;
    min-height:0;
    overflow:hidden;
  }

  #profile.active .patient-profile-workspace{
    height:100%;
    min-height:0;
    overflow:hidden;
  }

  #profile.active .patient-tab-panel:not([hidden]){
    height:100%;
    min-height:0;
    max-height:100%;
    padding:0 2px 2px 0;
    overflow-y:auto;
    overflow-x:hidden;
    overscroll-behavior:contain;
    scrollbar-width:thin;
  }

  #profile.active .patient-profile-workspace .profile-table-wrap,
  #profile.active .patient-profile-workspace .table-wrap{
    max-height:none!important;
    overflow-x:auto;
    overflow-y:visible;
  }

  #profile.active .patient-tab-panel[data-profile-panel="meds"]:not([hidden]){
    height:100%;
    min-height:0;
    max-height:100%;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior:contain;
    scrollbar-width:thin;
    scroll-padding-bottom:16px;
    padding-bottom:16px;
  }

  #profile.active .patient-med-cost-drugs,
  #profile.active #profileDrugTable{
    overflow:visible;
  }

  #profile.active .patient-med-cost-drugs .profile-table-wrap,
  #profile.active #profileDrugTable .profile-table-wrap{
    overflow-x:auto;
    overflow-y:visible;
  }

  #profile.active .patient-med-cost-summary{
    gap:8px;
    margin:8px 0 10px;
  }

  #profile.active .patient-med-kpi{
    min-height:76px;
    padding:9px 10px;
  }

  #profile.active .patient-med-kpi strong{
    margin-top:3px;
    font-size:17px;
    line-height:1.2;
  }

  #profile.active .patient-med-kpi small{
    margin-top:2px;
    line-height:1.25;
  }

  #profile.active .patient-med-change-analysis,
  #profile.active .patient-med-cost-drugs{
    margin:10px 0;
  }

  #profile.active .patient-med-history-head{
    margin-top:12px;
  }
}

@media (min-width:1440px) and (min-height:650px){
  #profile.active .patient-med-cost-summary{
    grid-template-columns:repeat(5,minmax(0,1fr))!important;
  }
}

@media (min-width:1200px) and (max-width:1439px) and (min-height:650px){
  #profile.active .patient-header-name{
    max-width:190px;
    font-size:17px;
  }
  #profile.active .patient-header-meta-inline span + span::before{
    margin-inline:7px;
  }
  #profile.active .patient-main-tabs button{
    padding-inline:6px;
    font-size:12px;
  }
  #profile.active .patient-context-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:0 20px;
  }
  #profile.active .patient-med-cost-summary{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
}

@media (min-width:1200px) and (max-height:749px){
  .main:has(> #profile.active){
    --profile-system-header-height:78px;
    padding-top:calc(var(--profile-system-header-height) + 6px)!important;
    padding-bottom:calc(var(--fixed-footer-height) + 4px)!important;
  }
  #profile.active{
    gap:6px;
  }
  #profile.active .patient-profile-header{
    min-height:56px;
    max-height:60px;
    padding:6px 10px;
  }
  #profile.active .patient-avatar-large{
    flex-basis:40px;
    width:40px;
    height:40px;
  }
  #profile.active .patient-header-name{
    font-size:16px;
  }
  #profile.active .patient-profile-workspace{
    grid-template-rows:46px minmax(0,1fr);
    gap:6px;
    padding:10px 12px;
  }
  #profile.active .patient-main-tabs{
    height:46px;
    min-height:46px;
    padding:3px;
  }
  #profile.active .patient-main-tabs button{
    min-height:40px;
    height:40px;
  }
}

/* Tablet / narrow laptop */
@media (max-width:1199px), (max-height:649px){
  #profile{
    overflow-x:hidden;
  }

  #profile .patient-profile-header{
    padding:8px 10px;
  }

  #profile .patient-header-row{
    flex-wrap:wrap;
    gap:7px 9px;
  }

  #profile .patient-header-meta-inline{
    flex:1 1 100%;
    order:4;
    padding-left:calc(44px + 9px);
    overflow-x:auto;
    scrollbar-width:thin;
  }

  #profile .patient-main-tabs{
    position:relative;
    top:auto;
  }

  #profile .patient-main-tabs button{
    flex:0 0 auto;
    min-width:92px;
  }

  #profile .patient-profile-layout,
  #profile .patient-profile-workspace{
    height:auto;
    min-height:0;
    overflow:visible;
  }

  #profile .patient-profile-workspace{
    display:block;
    padding:12px;
  }

  #profile .patient-tab-panel:not([hidden]){
    height:auto;
    max-height:none;
    margin-top:10px;
    overflow:visible;
  }

  #profile .patient-context-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  #profile .patient-med-cost-summary{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
}

@media (max-width:600px){
  #profile .patient-header-name{
    max-width:calc(100% - 135px);
    font-size:16px;
  }

  #profile .patient-header-meta-inline{
    padding-left:0;
    width:100%;
  }

  #profile .patient-context-grid{
    grid-template-columns:1fr;
  }

  #profile .patient-context-section{
    padding:9px 0;
  }

  #profile .patient-med-cost-summary{
    grid-template-columns:1fr!important;
  }
}

/* Patient medication sub-tabs v2.31.1 */
#profile .patient-med-subtabs{
  position:sticky;
  top:0;
  z-index:3;
  display:flex;
  align-items:center;
  width:100%;
  min-width:0;
  min-height:44px;
  padding:4px;
  gap:4px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--surface-soft);
}

#profile .patient-med-subtabs button{
  flex:1 1 0;
  min-width:0;
  min-height:34px;
  padding:0 10px;
  border:1px solid transparent;
  border-radius:8px;
  background:transparent;
  color:var(--muted);
  font-size:11px;
  font-weight:800;
  line-height:1.2;
  white-space:nowrap;
}

#profile .patient-med-subtabs button:hover{
  background:var(--blue-soft);
  color:var(--text);
}

#profile .patient-med-subtabs button.active,
#profile .patient-med-subtabs button[aria-selected="true"]{
  background:var(--teal);
  color:#fff;
  border-color:var(--teal);
  box-shadow:0 4px 12px rgba(15,118,110,.12);
}

#profile .patient-med-subpanel{
  width:100%;
  min-width:0;
  max-width:100%;
}

#profile .patient-med-subpanel[hidden]{
  display:none!important;
}

#profile .patient-med-subpanel .patient-med-cost-summary{
  margin-top:0;
}

#profile .patient-med-subpanel .patient-med-change-analysis,
#profile .patient-med-subpanel .patient-med-cost-drugs{
  margin-top:0;
}

#profile .patient-med-subpanel .patient-med-history-head{
  margin-top:0;
}

@media (max-width:900px){
  #profile .patient-med-subtabs{
    overflow-x:auto;
    scrollbar-width:thin;
  }
  #profile .patient-med-subtabs button{
    flex:0 0 auto;
    min-width:132px;
  }
}

/* Per-drug medication analysis v2.31.2 */
#profile .patient-med-per-drug-analysis{
  width:100%;
  min-width:0;
}
#profile .patient-med-per-drug-analysis .patient-section-head{
  margin-bottom:8px;
}
#profile .med-per-drug-table{
  min-width:1500px;
}
#profile .med-per-drug-table th,
#profile .med-per-drug-table td{
  vertical-align:top;
}
#profile .med-per-drug-table .med-dose-cell{
  min-width:190px;
  max-width:280px;
  white-space:normal;
}
#profile .med-per-drug-table th:first-child,
#profile .med-per-drug-table td:first-child{
  min-width:130px;
}

/* Medication fiscal comparison tables v2.32.0 */
#profile .patient-med-cost-summary{
  display:block!important;
  width:100%;
  min-width:0;
}

#profile .med-summary-kpi-row{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:12px;
  width:100%;
  margin:0 0 12px;
}

#profile .med-summary-kpi-row > .patient-med-kpi{
  width:100%;
  min-width:0;
  height:100%;
}

#profile .med-total-kpi{
  min-height:82px;
}

#profile .med-fiscal-summary-table,
#profile .patient-med-fiscal-analysis{
  width:100%;
  min-width:0;
}

#profile .med-fiscal-summary-table .patient-section-head,
#profile .patient-med-fiscal-analysis > .patient-section-head{
  margin:0 0 8px;
}

#profile .med-fiscal-table{
  min-width:920px;
}

#profile .med-fiscal-table th,
#profile .med-fiscal-table td{
  white-space:nowrap;
}

#profile .med-value-up{
  font-weight:800;
  color:var(--red);
}

#profile .med-value-down{
  font-weight:800;
  color:var(--green);
}

#profile .med-fiscal-matrix-wrap{
  position:relative;
  width:100%;
  max-width:100%;
  overflow-x:auto!important;
  border:1px solid var(--line);
  border-radius:10px;
}

#profile .med-fiscal-matrix{
  width:max-content;
  min-width:100%;
  border-collapse:separate;
  border-spacing:0;
}

#profile .med-fiscal-matrix th,
#profile .med-fiscal-matrix td{
  border-bottom:1px solid var(--line);
}

#profile .med-fiscal-matrix thead th{
  position:sticky;
  top:0;
  z-index:2;
  background:var(--surface-soft);
  white-space:nowrap;
}

#profile .med-fiscal-matrix .med-drug-sticky{
  position:sticky;
  left:0;
  z-index:3;
  min-width:150px;
  max-width:190px;
  background:var(--surface);
  text-align:left;
}

#profile .med-fiscal-matrix thead .med-drug-sticky{
  z-index:5;
  background:var(--surface-soft);
}

#profile .med-fiscal-matrix .med-drug-sticky strong{
  display:block;
  font-size:12px;
  overflow-wrap:anywhere;
}

#profile .med-fiscal-matrix .med-drug-sticky small{
  display:block;
  margin-top:4px;
  color:var(--muted);
  font-weight:600;
}

#profile .med-fiscal-matrix .med-year-column,
#profile .med-fiscal-matrix .med-year-cell{
  min-width:220px;
  max-width:250px;
}

#profile .med-year-cell{
  vertical-align:top;
  padding:10px 12px;
  white-space:normal;
}

#profile .med-year-regimen{
  display:grid;
  gap:4px;
  align-content:start;
}

#profile .med-year-regimen > strong{
  font-size:11px;
  line-height:1.35;
  overflow-wrap:anywhere;
}

#profile .med-year-regimen > b{
  font-size:12px;
  line-height:1.3;
}

#profile .med-year-regimen > small{
  color:var(--muted);
  font-size:10px;
  line-height:1.4;
  overflow-wrap:anywhere;
}

#profile .med-year-strength{
  display:inline-flex;
  width:max-content;
  max-width:100%;
  padding:2px 6px;
  border:1px solid var(--line);
  border-radius:999px;
  background:var(--surface-soft);
  color:var(--text);
  font-size:10px;
  font-weight:700;
}

#profile .med-year-regimen .med-trend{
  width:max-content;
  max-width:100%;
  margin-top:2px;
}

#profile .med-year-missing{
  text-align:center;
  vertical-align:middle;
  color:var(--muted);
  background:var(--surface-soft);
}

#profile .med-latest-analysis{
  min-width:130px;
  vertical-align:middle!important;
  text-align:center;
  white-space:nowrap;
}

#profile .med-event-detail-head{
  margin:14px 0 8px!important;
}

#profile .med-event-detail-table{
  min-width:1180px;
}

#profile .med-event-detail-table td{
  vertical-align:top;
}

@media (max-width:1199px){
  #profile .med-fiscal-matrix .med-year-column,
  #profile .med-fiscal-matrix .med-year-cell{
    min-width:200px;
  }
}

@media (max-width:900px){
  #profile .med-summary-kpi-row{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
}

@media (max-width:620px){
  #profile .med-summary-kpi-row{
    grid-template-columns:minmax(0,1fr);
  }
}

/* Medication inline title + sub-tabs v2.32.1 */
#profile .patient-med-panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  width:100%;
  min-width:0;
  min-height:46px;
  margin:0!important;
  padding:0;
}

#profile .patient-med-title{
  flex:0 1 300px;
  min-width:220px;
}

#profile .patient-med-title h2{
  margin:0;
  font-size:18px;
  line-height:1.2;
}

#profile .patient-med-title > span{
  display:block;
  margin-top:3px;
  color:var(--muted);
  font-size:10px;
  line-height:1.3;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

#profile .patient-med-panel-head .patient-med-subtabs{
  position:static;
  top:auto;
  z-index:auto;
  flex:1 1 620px;
  width:auto;
  max-width:900px;
  min-width:0;
  min-height:38px;
  height:38px;
  padding:3px;
  gap:3px;
  margin:0;
}

#profile .patient-med-panel-head .patient-med-subtabs button{
  flex:1 1 0;
  min-width:0;
  min-height:30px;
  height:30px;
  padding:0 8px;
  font-size:10px;
}

@media (min-width:1000px){
  #profile .patient-tab-panel[data-profile-panel="meds"]:not([hidden]){
    gap:8px;
  }
}

@media (max-width:999px){
  #profile .patient-med-panel-head{
    align-items:stretch;
    flex-wrap:wrap;
    gap:7px;
  }

  #profile .patient-med-title{
    flex:1 1 100%;
    min-width:0;
  }

  #profile .patient-med-title > span{
    white-space:normal;
  }

  #profile .patient-med-panel-head .patient-med-subtabs{
    flex:1 1 100%;
    width:100%;
    max-width:none;
    overflow-x:auto;
    scrollbar-width:thin;
  }

  #profile .patient-med-panel-head .patient-med-subtabs button{
    flex:0 0 auto;
    min-width:126px;
  }
}


/* Patient Profile blue clinical theme + chart interaction v2.44.4 */
#profile .patient-avatar-large{
  background:linear-gradient(135deg,#dbeafe 0%,#e0f2fe 100%)!important;
  color:#1d4ed8!important;
  border:1px solid #bfdbfe;
}
#profile .profile-status-badge:not(.uncontrolled):not(.lost):not(.watch):not(.controlled){
  background:#eff6ff!important;
  color:#1d4ed8!important;
}
#profile .patient-main-tabs button.active,
#profile .patient-main-tabs button[aria-selected="true"],
#profile .patient-lab-tabs button.active,
#profile .patient-lab-tabs button[aria-selected="true"]{
  border-color:#2563eb!important;
  background:linear-gradient(135deg,#2563eb 0%,#0ea5e9 100%)!important;
  color:#fff!important;
  box-shadow:0 6px 16px rgba(37,99,235,.18)!important;
}
#profile .patient-main-tabs button:hover:not(.active),
#profile .patient-main-tabs button:hover:not([aria-selected="true"]){
  border-color:#bfdbfe;
  background:#eff6ff;
  color:#1d4ed8;
}
#profile .patient-lab-summary article:first-child strong{
  color:#1d4ed8!important;
}
#profile .patient-lab-note{
  background:#eff6ff!important;
  color:#355b86!important;
  border:1px solid #dbeafe;
}
#profile .patient-chart-panel canvas,
#profile #vitalTrendChart{
  cursor:crosshair;
}
.profile-chart-tooltip{
  position:fixed;
  z-index:12050;
  max-width:260px;
  padding:9px 11px;
  border:1px solid #bfdbfe;
  border-radius:9px;
  background:rgba(15,39,71,.96);
  color:#fff;
  box-shadow:0 10px 28px rgba(15,39,71,.20);
  font:600 11px/1.55 Prompt,sans-serif;
  white-space:pre-line;
  pointer-events:none;
}
.profile-chart-tooltip[hidden]{display:none!important}
body.dark .profile-chart-tooltip{
  border-color:#315a88;
  background:rgba(7,24,44,.97);
}


#profile .patient-vital-tabs button.active,
#profile .patient-vital-tabs button[aria-selected="true"],
#profile .patient-med-subtabs button.active,
#profile .patient-med-subtabs button[aria-selected="true"]{
  background:linear-gradient(135deg,#2563eb 0%,#0ea5e9 100%)!important;
  border-color:#2563eb!important;
  color:#fff!important;
  box-shadow:0 5px 14px rgba(37,99,235,.16)!important;
}
