:root {
  --app-sidebar-width: 220px;
  --app-shell-bg: #eef3f9;
  --app-shell-surface: #ffffff;
  --app-shell-border: #dbe4ef;
  --app-shell-text: #162033;
  --app-shell-muted: #6b7280;
  --app-shell-blue: #173d74;
  --app-shell-blue-dark: #102f5c;
  --app-shell-blue-light: #edf4ff;
  --app-shell-green: #0f766e;
  --app-shell-shadow: 0 18px 44px rgba(15, 23, 42, 0.08);
  --app-mobile-header-h: 64px;
}

body.has-app-shell {
  background: var(--app-shell-bg);
}

/* ── Shell ─────────────────────────────────────────────── */

.app-shell {
  position: relative;
  width: 0;
  height: 0;
}

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

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--app-sidebar-width);
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.16), transparent 28%),
    linear-gradient(180deg, #102f5c 0%, #0b2447 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 10px 0 32px rgba(15, 23, 42, 0.16);
  z-index: 120;
  overflow: visible;
}

.app-sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  padding: 24px 16px 18px;
  overflow-y: auto;
  overflow-x: visible;
}

/* ── Brand ─────────────────────────────────────────────── */

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.app-brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-brand-mark svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.app-brand-copy {
  min-width: 0;
}

.app-brand-title {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.app-brand-sub {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-env-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.18);
  border: 1px solid rgba(110, 231, 183, 0.35);
  color: #d1fae5;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

/* ── Sidebar nav groups ────────────────────────────────── */

.app-sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.app-sidebar-label-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.48);
  font-family: inherit;
  transition: color 0.15s ease;
}

.app-sidebar-label-btn:hover {
  color: rgba(255, 255, 255, 0.85);
}

.app-sidebar-label-text {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: left;
  flex: 1;
}

.app-sidebar-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.app-sidebar-chevron svg {
  width: 100%;
  height: 100%;
}

.app-sidebar-group.collapsed .app-sidebar-chevron {
  transform: rotate(-90deg);
}

.app-sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 500px;
  opacity: 1;
}

.app-sidebar-group.collapsed .app-sidebar-links {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.app-sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: inherit;
  transition: transform 0.2s ease;
}

.app-sidebar-icon svg {
  width: 100%;
  height: 100%;
  stroke-width: 2.15;
}

.app-sidebar-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transform: translateX(2px);
}

.app-sidebar-link:hover .app-sidebar-icon {
  transform: scale(1.1);
}

.app-sidebar-link.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 800;
  box-shadow: inset 3px 0 0 #fff, 0 12px 24px rgba(15, 23, 42, 0.18);
}

.app-sidebar-link.active .app-sidebar-icon {
  color: #fff;
}

.app-sidebar-spacer {
  flex: 1;
}

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

.app-sidebar-footer {
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}

/* ── Avatar ────────────────────────────────────────────── */

.user-avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  user-select: none;
}

.user-avatar--sm {
  width: 32px;
  height: 32px;
  font-size: 12px;
}

.user-avatar--md {
  width: 40px;
  height: 40px;
  font-size: 15px;
  border: 2px solid rgba(255, 255, 255, 0.22);
}

.user-avatar--lg {
  width: 84px;
  height: 84px;
  font-size: 30px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.22);
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.user-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* ── Sidebar user profile trigger ──────────────────────── */

.user-profile {
  position: relative;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.user-menu:hover {
  background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.08));
  border-color: rgba(255,255,255,.2);
  transform: translateY(-1px);
}

.user-menu-info {
  flex: 1;
  min-width: 0;
}

.user-menu-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-role {
  margin-top: 2px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-caret {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.6);
  transition: transform 0.2s ease;
}

.user-menu[aria-expanded="true"] .user-menu-caret {
  transform: rotate(180deg);
}

/* ── Dropdown (shared) ─────────────────────────────────── */

.user-menu-dropdown {
  position: absolute;
  min-width: 200px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
  padding: 8px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96) translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.user-menu-dropdown.open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

/* Sidebar dropdown opens upward */
.user-menu-dropdown--up {
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  transform-origin: bottom center;
}

.user-menu-dropdown--up.open {
  transform: scale(1) translateY(0);
}

/* Mobile dropdown opens downward, fixed below header */
.user-menu-dropdown--mobile {
  position: fixed;
  top: calc(var(--app-mobile-header-h) + 8px);
  right: 12px;
  left: auto;
  width: 220px;
  transform-origin: top right;
}

/* ── Dropdown content ──────────────────────────────────── */

.user-menu-hd {
  padding: 6px 8px 10px;
}

.user-menu-hd-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--app-shell-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-hd-role {
  margin-top: 2px;
  font-size: 11px;
  color: var(--app-shell-muted);
}

.user-menu-divider {
  height: 1px;
  background: var(--app-shell-border);
  margin: 4px 0;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--app-shell-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.user-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--app-shell-muted);
}

.user-menu-item:hover {
  background: var(--app-shell-blue-light);
  color: var(--app-shell-blue);
}

.user-menu-item:hover svg {
  color: var(--app-shell-blue);
}

.user-menu-item--danger {
  color: #b91c1c;
}

.user-menu-item--danger svg {
  color: #b91c1c;
}

