/* ============================================
   Practitioner shell — rail + nav drawer + matter header + context panel
   ============================================ */

:root {
  --shell-rail-width: 72px;
  --shell-nav-drawer-width: 260px;
  --shell-context-width: min(360px, 32vw);
  --shell-matter-height: 56px;
  --shell-header-offset: calc(var(--shell-matter-height) + env(safe-area-inset-top, 0px));
}

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.app-shell--workspace .shell-body-inner {
  display: grid;
  grid-template-columns: 1fr var(--shell-context-width);
  flex: 1;
  min-width: 0;
}

.app-shell--workspace .shell-body-inner--solo {
  grid-template-columns: 1fr;
}

.app-shell--workspace .shell-body-inner--solo .shell-workspace-canvas {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-shell--workspace .shell-workspace-canvas:has(.ai-chat-layout--workspace) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.app-shell--nav-open .shell-main-area {
  margin-left: calc(var(--shell-rail-width) + var(--shell-nav-drawer-width));
}

.shell-main-area {
  flex: 1;
  min-width: 0;
  margin-left: var(--shell-rail-width);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--shell-header-offset);
  overflow-y: auto;
  overflow-x: hidden;
  transition: margin-left 0.2s ease;
  -webkit-overflow-scrolling: touch;
}

/* ---- Icon rail ---- */
.shell-rail {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--shell-rail-width);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) 0 12px;
  gap: 4px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.04);
}

.shell-rail-logo {
  width: auto;
  min-width: 48px;
  min-height: 48px;
  max-width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  padding: 4px 6px;
  overflow: visible;
  flex-shrink: 0;
}

.shell-rail-logo:hover {
  background: rgba(var(--brand-rgb), 0.08);
}

.shell-rail-logo .logo-rcs--rail,
.shell-rail-logo .logo-rcs,
.shell-rail-logo .logo-rcs-rail-svg {
  width: 40px !important;
  height: 40px !important;
  max-width: 48px !important;
  flex-shrink: 0;
  display: block;
}

.logo-rail-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  background: rgba(var(--brand-rgb), 0.1);
  border-radius: var(--radius-md);
}

.shell-rail-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  width: 100%;
  padding: 12px 8px 0;
}

.shell-rail-item {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  position: relative;
}

.shell-rail-item:hover {
  background: rgba(var(--brand-rgb), 0.08);
  color: var(--text-primary);
}

.shell-rail-item.active,
.shell-rail-item[aria-expanded="true"] {
  background: rgba(var(--brand-rgb), 0.1);
  color: var(--nav-accent-text, var(--primary));
  box-shadow: none;
}

.shell-rail-item .nav-tile {
  margin: 0;
  padding: 0;
  width: auto;
  min-width: 0;
}

.shell-rail-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--brand-gradient);
  color: #fff;
  line-height: 1.2;
}

.shell-rail-footer {
  padding: 8px;
  margin-top: auto;
}

/* ---- Nav drawer (flat links, exclusive) ---- */
.shell-nav-drawer {
  position: fixed;
  left: var(--shell-rail-width);
  top: 0;
  bottom: 0;
  width: var(--shell-nav-drawer-width);
  z-index: 999;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  overflow-y: auto;
}

.shell-nav-drawer.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.shell-nav-drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.shell-nav-drawer__logo-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  text-decoration: none;
}

.shell-nav-drawer__logo-link .logo-rcs,
.shell-nav-drawer__logo-link .logo-rcs--sm {
  height: 36px;
  width: auto;
  max-width: 160px;
}

.shell-nav-drawer__divider {
  height: 1px;
  background: var(--border-color);
  margin: 10px 0;
}

.shell-nav-drawer__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.matter-header__bar-spacer {
  flex: 1;
  min-width: 0;
}

.matter-header__title-row--risk {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}


.shell-nav-drawer__title {
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.shell-nav-drawer__hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0 0 16px;
}

.shell-nav-drawer__section {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin: 12px 0 8px;
}

.shell-nav-drawer__link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.shell-nav-drawer__link:hover {
  background: rgba(var(--brand-rgb), 0.08);
  color: var(--text-primary);
}

.shell-nav-drawer__link.active {
  background: rgba(var(--brand-rgb), 0.12);
  color: var(--nav-accent-text, var(--primary));
  font-weight: 600;
}

.shell-nav-drawer__link .nav-tile {
  flex-shrink: 0;
}

/* ---- Matter-centric header ---- */
.matter-header {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: var(--shell-rail-width);
  right: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  min-height: var(--shell-matter-height);
  background: color-mix(in srgb, var(--bg-primary) 90%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 80%, transparent);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 4px 20px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.app-shell--nav-open .matter-header {
  left: calc(var(--shell-rail-width) + var(--shell-nav-drawer-width));
}

[data-theme="light"] .matter-header {
  background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
}

.matter-header__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  min-width: 0;
}

.matter-header__menu {
  display: none;
  flex-shrink: 0;
}

.matter-header__crumbs {
  min-width: 0;
  overflow: hidden;
  justify-self: start;
}

