/**
 * HerbariumIQ Workstation Shell, Navigation, Drawers & Responsive Tables
 */

/* ==========================================================================
   1. Workstation Shell (Top Header + Persistent Left Sidebar + Main Workspace)
   ========================================================================== */
.herbarium-app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width-expanded) minmax(0, 1fr);
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  grid-template-areas:
    "header header"
    "sidebar workspace";
  min-block-size: 100dvh;
  background-color: var(--herbariumiq-ivory);
}

body[data-sidebar-collapsed="true"] .herbarium-app-shell {
  grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr);
}

/* Top Platform Header */
.herbarium-top-header {
  grid-area: header;
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  gap: 1rem;
  padding-inline: 1.25rem;
  block-size: var(--header-height);
  background-color: var(--herbariumiq-header-bg, var(--herbariumiq-forest));
  color: #ffffff;
  border-block-end: 1px solid rgba(255, 255, 255, 0.14);
  transition: background-color 0.25s ease;
  z-index: 40;
}

.herbarium-brand-group {
  display: flex;
  align-items: safe center;
  gap: 0.75rem;
  min-inline-size: 0;
}

.herbarium-brand-title {
  font-family: "Georgia", serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.herbarium-brand-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.14);
  color: #e6f2ec;
}

/* Global View Toggle Control in Header */
.herbarium-global-toggle-bar {
  display: flex;
  align-items: safe center;
  gap: 0.75rem;
  background-color: rgba(0, 0, 0, 0.24);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.herbarium-mode-pill-group {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.herbarium-mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  min-block-size: 34px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.herbarium-mode-btn[aria-pressed="true"] {
  background-color: var(--herbariumiq-teal-pop);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

body[data-herbarium-mode="clinical"] .herbarium-mode-btn[data-mode-target="clinical"][aria-pressed="true"] {
  background-color: var(--herbariumiq-amber-pop);
  color: #141a17;
}

.herbarium-mode-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8125rem;
  color: #ffffff;
  cursor: pointer;
}

/* ==========================================================================
   2. Persistent Left Sidebar (8 Primary Platform Navigation Items)
   ========================================================================== */
.herbarium-sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: var(--herbariumiq-forest);
  color: #ffffff;
  border-inline-end: 1px solid rgba(255, 255, 255, 0.12);
  padding-block: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.herbarium-sidebar-list {
  list-style: none;
  margin: 0;
  padding-inline: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.herbarium-nav-link {
  display: flex;
  align-items: safe center;
  gap: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.herbarium-nav-link:hover,
.herbarium-nav-link[aria-current="page"] {
  background-color: var(--herbariumiq-teal-pop);
  color: #ffffff;
}

.herbarium-nav-icon {
  inline-size: 20px;
  block-size: 20px;
  flex-shrink: 0;
}

body[data-sidebar-collapsed="true"] .herbarium-nav-label,
body[data-sidebar-collapsed="true"] .herbarium-sidebar-footer-text {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  white-space: nowrap !important;
}

body[data-sidebar-collapsed="true"] .herbarium-nav-link {
  justify-content: center;
  padding-inline: 0.5rem;
}

.herbarium-sidebar-collapse-btn {
  margin-inline: 0.75rem;
  margin-block-start: 1rem;
  display: flex;
  align-items: safe center;
  justify-content: center;
  gap: 0.5rem;
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
}

/* ==========================================================================
   3. Mobile Navigation Drawer (< 900px) - Modern Scroll-Snap Popover Sheet
   ========================================================================== */
.herbarium-mobile-menu-trigger {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
}

.Drawer {
  --drawer-width: min(20em, 80dvw);
  --drawer-backdrop: 0;
  width: auto;
  height: auto;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  overflow: visible;
  inset: 0;
}

.Drawer::backdrop {
  background: #000000;
  opacity: calc(var(--drawer-backdrop) / 2);
}

.Drawer-scroller {
  position: relative;
  display: grid;
  grid-template-columns: var(--drawer-width) 100%;
  overflow-x: scroll;
  overscroll-behavior: none;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}

@media (prefers-reduced-motion: no-preference) {
  .Drawer-scroller {
    scroll-behavior: smooth;
  }
}

.Drawer-scroller::after {
  content: "";
  scroll-snap-align: end;
  scroll-initial-target: nearest;
}

.Drawer-sheet {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100svh;
  background: var(--herbariumiq-forest);
  color: #ffffff;
  overflow-y: auto;
  scroll-snap-align: start;
  scrollbar-width: none;
  padding: 1.25rem;
}

@supports (animation-timeline: scroll()) {
  .Drawer {
    timeline-scope: --drawer-fade;
    animation: fade-drawer-backdrop linear both;
    animation-timeline: --drawer-fade;
  }

  .Drawer-scroller {
    scroll-timeline: --drawer-fade x;
  }

  @property --drawer-backdrop {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
  }

  @keyframes fade-drawer-backdrop {
    0% { --drawer-backdrop: 1; }
    100% { --drawer-backdrop: 0; }
  }
}

@media (max-width: 900px) {
  .herbarium-app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "workspace";
  }

  .herbarium-sidebar {
    display: none;
  }

  .herbarium-mobile-menu-trigger {
    display: inline-flex;
  }
}

/* ==========================================================================
   4. Secondary Slide-Out Detail Drawer ("View Full" / "Read Full")
   ========================================================================== */
.herbarium-detail-drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  inline-size: var(--drawer-width-desktop);
  max-inline-size: 100dvw;
  block-size: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-inline-start: 2px solid var(--herbariumiq-border-strong);
  background-color: var(--herbariumiq-ivory);
  color: var(--herbariumiq-charcoal);
  box-shadow: -12px 0 36px rgba(20, 51, 38, 0.22);
  z-index: 90;
  display: none;
  flex-direction: column;
}

.herbarium-detail-drawer[open],
.herbarium-detail-drawer.is-open {
  display: flex;
}

.herbarium-detail-drawer::backdrop {
  background-color: rgba(20, 51, 38, 0.48);
}

.herbarium-drawer-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  display: flex;
  align-items: safe center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background-color: var(--herbariumiq-forest);
  color: #ffffff;
  border-block-end: 1px solid var(--herbariumiq-border-subtle);
}

.herbarium-drawer-title {
  color: #ffffff;
  font-size: 1.25rem;
  margin: 0;
}

.herbarium-drawer-close {
  position: sticky;
  inset-block-start: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.herbarium-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 1.5rem;
}

@media (max-width: 900px) {
  .herbarium-detail-drawer {
    inline-size: 100dvw;
    border-inline-start: 0;
  }
}

/* ==========================================================================
   5. Responsive Sticky Clinical Data Table (@container query stacked fallback)
   ========================================================================== */
.clinical-data-table-wrapper,
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(500px, 80vh);
  container-type: inline-size;
  border: 1px solid var(--herbariumiq-border-subtle);
  border-radius: 8px;
  background: #ffffff;
}

