/* ─── Academy Layout ───
 * Header, Tab Bar, Page Content, Desktop Sidebar
 */

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 var(--page-padding);
  background: rgba(2,4,8,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-title {
  font-size: var(--font-lg);
  font-weight: var(--font-weight-bold);
  color: var(--brand-gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-left,
.header-right {
  min-width: var(--touch-target);
  display: flex;
  align-items: center;
}

.header-right { justify-content: flex-end; }

.header-back {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.header-back:active { background: var(--gold-glow); }

.user-badge {
  font-size: var(--font-xs);
  color: var(--gold-soft);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Page Content ── */
.page-content {
  padding: var(--page-padding);
  padding-bottom: var(--page-padding);
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
}

.page-content.has-tabbar {
  padding-bottom: calc(var(--tabbar-h) + var(--page-padding) + env(safe-area-inset-bottom, 0px));
}

/* ── Tab Bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-tabbar);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(2,4,8,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: var(--tabbar-h);
  color: var(--text-muted);
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-item.active {
  color: var(--brand-gold);
}

.tab-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: var(--brand-gold);
  border-radius: 0 0 2px 2px;
}

.tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.tab-label {
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  line-height: 1;
}

/* ── Desktop: Convert Tab Bar to top horizontal nav ── */
@media (min-width: 768px) {
  .tab-bar {
    position: fixed;
    top: var(--header-h);
    bottom: auto;
    left: 0;
    right: 0;
    height: 44px;
    padding-bottom: 0;
    border-top: none;
    border-bottom: 1px solid var(--border-subtle);
    justify-content: center;
    gap: var(--space-sm);
  }

  .tab-item {
    flex: 0 0 auto;
    flex-direction: row;
    gap: var(--space-sm);
    height: 44px;
    padding: 0 var(--space-lg);
    border-radius: var(--radius-btn);
  }

  .tab-item:hover {
    background: rgba(255,255,255,0.04);
  }

  .tab-item.active::before {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 2px;
    transform: none;
    border-radius: 2px 2px 0 0;
  }

  .tab-label {
    font-size: var(--font-xs);
  }

  .page-content {
    max-width: var(--content-max-w);
    margin: 0 auto;
    padding-bottom: var(--page-padding);
  }

  .page-content--wide {
    max-width: var(--content-max-w-wide);
  }

  /* Add top padding to account for fixed TabBar */
  .page-content.has-tabbar {
    padding-top: 44px;
    padding-bottom: var(--page-padding);
  }
}

/* ── Desktop: Sidebar (optional, rendered by app.js for L3+ on wide screens) ── */
.desktop-sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--space-xl);
    z-index: var(--z-header);
    overflow-y: auto;
  }

  .desktop-sidebar .sidebar-logo {
    font-size: var(--font-xl);
    font-weight: var(--font-weight-black);
    color: var(--brand-gold);
    margin-bottom: var(--space-3xl);
    padding: var(--space-sm) 0;
  }

  .desktop-sidebar .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }

  .desktop-sidebar .sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-btn);
    color: var(--text-secondary);
    font-size: var(--font-sm);
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-fast);
  }

  .desktop-sidebar .sidebar-link:hover {
    background: var(--gold-glow);
    color: var(--text-primary);
  }

  .desktop-sidebar .sidebar-link.active {
    background: var(--gold-bg);
    color: var(--brand-gold);
  }

  .desktop-sidebar .sidebar-link svg {
    flex-shrink: 0;
  }

  /* Offset main content */
  .has-sidebar .header {
    left: var(--sidebar-w);
  }

  .has-sidebar .page-content {
    margin-left: var(--sidebar-w);
  }
}
