/* Patient Shelf — inline bottom panel */

/* When shelf is open, lock dashboard to viewport height so grid scrolls independently */
.dashboard--shelf-open {
  height: 100vh;
  overflow: hidden;
}

.dashboard--shelf-open .dashboard-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.patient-shelf {
  flex-shrink: 0;
  height: 0;
  overflow: hidden;
  background-color: var(--c-app-bg);
  display: flex;
  flex-direction: column;
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.patient-shelf--open {
  height: var(--shelf-height, 50vh);
}

/* Header */

.patient-shelf__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.patient-shelf__header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.patient-shelf__avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background-color: var(--c-brand);
  color: var(--c-brand-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
}

.patient-shelf__title {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--c-base-text);
}

.patient-shelf__heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2rem;
  min-width: 0;
  flex: 1;
}

.patient-shelf__heading-sections {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}

.patient-shelf__heading-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

/* Stretch the recent-reports section to consume remaining horizontal space. */
.patient-shelf__heading-section[data-patient-shelf-target="recentReportsSection"] {
  flex: 1;
}

.patient-shelf__heading-icon {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--c-base-subtitle-text);
  flex-shrink: 0;
  display: block;
}

/* Custom tooltip — appears instantly on hover. */
.patient-shelf__tooltip-host {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
}

.patient-shelf__tooltip-host[data-tooltip]:hover::after,
.patient-shelf__tooltip-host[data-tooltip]:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.65rem;
  background-color: var(--c-popup-bg);
  color: var(--c-base-text);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  border-radius: 0.375rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12), 0 0 0 1px var(--c-border);
}

.patient-shelf__tooltip-host[data-tooltip]:hover::before,
.patient-shelf__tooltip-host[data-tooltip]:focus-visible::before {
  content: "";
  position: absolute;
  top: calc(100% + 0.15rem);
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 0.5rem;
  height: 0.5rem;
  background-color: var(--c-popup-bg);
  border-top: 1px solid var(--c-border);
  border-left: 1px solid var(--c-border);
  pointer-events: none;
  z-index: 1000;
}

.patient-shelf__heading-meta {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--c-base-subtitle-text);
  white-space: nowrap;
}

.patient-shelf__severity-badge {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.25rem 0.85rem;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  color: #fff;
  background-color: var(--c-base-subtitle-text);
}

.patient-shelf__severity-badge--good     { background-color: var(--c-severity-good); }
.patient-shelf__severity-badge--bad      { background-color: var(--c-severity-bad); color: #1A1A1A; }
.patient-shelf__severity-badge--severe   { background-color: var(--c-severity-severe); }
.patient-shelf__severity-badge--critical { background-color: var(--c-severity-critical); }

.patient-shelf__recent-reports {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  min-width: 0;
  padding-bottom: 0.25rem;
  scrollbar-width: thin;
}

.patient-shelf__recent-reports > .patient-shelf__report-chip {
  flex: 0 0 auto;
}

.patient-shelf__report-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.6rem 0.25rem 0.25rem;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-family: inherit;
  text-align: left;
  background-color: var(--c-popup-bg);
  color: inherit;
  max-width: 100%;
}

.patient-shelf__report-chip--clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.patient-shelf__report-chip--clickable:hover {
  border-color: var(--c-brand);
  background-color: var(--c-brand-highlight);
}

.patient-shelf__report-chip--empty .patient-shelf__report-chip-dot {
  background-color: #F3F4F6;
}

.patient-shelf__report-chip-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background-color: var(--c-base-subtitle-text);
  flex-shrink: 0;
  overflow: hidden;
}

.patient-shelf__report-chip-dot--shrink-1 { font-size: 0.6875rem; }
.patient-shelf__report-chip-dot--shrink-2 { font-size: 0.5625rem; letter-spacing: -0.02em; }
.patient-shelf__report-chip-dot--shrink-3 { font-size: 0.5rem;    letter-spacing: -0.04em; }

.patient-shelf__report-chip-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.15;
  min-width: 0;
}