.matter-header__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.matter-header__title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.35;
}

.matter-header .breadcrumbs {
  margin: 0;
  font-size: 0.8125rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
}

.matter-header .breadcrumbs::-webkit-scrollbar {
  display: none;
}

.matter-header__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  min-width: 0;
}

.matter-header__brand-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: var(--radius-md);
  padding: 2px 4px;
}

.matter-header__brand-link:hover {
  background: rgba(var(--brand-rgb), 0.06);
}

.matter-header__brand .logo-rcs {
  display: block;
  height: 32px;
  max-width: 140px;
}

.matter-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.matter-header__actions .btn-icon {
  width: 36px;
  height: 36px;
}

.matter-header__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 20px 8px;
  min-width: 0;
}

/* Legacy aliases kept for any remaining references */
.matter-header__left,
.matter-header__center {
  display: contents;
}

.matter-header-user {
  position: relative;
}

.matter-header-user-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

.matter-header-user-trigger:hover {
  opacity: 0.88;
}

.matter-header-user-trigger:focus-visible {
  outline: 2px solid rgba(var(--brand-rgb), 0.45);
  outline-offset: 2px;
}

.matter-header-user .dropdown-menu {
  right: 0;
  left: auto;
  top: calc(100% + 6px);
  min-width: 220px;
}

.matter-header-user .dropdown-menu.open {
  z-index: 200;
}

.user-menu__identity {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 4px;
}

.user-menu__name {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
}

.user-menu__email {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.35;
  word-break: break-word;
}

.user-menu__role {
  font-size: var(--font-xs);
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.35;
}

.user-menu__divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

.user-menu .menu-item--danger {
  color: var(--danger);
}

.user-menu .menu-item--danger:hover {
  background: rgba(var(--danger-rgb, 220, 53, 69), 0.08);
  color: var(--danger);
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--trust-blue);
  background: rgba(var(--trust-blue-rgb), 0.08);
  border: 1px solid rgba(var(--trust-blue-rgb), 0.15);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--verify-green);
  flex-shrink: 0;
}

.risk-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.risk-chip--critical {
  color: var(--badge-danger-text, #991B1B);
  background: rgba(var(--crimson-rgb), 0.12);
  border: 1px solid rgba(var(--crimson-rgb), 0.25);
}

.risk-chip--warning {
  color: var(--badge-warning-text, #92400E);
  background: rgba(var(--amber-rgb), 0.12);
  border: 1px solid rgba(var(--amber-rgb), 0.25);
}

.risk-chip--safe {
  color: var(--badge-success-text, #1A5636);
  background: rgba(var(--verify-rgb), 0.12);
  border: 1px solid rgba(var(--verify-rgb), 0.25);
}

/* ---- Workspace canvas + context panel ---- */
.shell-workspace-canvas {
  min-width: 0;
  padding: var(--space-md) 20px;
}

.shell-context-panel {
  border-left: 1px solid var(--border-color);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--shell-matter-height));
  max-height: calc(100vh - var(--shell-matter-height));
  overflow: hidden;
}

.shell-context-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.shell-context-panel__title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--trust-blue);
}

.shell-context-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.shell-context-fab {
  display: none;
}

.main-content--classic {
  padding: var(--space-lg) 24px;
  width: 100%;
  max-width: none;
  min-width: 0;
  box-sizing: border-box;
}

.app-shell .main-content {
  width: 100%;
  max-width: min(1440px, 100%);
  margin-left: auto;
  margin-right: auto;
  min-width: 0;
  box-sizing: border-box;
}

/* Hide legacy sidebar when shell active */
.app-shell .sidebar {
  display: none !important;
}

.app-shell .main-area {
  margin-left: 0 !important;
}

/* Practitioner shell needs the rail margin — must beat legacy !important reset above */
.app-shell .main-area.shell-main-area {
  margin-left: var(--shell-rail-width, 72px) !important;
}

.app-shell.app-shell--nav-open .main-area.shell-main-area {
  margin-left: calc(var(--shell-rail-width, 72px) + var(--shell-nav-drawer-width, 260px)) !important;
}

/* ---- Practitioner controls ---- */
.pract-segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.pract-segmented__btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.pract-segmented__btn:hover {
  border-color: rgba(var(--brand-rgb), 0.4);
  color: var(--text-primary);
}

.shell-context-panel__body .pract-segmented {
  flex-direction: column;
  align-items: stretch;
}

.shell-context-panel__body .pract-segmented__btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
}

.pract-segmented__btn.is-active {
  border-color: rgba(var(--brand-rgb), 0.5);
  background: rgba(var(--brand-rgb), 0.1);
  color: var(--nav-accent-text, var(--primary));
  box-shadow: var(--focus-ring);
}

.pract-disclosure {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--bg-card);
}

.pract-disclosure__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}

.pract-disclosure__body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border-color);
}

.pract-disclosure:not(.is-open) .pract-disclosure__body {
  display: none;
}

