/* Application shell — fixed left sidebar, off-canvas drawer below 1024px. */

:root {
  --app-sidebar-width: var(--ah-sidebar-w);
  /* Legacy aliases still read by feature stylesheets. */
  --app-surface: var(--ah-surface);
  --app-border: var(--ah-border);
  --app-text: var(--ah-ink);
  --app-text-soft: var(--ah-ink-2);
  --app-text-muted: var(--ah-ink-3);
  --app-mint: var(--ah-accent);
  --app-mint-strong: var(--ah-accent);
  --app-mint-soft: var(--ah-accent-soft);
  --app-shadow-sm: var(--ah-shadow-xs);
}

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

.app-shell__content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell__content .app-main {
  position: relative;
  flex: 1;
  padding: 0;
  isolation: isolate;
}

/* Canvas atmosphere: a faint teal wash behind the page header only. */
.app-shell__content .app-main::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 22rem;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60rem 18rem at 12% -6rem, rgba(20, 162, 145, 0.11), transparent 70%),
    radial-gradient(40rem 14rem at 92% -4rem, rgba(61, 111, 214, 0.06), transparent 70%);
}

.app-shell__backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 25, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ah-dur-3) var(--ah-ease-out);
}

/* ── Sidebar ─────────────────────────────────────────────── */

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: var(--app-sidebar-width);
  height: 100vh;
  height: 100dvh;
  padding: 0.875rem 0.625rem 0.75rem;
  padding-top: max(0.875rem, env(safe-area-inset-top));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  box-sizing: border-box;
  color: var(--ah-nav-text);
  background:
    radial-gradient(22rem 16rem at 0% 0%, rgba(45, 212, 191, 0.10), transparent 70%),
    linear-gradient(180deg, var(--ah-nav-bg-2) 0%, var(--ah-nav-bg) 42%);
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  overflow-y: auto;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  z-index: 50;
}

.app-sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ah-space-2);
  min-height: 3rem;
  height: auto;
  padding: 0.25rem 0.375rem;
  margin-bottom: 0.875rem;
}

.app-sidebar__brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--ah-nav-text-strong);
  text-decoration: none;
  border-radius: var(--ah-radius-sm);
}

.app-sidebar__brand:hover {
  text-decoration: none;
}

.app-sidebar__close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: var(--ah-radius-sm);
  background: transparent;
  color: var(--ah-nav-text);
  cursor: pointer;
  transition: background var(--ah-dur-1), color var(--ah-dur-1);
}

.app-sidebar__close:hover {
  background: var(--ah-nav-hover);
  color: var(--ah-nav-text-strong);
}

/* The panel scrolls when the nav is taller than the viewport; nothing shrinks. */
.app-sidebar > *,
.app-sidebar__nav > *,
.app-sidebar__sublist > * {
  flex-shrink: 0;
}

/* Primary action — a real button, same vocabulary as the page buttons. */
.app-sidebar__new-case {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.375rem;
  padding: 0 0.375rem 0 0.75rem;
  margin: 0 0 1.25rem;
  border: 0;
  border-radius: var(--ah-radius-md);
  background: var(--ah-accent-grad);
  color: #fff;
  font-size: var(--ah-text-sm);
  font-weight: var(--ah-weight-semibold);
  text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 6px 18px -8px var(--ah-accent-glow), 0 0 0 1px rgba(0, 0, 0, 0.25);
  transition: filter var(--ah-dur-2) var(--ah-ease-out), transform var(--ah-dur-1) var(--ah-ease-out), box-shadow var(--ah-dur-2);
}

.app-sidebar__new-case span {
  flex: 1;
}

/* Button-in-button: the plus sits in its own island. */
.app-sidebar__new-case svg {
  order: 2;
  width: 1.625rem;
  height: 1.625rem;
  padding: 0.3125rem;
  flex-shrink: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  box-sizing: border-box;
  transition: transform var(--ah-dur-3) var(--ah-ease-spring), background var(--ah-dur-2);
}

.app-sidebar__new-case:hover {
  color: #fff;
  text-decoration: none;
  filter: brightness(1.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 10px 24px -8px var(--ah-accent-glow), 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.app-sidebar__new-case:hover svg {
  transform: rotate(90deg);
  background: rgba(255, 255, 255, 0.24);
}

.app-sidebar__new-case:active {
  transform: scale(0.98);
}

.app-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
  flex: 1 0 auto;
}

.app-sidebar__group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.app-sidebar__group-head {
  padding: 0 0.625rem 0.375rem;
  font-size: var(--ah-text-xs);
  font-weight: var(--ah-weight-medium);
  color: var(--ah-nav-muted);
}

.app-sidebar__sublist {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.app-sidebar__link,
.app-sidebar__sublink {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2rem;
  padding: 0 0.625rem;
  border-radius: var(--ah-radius-sm);
  color: var(--ah-nav-text);
  font-size: var(--ah-text-sm);
  font-weight: var(--ah-weight-medium);
  text-decoration: none;
  transition: background var(--ah-dur-1), color var(--ah-dur-1);
}

.app-sidebar__link svg,
.app-sidebar__sublink svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--ah-nav-muted);
  transition: color var(--ah-dur-1);
}

/* Stage dots glow faintly on the dark rail. */
.app-sidebar__sublink .work-area-dot {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot) 22%, transparent);
}

.app-sidebar__sublink .work-area-dot {
  margin: 0 0.1875rem;
}

