/* ==========================================================================
   Layout — the shell, after the intranet's app-shell.tsx.

   src/components/topbar.js draws it on every signed-in page:

     .rail        the dark surgical-blue instrument rail on the left: the
                  wordmark, the pages as capsules with a squircle icon, and a
                  control to collapse it to icons. Below 1024 px it is a drawer
                  behind the menu button.
     .topbar      the ink bar over the page: the hospital, the page's own
                  actions and the user menu.

   The page itself starts beside the rail and under the bar, with the
   intranet's page padding.
   ========================================================================== */

/* ---------- Page column beside the rail ---------- */
@media (min-width: 1024px) {
  body.has-rail { padding-left: var(--rail-width); }
  body.has-rail.rail-collapsed { padding-left: var(--rail-width-collapsed); }
}

/* ---------- The shell's first frame ----------
   Every app page has an empty <header id="topbar"> until
   src/components/topbar.js fills it. From the first frame the page sits
   beside the rail and the ink bar and rail are drawn where they will be, so
   a menu click neither flashes nor makes the content jump. The rail's width
   comes from <html data-rail-collapsed> (design-system/theme.js, before
   paint) or <html data-rail="compact">. A page without a rail says so:
   <header id="topbar" data-nav="none">. */
@media (min-width: 1024px) {
  body:has(> #topbar:not([data-nav="none"])) { padding-left: var(--rail-width); }
  html[data-rail="compact"] body:has(> #topbar:not([data-nav="none"])),
  html[data-rail-collapsed] body:has(> #topbar:not([data-nav="none"])) { padding-left: var(--rail-width-collapsed); }
}
#topbar:empty {
  position: sticky;
  top: 0;
  z-index: 40;
  display: block;
  height: var(--bar-height);
  background: var(--ink-bar);
}
@media (min-width: 1024px) {
  #topbar:empty:not([data-nav="none"])::after {
    content: "";
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: var(--rail-width);
    background: var(--ink-rail);
  }
  html[data-rail="compact"] #topbar:empty::after,
  html[data-rail-collapsed] #topbar:empty::after { width: var(--rail-width-collapsed); }
}

/* Moving between pages: browsers that can (Chrome, Edge, Safari) cross-fade
   from one page to the next instead of blanking; the shell is the same on
   both, so only the content changes. */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.18s; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--bar-height);
  padding: 0 clamp(1rem, 2vw, 1.5rem);
  padding-top: env(safe-area-inset-top);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
/* The ink ground at 88 % with the page blurring under it. It is drawn on a
   pseudo-element, not the bar: a backdrop filter on the bar itself would make
   it the containing block of the fixed rail inside it. */
