/* Shell: navy sidebar, 65px top bar, main region. */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column; overflow-y: auto;
  transition: transform 0.2s ease;
}
.sidebar-brand {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-5); border-bottom: 1px solid var(--sidebar-border);
  color: var(--sidebar-ink); font-weight: 700; font-size: var(--fs-4); text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; color: var(--sidebar-ink); }
.sidebar-brand img { height: 2rem; width: auto; }
.sidebar-brand small { display: block; font-weight: 500; font-size: var(--fs-1); color: var(--sidebar-ink-muted); letter-spacing: 0.02em; }
.sidebar nav { padding: var(--space-3); flex: 1; }
.nav-heading { margin: var(--space-4) var(--space-3) var(--space-1); font-size: var(--fs-1); text-transform: uppercase; letter-spacing: 0.08em; color: var(--sidebar-ink-muted); }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3); padding: 0.55rem var(--space-3);
  border-radius: var(--radius-sm); color: var(--sidebar-ink); font-weight: 500; text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-active); color: var(--sidebar-ink); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--sidebar-active); font-weight: 700; }
.nav-item:focus-visible { outline-color: var(--sidebar-ink); }
.nav-rail { display: none; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-5); font-size: var(--fs-1); color: var(--sidebar-ink-muted); border-top: 1px solid var(--sidebar-border); }

.shell-main { margin-left: var(--sidebar-w); min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-5);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 0 1 auto; font-weight: 600; color: var(--ink); font-size: var(--fs-4); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.nav-toggle { display: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-2); padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { background: var(--surface-2); }
.avatar { width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent); font-weight: 700; border: 1px solid var(--accent-border); }
.user-name { font-weight: 600; color: var(--ink); line-height: 1.2; }
.user-role { font-size: var(--fs-1); color: var(--ink-muted); }
.user-panel {
  position: absolute; right: 0; top: calc(100% + 0.25rem); min-width: 14rem; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-1); padding: var(--space-2);
}
.user-panel .who { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-2); word-break: break-word; }
.user-panel button, .user-panel a { width: 100%; display: flex; gap: var(--space-2); align-items: center; padding: 0.5rem var(--space-3); border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; text-align: left; color: var(--body); text-decoration: none; }
.user-panel button:hover, .user-panel a:hover { background: var(--surface-2); text-decoration: none; }

.banner { padding: var(--space-2) var(--space-5); background: var(--warn-bg); color: var(--warn-ink); border-bottom: 1px solid var(--warn-border); font-size: var(--fs-2); display: flex; gap: var(--space-2); align-items: center; }

#main { padding: var(--space-5); max-width: var(--w-wide); margin: 0 auto; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.page-head p { margin: var(--space-1) 0 0; color: var(--ink-muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.page-head.page-toolbar { flex-direction: row; justify-content: flex-end; align-items: center; margin-bottom: var(--space-3); }
.page-head.page-toolbar > div:empty { display: none; }
.content-narrow { max-width: var(--w-content); }
.stack { display: grid; gap: var(--space-4); }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.scrim { display: none; }

.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
#main.htmx-request { opacity: 0.6; transition: opacity 0.2s; }

@media (max-width: 991px) {
  .shell-main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body[data-nav-open] .sidebar { transform: none; box-shadow: var(--shadow-2); }
  body[data-nav-open] .scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 35; }
  .nav-toggle { display: inline-grid; }
}
@media (max-width: 767px) {
  #main { padding: var(--space-4) var(--space-4); }
  .topbar { padding: 0 var(--space-3); }
  .user-name, .user-role { display: none; }
  .banner { padding: var(--space-2) var(--space-4); }
}
@media print {
  .sidebar, .topbar, .banner, .page-actions, .scrim { display: none !important; }
  .shell-main { margin: 0; }
  body { background: transparent; }
}

/* ---- Clinic additions (kit lane K0). Mobile first: the phone layout is the base. ---- */

