/* MOBILE-FIRST CSS FIXES FOR MKMRS DASHBOARD */
/* Replace the mobile-specific sections in styles.css with this code */

/* ===== BASE MOBILE FIXES ===== */
:root {
  /* Mobile-optimized sizes */
  --compass-size: min(70vw, 280px); /* Limit max size on mobile */
  --clock-size: 100px; /* Fixed smaller size */
  --container-padding: 0.5rem; /* Consistent padding */
  --grid-gap: 0.5rem; /* Consistent gaps */
}

/* ===== BODY & CONTAINER MOBILE ===== */
@media (max-width: 767px) {
  body {
    padding: 0;
    margin: 0;
  }
  #pointer {
    display: none;
  }
  .container {
    padding: 0.5rem;
    width: 100%;
  }

  /* Fix theme toggle and clock positioning */
  .theme-toggle {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    font-size: 0.875rem;
    z-index: 1050;
  }

  .floating-clock {
    position: fixed;
    top: 10px;
    left: 10px;
    width: 100px;
    height: 100px;
    z-index: 1040;
  }

  /* ===== CURRENT STATS GRID - SIMPLIFIED ===== */
  .current-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 80px; /* Space for clock and toggle */
    margin-bottom: 1rem;
    padding: 0;
    width: 100%;
  }

  /* Regular stat cards */
  .current-stat-card {
    padding: 0.75rem;
    min-height: 80px;
    width: 100%;
  }

  /* Compass takes full width */
  .current-stats > :nth-child(3) {
    grid-column: 1 / -1;
    width: min(70vw, 280px);
    height: min(70vw, 280px);
    justify-self: center;
    margin: 0.5rem 0;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  /* Wind speed also full width */
  .current-stats > :nth-child(4) {
    grid-column: 1 / -1;
    width: 60%;
    justify-self: center;
    margin: 0;
  }

  /* Compass container fixes */
  .detailed-compass-container {
    --compass-base-size: min(70vw, 280px) !important;
    width: min(70vw, 280px) !important;
    height: min(70vw, 280px) !important;
  }

  /* Text sizing for mobile */
  .current-stat-value {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
  }

  .current-stat-label {
    font-size: 0.75rem;
    line-height: 1.2;
  }

  /* ===== CHARTS MOBILE ===== */
  .chart-container {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 8px;
  }

  #windRoseChart,
  #temperatureChart {
    height: 500px !important;
  }
  #windBarbChart {
    height: 600px !important;
  }
  /* ===== MAP MOBILE ===== */
  .map-header {
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .map-header h3 {
    font-size: 1.25rem;
  }

  .map-controls {
    width: 100%;
    justify-content: space-between;
  }

  .map-btn {
    flex: 1;
    padding: 8px 4px;
    font-size: 0.75rem;
    min-height: 36px;
  }

  #buoyMap {
    height: 250px !important;
  }

  .map-info {
    padding: 0.75rem;
    font-size: 0.875rem;
  }

  /* ===== CONTROLS MOBILE ===== */
  .controls {
    padding: 1rem;
    gap: 0.5rem;
  }

  .btn {
    padding: 10px 16px;
    font-size: 0.875rem;
    min-height: 40px;
    min-width: auto;
  }

  select {
    padding: 10px;
    font-size: 0.875rem;
    min-height: 40px;
    width: 100%;
  }

  /* ===== STATS GRID MOBILE ===== */
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin: 1rem 0;
  }

  .stat-card {
    padding: 1rem;
    min-height: 80px;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .stat-label {
    font-size: 0.75rem;
  }

  /* ===== FOOTER MOBILE ===== */
  .credits {
    padding: 1.5rem 0.5rem;
  }

  .credits p {
    font-size: 0.875rem;
    margin: 0.25rem 0;
  }
}

