/* MedX app shell v4 "Calm": one labelled sidebar (only the current section expands),
   topbar with patient search, notifications drawer, help sheet, mobile tab bar, role views.
   Markup is generated by tools/build_shell.py. Load after polish.css. */

.skip-link { position: fixed; left: 12px; top: -60px; z-index: 400; padding: 10px 16px; border-radius: var(--r-sm); background: var(--c-text); color: var(--c-surface); font-weight: 650; }
.skip-link:focus { top: 12px; text-decoration: none; }

/* ================= Role views ================= */
html[data-role="reception"] [data-roles]:not([data-roles~="reception"]),
html[data-role="doctor"] [data-roles]:not([data-roles~="doctor"]),
html[data-role="labtech"] [data-roles]:not([data-roles~="labtech"]),
html[data-role="patho"] [data-roles]:not([data-roles~="patho"]),
html[data-role="cashier"] [data-roles]:not([data-roles~="cashier"]),
html:not([data-role]) .tabbar [data-roles]:not([data-roles~="owner"]),
html:not([data-role]) .for-staff,
html[data-role] .for-owner { display: none !important; }

/* ================= Sidebar ================= */
.snav { display: flex; flex-direction: column; gap: 14px; padding: 6px 12px 14px; flex: 1; }
.snav__group { display: flex; flex-direction: column; gap: 2px; }
.snav__label { padding: 8px 12px 4px; font-size: 13px; font-weight: 700; color: var(--c-text-3); }
.snav__link {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 42px; padding: 8px 12px; border-radius: var(--r-sm);
  color: var(--c-text-2); font-size: 15px; font-weight: 650;
  transition: background var(--t-fast), color var(--t-fast);
}
.snav__link .icon { width: 20px; height: 20px; color: var(--c-text-3); }
.snav__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snav__link:hover { background: var(--c-surface-3); color: var(--c-text); text-decoration: none; }
.snav__link:hover .icon { color: var(--c-text-2); }
.snav__link.is-active, .snav__link.is-here { color: var(--blue-800); }
.snav__link.is-active { background: var(--blue-100); }
.snav__link.is-active .icon, .snav__link.is-here .icon { color: var(--blue-700); }
.snav__link.is-active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--blue-700); }
.snav__sub { display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 21px; padding-left: 12px; border-left: 2px solid var(--c-border); }
.snav__sublink { position: relative; display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 12px; border-radius: var(--r-sm); color: var(--c-text-2); font-size: 14.5px; font-weight: 600; }
.snav__sublink:hover { background: var(--c-surface-3); color: var(--c-text); text-decoration: none; }
.snav__sublink.is-active { background: var(--blue-100); color: var(--blue-800); font-weight: 700; }
.snav__sublink.is-active::before { content: ""; position: absolute; left: -14px; top: 7px; bottom: 7px; width: 2px; background: var(--blue-700); }
.snav__foot { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 16px; border-top: 1px solid var(--c-border); }
.snav__foot .snav__sub { margin-bottom: 4px; }

/* Count badges (nav, tabs, bell). Severity is also in the aria-label. */
.count {
  margin-left: auto; min-width: 24px; height: 22px; padding: 0 7px; display: inline-grid; place-items: center;
  border-radius: 99px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--c-surface-3); color: var(--c-text-2);
}
.snav__link.is-active .count:not(.count--warn):not(.count--crit), .snav__sublink.is-active .count:not(.count--warn):not(.count--crit) { background: var(--c-surface); }
.count--warn { background: var(--st-warn-bg); color: var(--st-warn); }
.count--crit { background: var(--st-crit); color: var(--c-on-danger); }