.patient-shelf__report-chip--good .patient-shelf__report-chip-dot     { background-color: var(--c-severity-good); }
.patient-shelf__report-chip--bad .patient-shelf__report-chip-dot      { background-color: var(--c-severity-bad); color: #1A1A1A; }
.patient-shelf__report-chip--severe .patient-shelf__report-chip-dot   { background-color: var(--c-severity-severe); }
.patient-shelf__report-chip--critical .patient-shelf__report-chip-dot { background-color: var(--c-severity-critical); }

.patient-shelf__report-chip-label {
  color: var(--c-base-text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16ch;
}

.patient-shelf__report-chip-extra {
  color: var(--c-base-subtitle-text);
  font-weight: 500;
  font-size: 0.6875rem;
}

.patient-shelf__report-chip-time {
  color: var(--c-base-subtitle-text);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.patient-shelf__header-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 1.5rem;
  flex-shrink: 0;
}

.patient-shelf__reset {
  width: 2rem;
  height: 2rem;
  border: none;
  background: none;
  color: var(--c-base-subtitle-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.patient-shelf__reset:hover {
  color: var(--c-brand);
  background-color: var(--c-brand-highlight);
}

.patient-shelf__reset svg {
  width: 1.125rem;
  height: 1.125rem;
}

.patient-shelf__view-toggle {
  width: 2rem;
  height: 2rem;
  border: none;
  background: none;
  color: var(--c-base-subtitle-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.patient-shelf__view-toggle:hover {
  color: var(--c-brand);
  background-color: var(--c-brand-highlight);
}

.patient-shelf__view-toggle svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* Tabular view of a series */
.patient-shelf__series-table-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
}

.patient-shelf__series-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.patient-shelf__series-table th,
.patient-shelf__series-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.patient-shelf__series-table th {
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-base-subtitle-text);
  position: sticky;
  top: 0;
  background-color: var(--c-popup-bg);
  z-index: 1;
}

.patient-shelf__series-table tbody tr:hover {
  background-color: var(--c-brand-highlight);
}

.patient-shelf__series-table-date {
  vertical-align: top;
  font-weight: 600;
  white-space: nowrap;
  padding-top: 0.5rem !important;
}

.patient-shelf__series-table-time-main {
  line-height: 1.15;
}

.patient-shelf__series-table-time-meta {
  font-size: 0.6875rem;
  color: var(--c-base-subtitle-text);
  line-height: 1.15;
  margin-top: 0.1rem;
}

.patient-shelf__series-table-row--day-start td {
  border-top: 2px solid var(--c-border);
}

.patient-shelf__series-table tbody tr:first-child td {
  border-top: none;
}

/* Holistic pivot table: column-per-series, day-grouped, planned/extras sections. */
.patient-shelf__series-table--pivot {
  table-layout: auto;
  width: max-content;
  min-width: 100%;
}

.patient-shelf__series-table--pivot th,
.patient-shelf__series-table--pivot td {
  white-space: nowrap;
}

.patient-shelf__series-table-day-header td {
  font-weight: 700;
  font-size: 0.875rem;
  padding-top: 0.7rem !important;
  padding-bottom: 0.4rem !important;
  background-color: rgba(0, 0, 0, 0.025);
  border-top: 2px solid var(--c-border);
}

.patient-shelf__series-table--pivot tbody tr:first-child td {
  border-top: none;
}

.patient-shelf__series-table-extras-sep td {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--c-base-subtitle-text);
  padding: 0.25rem 0.6rem !important;
  border-top: 1px dashed var(--c-border);
}

.patient-shelf__series-table-rowlabel {
  color: var(--c-base-subtitle-text);
  font-size: 0.75rem;
  white-space: nowrap;
}

.patient-shelf__holistic-day-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.patient-shelf__holistic-day-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--c-base-text);
  font-variant-numeric: tabular-nums;
}


.patient-shelf__grade-swatch {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background-color: var(--c-base-subtitle-text);
  margin-right: 0.45rem;
  vertical-align: middle;
}

.patient-shelf__series-table-param {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.patient-shelf__series-table-param-dot {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background-color: var(--c-base-subtitle-text);
  flex-shrink: 0;
}

.patient-shelf__complex-table-pane {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100%;
  overflow: hidden;
}

.patient-shelf__complex-table-pane .complex-view__toggles {
  flex-shrink: 0;
}

.patient-shelf__complex-table-pane .patient-shelf__series-table-wrap {
  flex: 1;
  min-height: 0;
}

.patient-shelf__grade-swatch--good     { background-color: var(--c-severity-good); }
.patient-shelf__grade-swatch--bad      { background-color: var(--c-severity-bad); }
.patient-shelf__grade-swatch--severe   { background-color: var(--c-severity-severe); }
.patient-shelf__grade-swatch--critical { background-color: var(--c-severity-critical); }

.patient-shelf__close {
  width: 2rem;
  height: 2rem;
  border: none;
  background: none;
  color: var(--c-base-subtitle-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.patient-shelf__close:hover {
  color: var(--c-base-text);
  background-color: var(--c-brand-highlight);
}

.patient-shelf__close svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Body — two panels side-by-side */

.patient-shelf__body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.patient-shelf__panel:first-child {
  flex: 0 0 var(--panel-split, 50%);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.patient-shelf__panel:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Tabs */

.patient-shelf__tabs-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  min-width: 0;
}

.patient-shelf__tabs-row .patient-shelf__tabs {
  flex: 1;
  border-bottom: none;
  min-width: 0;
}

.patient-shelf__right-toolbar {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  border-right: 1px solid var(--c-border);
  flex-shrink: 0;
}

.patient-shelf__tabs {
  display: flex;
  gap: 1.5rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.patient-shelf__tabs::-webkit-scrollbar {
  display: none;
}

.patient-shelf__tab {
  padding: 0.75rem 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-base-subtitle-text);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.patient-shelf__tab:hover {
  color: var(--c-base-text);
}

.patient-shelf__tab--active {
  color: var(--c-base-text);
  border-bottom-color: var(--c-brand);
}

/* Panes */

.patient-shelf__panes {
  flex: 1;
  min-height: 0;
  position: relative;
}

.patient-shelf__pane {
  display: none;
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  position: absolute;
  inset: 0;
}

.patient-shelf__pane--active {
  display: flex;
  flex-direction: column;
}

/* Info rows */

.patient-shelf__info-row {
  display: flex;
  align-items: baseline;
  padding: 0.5rem 0;
}

.patient-shelf__info-row + .patient-shelf__info-row {
  border-top: 1px solid var(--c-border);
}

.patient-shelf__info-label {
  width: 140px;
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--c-base-subtitle-text);
}

.patient-shelf__info-value {
  font-size: 0.875rem;
  color: var(--c-base-text);
}

/* Treatment progress bar */

.patient-shelf__progress-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.patient-shelf__progress-track {
  flex: 1;
  height: 0.5rem;
  background-color: var(--c-border);
  border-radius: 0.25rem;
  overflow: hidden;
}

.patient-shelf__progress-bar {
  height: 100%;
  width: 0%;
  background-color: var(--c-brand);
  border-radius: 0.25rem;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.patient-shelf__progress-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-base-text);
  white-space: nowrap;
  min-width: 2.5rem;
}

/* Placeholder for coming-soon tabs */

.patient-shelf__placeholder {
  padding: 2rem 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--c-base-subtitle-text);
}

/* Horizontal drag handle (between grid and shelf) */

.patient-shelf__h-handle {
  height: 6px;
  cursor: row-resize;
  background: transparent;
  border-top: 1px solid var(--c-border);
  flex-shrink: 0;
  display: none;
}

.dashboard--shelf-open .patient-shelf__h-handle {
  display: block;
}

.patient-shelf__h-handle:hover {
  border-top-color: var(--c-brand);
}

/* Vertical drag handle (between left and right panels) */

.patient-shelf__v-handle {
  width: 6px;
  cursor: col-resize;
  background: transparent;
  border-left: 1px solid var(--c-border);
  flex-shrink: 0;
}

.patient-shelf__v-handle:hover {
  border-left-color: var(--c-brand);
}

/* Holistic overview — single overlay chart */

.patient-shelf__holistic-chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.patient-shelf__chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.5rem;
  border-top: 1px solid var(--c-border);
}

.patient-shelf__chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.patient-shelf__chart-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.patient-shelf__chart-legend-text {
  font-size: 0.75rem;
  color: var(--c-base-subtitle-text);
  transition: all 0.1s ease;
}

.patient-shelf__chart-legend-item--active .patient-shelf__chart-legend-text {
  text-decoration: underline;
  text-decoration-color: var(--c-brand);
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
  color: var(--c-base-text);
}

.patient-shelf__chart-legend-year {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--c-base-subtitle-text);
  white-space: nowrap;
}