/* ===== PORTRAIT MOBILE SPECIFIC ===== */
@media (max-width: 480px) and (orientation: portrait) {
  :root {
    --compass-size: min(80vw, 300px); /* Increased from 65vw, 250px */
  }
  #pointer {
    display: none;
  }
  .current-stats {
    margin-top: 70px;
  }

  .theme-toggle {
    top: 8px;
    right: 8px;
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .floating-clock {
    top: -15px;
    left: -10px;
    width: 110px;
    height: 110px;
  }

  .current-stat-value {
    font-size: 2.3rem;
  }

  .current-stat-label {
    font-size: 0.9rem;
  }
  .current-stats > :nth-child(3) {
    width: min(75vw, 300px) !important;
    height: min(75vw, 300px) !important;
    justify-self: center !important;
    background: transparent !important;
    border-radius: 8px !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Scale the compass like in landscape */
  .detailed-compass-container {
    --compass-base-size: min(50vw, 300px) !important;
    width: min(70vw, 400px) !important;
    height: min(70vw, 400px) !important;
    transform: scale(2.8) !important; /* Scale up by 2.5x */
    overflow: visible !important;
  }
}
/* Medium mobile - 481px to 767px */
@media (min-width: 481px) and (max-width: 767px) {
  :root {
    --compass-size: min(60vw, 260px);
  }
  .current-stat-value {
    font-size: 2.3rem;
  }

  .current-stat-label {
    font-size: 0.9rem;
  }
  .current-stats > :nth-child(3) {
    width: min(50vw, 260px) !important;
    height: min(50vw, 260px) !important;
  }

  .detailed-compass-container {
    --compass-base-size: min(50vw, 300px) !important;
    width: min(50%, 30px) !important;
    height: min(50vw, 300px) !important;
    transform: scale(1.8) !important; /* Scale up by 2.5x */
    overflow: visible !important;
  }
}
/* ===== LANDSCAPE MOBILE SPECIFIC ===== */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1200px) {
  :root {
    --compass-size: min(70vh, 250px);
  }
  #pointer {
    display: none;
  }
  .current-stats {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    grid-template-rows: minmax(80px, auto) minmax(50px, auto) !important; /* Increased row heights */
    gap: 0.5rem !important;
    margin-top: 50px;
    margin-bottom: 2rem !important;
    padding: 0 0.5rem !important;
  }

  /* Row 1: Wave Height, Wave Period, Compass, Air Temp, Water Temp */
  .current-stats > :nth-child(1) {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  .current-stats > :nth-child(2) {
    grid-column: 2 !important;
    grid-row: 1 !important;
  }

  .current-stats > :nth-child(3) {
    grid-column: 3 !important;
    grid-row: 1 !important;
    width: min(70vh, 250px) !important;
    height: min(70vh, 250px) !important;
    justify-self: center !important;
    align-self: center !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .current-stats > :nth-child(5) {
    grid-column: 4 !important;
    grid-row: 1 !important;
  }

  .current-stats > :nth-child(6) {
    grid-column: 5 !important;
    grid-row: 1 !important;
  }

  /* Row 2: Wind Speed centered under compass */
  .current-stats > :nth-child(4) {
    grid-column: 3 !important;
    grid-row: 2 !important;
    width: 70% !important;
    justify-self: center !important;
    align-self: start !important; /* Align to top of row 2 */
    margin-top: -20px !important;
  }

  /* First row stat cards - make them narrower and taller */
  .current-stats > :nth-child(1),
  .current-stats > :nth-child(2),
  .current-stats > :nth-child(5),
  .current-stats > :nth-child(6) {
    width: 80% !important; /* Reduced from 85% to make narrower */
    height: 120px !important; /* Increased from 55px to make taller */
    justify-self: center !important;
    align-self: center !important;
    padding: 0.5rem 0.3rem !important; /* Slightly more padding */
    background: var(--card-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow-sm) !important;
  }

  /* Second row wind speed card - narrower and positioned lower */
  .current-stats > :nth-child(4) {
    grid-column: 3 !important; /* Places in column 3 of grid */
    grid-row: 2 !important; /* Places in row 2 of grid */
    width: 97% !important; /* Nearly full width of its grid cell */
    height: 75px !important; /* Fixed height */
    min-height: 70px !important; /* Prevents shrinking below 70px */
    max-height: 80px !important; /* Prevents growing above 80px */
    justify-self: center !important; /* Centers horizontally in grid cell */
    align-self: center !important; /* Centers vertically in grid cell */
    margin-top: 10px !important; /* Pushes down from grid cell top */
    padding: 0.3rem 0.5rem !important; /* Internal spacing */
    background: var(--card-bg) !important; /* Card background color */
    border: 1px solid var(--border-color) !important;
    border-radius: 15px !important;
    box-shadow: var(--shadow-sm) !important;

    /* NEW: Flexbox to center content inside card */
    display: flex !important; /* Makes card a flex container */
    flex-direction: column !important; /* Stacks value above label */
    justify-content: center !important; /* Centers content vertically */
    align-items: center !important; /* Centers content horizontally */
  }

  /* Smaller fonts for all stat cards */
  .current-stats > :nth-child(1) .current-stat-value,
  .current-stats > :nth-child(2) .current-stat-value,
  .current-stats > :nth-child(5) .current-stat-value,
  .current-stats > :nth-child(6) .current-stat-value {
    font-size: 2rem !important;
  }

  .current-stats > :nth-child(1) .current-stat-label,
  .current-stats > :nth-child(2) .current-stat-label,
  .current-stats > :nth-child(5) .current-stat-label,
  .current-stats > :nth-child(6) .current-stat-label {
    font-size: 0.8rem !important;
    line-height: 1 !important;
  }

  /* Wind speed card fonts */
  .current-stats > :nth-child(4) .current-stat-value {
    font-size: 2rem !important;
    margin: 0 !important;
    margin-bottom: 4px !important; /* Gap to label */
  }

  .current-stats > :nth-child(4) .current-stat-label {
    font-size: 0.8rem !important;
    margin: 0 !important;
  }
  /* Bigger compass */
  .detailed-compass-container {
    --compass-base-size: min(70vh, 250px) !important;
    width: min(70vh, 250px) !important;
    height: min(70vh, 250px) !important;
    transform: scale(2) !important; /* Ensure no scaling issues */
    overflow: visible !important; /* Let compass elements extend if needed */
  }

  /* Separate chart heights */
  .chart-container {
    padding: 0.75rem;
  }

  /* Wind Rose Chart - shorter */
  #windRoseChart {
    height: 400px !important;
  }

  /* Wind Barb Chart - medium */
  #windBarbChart {
    height: 400px !important;
  }

  /* Temperature Chart - shorter */
  #temperatureChart {
    height: 400px !important;
  }

  /* Map container - compact */
  #buoyMap {
    height: 300px !important;
  }

  /* Smaller clock and theme toggle */
  .floating-clock {
    width: 110px !important;
    height: 110px !important;
    top: -10px !important;
    left: -5px !important;
  }

  .theme-toggle {
    top: 5px !important;
    right: 5px !important;
    padding: 5px 8px !important;
    font-size: 0.7rem !important;
  }
}

/* ===== SMALL PHONES ===== */
@media (max-width: 360px) {
  :root {
    --compass-size: min(60vw, 200px);
  }

  .current-stats {
    gap: 0.25rem;
  }

  .current-stat-card {
    padding: 0.5rem;
    min-height: 70px;
  }

  .current-stat-value {
    font-size: 1.1rem;
  }

  .current-stat-label {
    font-size: 0.65rem;
  }

  .map-btn {
    font-size: 0.7rem;
    padding: 6px 2px;
  }
}

/* ===== PREVENT HORIZONTAL SCROLL ===== */
@media (max-width: 767px) {
  html,
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  * {
    max-width: 100vw;
  }

  /* Ensure nothing extends beyond viewport */
  .current-stats > :nth-child(3),
  .detailed-compass-container {
    max-width: 100vw;
  }
}

/* ===== HIGH-CONTRAST MODE FOR MOBILE ===== */
@media (max-width: 767px) and (prefers-contrast: high) {
  .current-stat-card {
    border: 2px solid currentColor;
  }

  .btn,
  select {
    border: 2px solid currentColor;
  }
}
