/* Comprehensive Premium Mobile Responsive Engine */

/* Default hide mobile nav on desktop */
.mobile-tab-nav {
  display: none;
}

@media (max-width: 1024px) {
  .dashboard-grid,
  .selector-layout,
  .my-team-container,
  .admin-grid {
    grid-template-columns: 1fr;
  }
  .position-slots-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  /* GLOBAL LAYOUT */
  body {
    padding-bottom: 75px; 
  }
  
  .main-layout {
    padding: 1rem !important; 
  }

  /* HEADER OVERHAUL */
  .nav-container {
    padding: 0.75rem 1rem;
  }
  .nav-links {
    display: none !important;
  }
  
  /* MOBILE BOTTOM TAB BAR */
  .mobile-tab-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 65px;
    background: var(--bg-card);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 600;
    width: 25%;
    gap: 3px;
  }
  .tab-link svg {
    width: 22px; height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
  }
  .tab-link.active {
    color: var(--accent-blue);
  }
  .tab-link.active svg {
    stroke-width: 2.5;
  }

  /* LOGGED OUT HERO */
  .hero-title {
    font-size: clamp(2rem, 8vw, 3rem) !important;
  }
  .hero-actions {
    flex-direction: column !important;
    gap: 0.75rem !important;
    width: 100%;
    margin-bottom: 2rem !important;
  }
  .hero-actions .btn {
    width: 100%;
    text-align: center;
    padding: 1rem !important;
  }

  /* DASHBOARD WIDGETS REDESIGN */
  .stats-banner {
    padding: 1.5rem 1.25rem !important;
  }
  .manager-welcome h2 {
    font-size: clamp(1.5rem, 6vw, 2rem) !important;
  }
  .manager-meta {
    flex-direction: row !important;
    flex-wrap: wrap;
    gap: 1rem !important;
  }
  
  .stats-banner-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0; /* Remove column gap to merge cards */
    row-gap: 0.75rem; /* Keep gap between profile and stats */
    margin-bottom: 1rem !important; /* Fix: Reduce padding/margin below */
  }
  .stats-banner-grid > :nth-child(1) {
    grid-column: span 3; /* Profile spans full width */
  }
  
  /* Unified Stats Bar Concept */
  .stat-banner-card {
    padding: 0.75rem 0.25rem !important;
    text-align: center;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    background: rgba(255,255,255,0.03) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    position: relative;
  }
  
  /* Merge borders and add radius to the ends */
  .stats-banner-grid > :nth-child(2) {
    border-top-left-radius: 12px !important;
    border-bottom-left-radius: 12px !important;
    border-right: none !important;
  }
  .stats-banner-grid > :nth-child(3) {
    border-right: none !important;
  }
  .stats-banner-grid > :nth-child(4) {
    border-top-right-radius: 12px !important;
    border-bottom-right-radius: 12px !important;
  }
  
  .stat-banner-link {
    cursor: pointer;
    transition: background-color 0.2s ease !important;
  }
  @media (hover: hover) {
    .stat-banner-link:hover {
      background: rgba(255,255,255,0.08) !important;
    }
  }
  .stat-banner-link:active {
    background: rgba(255,255,255,0.12) !important;
  }

  .stat-banner-card .stat-icon-wrapper {
    display: none !important; /* Hide icons for ultra-clean look */
  }
  
  .stat-banner-card .stat-info {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .stat-banner-card .stat-label {
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-bottom: 0.2rem;
  }
  .stat-banner-card .stat-value {
    font-size: clamp(1rem, 4vw, 1.25rem) !important;
    font-weight: 800;
    text-shadow: none;
  }
  .stat-banner-card .stat-value small {
    font-size: 0.7rem !important;
    color: var(--text-muted);
    font-weight: 500;
  }

  /* DEADLINE CLOCK */
  .deadline-clock {
    gap: 0.5rem;
  }
  .deadline-clock .time-box {
    min-width: 0 !important;
    flex: 1;
    padding: 0.5rem 0.25rem !important;
  }
  .deadline-clock .time-num {
    font-size: clamp(1rem, 4vw, 1.2rem) !important;
  }
  .deadline-clock .time-unit {
    font-size: 0.65rem !important;
  }

  /* FLUID FUT CARDS (Dynamic Viewport Sizing) */
  .pitch-container {
    min-height: 0 !important;
    aspect-ratio: 2 / 1 !important; /* Force a very short, wide pitch */
    padding: 0.25rem;
  }
  .fut-card {
    transform: none !important;
    margin: 0 !important;
    width: 25vw !important;
    max-width: 110px !important;
    min-width: 75px !important;
    height: auto !important;
    aspect-ratio: 140 / 200; /* Let the browser calculate perfect height */
  }
  .fut-card-bottom {
    padding: 0.25rem !important;
  }
  .fut-card .player-last-name {
    font-size: clamp(0.6rem, 2.5vw, 0.8rem) !important;
  }
  .fut-card .player-pos {
    font-size: clamp(0.55rem, 2vw, 0.75rem) !important;
  }
  .fut-card .points-badge {
    font-size: clamp(0.6rem, 2vw, 0.8rem) !important;
    padding: 0.15rem 0.35rem !important;
  }
  .fut-captain-shield, .card-chip-badge {
    font-size: clamp(0.5rem, 2vw, 0.65rem) !important;
    padding: 2px 4px !important;
    top: 4px !important;
  }
  .fut-captain-shield { left: 4px !important; }
  .card-chip-badge { right: 4px !important; }

  /* LEAGUES & SEGMENTED TABS */
  #chip-banners-container {
    gap: 0.25rem !important;
    width: 100% !important;
    justify-content: center !important;
  }
  #chip-banners-container > div {
    font-size: clamp(0.5rem, 2vw, 0.75rem) !important;
    padding: 0.2rem 0.6rem !important;
    border-width: 1px !important;
    letter-spacing: 0px !important;
  }

  .league-tabs {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    background: rgba(37,99,235,0.1);
    border-radius: var(--radius-md);
    padding: 0.25rem !important;
    gap: 0 !important;
  }
  .league-tabs .tab-btn {
    flex: 1;
    border: none !important;
    background: transparent;
    padding: 0.6rem 0.25rem !important;
    font-size: clamp(0.7rem, 2.8vw, 0.9rem) !important;
    border-radius: var(--radius-sm);
  }
  .league-tabs .tab-btn.active {
    background: var(--accent-blue) !important;
    color: white !important;
    box-shadow: var(--shadow-sm);
  }

  /* TABLES SCROLLING & TYPOGRAPHY */
  .table-container {
    overflow-x: auto;
    width: calc(100vw - 2rem);
    margin: 0;
    border-radius: var(--radius-md);
  }
  .app-table th, .app-table td {
    padding: 0.75rem 0.5rem !important;
    font-size: clamp(0.75rem, 3vw, 0.9rem);
    white-space: nowrap;
  }
  
  /* DASHBOARD GRID REORDERING */
  .dashboard-grid {
    display: flex;
    flex-direction: column;
  }
  .dashboard-main {
    display: contents;
  }
  .dashboard-main > :nth-child(4) {
    order: 99;
  }
  .dashboard-sidebar {
    order: 10;
    margin-bottom: 2rem;
  }

  /* FIX NAV BAR ON TOP FOR MOBILE */
  .brand-text span {
    display: none; /* Hide "BERGAMO" on very small screens to save space */
  }
  .brand-text {
    font-size: 1rem; /* Shrink logo text */
  }
  .user-team-name {
    display: none; /* Hide the text team name, keep only avatar circle */
  }
  .nav-actions {
    gap: 0.25rem;
  }
  #theme-toggle-btn {
    display: none !important;
  }
  #logout-link-btn {
    padding: 0.4rem !important;
    font-size: 0 !important; /* Hide text */
  }
  #logout-link-btn::before {
    content: "\2716"; /* Simple icon */
    font-size: 1rem;
    display: block;
  }

  /* LEAGUES PAGE TABS (auth-tabs class used in leagues.html) */
  .auth-tabs {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    background: rgba(37,99,235,0.1);
    border-radius: var(--radius-md);
    padding: 0.25rem !important;
    gap: 0 !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100% !important;
  }
  .auth-tabs .auth-tab {
    flex: 1 0 auto;
    border: none !important;
    background: transparent;
    padding: 0.6rem 0.75rem !important;
    font-size: clamp(0.75rem, 2.8vw, 0.9rem) !important;
    border-radius: var(--radius-sm);
    text-align: center;
  }
  .auth-tabs .auth-tab.active {
    background: var(--accent-blue) !important;
    color: white !important;
    box-shadow: var(--shadow-sm);
  }
  /* NAV BAR HEIGHT & LOGO RESCALE */
  .nav-container {
    padding: 0.5rem 1rem !important; /* Reduce height */
  }
  .brand-text {
    font-size: 1rem !important; /* Rescale smaller */
    white-space: nowrap;
  }
  .brand-text span {
    display: inline !important; /* Keep BERGAMO visible */
  }
  
  /* MODAL CLOSE (X) BTN STYLE */
  .modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    line-height: 1;
    padding: 0.5rem;
    cursor: pointer;
    transition: color 0.2s;
  }
  .modal-close:hover {
    color: var(--text-primary);
  }

  /* TEAM SELECTOR BUTTONS */
  .selector-main-card .section-header .btn {
    padding: 0.5rem 1rem !important; /* Shrink button size */
    font-size: 0.8rem !important;
    width: 100%; /* Make them stretch cleanly on mobile if they stack */
  }
  .selector-main-card .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  /* LEAGUES PAGE TABS - 2x2 GRID INSTEAD OF SCROLLING */
  .league-tabs, .auth-tabs {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    width: 100% !important;
  }
  .league-tabs .tab-btn, .auth-tabs .auth-tab {
    border-radius: var(--radius-md) !important;
    background: rgba(255,255,255,0.03) !important;
    color: var(--text-muted) !important;
    padding: 0.75rem 0.5rem !important;
    font-size: 0.85rem !important;
    border: 1px solid rgba(255,255,255,0.05) !important;
    text-align: center !important;
    box-shadow: none !important;
    flex: none !important;
  }
  .league-tabs .tab-btn.active, .auth-tabs .auth-tab.active {
    background: rgba(37,99,235,0.1) !important;
    color: var(--accent-blue) !important;
    border: 1px solid var(--accent-blue) !important;
  }
  /* FIX MY TEAM EDIT SELECTION BUTTON & SCORE CARD */
  #my-team-header-actions {
    gap: 0.25rem !important;
  }
  #my-team-score-card {
    padding: 0.35rem 0.5rem !important;
    gap: 0.25rem !important;
  }
  #matchday-indicator {
    font-size: 0.6rem !important;
  }
  #edit-selection-btn {
    padding: 0.35rem 0.4rem !important;
    font-size: 0.65rem !important;
    width: auto !important;
  }
  .main-layout .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  /* LEAGUE TABLES MOBILE SCALING */
  .league-table th {
    padding: 0 0.5rem 0.5rem !important;
    font-size: 0.65rem !important;
  }
  .league-table td {
    padding: 0.75rem 0.5rem !important;
    font-size: 0.85rem !important;
  }
  .league-table .team-cell-name {
    font-size: 0.85rem !important;
  }
  .league-table .team-cell-manager {
    font-size: 0.65rem !important;
  }
  .league-table .rank-badge {
    width: 24px !important;
    height: 24px !important;
    font-size: 0.75rem !important;
  }

  /* H2H TABLE MOBILE OPTIMIZATION - Hide non-essential columns */
  #section-h2h table th:nth-child(3),
  #section-h2h table td:nth-child(3),
  #section-h2h table th:nth-child(7),
  #section-h2h table td:nth-child(7) {
    display: none;
  }
  
  /* Classic League Optimization */
  #section-classic table th:nth-child(3),
  #section-classic table td:nth-child(3) {
    display: none; /* Hide GW Points on mobile to save space */
  }

  /* Section Title resize on mobile to prevent squishing */
  .section-title {
    font-size: 1.15rem !important;
  }
  /* ANDROID COUNTDOWN FIX */
  .deadline-clock {
    gap: 0.25rem !important;
  }
  .deadline-clock .time-box {
    padding: 0.35rem 0.15rem !important;
    min-width: 0 !important;
    flex: 1;
  }
  .deadline-clock .time-num {
    font-size: clamp(0.9rem, 3.5vw, 1.1rem) !important;
  }
  .deadline-clock .time-unit {
    font-size: 0.55rem !important;
    letter-spacing: 0;
  }

  /* FORCE CENTERING OF EMPTY CARDS AND GRID */
  .position-slots-grid {
    justify-items: center !important;
    justify-content: center !important;
    width: 100% !important;
  }

  /* BUTTONS RESIZE */
  .hero-actions .btn, .auth-card .btn {
    padding: 0.75rem 1rem !important;
    font-size: 0.95rem !important;
  }

  

  /* GRACEFUL SCALING FOR MODERN GRID CLOCK */
    /* MOBILE COUNTDOWN SPACING */
  .deadline-clock-grid {
    gap: 0.75rem;
  }
  
  .clock-val {
    font-size: clamp(1.2rem, 5vw, 2rem);
  }
  .clock-label {
    font-size: 0.65rem;
  }

  
    .clock-unit {
      padding: 0.5rem 0.25rem;
    }
    .clock-val {
      font-size: clamp(1rem, 4.5vw, 1.5rem);
    }
    .clock-label {
      font-size: 0.55rem;
    }
  /* H2H MATCHUP BAR MOBILE FIX */
  .matchup-bar {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem !important;
  }
  .matchup-team-section {
    width: 100%;
    justify-content: space-between !important;
    gap: 0.5rem !important;
  }
  .matchup-team-section.right {
    flex-direction: row-reverse;
  }
  .matchup-vs-badge {
    display: none;
  }
  .matchup-team-name {
    font-size: clamp(0.85rem, 3.5vw, 1rem) !important;
    white-space: normal;
    word-break: break-word;
    text-align: left !important;
  }
  .matchup-score {
    font-size: clamp(1.1rem, 4vw, 1.3rem) !important;
    min-width: 40px !important;
    padding: 0.2rem 0.5rem !important;
  }
}

@media (max-width: 480px) {
  .brand-crest {
    width: 28px !important;
    height: 28px !important;
  }
  .brand-text {
    font-size: 0.8rem !important;
    letter-spacing: 0px !important;
  }
  .nav-actions .btn {
    padding: 0.4rem 1rem !important;
    font-size: 0.7rem !important;
    gap: 0.25rem !important;
  }
  .nav-actions .btn svg {
    width: 12px !important;
    height: 12px !important;
  }
}