/* Chart container */

.patient-shelf__chart-container {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 0.5rem;
}

/* Photo gallery — horizontal scroll */

.patient-shelf__photo-gallery {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1 1 0;
  min-height: 0;
  scrollbar-width: thin;
}

.patient-shelf__photo-gallery::-webkit-scrollbar {
  height: 4px;
}

.patient-shelf__photo-gallery::-webkit-scrollbar-thumb {
  background-color: var(--c-border);
  border-radius: 2px;
}

.patient-shelf__photo-item {
  flex: 0 0 auto;
}

.patient-shelf__photo-thumb {
  display: block;
  width: auto;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.patient-shelf__photo-thumb:hover {
  opacity: 0.8;
}

.patient-shelf__photo-caption {
  font-size: 0.6875rem;
  line-height: 1;
  color: var(--c-base-subtitle-text);
  white-space: nowrap;
  margin-top: 0.25rem;
}

/* Tab drag-and-drop */

.patient-shelf__tab[draggable="true"] {
  cursor: grab;
}

.patient-shelf__tab--dragging {
  opacity: 0.35;
}

.patient-shelf__tabs--drop-target {
  background-color: var(--c-brand-highlight);
  border-bottom-color: var(--c-brand);
}

/* Complex view — toggle panel */

.complex-view__toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 0 0.5rem;
  flex-shrink: 0;
}

.complex-view__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 1rem;
  border: 1px solid var(--c-border);
  background: var(--c-app-bg);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.complex-view__toggle:hover {
  border-color: var(--c-base-subtitle-text);
}

.complex-view__toggle--active {
  border-color: var(--c-brand);
  background: var(--c-brand-highlight);
}

.complex-view__toggle--all {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-base-subtitle-text);
  padding: 0.25rem 0.75rem;
}

.complex-view__toggle--all.complex-view__toggle--active {
  color: var(--c-base-text);
}

.complex-view__checkbox {
  display: none;
}

.complex-view__toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.complex-view__toggle--active .complex-view__toggle-dot {
  opacity: 1;
}

.complex-view__toggle-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-base-subtitle-text);
  transition: color 0.15s ease;
}

.complex-view__toggle--active .complex-view__toggle-name {
  color: var(--c-base-text);
}

.complex-view__toggle-type {
  font-size: 0.625rem;
  color: var(--c-base-subtitle-text);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Dragging state — disable transitions and text selection */

.patient-shelf--dragging,
.patient-shelf--dragging * {
  transition: none !important;
  user-select: none;
}