.user-menu-item--danger:hover {
  background: #fef2f2;
  color: #991b1b;
}

.user-menu-item--danger:hover svg {
  color: #991b1b;
}

/* ── Main content area ─────────────────────────────────── */

.app-main {
  margin-left: var(--app-sidebar-width);
  min-height: 100vh;
  padding: 28px 24px 34px;
}

.app-main-narrow {
  max-width: 640px;
}

/* ── Mobile header (hidden on desktop) ─────────────────── */

.app-mobile-header {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

/* ── Mobile profile button ─────────────────────────────── */

.mobile-user-profile {
  position: relative;
  flex-shrink: 0;
}

.mobile-user-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}

.mobile-user-btn .user-avatar--sm {
  border: 2px solid rgba(26, 58, 107, 0.18);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.mobile-user-btn:hover .user-avatar--sm,
.mobile-user-btn[aria-expanded="true"] .user-avatar--sm {
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
  transform: scale(1.06);
}

/* ── Page shell header ─────────────────────────────────── */

.page-shell-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 20px;
  padding: 22px 24px;
  background:
    radial-gradient(circle at top left, rgba(22, 119, 255, 0.08), transparent 28%),
    linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--app-shell-border);
  border-radius: 22px;
  box-shadow: var(--app-shell-shadow);
}

.page-shell-title h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--app-shell-blue);
}

.page-shell-title p {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--app-shell-muted);
}

.page-shell-eyebrow {
  display: inline-block;
  margin-bottom: 0px;
  font-size: 11px;
  font-weight: 700;
  color: var(--app-shell-green);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-shell-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.page-action,
.page-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--app-shell-border);
  background: #fff;
  color: var(--app-shell-blue);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.page-action {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.page-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08);
}

.page-action-accent {
  background: var(--app-shell-blue);
  border-color: var(--app-shell-blue);
  color: #fff;
}

.page-action-green {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}

.page-status-pill {
  color: var(--app-shell-green);
  background: #ecfdf5;
  border-color: #bbf7d0;
}

/* ── Profile modal ─────────────────────────────────────── */

.profile-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.profile-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.profile-modal--open .profile-modal-backdrop {
  opacity: 1;
}

.profile-modal-inner {
  position: relative;
  background: #fff;
  border-radius: 24px;
  padding: 36px 32px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.profile-modal--open .profile-modal-inner {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.profile-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--app-shell-border);
  background: #f8fafc;
  color: var(--app-shell-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.profile-modal-close:hover {
  background: var(--app-shell-border);
  color: var(--app-shell-text);
}

.profile-modal-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 0px;
}

.profile-avatar-change {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--app-shell-border);
  background: #f8fafc;
  color: var(--app-shell-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: not-allowed;
  opacity: 0.75;
}

.profile-avatar-change svg {
  width: 14px;
  height: 14px;
}

.profile-modal-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--app-shell-text);
  margin-top: 4px;
}

.profile-modal-role {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--app-shell-blue-light);
  color: var(--app-shell-blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.profile-modal-email {
  font-size: 13px;
  color: var(--app-shell-muted);
  margin-top: 2px;
}

.profile-modal-note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--app-shell-muted);
  line-height: 1.5;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid var(--app-shell-border);
  width: 100%;
}

/* ── Responsive: 900px ─────────────────────────────────── */

@media (max-width: 900px) {
  .page-shell-header {
    padding: 20px;
  }

  .page-shell-title h1 {
    font-size: 24px;
  }
}

/* ── Responsive: mobile ≤768px ─────────────────────────── */

@media (max-width: 768px) {
  .app-sidebar {
    display: none;
  }

  .app-main {
    margin-left: 0;
    padding: 84px 14px 88px;
  }

  /* Mobile header */
  .app-mobile-header {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--app-mobile-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(219, 228, 239, 0.9);
    z-index: 110;
  }

  .app-mobile-title {
    flex: 1;
    min-width: 0;
  }

  .app-mobile-title strong {
    display: block;
    font-size: 16px;
    color: var(--app-shell-blue);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .app-mobile-title span {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    color: var(--app-shell-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* Bottom nav */
  .mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    display: flex;
    align-items: stretch;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid rgba(219, 228, 239, 0.95);
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
    z-index: 110;
  }

  .mobile-bottom-link {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 4px 12px;
    color: var(--app-shell-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-bottom-link.active {
    color: var(--app-shell-blue);
    background: rgba(26, 58, 107, 0.06);
  }

  .mobile-bottom-icon {
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
  }

  .mobile-bottom-icon svg {
    width: 100%;
    height: 100%;
  }

  /* Page shell on mobile */
  .page-shell-header {
    flex-direction: column;
    padding: 18px 16px;
    border-radius: 18px;
    margin-bottom: 16px;
  }

  .page-shell-title h1 {
    font-size: 22px;
  }

  .page-shell-title p {
    font-size: 13px;
  }

  .page-shell-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .page-action,
  .page-status-pill {
    min-height: 38px;
    font-size: 12px;
  }

  /* Profile modal on mobile */
  .profile-modal {
    align-items: flex-end;
    padding: 0;
  }

  .profile-modal-inner {
    border-radius: 24px 24px 0 0;
    max-width: 100%;
    padding: 32px 24px 36px;
  }
}