/* ================= Topbar ================= */
.nav-burger { display: none; gap: 8px; padding: 0 12px; }
@media (max-width: 1024px) { .nav-burger { display: inline-flex; } }
.icon-btn .count { position: absolute; top: -3px; right: -5px; min-width: 22px; height: 20px; padding: 0 6px; border: 2px solid var(--c-surface); box-sizing: content-box; }
.topbar__search {
  flex: 1; max-width: 560px; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 16px;
  border: 1px solid var(--c-border-strong); border-radius: var(--r-full); background: var(--c-surface-2); color: var(--c-text-3); font-size: 15px;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.topbar__search:hover { border-color: var(--c-primary); background: var(--c-surface); text-decoration: none; color: var(--c-text-2); }
.topbar__search .icon { color: var(--c-text-2); }
.topbar__search-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Menus (<details> popovers) */
.menu, .more-menu { position: relative; }
.menu > summary, .more-menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker, .more-menu > summary::-webkit-details-marker { display: none; }
.menu__pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 80; min-width: 240px; padding: 6px;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); box-shadow: var(--shadow-lg);
}
.menu__pop--right { left: auto; right: 0; }
.menu__head { padding: 8px 10px 6px; font-size: 13px; font-weight: 700; color: var(--c-text-3); }
.menu__item, .menu__row { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border-radius: 8px; color: var(--c-text); font-size: 15px; }
.menu__item:hover, .menu__item:focus-visible { background: var(--c-surface-3); text-decoration: none; }
.menu__item .icon, .menu__row > .icon { color: var(--c-text-3); }
.menu__item > span:not(.grow):not(.avatar) { flex: 1; }
.menu__item--danger { color: var(--c-danger); }
.menu__item--danger .icon { color: var(--c-danger); }
.menu__strong { display: block; font-weight: 650; }
.menu__sub { font-size: 13px; color: var(--c-text-3); font-weight: 500; margin-left: 4px; }
.menu__sep { height: 1px; background: var(--c-border); margin: 6px 4px; }
.user-chip { border-radius: var(--r-full); padding: 3px 10px 3px 3px; transition: background var(--t-fast); }
.user-chip:hover, .user-menu[open] > .user-chip { background: var(--c-surface-3); }
.user-chip__text { display: flex; flex-direction: column; }
.user-chip > .icon { color: var(--c-text-3); }

/* Theme switch (injected by theme.js into [data-theme-slot]) */
.switch-btn { position: relative; width: 44px; height: 26px; flex: none; border: 0; border-radius: 99px; background: var(--c-border-strong); cursor: pointer; transition: background var(--t-med); }
.switch-btn::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform var(--t-med) var(--ease); }
.switch-btn[aria-checked="true"] { background: var(--c-primary); }
.switch-btn[aria-checked="true"]::after { transform: translateX(18px); }

/* "⋯" row/page menu */
.more-menu > summary { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-full); color: var(--c-text-2); }
.more-menu > summary:hover, .more-menu[open] > summary { background: var(--c-surface-3); color: var(--c-text); }
.more-menu .menu__pop { left: auto; right: 0; min-width: 200px; }

