/* ══════════════════════════════════════════
   Patient Portal – Shared layout & sidebar
   ══════════════════════════════════════════ */

:root {
  --primary: #447569;
  --primary-dark: #03494b;
  --text: #000000;
  --muted: #565e5f;
  --border: rgba(68, 117, 105, 0.2);
  --panel-border: rgba(68, 117, 105, 0.3);
  --card-border: rgba(68, 117, 105, 0.36);
  --bg: #ffffff;
  --required: #f75624;
  --tracy-bg: rgba(215, 230, 227, 0.5);
  --send-gradient: linear-gradient(180deg, #f99522 0%, #fee478 100%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
}

body {
  min-height: 100vh;
}

/* ── Portal layout ── */

.portal-layout {
  min-height: 100vh;
  display: flex;
  background: #fff;
}

/* ── Sidebar ── */

.sidebar {
  width: 232px;
  min-width: 232px;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100vh;
  position: sticky;
  top: 0;
  background: #fff;
  transition: width 0.22s ease, min-width 0.22s ease;
  overflow: hidden;
}

.sidebar-top {
  padding: 34px 16px 0;
}

/* New wrapper around .side-nav + .sidebar-user (introduced so the mobile
   menu can drop down as a SINGLE absolute panel containing both, instead
   of pushing content in flow). On desktop it just fills the remaining
   sidebar space; .sidebar-user uses margin-top:auto to stay pinned at the
   bottom. Wrapper itself carries no padding — its two children own theirs. */
.sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-body .side-nav {
  padding: 0 16px;
}
.sidebar-body .sidebar-user {
  margin-top: auto;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 34px;
}

.brand {
  font-family: "Comfortaa", cursive;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
  text-decoration: none;
}

.menu-btn {
  border: 0;
  background: transparent;
  width: 24px;
  height: 24px;
  padding: 4px 2px;
  display: grid;
  align-content: center;
  gap: 5px;
  cursor: pointer;
}

.menu-btn span {
  display: block;
  height: 1.5px;
  width: 100%;
  background: #b2b7b6;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Animate burger → X when mobile overlay is open */
.sidebar.menu-open .menu-btn span:nth-child(1) {
  transform: translateY(6.5px) rotate(45deg);
}

.sidebar.menu-open .menu-btn span:nth-child(2) {
  opacity: 0;
}

.sidebar.menu-open .menu-btn span:nth-child(3) {
  transform: translateY(-6.5px) rotate(-45deg);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-item {
  height: 48px;
  border-radius: 31px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  color: var(--primary);
  text-decoration: none;
  font-size: 20px;
  font-weight: 500;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.nav-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
}

.nav-icon svg {
  width: 24px;
  height: 24px;
  display: block;
}

.icon-fill {
  fill: currentColor;
}

.icon-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-user {
  border-top: 1px solid #e8e8e8;
  min-height: 48px;
  padding: 8px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.sidebar-user-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  padding: 8px 13px;
  margin: -8px -13px;
  cursor: pointer;
  text-align: left;
  border-radius: 10px;
}

.sidebar-user-btn:hover {
  background: rgba(68, 117, 105, 0.06);
}

.sidebar-user-btn:focus-visible {
  outline: 2px solid rgba(68, 117, 105, 0.45);
  outline-offset: 2px;
}

.sidebar-user-caret {
  margin-left: auto;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: rgba(0, 0, 0, 0.7);
}

.sidebar-user-menu {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(100% + 8px);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 8px;
  z-index: 50;
  display: none;
}

.sidebar-user-menu.is-open {
  display: block;
}

.sidebar-user-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.sidebar-user-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-user-menu-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: block;
}

.sidebar-user-menu-item.billing,
.sidebar-user-menu-item.settings {
  color: rgba(0, 0, 0, 0.6);
}

.sidebar-user-menu-divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.07);
  margin: 4px 0;
}

.sidebar-user-menu-item.signout {
  color: #d92d20;
}

.avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  background: linear-gradient(145deg, #d6ebe6, #80a89f);
  /* Holds the user's initials (no stored photo) — centered, dark teal so it
     reads on the light gradient. */
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Inter", sans-serif;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #1c5b5d;
}

.user-meta {
  min-width: 0;
}

.user-meta .name {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 500;
}

.user-meta .email {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.2;
  color: rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 122px;
}

/* legacy .settings button removed in favor of dropdown */

/* ── Sidebar collapsed ── */

.portal-layout.sidebar-collapsed .sidebar {
  /* Collapsed rail mimics the Figma "Side nav" frame (prototype, look-only):
     64px wide, slightly translucent white, thin neutral right border.
     Use a translucent BACKGROUND (not element `opacity`) — element opacity
     would also fade every descendant, incl. the fixed user-menu pop-out, making
     it see-through. Background-only keeps icons/avatar/menu fully opaque. */
  width: 64px;
  min-width: 64px;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid #c4c7c5;
}

.portal-layout.sidebar-collapsed .sidebar-top {
  padding: 16px;
}

.portal-layout.sidebar-collapsed .brand {
  display: none;
}

.portal-layout.sidebar-collapsed .brand-row {
  justify-content: center;
  /* Drop the 34px expanded spacer — collapsed spacing is owned by the
     sidebar-top / side-nav paddings (≈24px burger→first icon). */
  margin-bottom: 0;
}

.portal-layout.sidebar-collapsed .side-nav {
  align-items: center;
  /* Figma "Main Pages": 16px gap between buttons. Horizontal gutters stay auto
     (via align-items:center) so buttons don't clip in 64px. Small top padding so
     the burger→first-icon gap reads ~24px (sidebar-top's 16px bottom + 8px). */
  gap: 16px;
  padding: 8px 0 16px;
}