/* Collapsible nav groups */
.nav-group { margin: 0; }
.nav-group > summary.nav-heading { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.nav-group > summary.nav-heading::-webkit-details-marker { display: none; }
.nav-group[open] > summary.nav-heading .icon { transform: rotate(180deg); }

/* Topbar: search and clinic switcher */
.topbar-search { display: none; position: relative; align-items: center; flex: 0 100 14rem; min-width: 11rem; }
.topbar-search .icon { position: absolute; left: 0.6rem; pointer-events: none; color: var(--ink-muted); }
.topbar-search input { width: 100%; min-width: 0; padding: 0.45rem 0.75rem 0.45rem 2.2rem; border: 1px solid var(--border-control); border-radius: var(--radius-sm); background: var(--surface); }
.clinic-switch { position: relative; }
.clinic-switch > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-2); padding: 0.35rem 0.6rem; border-radius: var(--radius-sm); max-width: 12rem; }
.clinic-switch > summary::-webkit-details-marker { display: none; }
.clinic-switch > summary:hover { background: var(--surface-2); }
.clinic-name { display: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink); }
.clinic-panel { position: absolute; right: 0; top: calc(100% + 0.25rem); min-width: 14rem; max-width: 90vw; z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-1); padding: var(--space-2); display: grid; gap: 2px; }
.clinic-option { display: flex; width: 100%; gap: var(--space-2); align-items: center; padding: 0.5rem var(--space-3); border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; text-align: left; color: var(--body); }
button.clinic-option:hover { background: var(--surface-2); }
.clinic-option[aria-current] { font-weight: 700; color: var(--ink); }

/* Top bar trail (ui/breadcrumb): the parents are links, the last item is the page. Phones show the last item only. */
.breadcrumb { min-width: 0; }
.breadcrumb ol { display: flex; align-items: center; flex-wrap: nowrap; list-style: none; margin: 0; padding: 0; min-width: 0; }
.breadcrumb li { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumb li + li::before { content: "/"; margin: 0 var(--space-2); color: var(--ink-muted); font-weight: 400; }
.breadcrumb a { color: var(--ink-muted); font-weight: 500; }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.breadcrumb [aria-current] { color: var(--ink); font-weight: 600; }
@media (max-width: 639px) {
  .breadcrumb li:not(:last-child) { display: none; }
  .breadcrumb li + li::before { content: none; }
}

/* Omni search (ui/omni): the top bar input, the platform key hint and the result panel (the listbox). */
.omni input { width: 100%; min-width: 0; padding-right: 4.5rem; }
.omni-hint { display: none; position: absolute; right: 0.5rem; padding: 0 var(--space-1); font: inherit; font-size: var(--fs-1); color: var(--ink-muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); pointer-events: none; }
.omni.omni-ready .omni-hint { display: block; }
.omni input:focus ~ .omni-hint { display: none; }
.omni-panel { position: absolute; right: 0; top: calc(100% + 0.25rem); z-index: 50; width: 26rem; max-width: calc(100vw - 2rem); max-height: 70vh; overflow-y: auto; padding: var(--space-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-1); }
.omni-panel[hidden] { display: none; }
.omni-group-title { margin: var(--space-2) var(--space-3) var(--space-1); font-size: var(--fs-1); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.omni-option { display: flex; align-items: center; gap: var(--space-3); padding: 0.5rem var(--space-3); border-radius: var(--radius-sm); color: var(--body); text-decoration: none; }
.omni-option:hover, .omni-option.is-active { background: var(--accent-wash); color: var(--accent); text-decoration: none; }
.omni-option .icon { position: static; flex: none; width: 1.1rem; height: 1.1rem; color: var(--ink-muted); }
.omni-option small { margin-left: auto; color: var(--ink-muted); }
.omni-empty { margin: 0; padding: var(--space-3); color: var(--ink-muted); }

/* Page head: phone first, actions wrap under the title at full width */
.page-head { align-items: stretch; flex-direction: column; }
.page-head h1 { overflow-wrap: anywhere; }
.page-back { margin: 0 0 var(--space-1); font-size: var(--fs-2); }
.page-back a { display: inline-flex; align-items: center; gap: 2px; }
.page-head .page-actions .btn { flex: 1 1 auto; justify-content: center; }

/* Shell dialogs: full-screen sheet on phones */
.shell-dialog { max-width: 100%; width: 100%; height: 100%; max-height: none; margin: 0; }
.shell-dialog .dialog-panel { height: 100%; max-height: none; border-radius: 0; border-width: 0; padding-top: var(--safe-t); }
.shell-dialog.dialog-confirm { height: auto; max-width: min(28rem, calc(100vw - 2rem)); margin: auto; }
.shell-dialog.dialog-confirm .dialog-panel { height: auto; border-radius: var(--radius-md); border-width: 1px; padding-top: 0; }
.reminder { margin: auto; }

/* Auth card (L-H) and public column */
main.bare { padding-left: max(var(--space-4), var(--safe-l)); padding-right: max(var(--space-4), var(--safe-r)); padding-bottom: max(var(--space-4), var(--safe-b)); }
main.bare.public { max-width: var(--w-public); }
.auth-card { max-width: var(--w-auth); margin: 0 auto; padding: var(--space-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); display: grid; gap: var(--space-3); }
main.bare:has(> .auth-card) { max-width: var(--w-auth); }
.auth-logo { justify-self: center; height: 3rem; width: auto; }
.auth-card h1 { text-align: center; }
.auth-card .muted { text-align: center; margin: 0; }
.auth-form { display: grid; gap: var(--space-2); }
.btn-block { width: 100%; justify-content: center; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); margin: 0; }
.auth-footer { text-align: center; margin: 0; }

/* Global progress bar for htmx requests (CSS only; htmx puts .htmx-request on the requesting element) */
.topbar::after { content: ""; position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--accent-brand); opacity: 0; }
body.htmx-request .topbar::after, body:has(.htmx-request) .topbar::after { opacity: 1; width: 100%; transition: width 8s cubic-bezier(0.1, 0.7, 0.2, 1); }

