/* ==========================================================================
   OrbisX — Layout: Sidebar, Topbar, Content, Tab Bar
   ========================================================================== */

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

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

/* ── Sidebar (Desktop) ─────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateX(-100%);
  transition: transform var(--duration-medium) var(--ease-default);
  box-shadow: var(--shadow-xl);
  border-right: 1px solid var(--color-sidebar-border);
}
.sidebar.open {
  transform: translateX(0);
}

.sidebar-logo {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-sidebar-border);
}

.sidebar-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease-default);
}
.sidebar-close:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-text-primary);
}

.sidebar-logo .logo-text {
  font-size: 1.5rem;
  font-weight: var(--weight-bold);
  color: var(--color-text-primary);
  letter-spacing: -0.5px;
  user-select: none;
}
.sidebar-logo .logo-text span {
  color: var(--color-brand-emerald);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-3) 0;
}

.nav-section-label {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-disabled);
  padding: var(--space-4) var(--space-6) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 11px var(--space-4);
  border-radius: var(--radius-sm);
  margin: 2px var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-sidebar-text);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  text-decoration: none;
  user-select: none;
}

.nav-item:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-text-hover);
}

.nav-item.active {
  background: var(--color-sidebar-active-bg);
  color: #FFFFFF;
  font-weight: var(--weight-semibold);
  box-shadow: 0 6px 16px -8px rgba(16, 185, 129, 0.55);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  opacity: 1;
}

/* ── Collapsible nav groups ──────────────────────────────────────────── */
.nav-group {
  display: flex;
  flex-direction: column;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: calc(100% - var(--space-3) * 2);
  padding: 11px var(--space-4);
  margin: 2px var(--space-3);
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-sidebar-text);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
.nav-group-toggle:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-text-hover);
}
.nav-group-toggle .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-group-toggle:hover .nav-icon,
.nav-group.is-open .nav-group-toggle .nav-icon {
  opacity: 1;
}
.nav-group-label { flex: 1; }
.nav-group-chev {
  width: 14px;
  height: 14px;
  opacity: 0.6;
  transition: transform var(--duration-fast) var(--ease-default),
              opacity var(--duration-fast) var(--ease-default);
}
.nav-group-toggle:hover .nav-group-chev { opacity: 0.9; }
.nav-group.is-open .nav-group-chev { transform: rotate(90deg); opacity: 0.9; }
.nav-group.is-open > .nav-group-toggle { color: var(--color-sidebar-text-hover); }

/* Animated collapse — max-height keeps it simple + compatible */
.nav-group-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--duration-base) var(--ease-default);
}
.nav-group.is-open > .nav-group-items { max-height: 600px; }
.nav-group-items > div {
  display: flex;
  flex-direction: column;
  padding-bottom: 4px;
}

/* Sub-item: indented, smaller, no icon column */
.nav-item-sub {
  padding: 7px var(--space-4) 7px calc(var(--space-4) + 32px);
  margin: 1px var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  color: var(--color-sidebar-text);
  opacity: 0.78;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.nav-item-sub:hover {
  opacity: 1;
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-text-hover);
  box-shadow: none;
}
.nav-item-sub.active {
  background: var(--color-brand-emerald-50, #E6F9FD);
  color: var(--color-brand-emerald-deep, #007F93);
  font-weight: var(--weight-semibold);
  border-left-color: var(--color-brand-emerald);
  opacity: 1;
  box-shadow: inset 3px 0 0 var(--color-brand-emerald);
}
.nav-item-sub.active:hover {
  background: var(--color-brand-emerald-light, #CFF5FB);
  color: var(--color-brand-emerald-deep, #007F93);
}

/* Super-admin group gets a subtle accent so it's distinct */
.nav-group-super > .nav-group-toggle .nav-icon { color: var(--color-brand-amber, #f59e0b); opacity: 1; }

/* Divider between the collapsible groups and pinned bottom items */
.nav-divider {
  height: 1px;
  background: var(--color-sidebar-border);
  margin: var(--space-3) var(--space-4);
  opacity: 0.4;
}

.sidebar-footer {
  padding: var(--space-3) var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ── Sidebar: User Card ────────────────────────────────────────────────── */

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-default);
}
.sidebar-user:hover {
  background: var(--color-sidebar-hover);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-brand-emerald);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 11px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Sidebar: Membership Card ──────────────────────────────────────────── */

.membership-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.membership-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.membership-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-success);
}

.membership-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Status variants */
.membership-card[data-status="trial"] .membership-status { color: var(--color-info); }
.membership-card[data-status="trial"] .membership-status-dot { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }

.membership-card[data-status="renewing-soon"] .membership-status { color: var(--color-warning); }
.membership-card[data-status="renewing-soon"] .membership-status-dot { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2); }

.membership-card[data-status="past-due"] .membership-status,
.membership-card[data-status="canceled"] .membership-status { color: var(--color-danger); }
.membership-card[data-status="past-due"] .membership-status-dot,
.membership-card[data-status="canceled"] .membership-status-dot { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

.membership-plan {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  color: var(--color-brand-emerald-deep);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--color-brand-emerald-light);
  border: 1px solid transparent;
}

.membership-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: 11px;
}

.membership-meta-label {
  color: var(--color-text-secondary);
}

.membership-meta-value {
  color: var(--color-text-primary);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.membership-cta {
  display: block;
  text-align: center;
  font-size: 12px;
  font-weight: var(--weight-semibold);
  color: var(--color-brand-emerald);
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-default);
}
.membership-cta:hover {
  background: var(--color-brand-emerald);
  border-color: var(--color-brand-emerald);
  color: #fff;
}

.nav-item-signout {
  margin: 0 !important;
}

/* ── Sidebar: What's New Badge ─────────────────────────────────────────── */

.nav-item-text {
  flex: 1;
}

.nav-item-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  background: var(--color-brand-cyan);
  color: #fff;
  font-size: 10px;
  font-weight: var(--weight-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 0 0 3px rgba(0, 196, 224, 0.15);
}
.nav-item.active .nav-item-badge {
  background: rgba(255, 255, 255, 0.25);
  box-shadow: none;
}
.nav-item-badge:empty,
.nav-item-badge[data-count="0"] {
  display: none;
}

/* ── Main Wrapper ──────────────────────────────────────────────────────── */

.main-wrapper {
  flex: 1;
  margin-left: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ── Top Bar ───────────────────────────────────────────────────────────── */

.topbar {
  height: var(--topbar-height);
  background: var(--color-bg-primary);
  border-bottom: 1px solid var(--color-border-subtle);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 30;
  gap: var(--space-4);
}

.topbar-left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-search {
  position: relative;
  width: 280px;
}

.topbar-search input {
  width: 100%;
  background: var(--color-bg-secondary);
  border: 1.5px solid transparent;
  border-radius: var(--radius-full);
  padding: 8px 14px 8px 36px;
  font-size: var(--text-sm);
  color: var(--color-text-body);
  transition: all var(--duration-fast) var(--ease-default);
}

.topbar-search input:focus {
  border-color: var(--color-brand-emerald);
  background: var(--color-bg-primary);
  box-shadow: 0 0 0 3px var(--color-brand-emerald-glow);
}

.topbar-search input::placeholder {
  color: var(--color-text-disabled);
}

.topbar-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-disabled);
  pointer-events: none;
}