/* ================= Search dialog ================= */
.cmdk { place-items: start center; padding-top: min(10vh, 96px); }
.cmdk__box {
  width: min(660px, 100%); max-height: min(76vh, 640px); display: flex; flex-direction: column; overflow: hidden;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
}
.cmdk__search { display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--c-border); }
.cmdk__search > .icon { color: var(--c-text-2); width: 22px; height: 22px; }
.cmdk__search input { flex: 1; height: 40px; border: 0; outline: 0; background: none; font: inherit; font-size: 18px; color: var(--c-text); min-width: 0; }
.cmdk__search input::-webkit-search-cancel-button { display: none; }
.cmdk__search input:focus, .cmdk__search input:focus-visible { outline: 0; }
.cmdk__list { overflow-y: auto; padding: 6px 10px 12px; }
.cmdk__label { font-size: 13px; font-weight: 700; color: var(--c-text-3); padding: 12px 10px 4px; }
.cmdk__item { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 8px 10px; border-radius: 10px; color: var(--c-text); font-size: 15px; font-weight: 600; scroll-margin: 8px; }
.cmdk__item > .icon { color: var(--c-text-3); width: 20px; height: 20px; margin: 0 5px; }
.cmdk__item:hover { text-decoration: none; background: var(--c-surface-3); }
.cmdk__item.is-sel, .cmdk__item:focus-visible { background: var(--blue-100); outline: none; }
.cmdk__item.is-sel > .icon { color: var(--blue-700); }
.cmdk__sub { display: block; font-size: 13.5px; font-weight: 500; color: var(--c-text-3); }
.cmdk__item mark { background: none; color: var(--blue-800); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.cmdk__empty { display: none; padding: 28px 16px; text-align: center; color: var(--c-text-3); }
.cmdk__list.is-empty .cmdk__empty { display: block; }
html.js .cmdk__list:not(.is-searching) .cmdk__group--find,
.cmdk__list.is-searching .cmdk__group--idle { display: none; }
[hidden] { display: none !important; }

/* ================= Notifications drawer ================= */
.drawer__intro { padding: 12px 22px 0; font-size: 14px; color: var(--c-text-3); }
.note-list { gap: 10px; padding: 14px 16px; }
.note { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--c-border); background: var(--c-surface); }
.note > .btn { align-self: center; }
.note__icon { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--st-info-bg); color: var(--st-info); }
.note--crit { border-color: color-mix(in srgb, var(--st-crit) 35%, var(--c-border)); box-shadow: inset 4px 0 0 var(--st-crit); }
.note--crit .note__icon { background: var(--st-crit); color: var(--c-on-danger); }
.note--warn .note__icon { background: var(--st-warn-bg); color: var(--st-warn); }
.note__kind { font-size: 13px; font-weight: 700; color: var(--c-text-3); }
.note--crit .note__kind { color: var(--st-crit); }
.note--warn .note__kind { color: var(--st-warn); }
.note__title { font-weight: 700; font-size: 15px; color: var(--c-text); }
.note__sub { font-size: 14px; color: var(--c-text-2); margin-top: 2px; }
.note__time { font-size: 13px; color: var(--c-text-3); margin-top: 4px; }

/* ================= Help sheet ================= */
.help-tips { display: flex; flex-direction: column; gap: 12px; }
.help-tips li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; color: var(--c-text-2); }
.help-tips .icon { margin-top: 4px; color: var(--blue-700); }
.help-tips b { color: var(--c-text); }
.keygrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; margin-top: 6px; }
.keyrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--c-border); font-size: 14px; }
.keys { white-space: nowrap; }

/* SLA chip (age of work) */
.sla { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--st-ok-bg); color: var(--st-ok); white-space: nowrap; }
.sla--warn { background: var(--st-warn-bg); color: var(--st-warn); }
.sla--crit { background: var(--st-crit); color: var(--c-on-danger); }
.sla--info { background: var(--st-info-bg); color: var(--st-info); }

/* ================= Mobile ================= */
.tabbar { display: none; }
@media (max-width: 1024px) {
  .snav__link, .snav__sublink, .menu__item, .cmdk__item { min-height: 46px; }
  .user-chip__text { display: none; }
}
@media (max-width: 760px) {
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; display: flex;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--c-surface); border-top: 1px solid var(--c-border);
  }
  .tabbar__link { flex: 1; min-width: 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 12px; font-size: 13px; font-weight: 650; color: var(--c-text-3); cursor: pointer; }
  .tabbar__link .icon { width: 22px; height: 22px; }
  .tabbar__link:hover { text-decoration: none; color: var(--c-text); }
  .tabbar__link.is-active { color: var(--blue-800); background: var(--blue-100); }
  .main { padding-bottom: 76px; }
  .nav-burger span { display: none; }
  .topbar { gap: 8px; }
  .topbar__search { height: 42px; padding: 0 14px; font-size: 14px; }
  .keygrid { grid-template-columns: minmax(0, 1fr); }
  .menu__pop { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 4px); min-width: 0; }
  .cmdk { padding: 8px; }
  .cmdk__box { max-height: calc(100vh - 16px); }
}
@media (max-width: 420px) {
  .topbar__search-text { font-size: 0; }
  .topbar__search-text::after { content: "Find a patient"; font-size: 14px; }
}

@media print { .sidebar, .topbar, .tabbar, .skip-link { display: none !important; } }
