/* Portal shell, navigation, topbar, and profile styles */

    .wrap {
      min-height: 100vh;
      height: 100vh;
      overflow: hidden;
    }
    .app-shell {
      display: grid;
      grid-template-columns: 300px 1fr;
      min-height: 100vh;
      height: 100vh;
      overflow: hidden;
      transition: grid-template-columns 0.2s ease;
    }
    .app-shell.sidebar-collapsed {
      grid-template-columns: 64px 1fr;
    }
    .sidebar {
      background: linear-gradient(180deg, #14171b, #111417 40%, var(--nav) 100%);
      color: #fff;
      padding: 18px 16px;
      border-right: 1px solid var(--nav-line);
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      position: sticky;
      top: 0;
      height: 100vh;
      overflow: hidden;
      overflow-x: hidden;
      scrollbar-width: none;
      transition: transform 0.2s ease, opacity 0.2s ease;
      z-index: 30;
    }
    .sidebar::-webkit-scrollbar {
      display: none;
    }
    .app-shell.sidebar-collapsed .sidebar {
      display: flex;
      padding: 12px 6px;
    }
    .app-shell.sidebar-collapsed .brand-wordmark,
    .app-shell.sidebar-collapsed .sidebar-k,
    .app-shell.sidebar-collapsed .portal-nav button > span:last-child,
    .app-shell.sidebar-collapsed .sidebar table {
      display: none;
    }
    .app-shell.sidebar-collapsed .sidebar-head {
      justify-content: center;
    }
    .app-shell.sidebar-collapsed .brand {
      padding: 8px 0 12px;
      display: flex;
      justify-content: center;
    }
    .app-shell.sidebar-collapsed .brand-lockup {
      justify-content: center;
    }
    .app-shell.sidebar-collapsed .sidebar-block {
      margin-top: 10px;
      padding-top: 8px;
    }
    .app-shell.sidebar-collapsed .portal-nav {
      gap: 8px;
      margin-top: 8px;
    }
    .app-shell.sidebar-collapsed .portal-nav button {
      justify-content: center;
      width: auto;
      min-width: 0;
      padding: 0;
      margin: 0 auto 8px;
      border-radius: 0;
      background: transparent;
      border: 0;
    }
    .app-shell.sidebar-collapsed .portal-nav button.active {
      background: transparent;
      border-color: transparent;
    }
    .app-shell.sidebar-collapsed .portal-nav-icon {
      width: 24px;
      height: 24px;
      font-size: 10px;
    }
    .app-shell.sidebar-collapsed .portal-nav button.active .portal-nav-icon {
      background: var(--nav-active-bg);
      border-color: rgba(28,143,132,0.24);
      color: #dffaf6;
    }
    .sidebar-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
    }
    .sidebar-toggle {
      width: auto;
      min-width: 42px;
      height: 42px;
      padding: 0 12px;
      border-radius: 10px;
      background: rgba(255,255,255,0.05);
      color: #fff;
      border: 1px solid rgba(255,255,255,0.08);
      font-size: 13px;
      font-weight: 600;
    }
    .sidebar-close-mobile {
      display: none;
    }
    .sidebar-hide-desktop {
      display: inline-flex;
    }
    .mobile-sidebar-backdrop {
      display: none;
    }
    .brand {
      padding: 10px 10px 18px;
      border-bottom: 1px solid var(--nav-line);
      margin-bottom: 14px;
      flex: 0 0 auto;
    }
    .sidebar-scroll {
      min-height: 0;
      flex: 1 1 auto;
      overflow-y: auto;
      overflow-x: hidden;
      overscroll-behavior: contain;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: none;
    }
    .sidebar-scroll::-webkit-scrollbar {
      display: none;
    }
    .brand h1 { margin: 0; font-size: 16px; letter-spacing: -0.02em; }
    .brand-mark {
      width: 28px;
      height: 28px;
      border-radius: 10px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: rgba(28,143,132,0.12);
      border: 1px solid rgba(28,143,132,0.22);
      color: #49d8bf;
      font-size: 18px;
      line-height: 1;
      box-shadow: inset 0 0 0 1px rgba(73,216,191,0.08);
      flex: 0 0 auto;
    }
    .brand-lockup {
      display: flex;
      align-items: center;
      gap: 12px;
      min-width: 0;
    }
    .brand-wordmark {
      display: flex;
      align-items: baseline;
      gap: 3px;
      white-space: nowrap;
      font-size: 16px;
      line-height: 1;
    }
    .brand-wordmark strong {
      color: #f7fafc;
      font-weight: 800;
    }
    .brand-wordmark span {
      color: rgba(255,255,255,0.88);
      font-weight: 500;
    }
    .sidebar-block {
      margin-top: 18px;
      padding-top: 14px;
      border-top: 1px solid var(--nav-line);
    }
    .portal-nav {
      display: grid;
      gap: 6px;
      margin-top: 14px;
    }
    .portal-nav button {
      width: 100%;
      text-align: left;
      background: transparent;
      color: var(--nav-text);
      border: 1px solid transparent;
      padding: 10px 12px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      gap: 10px;
      font-size: var(--fs-body);
      font-weight: 600;
    }
    .portal-nav button.active {
      background: var(--nav-active-bg);
      color: var(--nav-active);
      border-color: rgba(28,143,132,0.22);
    }
    .portal-nav-icon {
      width: 24px;
      height: 24px;
      border-radius: 8px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: rgba(255,255,255,0.04);
      color: #a9b4c1;
      border: 1px solid rgba(255,255,255,0.06);
      font-size: 11px;
      font-weight: 700;
      flex: 0 0 auto;
    }
    .portal-nav button.active .portal-nav-icon {
      background: rgba(28,143,132,0.2);
      color: #dffaf6;
      border-color: rgba(28,143,132,0.24);
    }
    .nav-count-badge {
      margin-left: auto;
      min-width: 20px;
      height: 20px;
      border-radius: 999px;
      padding: 0 6px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 800;
      line-height: 1;
      color: #fff;
      background: rgba(209, 106, 104, 0.95);
    }
    .nav-count-badge.hidden {
      display: none;
    }
    .sidebar-k {
      font-size: var(--fs-helper);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: rgba(255,255,255,0.45);
    }
    .sidebar-v {
      margin-top: 8px;
      font-size: 16px;
      font-weight: 700;
      color: #fff;
    }
    .main {
      display: grid;
      grid-template-rows: auto minmax(0, 1fr);
      gap: 10px;
      align-content: start;
      padding: 0 18px 0;
      background: linear-gradient(180deg, rgba(255,255,255,0.01), rgba(255,255,255,0));
      min-width: 0;
      height: 100vh;
      overflow: hidden;
    }
    .main-scroll {
      display: grid;
      gap: 10px;
      align-content: start;
      min-height: 0;
      overflow-y: auto;
      overflow-x: hidden;
      padding-bottom: 18px;
    }
    .topbar {
      display: flex;
      justify-content: space-between;
      gap: 14px;
      align-items: center;
      min-width: 0;
      padding: 14px 0 12px;
      border-bottom: 1px solid var(--line);
    }
    .topbar-actions {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: nowrap;
      justify-content: flex-start;
      min-width: 0;
    }
    .portal-session-check-overlay {
      position: fixed;
      right: 22px;
      bottom: 22px;
      z-index: 80;
      pointer-events: none;
    }
    .portal-session-check-overlay.hidden {
      display: none;
    }
    .portal-session-check-pill {
      display: inline-flex;
      align-items: center;
      gap: 9px;
      min-height: 42px;
      padding: 0 14px;
      border-radius: 999px;
      border: 1px solid var(--line);
      background: var(--panel);
      color: var(--text);
      box-shadow: 0 12px 28px rgba(0,0,0,0.22);
      font-size: 13px;
      font-weight: 700;
    }
    .portal-session-check-dot {
      width: 9px;
      height: 9px;
      border-radius: 50%;
      background: var(--brand);
      animation: portalSessionPulse 0.9s ease-in-out infinite;
    }
    @keyframes portalSessionPulse {
      0%, 100% { transform: scale(0.85); opacity: 0.55; }
      50% { transform: scale(1.15); opacity: 1; }
    }
    .topbar-search-wrap {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 6px;
      min-width: 0;
      position: relative;
    }
    .topbar-menu {
      width: auto;
      min-width: 40px;
      height: 40px;
      padding: 0 11px;
      border-radius: 10px;
      background: rgba(28,143,132,0.14);
      color: #fff;
      border: 1px solid rgba(28,143,132,0.22);
      font-size: 16px;
      font-weight: 800;
      line-height: 1;
    }
    .theme-toggle {
      width: auto;
      height: 44px;
      padding: 0 14px;
      border-radius: 999px;
      background: #161a1f;
      color: #f4f7fb;
      border: 1px solid var(--line);
      font-size: var(--fs-body);
      font-weight: 700;
    }
    .page-heading {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      min-width: 0;
    }
    .page-heading h2 {
      margin: 0;
      font-size: var(--fs-title);
      letter-spacing: -0.03em;
    }
    .badge {
      background: rgba(28,143,132,0.12);
      color: #fff;
      border: 1px solid rgba(28,143,132,0.22);
      padding: 8px 12px;
      border-radius: 999px;
      font-size: var(--fs-body);
    }
    .hero-profile {
      display: inline-flex;
      align-items: center;
      gap: 10px;
      padding: 7px 10px;
      border-radius: 14px;
      background: #15191d;
      border: 1px solid var(--line);
      min-width: 220px;
      cursor: pointer;
      position: relative;
    }
    .hero-profile-avatar {
      width: 34px;
      height: 34px;
      border-radius: 999px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background: #2a3138;
      color: #f4f7fb;
      font-size: var(--fs-helper);
      font-weight: 800;
      flex: 0 0 auto;
    }
    .hero-profile-meta {
      min-width: 0;
    }
    .hero-profile-name {
      color: #f4f7fb;
      font-size: var(--fs-body);
      font-weight: 700;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .hero-profile-plan {
      color: #8fd7cb;
      font-size: var(--fs-helper);
      margin-top: 2px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .profile-dropdown {
      position: absolute;
      top: calc(100% + 10px);
      right: 0;
      width: min(360px, 92vw);
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 14px;
      box-shadow: 0 18px 36px rgba(0,0,0,0.22);
      z-index: 40;
      display: none;
      cursor: default;
    }
    .hero-profile.open .profile-dropdown {
      display: block;
    }
    .profile-dropdown h4 {
      margin: 0 0 6px;
      color: var(--ink);
      font-size: 16px;
    }
    .profile-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      margin-top: 12px;
      margin-bottom: 12px;
    }
    .profile-stat {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 12px;
      padding: 10px;
    }
    .profile-stat .k {
      font-size: 11px;
      color: var(--muted);
      text-transform: uppercase;
      letter-spacing: 0.06em;
      margin-bottom: 6px;
    }
    .profile-stat .v {
      color: var(--ink);
      font-size: 16px;
      font-weight: 700;
      word-break: break-word;
    }
    .profile-dropdown .toolbar {
      margin-top: 0;
    }

    body.light-theme .main {
      background: linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0.12));
    }
    body.light-theme .sidebar {
      background: linear-gradient(180deg, #f8fbfe, #eef4fa 42%, #e7eef6 100%);
      border-right-color: var(--line);
      color: var(--ink);
    }
    body.light-theme .mobile-sidebar-backdrop {
      background: rgba(235, 241, 247, 0.92);
    }
    body.light-theme .brand {
      border-bottom-color: var(--line);
    }
    body.light-theme .brand-mark {
      background: rgba(13,59,102,0.08);
      border-color: rgba(13,59,102,0.16);
      color: var(--brand);
      box-shadow: inset 0 0 0 1px rgba(13,59,102,0.04);
    }
    body.light-theme .brand-wordmark strong,
    body.light-theme .brand-wordmark span,
    body.light-theme .sidebar-v {
      color: var(--ink);
    }
    body.light-theme .sidebar-k {
      color: var(--muted);
    }
    body.light-theme .portal-nav button {
      color: var(--muted);
      border-color: transparent;
    }
    body.light-theme .portal-nav button:hover {
      background: rgba(13,59,102,0.06);
      color: var(--ink);
    }
    body.light-theme .portal-nav button.active {
      background: rgba(13,59,102,0.1);
      border-color: rgba(13,59,102,0.14);
      color: var(--ink);
    }
    body.light-theme .portal-nav-icon {
      background: #eef3f8;
      color: var(--brand);
    }
    body.light-theme .topbar,
    body.light-theme .page-heading {
      border-color: var(--line);
    }
    body.light-theme .topbar-menu,
    body.light-theme .hero-profile,
    body.light-theme .theme-toggle {
      background: #ffffff;
      border-color: var(--line);
      color: var(--ink);
    }
    body.light-theme .hero-profile-avatar {
      background: #ebf1f7;
      color: var(--ink);
    }
    body.light-theme .hero-profile-name {
      color: var(--ink);
    }
    body.light-theme .hero-profile-plan {
      color: var(--brand);
    }
    body.light-theme .profile-dropdown {
      background: #ffffff;
      box-shadow: 0 18px 36px rgba(31, 60, 92, 0.14);
    }