/* Safe areas (iOS and Android shells) */
:root[data-shell] .topbar { padding-top: var(--safe-t); height: calc(var(--topbar-h) + var(--safe-t)); padding-left: max(var(--space-3), var(--safe-l)); padding-right: max(var(--space-3), var(--safe-r)); }
:root[data-shell] .sidebar { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
:root[data-shell] #main { padding-bottom: max(var(--space-4), var(--safe-b)); }
:root[data-shell] .toasts { bottom: max(var(--space-4), var(--safe-b)); }

/* Desktop rail: toggled by dproph.shell (body.nav-mini) */
@media (min-width: 768px) {
  .topbar-search { display: flex; }
  .page-head { flex-direction: row; align-items: flex-end; }
  .page-head .page-actions .btn { flex: 0 0 auto; }
  .shell-dialog { max-width: min(34rem, calc(100vw - 2rem)); height: auto; max-height: calc(100vh - 2rem); margin: auto; }
  .shell-dialog .dialog-panel { height: auto; max-height: calc(100vh - 2rem); border-radius: var(--radius-md); border-width: 1px; padding-top: 0; }
  .shell-dialog.dialog-lightbox { max-width: min(64rem, calc(100vw - 2rem)); }
}
@media (min-width: 992px) {
  .nav-rail { display: inline-flex; }
  body.nav-mini .sidebar { width: var(--rail-w); }
  body.nav-mini .shell-main { margin-left: var(--rail-w); }
  body.nav-mini .sidebar-brand span, body.nav-mini .nav-item span, body.nav-mini .nav-heading, body.nav-mini .sidebar-foot { display: none; }
  body.nav-mini .sidebar-brand, body.nav-mini .nav-item { justify-content: center; padding-left: 0; padding-right: 0; }

}

/* KFR-01: below 1100 px the top bar is tight. The clinic name, the user greeting and the Ctrl K hint wait for the wide shell, so the
   trail and the search placeholder both stay readable (the clinic switch and the user menu keep their icons). */
@media (min-width: 1100px) {
  .clinic-name { display: inline; }
}
@media (max-width: 1099px) {
  .omni input { padding-right: 0.75rem; }
  .omni.omni-ready .omni-hint { display: none; }
  .user-name, .user-role { display: none; }
}