.app-sidebar__label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar__count {
  flex-shrink: 0;
  min-width: 1.25rem;
  font-size: var(--ah-text-xs);
  font-weight: var(--ah-weight-medium);
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 0.0625rem 0.375rem;
  border-radius: var(--ah-radius-pill);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ah-nav-text-strong);
}

.app-sidebar__count--zero {
  background: transparent;
  color: var(--ah-nav-muted);
  font-weight: var(--ah-weight-regular);
}

.app-sidebar__link:hover,
.app-sidebar__sublink:hover {
  background: var(--ah-nav-hover);
  color: var(--ah-nav-text-strong);
  text-decoration: none;
}

.app-sidebar__link:hover svg,
.app-sidebar__sublink:hover svg {
  color: var(--ah-nav-text-strong);
}

.app-sidebar__link--active,
.app-sidebar__sublink--active,
.app-sidebar__link--active:hover,
.app-sidebar__sublink--active:hover {
  background: var(--ah-nav-active);
  color: var(--ah-nav-text-strong);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.16);
}

/* Luminous indicator on the active item. */
.app-sidebar__link--active::before,
.app-sidebar__sublink--active::before {
  content: "";
  position: absolute;
  left: -0.625rem;
  top: 50%;
  width: 3px;
  height: 1rem;
  margin-top: -0.5rem;
  border-radius: 0 3px 3px 0;
  background: var(--ah-accent-bright);
  box-shadow: 0 0 12px 1px var(--ah-accent-glow);
  animation: ah-fade var(--ah-dur-3) var(--ah-ease-out);
}

.app-sidebar__link--active svg,
.app-sidebar__sublink--active svg {
  color: var(--ah-accent-bright);
}

.app-sidebar__sublink--active .app-sidebar__count {
  background: rgba(45, 212, 191, 0.2);
  color: #fff;
}

/* Work areas listed before the RX resource exists: shown, but not navigable. */
.app-sidebar__sublink--disabled,
.app-sidebar__sublink--disabled:hover {
  background: transparent;
  color: var(--ah-nav-muted);
  cursor: not-allowed;
}

/* ── Footer: account ─────────────────────────────────────── */

.app-sidebar__footer {
  display: flex;
  align-items: center;
  gap: var(--ah-space-2);
  margin-top: var(--ah-space-4);
  padding: 0.625rem 0.375rem 0.625rem 0.5rem;
  border-radius: var(--ah-radius-md);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px var(--ah-nav-line);
}

.app-sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: 1;
  min-width: 0;
}

.app-sidebar__avatar {
  display: inline-grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #2dd4bf, #0d7a70);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: var(--ah-text-2xs);
  font-weight: var(--ah-weight-semibold);
  letter-spacing: 0.02em;
}

.app-sidebar__user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.app-sidebar__user-name {
  font-size: var(--ah-text-sm);
  font-weight: var(--ah-weight-medium);
  color: var(--ah-nav-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar__user-role {
  font-size: var(--ah-text-xs);
  color: var(--ah-nav-muted);
}

.app-sidebar__logout-form {
  margin: 0;
}

.app-sidebar__logout {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: var(--ah-radius-sm);
  background: transparent;
  color: var(--ah-nav-muted);
  cursor: pointer;
  transition: background var(--ah-dur-1), color var(--ah-dur-1);
}

.app-sidebar__logout:hover {
  background: var(--ah-nav-hover);
  color: var(--ah-nav-text-strong);
}

.app-sidebar__logout svg {
  width: 16px;
  height: 16px;
}

/* ── Mobile top bar ──────────────────────────────────────── */

.app-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  gap: var(--ah-space-2);
  height: var(--ah-topbar-h);
  padding: 0 calc(var(--ah-gutter) - 0.5rem);
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background: rgba(238, 241, 242, 0.84);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--ah-border);
}

.app-topbar__toggle,
.app-topbar__action {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--ah-radius-md);
  background: transparent;
  color: var(--ah-ink-2);
  cursor: pointer;
  transition: background var(--ah-dur-1);
}

.app-topbar__toggle:active,
.app-topbar__action:active {
  background: var(--ah-surface-3);
}

.app-topbar__toggle svg,
.app-topbar__action svg {
  width: 20px;
  height: 20px;
}

.app-topbar__action {
  color: var(--ah-accent);
}

.app-topbar__title {
  flex: 1;
  min-width: 0;
  font-size: var(--ah-text-md);
  font-weight: var(--ah-weight-semibold);
  letter-spacing: -0.01em;
  color: var(--ah-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1024px) {
  .app-topbar {
    display: flex;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(18rem, 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--ah-dur-3) var(--ah-ease-out), visibility 0s linear var(--ah-dur-3);
    box-shadow: var(--ah-shadow-modal);
    border-right: 0;
  }

  .app-sidebar__close {
    display: inline-flex;
  }

  .app-sidebar__link,
  .app-sidebar__sublink {
    min-height: 2.75rem;
    font-size: var(--ah-text-base);
  }

  .app-sidebar__new-case {
    height: 2.75rem;
    font-size: var(--ah-text-base);
  }

  .app-sidebar__logout {
    width: 2.75rem;
    height: 2.75rem;
  }

  .app-shell--nav-open .app-sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--ah-dur-3) var(--ah-ease-out), visibility 0s;
  }

  .app-shell--nav-open .app-shell__backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body:has(.app-shell--nav-open) {
    overflow: hidden;
  }
}