.pract-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.pract-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(var(--trust-blue-rgb), 0.1);
  color: var(--trust-blue);
  border: 1px solid rgba(var(--trust-blue-rgb), 0.2);
}

.pract-filter-chip button {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  line-height: 1;
}

/* ---- AI workspace canvas ---- */
.ai-chat-layout--workspace {
  display: flex;
  flex-direction: column;
  min-height: min(70vh, 720px);
  width: 100%;
  max-width: 100%;
}

.ai-chat-layout--workspace .chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 100%;
}

.lib-context-panel .lib-context-tabs .tab {
  border-radius: var(--radius-sm);
}

@media (max-width: 1280px) {
  .app-shell--workspace .shell-body-inner {
    grid-template-columns: 1fr min(300px, 30vw);
  }

  :root {
    --shell-context-width: min(300px, 30vw);
  }
}

@media (max-width: 1024px) {
  .app-shell--nav-open .shell-main-area {
    margin-left: calc(var(--shell-rail-width) + min(var(--shell-nav-drawer-width), 240px));
  }

  .shell-workspace-canvas,
  .main-content--classic {
    padding-left: 16px;
    padding-right: 16px;
  }

  .matter-header__bar {
    padding: 10px 16px;
  }

  .matter-header__meta {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  .shell-rail {
    display: none;
  }

  .shell-nav-drawer {
    left: 0;
    width: min(300px, 88vw);
    z-index: 1001;
  }

  .matter-header,
  .app-shell--nav-open .matter-header {
    left: 0;
    right: 0;
  }

  .shell-main-area,
  .app-shell--nav-open .shell-main-area,
  .app-shell .main-area.shell-main-area,
  .app-shell.app-shell--nav-open .main-area.shell-main-area {
    margin-left: 0 !important;
  }

  .app-shell--workspace .shell-body-inner {
    grid-template-columns: 1fr;
  }

  .shell-context-panel {
    display: none;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(360px, 92vw);
    z-index: 1002;
    max-height: 100vh;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
  }

  .shell-context-panel.is-mobile-open {
    display: flex;
  }

  .shell-context-fab {
    display: flex;
    position: fixed;
    right: 16px;
    bottom: calc(var(--bottom-nav-height, 64px) + 16px);
    z-index: 998;
    padding: 12px 16px;
    border-radius: 999px;
    border: none;
    background: var(--brand-gradient);
    color: #fff;
    font-weight: 700;
    font-size: 0.8125rem;
    box-shadow: var(--shadow-glow-sm);
    cursor: pointer;
  }

  .shell-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .shell-nav-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .matter-header__bar {
    gap: 6px;
    padding: 8px 10px;
  }

  .matter-header__menu {
    display: flex;
  }

  .shell-nav-drawer {
    padding-top: max(12px, env(safe-area-inset-top, 0px));
  }

  .matter-header__meta {
    padding: 0 10px 8px;
  }

  .shell-workspace-canvas {
    padding: var(--space-sm) 10px;
    padding-bottom: calc(var(--bottom-nav-height, 56px) + 64px + env(safe-area-inset-bottom, 0px));
  }

  .matter-header__actions {
    gap: 2px;
  }

  .matter-header__actions .btn-icon {
    width: 34px;
    height: 34px;
  }

  .shell-context-fab {
    bottom: calc(var(--bottom-nav-height, 56px) + 12px);
    right: 12px;
    padding: 10px 14px;
    font-size: 0.75rem;
  }
}

[data-theme="light"] .shell-rail,
[data-theme="light"] .shell-nav-drawer {
  background: var(--brand-white);
}


/* Corpus sync badge — context sidebar & nav drawer (not header) */
.corpus-sync-sidebar {
  margin-bottom: 12px;
}

.corpus-sync-sidebar .sync-pill--sidebar {
  width: 100%;
  box-sizing: border-box;
  justify-content: flex-start;
}

.shell-nav-drawer__sync {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 4px;
}

.shell-nav-drawer__sync .corpus-sync-sidebar {
  margin-bottom: 0;
}

.corpus-sync-hint {
  color: var(--text-muted);
}

.matter-header__meta:empty { display: none; }

/* ---- Ask AI header pill (Kodee-style) ---- */
.matter-header__ask-ai {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background:
    linear-gradient(var(--bg-primary), var(--bg-primary)) padding-box,
    linear-gradient(90deg, var(--primary), var(--secondary, #3b82f6)) border-box;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  flex-shrink: 0;
}

.matter-header__ask-ai:hover {
  box-shadow: var(--shadow-glow-sm);
  transform: translateY(-1px);
}

.matter-header__ask-ai.is-active {
  background:
    linear-gradient(rgba(var(--brand-rgb), 0.08), rgba(var(--brand-rgb), 0.08)) padding-box,
    linear-gradient(90deg, var(--primary), var(--secondary, #3b82f6)) border-box;
}

.matter-header__ask-ai .fcp-sparkle {
  width: 18px;
  height: 18px;
}

@media (max-width: 1024px) {
  .matter-header__ask-ai {
    display: none;
  }
}
