/* CRM V65 refinements */

/* Therapy List and Card views */
#page-therapy .crm-therapy-view-tabs{
  flex:0 0 auto!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-card-grid{
  display:flex!important;
  flex-direction:column!important;
  gap:8px!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-session-card,
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-request-card{
  width:100%!important;
  display:grid!important;
  grid-template-columns:minmax(210px,1fr) minmax(330px,1.55fr) minmax(185px,.72fr)!important;
  align-items:center!important;
  column-gap:16px!important;
  row-gap:10px!important;
  padding:12px 14px!important;
  margin:0!important;
  border-radius:13px!important;
  box-shadow:none!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-card-head{
  margin:0!important;
  min-width:0!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-person-wrap{
  min-width:0!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-person-row{
  flex-wrap:wrap!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-meta-grid{
  display:grid!important;
  grid-template-columns:repeat(3,minmax(0,1fr))!important;
  gap:8px!important;
  margin:0!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-meta-item{
  min-height:58px!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-actions{
  display:flex!important;
  align-items:center!important;
  justify-content:flex-end!important;
  gap:7px!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  flex-wrap:wrap!important;
}
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-note-alert,
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-observation-box,
#page-therapy.crm-therapy-list-view #therapy-page-body .therapy-request-reason{
  grid-column:1 / -1!important;
  margin:0!important;
}

/* Medication action buttons use standard CRM button sizing and styling */
#page-medications .crm-med-actions{
  display:flex!important;
  align-items:center!important;
  justify-content:flex-start!important;
  gap:7px!important;
  flex-wrap:nowrap!important;
  white-space:nowrap!important;
}
#page-medications .crm-med-view-prescription,
#page-medications .crm-med-secondary-action{
  min-height:36px!important;
  height:36px!important;
  padding:0 12px!important;
  border-radius:9px!important;
  font-size:11px!important;
  line-height:1!important;
  font-weight:850!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  white-space:nowrap!important;
  box-shadow:none!important;
}
#page-medications .crm-med-view-prescription{
  border:1px solid #ff5c35!important;
  background:#ff5c35!important;
  color:#fff!important;
}
#page-medications .crm-med-view-prescription:hover{
  background:#e94f2a!important;
  border-color:#e94f2a!important;
}
#page-medications .crm-med-secondary-action{
  border:1px solid #d6e0ec!important;
  background:#fff!important;
  color:#263b54!important;
}
#page-medications .crm-med-secondary-action:hover{
  background:#f5f8fb!important;
  border-color:#bdcadd!important;
}

/* Patient file tabs alignment */
#detail-panel .dp-tabs{
  width:100%!important;
  display:flex!important;
  align-items:center!important;
  justify-content:flex-start!important;
  gap:4px!important;
  padding:10px 16px!important;
  margin:0!important;
  overflow-x:auto!important;
  overflow-y:hidden!important;
  white-space:nowrap!important;
  scrollbar-width:thin!important;
  background:#f7fafc!important;
  border-bottom:1px solid #e3ebf3!important;
}
#detail-panel .dp-tab{
  flex:0 0 auto!important;
  min-height:36px!important;
  height:36px!important;
  padding:0 11px!important;
  margin:0!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  border:1px solid transparent!important;
  border-radius:9px!important;
  font-size:11px!important;
  line-height:1!important;
  font-weight:800!important;
  color:#5f7289!important;
}
#detail-panel .dp-tab:hover{
  background:#fff!important;
  border-color:#e0e7ef!important;
  color:#263b54!important;
}
#detail-panel .dp-tab.active{
  background:#fff!important;
  border-color:#dbe4ee!important;
  color:#ff5c35!important;
  box-shadow:0 3px 10px rgba(15,23,42,.08)!important;
}
#detail-panel #dp-meds:empty:before{
  content:"Loading medications...";
  display:block;
  padding:24px;
  text-align:center;
  color:var(--text4);
}

/* Flexible patient columns. Keep phone and MR number on one line. */
#page-patients .tbl-wrap{
  overflow-x:auto!important;
}
#page-patients .crm-patients-table-v57{
  width:100%!important;
  min-width:1320px!important;
  table-layout:auto!important;
}
#page-patients .crm-patients-table-v57 th,
#page-patients .crm-patients-table-v57 td{
  overflow-wrap:normal!important;
  word-break:normal!important;
}
#page-patients .crm-patients-table-v57 th:nth-child(1),
#page-patients .crm-patients-table-v57 td:nth-child(1){min-width:155px!important;width:auto!important;}
#page-patients .crm-patients-table-v57 th:nth-child(2),
#page-patients .crm-patients-table-v57 td:nth-child(2){min-width:185px!important;width:auto!important;}
#page-patients .crm-patients-table-v57 th:nth-child(3),
#page-patients .crm-patients-table-v57 td:nth-child(3){min-width:145px!important;width:auto!important;white-space:nowrap!important;}
#page-patients .crm-patients-table-v57 th:nth-child(4),
#page-patients .crm-patients-table-v57 td:nth-child(4){min-width:125px!important;width:auto!important;white-space:nowrap!important;}
#page-patients .crm-patients-table-v57 th:nth-child(5),
#page-patients .crm-patients-table-v57 td:nth-child(5){min-width:180px!important;width:auto!important;white-space:nowrap!important;}
#page-patients .crm-patients-table-v57 th:nth-child(6),
#page-patients .crm-patients-table-v57 td:nth-child(6){min-width:120px!important;width:auto!important;white-space:nowrap!important;}
#page-patients .crm-patients-table-v57 th:nth-child(7),
#page-patients .crm-patients-table-v57 td:nth-child(7){min-width:95px!important;width:auto!important;}
#page-patients .crm-patients-table-v57 th:nth-child(8),
#page-patients .crm-patients-table-v57 td:nth-child(8){min-width:95px!important;width:auto!important;}
#page-patients .crm-patients-table-v57 th:nth-child(9),
#page-patients .crm-patients-table-v57 td:nth-child(9){min-width:190px!important;width:auto!important;white-space:nowrap!important;}
#page-patients .crm-patients-table-v57 .crm-patient-actions{
  white-space:nowrap!important;
  flex-wrap:nowrap!important;
}

body.crm-night-mode #detail-panel .dp-tabs{
  background:#252c33!important;
  border-color:#46515e!important;
}
body.crm-night-mode #detail-panel .dp-tab.active,
body.crm-night-mode #detail-panel .dp-tab:hover{
  background:#2f3741!important;
  border-color:#4a5664!important;
}
body.crm-night-mode #page-medications .crm-med-secondary-action{
  background:#2b323a!important;
  border-color:#46515e!important;
  color:#edf2f7!important;
}

@media(max-width:1080px){
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-session-card,
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-request-card{
    grid-template-columns:minmax(180px,.85fr) minmax(300px,1.4fr)!important;
  }
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-actions{
    grid-column:1 / -1!important;
    justify-content:flex-start!important;
  }
}

@media(max-width:760px){
  #page-therapy .crm-therapy-view-tabs{
    width:100%!important;
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-session-card,
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-request-card{
    display:block!important;
    padding:14px!important;
  }
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-card-head,
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-meta-grid,
  #page-therapy.crm-therapy-list-view #therapy-page-body .therapy-actions{
    margin-top:10px!important;
  }
  #page-medications .crm-med-actions{
    flex-wrap:wrap!important;
  }
  #detail-panel .dp-tabs{
    padding:9px 10px!important;
  }
}