/* Figma ".SideNavButton": a 48×48 button with the icon stacked OVER a tiny
   label (not icon-only). Inactive = grey icon+label; active = light-green pill
   with primary-green icon+label. */
.portal-layout.sidebar-collapsed .nav-item {
  width: 48px;
  height: 48px;
  padding: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  border-radius: 4px;
  color: #444846;
}

.portal-layout.sidebar-collapsed .nav-item.active {
  background: #eff5f1;
  color: #447569;
}

.portal-layout.sidebar-collapsed .nav-icon,
.portal-layout.sidebar-collapsed .nav-icon svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

/* The small caption under each icon (Figma "Label" was 8px; bumped to 10px for
   legibility — still fits "Documents" within the 64px rail). */
.portal-layout.sidebar-collapsed .nav-label {
  display: block;
  font-family: "Poppins", var(--font, sans-serif);
  font-size: 10px;
  font-weight: 500;
  line-height: 14px;
  letter-spacing: -0.03em;
  text-align: center;
  white-space: nowrap;
}

/* Collapsed: keep the user block pinned at the bottom of the 64px rail but show
   ONLY the avatar (centered); the name/email + caret are hidden. The avatar is
   still the menu trigger — but the rail's overflow:hidden would clip the
   dropdown, so when collapsed the menu is re-anchored as a fixed pop-out just to
   the right of the rail. */
.portal-layout.sidebar-collapsed .sidebar-user {
  padding: 10px 0;
  justify-content: center;
}

.portal-layout.sidebar-collapsed .sidebar-user-btn {
  width: auto;
  justify-content: center;
  gap: 0;
  padding: 6px;
  margin: 0;
}

.portal-layout.sidebar-collapsed .user-meta,
.portal-layout.sidebar-collapsed .sidebar-user-caret {
  display: none;
}

/* ── Sidebar responsive (≤ 900px) ── */

@media (max-width: 900px) {
  /* Mobile portal nav redesigned to match the landing-page header look:
     a clean white top bar with logo on the left and a burger on the right.
     When the burger opens, the nav drops down from BELOW the header bar
     (absolute-positioned, white bg, soft shadow) — NOT a full-screen blur
     overlay. Burger animation also mirrors landing's rotate-translate. */

  .portal-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
    background: #fff;
    z-index: 100;
    overflow: visible; /* allow drop-down to escape */
  }

  .sidebar-top {
    padding: 12px 20px;
    position: relative; /* anchor for the absolute drop-down */
  }

  /* Top bar: logo left, burger right. Kill the desktop 34px below brand. */
  .sidebar .brand-row {
    margin-bottom: 0;
  }
  .sidebar .brand {
    font-size: 24px;
  }

  /* Burger lines styled to match landing's .menu-toggle visual (thicker
     bars, dark primary color, rounded). Container sized up so the wider
     lines fit. Animation NOT touched — inherits the original portal
     translateY+rotate close behavior from the base .menu-btn rules. */
  .sidebar .menu-btn {
    width: auto;
    height: auto;
    padding: 8px;
    gap: 5px;
    position: relative;
    z-index: 10001;
  }
  .sidebar .menu-btn span {
    width: 25px;
    height: 3px;
    background: var(--primary-dark, var(--primary));
    border-radius: 2px;
  }

  /* Default mobile state: collapsed bar — only brand + burger visible.
     Hide the entire .sidebar-body wrapper (nav + user account both). */
  .sidebar .sidebar-body {
    display: none;
  }

  /* Open state: .sidebar-body becomes an absolute drop-down panel below
     the sidebar bar. The sidebar's collapsed-state height stays unchanged
     (it remains sticky at the brand-row height), so opening the menu does
     NOT push the chat / page content down. The panel overlays content. */
  .sidebar {
    position: sticky; /* keep sticky on open so the bar stays anchored */
  }
  .sidebar.menu-open .sidebar-body {
    display: flex;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    padding: 8px 0 12px;
    background: #fff;
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
    z-index: 10000;
    max-height: calc(100dvh - 100%);
    overflow-y: auto;
  }
  /* Inside the drop-down: side-nav at top, user at bottom (natural in-flow
     stacking inside the absolute panel — no margin-top:auto needed since
     the panel is height: auto). */
  .sidebar.menu-open .sidebar-body .side-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 16px 12px;
  }
  .sidebar.menu-open .sidebar-body .sidebar-user {
    margin-top: 0;
    padding: 12px 16px 4px;
    border-top: 1px solid var(--panel-border);
  }

  /* Nav items in the drop-down: slimmer than desktop's 48px pill, lighter
     visual weight, icons retained for at-a-glance scan. */
  .sidebar.menu-open .nav-item {
    height: 42px;
    font-size: 15px;
    gap: 12px;
    padding: 0 14px;
    border-radius: 10px;
  }
  .sidebar.menu-open .nav-icon,
  .sidebar.menu-open .nav-icon svg {
    width: 18px;
    height: 18px;
  }
  .sidebar.menu-open .nav-icon {
    flex: 0 0 18px;
  }

  /* Desktop's sidebar-collapsed has no meaning on mobile (we use .menu-open instead);
     ensure rules from desktop don't leak. */
  .portal-layout.sidebar-collapsed .sidebar {
    width: 100%;
    min-width: 100%;
  }
}

/* ── Portal boot loading overlay ── */

.portal-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg);
}

.portal-loading-overlay.is-hidden {
  display: none;
  pointer-events: none;
}

.portal-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.portal-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: portal-loading-spin 0.75s linear infinite;
}

@keyframes portal-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.portal-loading-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
}