.herbarium-clinical-table {
  inline-size: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}

.herbarium-clinical-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  background-color: var(--herbariumiq-forest);
  color: #ffffff;
}

.herbarium-clinical-table th,
.herbarium-clinical-table td {
  padding: 0.65rem 0.85rem;
  text-align: start;
  border-block-end: 1px solid var(--herbariumiq-border-subtle);
}

.herbarium-clinical-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: #ffffff;
  font-weight: 700;
  color: var(--herbariumiq-forest);
}

@container (width < 600px) {
  .herbarium-clinical-table,
  .herbarium-clinical-table thead,
  .herbarium-clinical-table tbody,
  .herbarium-clinical-table tr,
  .herbarium-clinical-table th,
  .herbarium-clinical-table td {
    display: block;
  }

  .herbarium-clinical-table thead {
    display: none;
  }

  .herbarium-clinical-table tr {
    margin-block-end: 1.25rem;
    border: 1px solid var(--herbariumiq-border-strong);
    border-radius: 6px;
  }

  .herbarium-clinical-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--herbariumiq-parchment);
  }

  .herbarium-clinical-table {
    --label-2: "Study Design";
    --label-3: "Population (N)";
    --label-4: "Extract & Dose";
    --label-5: "Outcomes & Limits";
    --label-6: "PubMed Source";
  }

  .herbarium-clinical-table td:nth-child(2)::before {
    content: var(--label-2) ": " / var(--label-2);
    font-weight: 700;
  }

  .herbarium-clinical-table td:nth-child(3)::before {
    content: var(--label-3) ": " / var(--label-3);
    font-weight: 700;
  }

  .herbarium-clinical-table td:nth-child(4)::before {
    content: var(--label-4) ": " / var(--label-4);
    font-weight: 700;
  }

  .herbarium-clinical-table td:nth-child(5)::before {
    content: var(--label-5) ": " / var(--label-5);
    font-weight: 700;
  }

  .herbarium-clinical-table td:nth-child(6)::before {
    content: var(--label-6) ": " / var(--label-6);
    font-weight: 700;
  }
}
