/*
 * RXOPD canonical authenticated role shell.
 * Owns structural layout only: sidebar, topbar, main viewport, mobile drawer and bottom navigation.
 * Visual page components remain owned by rxopd-unified-ui.css and rxopd-operational-ui.css.
 */

:root {
  --rx-role-sidebar-width: 272px;
  --rx-role-topbar-height: 68px;
  --rx-role-mobile-topbar-height: 64px;
  --rx-role-bottom-nav-height: 76px;
  --rx-role-shell-bg: #f4f9ff;
  --rx-role-shell-line: #d9e8fa;
  --rx-role-shell-ink: #0f172a;
  --rx-role-shell-muted: #64748b;
  --rx-role-shell-blue: #0b5ed7;
  --rx-role-shell-green: #079b72;
  --rx-role-shell-navy: #08245c;
}

body.rx-role-shell {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--rx-role-shell-bg);
  color: var(--rx-role-shell-ink);
}

body.rx-role-shell,
body.rx-role-shell * {
  box-sizing: border-box;
}

body.rx-role-shell img,
body.rx-role-shell svg,
body.rx-role-shell video,
body.rx-role-shell canvas {
  max-width: 100%;
}

/* Mobile drawer backdrop. */
body.rx-role-shell .rx-role-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  display: block;
  background: rgba(2, 15, 38, 0.52);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

/* Canonical sidebar. */
body.rx-role-shell .rx-role-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1100;
  width: var(--rx-role-sidebar-width);
  max-width: 100%;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border-right: 1px solid var(--rx-role-shell-line);
  box-shadow: 12px 0 32px rgba(8, 36, 92, 0.08);
}

body.rx-role-shell .rx-role-brand-row {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rx-role-shell-line);
}

body.rx-role-shell .rx-role-brand {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--rx-role-shell-navy);
  text-decoration: none;
}

body.rx-role-shell .rx-role-brand img {
  display: block;
  width: 112px;
  max-width: 52%;
  height: 38px;
  object-fit: contain;
  object-position: left center;
  flex: 0 1 auto;
}

