/* ============================================================
   PlayCaller App Shell — Gridiron Gold v2
   Grid layout: Sidebar + Topbar + Main content
   Depends on: design-system.css (tokens)
   ============================================================ */

/* ─── App Grid Layout ─────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden; /* contain all; .app-main scrolls internally */
  background: var(--surface-0);
}

/* ─── Sidebar ─────────────────────────────────────────── */
.app-sidebar {
  grid-column: 1;
  grid-row: 1 / 3; /* spans topbar + content rows */
  background: var(--surface-1);
  border-right: 1px solid rgba(201, 168, 76, 0.06);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  min-height: 100%; /* allow content to expand; sidebar overflow-y:auto handles scroll */
  padding: 20px 12px;
}

/* Sidebar logo area */
.sidebar-logo {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--gold);
  letter-spacing: 2px;
  text-decoration: none;
  padding: 0 8px 20px;
  border-bottom: 1px solid rgba(201, 168, 76, 0.06);
  margin-bottom: 20px;
  display: block;
  flex-shrink: 0;
}

/* Section labels */
.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 6px;
  margin-top: 8px;
  flex-shrink: 0; /* never compress — prevents overlap */
  line-height: 1.2;
}

.sidebar-divider {
  height: 1px;
  background: rgba(201, 168, 76, 0.04);
  margin: 12px 0 4px; /* less bottom margin — section label adds its own top */
  flex-shrink: 0;
}

/* Nav items */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  flex-shrink: 0; /* never compress nav sections */
  /* Reset generic nav/header element styles from design-system.css
     which applies height:64px, padding, background, sticky position etc.
     to ALL <nav> elements — including our .sidebar-nav containers. */
  height: auto;
  padding: 0;
  background: none;
  position: static;
  border-bottom: none;
  backdrop-filter: none;
  top: auto;
  z-index: auto;
  align-items: stretch;
  justify-content: flex-start;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

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

.sidebar-nav-item.active {
  background: var(--surface-3);
  color: var(--gold);
  border-left-color: var(--gold);
}

.sidebar-nav-item .nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav-item .nav-label {
  flex: 1;
}

/* Badge */
.nav-badge {
  background: var(--gold);
  color: #000;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

/* Flex spacer to push autopilot badge down */
.sidebar-spacer {
  flex: 1;
}

/* Autopilot badge card at sidebar bottom */
.sidebar-autopilot-card {
  margin: 12px 4px 4px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  border: 1px solid rgba(201, 168, 76, 0.10);
  transition: all 0.2s ease;
  cursor: default;
}

.sidebar-autopilot-card:hover {
  border-color: rgba(201, 168, 76, 0.30);
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.08);
}

.sidebar-autopilot-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--gold);
  margin-bottom: 4px;
}

.sidebar-autopilot-sub {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ─── Topbar ──────────────────────────────────────────── */
.app-topbar {
  grid-column: 2;
  grid-row: 1;
  height: 56px;
  background: var(--surface-1);
  border-bottom: 2px solid rgba(201, 168, 76, 0.18);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: border-color 0.35s ease;
}

/* Sport-specific topbar accent bar */
.app-topbar[data-sport="NFL"] { border-bottom-color: rgba(201, 168, 76, 0.35); }
.app-topbar[data-sport="MLB"] { border-bottom-color: rgba(74, 144, 226, 0.45); }
.app-topbar[data-sport="NBA"] { border-bottom-color: rgba(155, 109, 255, 0.45); }

/* Topbar logo — shown on mobile only */
.topbar-logo {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 2px;
  text-decoration: none;
  display: none; /* hidden on desktop — logo is in sidebar */
}

/* Sport switcher pill */
.sport-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-3);
  border-radius: 20px;
  padding: 3px;
}

.sport-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  border-radius: 17px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.25s ease;
  white-space: nowrap;
}

/* Sport icon inside buttons */
.sport-icon {
  font-size: 13px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.25s ease;
}

.sport-btn:hover { color: var(--text-secondary); }
.sport-btn:hover .sport-icon { transform: scale(1.15); }

/* NFL = Gridiron Gold */
.sport-btn[data-sport="NFL"]:hover { background: rgba(201, 168, 76, 0.08); }
.sport-btn[data-sport="NFL"].active {
  background: var(--gold);
  color: #000;
  font-weight: 700;
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.4);
}

/* MLB = Steel Blue */
.sport-btn[data-sport="MLB"]:hover { background: rgba(74, 144, 226, 0.08); }
.sport-btn[data-sport="MLB"].active {
  background: #4A90E2;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 12px rgba(74, 144, 226, 0.4);
}

/* NBA = Royal Purple */
.sport-btn[data-sport="NBA"]:hover { background: rgba(155, 109, 255, 0.08); }
.sport-btn[data-sport="NBA"].active {
  background: #9B6DFF;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 12px rgba(155, 109, 255, 0.4);
}

/* ── Drawer sport badge ──────────────────────────────── */
.drawer-sport-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--border-subtle, rgba(255,255,255,0.05));
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.drawer-sport-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
}

.drawer-sport-badge[data-sport="NFL"] .drawer-sport-label {
  background: rgba(201, 168, 76, 0.15);
  color: var(--gold);
  border: 1px solid rgba(201, 168, 76, 0.3);
}

.drawer-sport-badge[data-sport="MLB"] .drawer-sport-label {
  background: rgba(74, 144, 226, 0.15);
  color: #4A90E2;
  border: 1px solid rgba(74, 144, 226, 0.3);
}