.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: hsl(217 72% 9% / 0.88);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
}
@supports not ((backdrop-filter: blur(0)) or (-webkit-backdrop-filter: blur(0))) {
  .topbar::before { background: var(--ink-bar); }
}
.topbar .capla-wordmark { color: #fff; }

.topbar__menu {
  display: none;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin-left: -0.25rem;
  border: 0;
  border-radius: var(--radius-field);
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.topbar__menu:hover { background: rgba(255, 255, 255, 0.1); }
.topbar__menu svg { width: 1.25rem; height: 1.25rem; }
.topbar__brand .capla-wordmark__logo { height: 1.5rem; }

/* With a rail, the bar's own wordmark and menu button are for narrow screens. */
@media (min-width: 1024px) {
  body.has-rail .topbar__brand { display: none; }
}
@media (max-width: 1023.98px) {
  body.has-rail .topbar__menu { display: inline-grid; }
}

.topbar__tenant { min-width: 0; margin-left: 0.25rem; }
/* Dev and local copies of the portal: test data only (src/config.js environment). */
.topbar__env {
  flex: none;
  padding: 0.1875rem 0.5rem;
  border: 1px solid hsl(var(--warning) / 0.6);
  border-radius: 999px;
  background: hsl(var(--warning) / 0.2);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 0.75rem; min-width: 0; margin-left: auto; }
.topbar__actions .btn--ghost { --btn-bg: rgba(255, 255, 255, 0.1); --btn-fg: #fff; --btn-bg-hover: rgba(255, 255, 255, 0.16); }

/* ---------- Rail ---------- */
.rail {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: var(--rail-width);
  color: #fff;
  background: var(--ink-rail);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  transition: width 0.2s var(--ease-capla), transform 0.25s var(--ease-capla);
}
body.rail-collapsed .rail { width: var(--rail-width-collapsed); }

.rail__head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.625rem;
  height: var(--bar-height);
  padding: 0 1.25rem;
}
.rail__head .capla-wordmark__logo { height: 1.75rem; }
.rail__product {
  font-size: 10px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
}
.rail__mark { display: none; width: 1.75rem; height: 1.75rem; color: #fff; }
.rail__mark svg { width: 100%; height: 100%; }

.rail__nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.rail__section { display: flex; flex-direction: column; gap: 0.125rem; }
/* A section whose every page is role-gated away disappears with its heading. */
.rail__section:not(:has(.home-nav__link:not([hidden]))) { display: none; }
.rail__heading {
  margin-bottom: 0.375rem;
  padding: 0 0.75rem;
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
}

/* A filled capsule for the current page, the way a source list marks
   selection; the icon sits in a squircle that lights up in the brand blue. */
.home-nav__link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 0.5rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  transition:
    transform 0.34s var(--ease-spring),
    background-color 0.2s ease,
    color 0.2s ease;
}
.home-nav__link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.home-nav__link:active { transform: scale(0.972); }
.home-nav__link.is-active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: var(--weight-semibold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.home-nav__link[hidden] { display: none; }
.home-nav__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 30%;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.55);
  transition: color 0.2s ease;
}
.home-nav__icon svg { width: 17px; height: 17px; stroke-width: 1.9; }
.home-nav__link:hover .home-nav__icon { color: rgba(255, 255, 255, 0.85); }
.home-nav__link.is-active .home-nav__icon {
  background-image: linear-gradient(180deg, #4aa3ff, #0b59bf);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.home-nav__link.is-active .home-nav__icon svg { stroke-width: 2.3; }
.home-nav__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rail__foot {
  flex: none;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.rail__toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: var(--radius-field);
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.rail__toggle:hover { background: rgba(255, 255, 255, 0.05); color: rgba(255, 255, 255, 0.8); }
.rail__toggle svg { width: 18px; height: 18px; flex: none; }
.rail__toggle .when-collapsed { display: none; }

/* Collapsed: icons only, a hairline for each section heading. */
body.rail-collapsed .rail__head { justify-content: center; padding: 0; }
body.rail-collapsed .rail__head .capla-wordmark,
body.rail-collapsed .rail__product { display: none; }
body.rail-collapsed .rail__mark { display: block; }
body.rail-collapsed .rail__nav { padding: 1rem 0.5rem; gap: 0.75rem; }
body.rail-collapsed .rail__heading {
  height: 1px;
  width: 1.5rem;
  margin: 0 auto 0.5rem;
  padding: 0;
  overflow: hidden;
  color: transparent;
  background: rgba(255, 255, 255, 0.1);
}
body.rail-collapsed .home-nav__link { justify-content: center; padding: 0.5rem 0; }
body.rail-collapsed .home-nav__label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
body.rail-collapsed .rail__foot { padding: 0.5rem; }
body.rail-collapsed .rail__toggle { justify-content: center; padding: 0.5rem 0; }
body.rail-collapsed .rail__toggle .when-expanded { display: none; }
body.rail-collapsed .rail__toggle .when-collapsed { display: inline; }
body.rail-collapsed .rail__toggle-label { display: none; }

/* Narrow screens: the rail is a drawer behind the menu button. */
.rail-scrim { display: none; }
@media (max-width: 1023.98px) {
  .rail { width: min(16rem, 85vw); transform: translateX(-100%); box-shadow: var(--shadow-xl); }
  body.rail-collapsed .rail { width: min(16rem, 85vw); }
  body.rail-open .rail { transform: none; }
  body.rail-open .rail-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0, 0, 0, 0.5);
  }
  .rail__foot { display: none; }
  /* The drawer always shows labels, whatever the desktop rail was set to. */
  body.rail-collapsed .rail__head { justify-content: flex-start; padding: 0 1.25rem; }
  body.rail-collapsed .rail__head .capla-wordmark,
  body.rail-collapsed .rail__product { display: inline-flex; }
  body.rail-collapsed .rail__mark { display: none; }
  body.rail-collapsed .rail__nav { padding: 1rem 0.875rem; gap: 1.25rem; }
  body.rail-collapsed .rail__heading { height: auto; width: auto; margin: 0 0 0.375rem; padding: 0 0.75rem; color: rgba(255, 255, 255, 0.4); background: none; }
  body.rail-collapsed .home-nav__link { justify-content: flex-start; padding: 0.5rem 0.75rem 0.5rem 0.5rem; }
  body.rail-collapsed .home-nav__label { position: static; width: auto; height: auto; clip: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .rail, .home-nav__link { transition: none; }
}

/* ---------- User menu (user-menu.tsx) ---------- */
.user-menu { position: relative; min-width: 0; }
.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  padding: 0.125rem 0.5rem 0.125rem 0.125rem;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition: transform 0.34s var(--ease-spring), background-color 0.2s ease;
}
.user-menu__trigger:hover { background: rgba(255, 255, 255, 0.05); }
.user-menu__trigger:active { transform: scale(0.972); }
.user-menu__avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-full);
  background-image: linear-gradient(160deg, #4aa3ff, #0b59bf);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: 13px;
  font-weight: var(--weight-bold);
  letter-spacing: 0.02em;
}
.user-menu__who { display: none; min-width: 0; text-align: right; line-height: 1.2; }
@media (min-width: 40rem) { .user-menu__who { display: block; } }
.user-menu__name { display: block; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.user-menu__role { display: block; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: rgba(255, 255, 255, 0.5); }
.user-menu__caret { display: none; width: 1rem; height: 1rem; color: rgba(255, 255, 255, 0.5); }
@media (min-width: 40rem) { .user-menu__caret { display: block; } }
.user-menu__caret svg { width: 100%; height: 100%; }

.user-menu__panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 60;
  width: 18rem;
  padding: 0.5rem;
  color: hsl(var(--card-foreground));
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-field);
  box-shadow: var(--shadow-xl);
}
.user-menu__panel[hidden] { display: none; }
.user-menu__head { padding: 0.375rem 0.5rem; }
.user-menu__panel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.user-menu__panel-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-xs); color: hsl(var(--muted-foreground)); }
.user-menu__sep { height: 1px; margin: 0.25rem 0; background: hsl(var(--border)); }
.user-menu__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: hsl(var(--foreground));
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.user-menu__item:hover { background: hsl(var(--muted)); text-decoration: none; }
.user-menu__item svg { width: 1rem; height: 1rem; flex: none; }
.user-menu__label { padding: 0.5rem 0.5rem 0.25rem; font-size: var(--text-xs); font-weight: var(--weight-medium); color: hsl(var(--muted-foreground)); }
.user-menu__themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.25rem; padding: 0 0.25rem; }
.user-menu__theme {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: hsl(var(--muted-foreground));
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.user-menu__theme svg { width: 1rem; height: 1rem; }
.user-menu__theme:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.user-menu__theme[aria-checked="true"] { background: hsl(var(--primary) / 0.1); color: hsl(var(--primary)); }
.user-menu__note { padding: 0.375rem 0.5rem 0; font-size: 11px; color: hsl(var(--muted-foreground)); }

/* ---------- Page content ----------
   The intranet's page padding, beside the rail and under the bar. */
.page {
  position: relative;
  width: 100%;
  padding: 1.5rem clamp(1rem, 2.5vw, 2rem) 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---------- Footer ---------- */
.footer {
  margin-top: var(--space-12);
  padding: var(--space-6) 0;
  border-top: 1px solid hsl(var(--border) / 0.7);
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
}
.footer .container { max-width: none; padding-inline: clamp(1rem, 2.5vw, 2rem); }
.footer__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: space-between;
  align-items: center;
}

/* ---------- Print: strip the chrome ---------- */
@media print {
  .rail, .topbar, .rail-scrim, .footer, [data-print-hide] { display: none !important; }
  body.has-rail { padding-left: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  body::before, body::after { display: none !important; }
}