.topbar-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-text-secondary);
  border: none;
  cursor: pointer;
  position: relative;
  transition: all var(--duration-fast) var(--ease-default);
}
.topbar-btn:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}
.topbar-btn .badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 2px solid var(--color-bg-primary);
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-brand-emerald);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--ease-default);
}
.topbar-avatar:hover { opacity: 0.85; }

.hamburger-btn {
  display: flex;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default);
}
.hamburger-btn:hover {
  background: var(--color-bg-secondary);
}

/* ── Main Content ──────────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  padding: var(--space-6);
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ── App Footer ────────────────────────────────────────────────────────── */

.app-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  background: var(--color-bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.app-footer-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: var(--weight-medium);
  color: var(--color-text-body);
}

.app-footer-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.app-footer-sep {
  color: var(--color-text-disabled);
}

.app-footer-link {
  color: var(--color-brand-emerald);
  text-decoration: none;
  font-weight: var(--weight-medium);
  transition: color var(--duration-fast) var(--ease-default);
}
.app-footer-link:hover {
  color: var(--color-brand-emerald-dark);
  text-decoration: underline;
}

/* reCAPTCHA disclosure — required by Google when the badge is hidden, but
   kept visually muted so it doesn't compete with the rest of the footer. */
.app-footer-recaptcha {
  font-size: 10px;
  line-height: 1.4;
  color: var(--color-text-disabled);
  opacity: 0.55;
  text-align: center;
  max-width: 480px;
  margin-top: 2px;
}
.app-footer-recaptcha a {
  color: inherit;
  text-decoration: underline;
}
.app-footer-recaptcha a:hover { color: var(--color-text-secondary); }

.app-footer .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  position: relative;
  flex-shrink: 0;
}
.app-footer .pulse-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--color-success);
  opacity: 0;
  animation: app-footer-pulse 2s ease-out infinite;
}
@keyframes app-footer-pulse {
  0%   { transform: scale(1);   opacity: 0.5; }
  100% { transform: scale(2.4); opacity: 0;   }
}

/* ── Bottom Tab Bar (Mobile) ───────────────────────────────────────────── */

.tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tabbar-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border-subtle);
  justify-content: space-around;
  align-items: center;
  z-index: 40;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.tab-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: var(--weight-medium);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-default);
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}

.tab-bar-item .tab-icon {
  width: 22px;
  height: 22px;
}

.tab-bar-item.active {
  color: var(--color-brand-cyan);
}
.tab-bar-item.active .tab-icon {
  color: var(--color-brand-cyan);
}

/* ── Sidebar Overlay (Tablet) ──────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 39;
}

.sidebar-overlay.visible {
  display: block;
  animation: fadeIn var(--duration-normal) var(--ease-default);
}

/* ── Quick Panel (Right Slide-Out) ─────────────────────────────────────── */

.quick-panel {
  width: 420px;
  max-width: 92vw;
  background: var(--color-bg-primary);
  height: 100vh;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform var(--duration-medium) var(--ease-default);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
  border-left: 1px solid var(--color-border-subtle);
}
.quick-panel.open {
  transform: translateX(0);
}

.quick-panel-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.quick-panel-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.quick-panel-close {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default);
}
.quick-panel-close:hover {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.quick-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.quick-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 49;
}
.quick-panel-overlay.visible {
  display: block;
  animation: fadeIn var(--duration-normal) var(--ease-default);
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 639px) {
  .tab-bar {
    display: flex;
  }
  .main-content {
    padding: var(--space-4);
  }
  .app-footer {
    padding: var(--space-4) var(--space-4);
    margin-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
  }
  .topbar {
    padding: 0 var(--space-4);
  }
  .topbar-search {
    display: none;
  }
}

/* ── Login Layout (no sidebar/topbar) ──────────────────────────────────── */

.login-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-6);
  background: var(--color-brand-gunmetal);
}

.login-card {
  background: #242D40;
  border: 1px solid #2E3A52;
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 196, 224, 0.04);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-6) 0;
  color: #7A8FA8;
  font-size: var(--text-sm);
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #2E3A52;
}