.drawer-sport-badge[data-sport="NBA"] .drawer-sport-label {
  background: rgba(155, 109, 255, 0.15);
  color: #9B6DFF;
  border: 1px solid rgba(155, 109, 255, 0.3);
}

/* Right side actions */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Autopilot status */
.autopilot-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.autopilot-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-green);
  animation: autopilot-pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes autopilot-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
  50% { opacity: 0.8; box-shadow: 0 0 0 4px rgba(76, 175, 80, 0); }
}

/* User avatar */
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1.5px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.user-avatar:hover {
  background: var(--gold-glow);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

/* ─── Main Content Area ───────────────────────────────── */
.app-main {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  padding: 32px;
  min-height: 0; /* allow grid to constrain height */
  /* Override design-system.css 'main' element styles that break the grid layout */
  max-width: none;
  margin: 0;
}

/* ─── Mobile Bottom Nav ───────────────────────────────── */
.app-mobile-nav {
  display: none; /* hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--surface-1);
  border-top: 1px solid rgba(201, 168, 76, 0.06);
  z-index: 60;
  align-items: stretch;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 4px;
  min-height: 44px; /* accessibility: minimum tap target */
  transition: color 0.2s ease;
  cursor: pointer;
  border: none;
  background: transparent;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
  color: var(--gold);
}

.mobile-nav-icon {
  font-size: 18px;
  line-height: 1;
}

/* ─── Hamburger Menu Button ───────────────────────────── */
/* IMPORTANT: Must come BEFORE the media query so mobile display:flex wins */
.hamburger-btn {
  display: none; /* desktop: hidden */
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  margin-right: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, background 0.2s ease;
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
}

.hamburger-btn:hover {
  color: var(--gold);
  background: var(--surface-2);
}

/* ─── Responsive: 1024px breakpoint (covers all phones portrait + landscape) ── */
@media (max-width: 1024px) {
  /* Sidebar hides completely */
  .app-sidebar {
    display: none;
  }

  /* Grid becomes single-column */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
  }

  /* Topbar spans full width, show logo and hamburger */
  .app-topbar {
    grid-column: 1;
    grid-row: 1;
  }

  .topbar-logo {
    display: block;
  }

  /* Show hamburger button on mobile */
  .hamburger-btn {
    display: flex;
  }

  /* Sport switcher may shrink */
  .sport-btn {
    padding: 5px 10px;
    font-size: 11px;
  }

  /* Hide autopilot text on mobile — dot only */
  .autopilot-status span {
    display: none;
  }

  /* Main content — bottom padding for mobile nav */
  .app-main {
    grid-column: 1;
    grid-row: 2;
    padding: 20px 16px 88px; /* 88px = 64px nav + 24px breathing room */
  }

  /* Mobile bottom nav shows */
  .app-mobile-nav {
    display: flex;
  }
}

/* ─── Nav Drawer Overlay (backdrop) ───────────────────── */
.nav-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.nav-drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Nav Drawer Panel ────────────────────────────────── */
.app-nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  height: 100vh;
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  z-index: 100;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.app-nav-drawer.open {
  transform: translateX(0);
}

/* Drawer header: logo + close button */
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(201, 168, 76, 0.06);
  flex-shrink: 0;
}

.drawer-logo {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 2px;
  text-decoration: none;
}

.drawer-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, background 0.2s ease;
  min-width: 32px;
  min-height: 32px;
}

.drawer-close-btn:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

/* Drawer nav content area */
.drawer-nav-content {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
}

/* ─── Drawer Navigation Styling (Mobile Menu) ──────────────── */

/* Section labels within drawer */
.app-nav-drawer .sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.35em;
  color: var(--text-muted);
  padding: 0 8px;
  margin-top: 12px;
  margin-bottom: 6px;
  flex-shrink: 0;
  line-height: 1.2;
}

/* First section label — no top margin */
.app-nav-drawer .drawer-nav-content > .sidebar-section-label:first-of-type {
  margin-top: 0;
}

/* Dividers between sections */
.app-nav-drawer .sidebar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 8px 0 8px 0;
  flex-shrink: 0;
}

/* Nav items in drawer */
.app-nav-drawer .sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: auto;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
  margin-bottom: 4px;
}

/* Icon alignment — consistent vertical grid */
.app-nav-drawer .sidebar-nav-item .nav-icon {
  font-size: 14px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Hover/tap state */
.app-nav-drawer .sidebar-nav-item:hover,
.app-nav-drawer .sidebar-nav-item:active {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: transparent;
}

/* Active state — gold-faint background + gold border */
.app-nav-drawer .sidebar-nav-item.active {
  background: var(--gold-faint, rgba(201, 168, 76, 0.12));
  color: var(--gold);
  border-color: var(--gold, rgba(201, 168, 76, 0.4));
  border-left-color: var(--gold);
}

/* ─── Utilities for pages using app shell ─────────────── */

/* Remove old header/nav when shell is active */
.has-app-shell > header,
.has-app-shell > nav,
.has-app-shell .field-bg,
.has-app-shell .wrap > header {
  display: none;
}

/* Shell-aware page title area */
.shell-page-header {
  margin-bottom: 28px;
}

.shell-page-title {
  font-family: var(--font-primary);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.shell-page-sub {
  font-size: 14px;
  color: var(--text-secondary);
}