body.rx-role-shell .rx-role-brand span {
  min-width: 0;
  overflow: hidden;
  color: var(--rx-role-shell-navy);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.rx-role-shell .rx-role-brand-row > button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: none;
  place-items: center;
  padding: 0;
  border: 1px solid var(--rx-role-shell-line);
  border-radius: 12px;
  background: #eef7ff;
  color: var(--rx-role-shell-navy);
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

body.rx-role-shell .rx-role-user-card {
  flex: 0 0 auto;
  min-width: 0;
  margin: 12px;
  padding: 13px 14px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--rx-role-shell-line);
  border-radius: 16px;
  background: linear-gradient(135deg, #f8fbff, #ecfdf5);
}

body.rx-role-shell .rx-role-user-card small,
body.rx-role-shell .rx-role-user-card strong,
body.rx-role-shell .rx-role-user-card span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.rx-role-shell .rx-role-user-card small {
  color: var(--rx-role-shell-blue);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body.rx-role-shell .rx-role-user-card strong {
  color: var(--rx-role-shell-ink);
  font-size: 13px;
}

body.rx-role-shell .rx-role-user-card span {
  color: var(--rx-role-shell-muted);
  font-size: 10px;
}

body.rx-role-shell .rx-role-navigation {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 9px 16px;
  scrollbar-width: thin;
}

body.rx-role-shell .rx-role-nav-group {
  min-width: 0;
  margin: 0 0 8px;
}

body.rx-role-shell .rx-role-nav-group h2 {
  margin: 12px 8px 6px;
  color: #7890a8;
  font-size: 9px;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

body.rx-role-shell .rx-role-nav-group a {
  min-width: 0;
  min-height: 42px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin: 3px 0;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #244566;
  text-decoration: none;
}

body.rx-role-shell .rx-role-nav-group a > .rx-nav-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #eef7ff;
  color: var(--rx-role-shell-blue);
}

body.rx-role-shell .rx-role-nav-group a strong {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.22;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.rx-role-shell .rx-role-nav-group a:hover,
body.rx-role-shell .rx-role-nav-group a:focus-visible {
  background: #f3f9ff;
  border-color: #dbeafe;
}

body.rx-role-shell .rx-role-nav-group a.active {
  color: #ffffff;
  background: var(--rx-role-shell-green);
  border-color: var(--rx-role-shell-green);
  box-shadow: 0 9px 18px rgba(7, 155, 114, 0.2);
}

body.rx-role-shell .rx-role-nav-group a.active > .rx-nav-icon {
  color: var(--rx-role-shell-navy);
  background: #ffffff;
  border-color: #ffffff;
}

body.rx-role-shell .rx-role-logout {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--rx-role-shell-line);
  background: #ffffff;
}

body.rx-role-shell .rx-role-logout button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--rx-role-shell-line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--rx-role-shell-navy);
  font: inherit;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

/* Canonical topbar. Final true-centre logo geometry is applied by
   rxopd-post-login-header-center.css, loaded after all UI layers. */
body.rx-role-shell .rx-role-topbar {
  position: fixed;
  top: 0;
  left: var(--rx-role-sidebar-width);
  right: 0;
  z-index: 1000;
  min-width: 0;
  min-height: var(--rx-role-topbar-height);
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--rx-role-shell-line);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 8px 26px rgba(8, 36, 92, 0.06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

body.rx-role-shell .rx-role-menu-button {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: var(--rx-role-shell-navy);
  cursor: pointer;
}

body.rx-role-shell .rx-role-menu-button span {
  width: 20px;
  height: 2px;
  display: block;
  border-radius: 2px;
  background: #ffffff;
}

body.rx-role-shell .rx-role-top-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

body.rx-role-shell .rx-role-top-brand img {
  display: block;
  width: 108px;
  max-width: 100%;
  height: 38px;
  object-fit: contain;
  object-position: center;
}

body.rx-role-shell .rx-role-page-title {
  min-width: 0;
  display: grid;
  gap: 1px;
}

body.rx-role-shell .rx-role-page-title small,
body.rx-role-shell .rx-role-page-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.rx-role-shell .rx-role-page-title small {
  color: var(--rx-role-shell-green);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

body.rx-role-shell .rx-role-page-title strong {
  color: var(--rx-role-shell-navy);
  font-size: 15px;
  line-height: 1.2;
}

body.rx-role-shell .rx-role-top-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

body.rx-role-shell .rx-role-top-actions > a,
body.rx-role-shell .rx-role-top-actions button {
  min-width: 40px;
  min-height: 40px;
}

body.rx-role-shell .rxopd-header-logout {
  margin: 0;
}

/* Main authenticated viewport. */
body.rx-role-shell .rx-role-main {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin-left: var(--rx-role-sidebar-width);
  padding: 88px 24px 40px;
  background: var(--rx-role-shell-bg);
}

body.rx-role-shell .rx-role-main > * {
  min-width: 0;
  max-width: 100%;
}

body.rx-role-shell .rx-role-main :where(.table-wrap, .table-responsive, .rx-table-wrap, [data-table-scroll]) {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile quick navigation is hidden on desktop. */
body.rx-role-shell .rx-role-bottom-nav {
  display: none;
}

@media (max-width: 1100px) and (min-width: 861px) {
  body.rx-role-shell .rx-role-page-title {
    max-width: 210px;
  }
}

@media (max-width: 860px) {
  body.rx-role-shell {
    padding-bottom: var(--rx-role-bottom-nav-height);
  }

  body.rx-role-shell.rx-role-menu-open {
    overflow: hidden;
  }

  body.rx-role-shell .rx-role-sidebar {
    width: min(88vw, 320px);
    max-width: min(88vw, 320px);
    transform: translate3d(-105%, 0, 0);
    transition: transform 200ms ease;
    will-change: transform;
  }

  body.rx-role-shell.rx-role-menu-open .rx-role-sidebar {
    transform: translate3d(0, 0, 0);
  }

  body.rx-role-shell .rx-role-brand-row > button {
    display: grid;
  }

  body.rx-role-shell.rx-role-menu-open .rx-role-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.rx-role-shell .rx-role-topbar {
    left: 0;
    min-height: var(--rx-role-mobile-topbar-height);
  }

  body.rx-role-shell .rx-role-menu-button {
    display: flex;
  }

  body.rx-role-shell .rx-role-page-title {
    display: none;
  }

  body.rx-role-shell .rx-role-main {
    margin-left: 0;
    padding: 76px 14px calc(var(--rx-role-bottom-nav-height) + 18px);
  }

  body.rx-role-shell .rx-role-bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 980;
    min-width: 0;
    min-height: var(--rx-role-bottom-nav-height);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    align-items: stretch;
    padding: 4px max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    border-top: 1px solid var(--rx-role-shell-line);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -8px 24px rgba(8, 36, 92, 0.09);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  body.rx-role-shell .rx-role-bottom-nav > a,
  body.rx-role-shell .rx-role-bottom-nav > button {
    min-width: 0;
    min-height: 62px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 3px 6px;
    border: 0;
    background: transparent;
    color: #244566;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
  }

  body.rx-role-shell .rx-role-bottom-nav strong {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    font-size: 9px;
    line-height: 1.08;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 480px) {
  body.rx-role-shell .rx-role-main {
    padding-right: 10px;
    padding-left: 10px;
  }
}

@media (max-width: 360px) {
  body.rx-role-shell .rx-role-main {
    padding-right: 8px;
    padding-left: 8px;
  }

  body.rx-role-shell .rx-role-bottom-nav strong {
    font-size: 8.5px;
  }
}

@media (min-width: 861px) {
  body.rx-role-shell .rx-role-sidebar {
    transform: none !important;
  }

  body.rx-role-shell .rx-role-backdrop {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.rx-role-shell .rx-role-sidebar,
  body.rx-role-shell .rx-role-backdrop {
    transition: none;
  }
}

/* Doctor navigation uses the Admin Desk navy/blue card language. */
body.rx-role-shell.role-doctor .rx-role-nav-group h2 {
  color: #526d8d;
}

body.rx-role-shell.role-doctor .rx-role-nav-group a {
  border-color: #d8e4f2;
  background: linear-gradient(145deg, #f8fbff, #eef5fc);
  color: #0b2b55;
  box-shadow: 0 3px 10px rgba(8, 36, 92, 0.035);
}

body.rx-role-shell.role-doctor .rx-role-nav-group a > .rx-nav-icon {
  border-color: #cbdcf0;
  background: #e4eef9;
  color: #0d4f93;
}

body.rx-role-shell.role-doctor .rx-role-nav-group a:hover,
body.rx-role-shell.role-doctor .rx-role-nav-group a:focus-visible {
  border-color: #9fc0e3;
  background: #e7f1fb;
  color: #082d5d;
  box-shadow: 0 5px 14px rgba(8, 36, 92, 0.08);
}

body.rx-role-shell.role-doctor .rx-role-nav-group a.active {
  border-color: #0b3d78;
  background: linear-gradient(135deg, #0a2f63, #0d5aa6);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(8, 47, 99, 0.22);
}

body.rx-role-shell.role-doctor .rx-role-nav-group a.active > .rx-nav-icon {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}
