/*
 * The frame of every signed-in page: the rail, the main column, the detail panel, the alert above a
 * page, toasts and the keyboard help. Under 900px the rail folds into a top row with a menu.
 */

html:has(body.shell), body.shell { height: 100%; }
body.shell { overflow: hidden; }
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); height: 100%; }
.app:has(#detail > *) { grid-template-columns: 232px minmax(0, 1fr) 380px; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }

/* The rail */
.rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  padding: 12px 10px;
  overflow: hidden;
  background: var(--chrome);
  color: var(--chrome-ink);
  border-right: 1px solid var(--chrome-line);
}
.rail__top { display: flex; flex-direction: column; gap: 2px; }
.rail .brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 10px; font-weight: 600; color: var(--chrome-ink); }
.rail .brand:hover { text-decoration: none; }
.rail .brand img { width: 20px; height: 20px; border-radius: 6px; flex: none; }

.facility { position: relative; margin-bottom: 8px; }
.facility > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  border: 1px solid var(--chrome-line);
  border-radius: var(--radius-sm);
  list-style: none;
  cursor: pointer;
}
.facility > summary::-webkit-details-marker { display: none; }
.facility > summary:hover { background: var(--chrome-hover); }
.facility > summary > span:first-child { min-width: 0; }
.facility__name, .facility__org { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.25; }
.facility__name { font-weight: 500; }
.facility__org { font-size: 11px; color: var(--chrome-ink-2); }
.facility__caret { color: var(--chrome-ink-2); }
.facility__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  gap: 1px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.facility__menu a { display: block; padding: 6px 8px; border-radius: 4px; color: var(--ink); }
.facility__menu a:hover { background: var(--hover); text-decoration: none; }
.facility__menu a[aria-current="true"] { background: var(--selected); color: var(--accent-ink); font-weight: 500; }

.rail__menu { display: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.rail__label { padding: 10px 8px 4px; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--chrome-ink-2); }
.nav a { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm); color: var(--chrome-ink); }
.nav a:hover { background: var(--chrome-hover); text-decoration: none; }
.nav a[aria-current] { background: var(--chrome-active); color: var(--chrome-active-ink); font-weight: 500; }
.nav a.sub { padding-left: 24px; font-size: var(--fs-dense); font-weight: 400; color: var(--chrome-ink-2); }
.nav a.sub[aria-current] { color: var(--chrome-active-ink); font-weight: 500; }
.badge { margin-left: auto; padding: 1px 7px; border-radius: 999px; background: var(--warn-soft); color: var(--warn-ink); font-size: 11px; font-weight: 600; }

/* Who is signed in stays on every page: PCC signs a shared workstation in as the last person (OQ-100). */
.rail__foot { flex: none; margin-top: auto; padding: 8px; display: grid; gap: 4px; font-size: 12px; color: var(--chrome-ink-2); border-top: 1px solid var(--chrome-line); }
.rail__foot strong { color: var(--chrome-ink); font-weight: 500; }
.rail__links { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.rail__links form { display: inline; margin: 0; }
.rail__links a, .rail__links .link { color: var(--chrome-ink-2); }
.rail__help { margin-left: auto; padding: 0; border: 0; background: none; }

/* A button that reads as a link. */
.link { padding: 0; border: 0; background: none; color: var(--accent-ink); }
.link:hover { text-decoration: underline; }

/* The one alert above a page: a refusal that came back through a redirect. */
.flash { margin: 16px 28px 0; padding: 10px 14px; border: 1px solid; border-radius: var(--radius-sm); font-size: var(--fs-dense); }
.flash--alert { background: var(--bad-soft); color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.flash--notice { background: var(--ok-soft); color: var(--ok-ink); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }

/* The detail panel of a working screen: shown once a row's link fills its frame. */
.panel { min-width: 0; min-height: 0; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--line); font-size: var(--fs-dense); }
.panel:not(:has(#detail > *)) { display: none; }

.toasts {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  z-index: 30;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow);
  font-size: var(--fs-dense);
}
.toast form { display: inline; margin: 0; }
.toast button { padding: 2px 6px; border: 0; border-radius: 4px; background: transparent; color: inherit; font-weight: 600; }
.toast button:hover { background: color-mix(in srgb, var(--surface) 15%, transparent); }

.help {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 25;
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12px;
}
.help div { display: flex; justify-content: space-between; gap: 18px; }

@media (prefers-reduced-motion: no-preference) {
  .panel { animation: panel-in .16s ease-out; }
  @keyframes panel-in { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* Wide enough for the rail, not for the panel beside the list: the panel lies over it. */
@media (max-width: 1100px) {
  .app:has(#detail > *) { grid-template-columns: 232px minmax(0, 1fr); }
  .panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 15; width: min(380px, 100%); box-shadow: var(--shadow); }
}

/* On a desktop the section list is always shown, and only it scrolls; the popover opens it as a sheet on a phone. */
@media (width >= 900px) {
  .rail__sheet[popover] {
    position: static;
    display: block;
    flex: 1 1 auto;
    width: auto;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    border: 0;
    background: none;
    color: inherit;
  }
}

/* A top row: brand, facility and a menu, with who is signed in under it. */
@media (width < 900px) {
  .app, .app:has(#detail > *) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .rail {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 7px max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--chrome-line);
  }
  .rail__top { flex: 1; flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
  .rail .brand { padding: 0; }
  .rail .brand span { display: none; }
  .facility { flex: 1; min-width: 0; margin: 0; }
  .facility__org { display: none; }
  .rail__menu {
    display: inline-flex;
    align-items: center;
    height: var(--control-sm);
    padding: 0 10px;
    border: 1px solid var(--chrome-line);
    border-radius: var(--radius-sm);
    background: var(--chrome);
    color: var(--chrome-ink);
    font-weight: 500;
  }
  .rail__sheet:popover-open {
    inset: 0 auto 0 0;
    width: min(300px, 85vw);
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 12px 10px;
    overflow-y: auto;
    border: 0;
    border-right: 1px solid var(--chrome-line);
    background: var(--chrome);
    color: var(--chrome-ink);
    box-shadow: var(--shadow);
  }
  .rail__sheet::backdrop { background: color-mix(in srgb, var(--ink) 35%, transparent); }
  .rail__foot { width: 100%; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 6px; border-top: 0; }
  .rail__help { display: none; }
  .flash { margin-left: 16px; margin-right: 16px; }
  .site-header, .site-footer { padding-left: 16px; padding-right: 16px; }
}

/* Signed out: the brand in a bar, the page, and support and privacy in the footer */
body.signed-out { display: flex; flex-direction: column; min-height: 100dvh; }
body.signed-out > main { flex: 1; }
.site-header { display: flex; align-items: center; height: 56px; padding: 0 28px; background: var(--chrome); border-bottom: 1px solid var(--chrome-line); }
.site-header .brand { display: flex; align-items: center; gap: 8px; color: var(--chrome-ink); font-weight: 600; }
.site-header .brand:hover { text-decoration: none; }
.site-header .brand img { width: 20px; height: 20px; border-radius: 6px; }
.site-header .brand span { color: var(--chrome-ink-2); font-weight: 400; }
.site-footer { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 14px 28px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: var(--fs-dense); }
body.signed-out > .flash { margin-bottom: 0; }

/* Printing a page prints all of it: no rail, no inner scroll. */
@media print {
  html:has(body.shell), body.shell { height: auto; overflow: visible; }
  .app, .app:has(#detail > *) { display: block; height: auto; }
  .rail, .toasts, .help, .panel { display: none !important; }
  .main { overflow: visible; }
}
