/* Mobile-first layout tuned for handheld widths (360–430px) */
/* FIX: overflow-x na mobile */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Fix modal on mobile */
@media (max-width: 768px) {
  .modal {
    padding: 0;
    align-items: flex-end;
  }
  
  .modal__dialog {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
    padding: 1.5rem 1rem;
    margin: 0;
    animation: modalSlideUp 0.3s ease;
  }
  
  @keyframes modalSlideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
  
  .modal__close {
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
    z-index: 10;
  }
  
  .auth-modal__tabs {
    gap: 0.5rem;
  }
  
  .auth-modal__tab {
    padding: 0.5rem 0.25rem;
    font-size: 0.875rem;
  }
  
  .auth-form input,
  .auth-form select,
  .auth-form textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    -webkit-appearance: none;
    appearance: none;
  }
  
  .auth-form__actions {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .auth-form__actions .btn {
    width: 100%;
  }
  
  /* Fix tap highlight on mobile */
  .modal,
  .modal__dialog,
  .auth-modal__tab,
  .auth-form button {
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Ensure modal is touchable */
  .modal.is-open {
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .modal__dialog {
    touch-action: auto;
    -webkit-overflow-scrolling: touch;
  }
}

img,
iframe,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

.section,
.container,
.standalone-page {
  max-width: 100%;
}

.section {
  padding: var(--space-8) var(--space-4);
  max-width: 100%;
}

.grid {
  display: grid;
  gap: var(--space-4);
  max-width: 100%;
}

.hide-on-mobile {
  display: none;
}

.app-header,
.header-top,
.header-top-actions,
.header-actions,
.header-actions-primary,
.header-metrics,
.header-tabs,
.surface-card,
.standalone-page,
.standalone-main,
.standalone-header {
  max-width: 100%;
}

.header-actions-primary > *,
.header-actions .header-link,
.header-actions button,
.header-coupon-button,
.metric-card,
.header-tab {
  min-width: 0;
  word-break: break-word;
}

@media (max-width: 430px) {
  body,
  html {
    max-width: 100%;
  }

  .app-header {
    padding: var(--space-8) var(--space-4);
    gap: var(--space-6);
    border-radius: 28px;
  }

  .auth-bar {
    margin-bottom: var(--space-4);
  }

  .auth-controls {
    width: 100%;
  }

  /* .brand styling handled in components.css */

  .header-top {
    gap: var(--space-6);
  }

  .header-top-actions,
  .header-actions {
    gap: var(--space-4);
  }

  .header-coupon-button {
    align-self: stretch;
    white-space: normal;
    text-align: center;
    width: 100%;
  }

  .header-actions-primary {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .header-actions-primary a,
  .header-actions-primary button {
    width: 100%;
  }

  .header-actions .header-link,
  .header-actions button {
    width: 100%;
  }

  .header-tabs {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
  }

  .header-tab {
    flex: 1 1 calc(50% - 0.5rem);
    text-align: center;
    padding: 0.5rem 1rem;
  }
}

@media (min-width: var(--bp-sm)) {
  .section {
    padding: var(--space-10) var(--space-6);
  }

  .grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: var(--bp-md)) {
  .section {
    padding: var(--space-12) var(--space-8);
  }

  .grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .app-header {
    gap: 0;
    padding: 0.25rem;
    border-radius: 0;
    border: none;
    background: linear-gradient(135deg, rgba(226, 232, 240, 0.6) 0%, rgba(241, 245, 249, 0.8) 100%);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  }

  .app-header .auth-bar,
  .app-header .header-top-actions,
  .app-header .header-metrics,
  .app-header .header-tabs {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 24px;
    padding: var(--space-4);
    backdrop-filter: none;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  }

  .auth-bar {
    display: grid;
    gap: var(--space-3);
  }

  .auth-controls {
    gap: var(--space-3);
  }

  .auth-controls > button {
    min-height: 48px;
    border-radius: 16px;
    font-weight: 600;
  }

  .app-header .ghost {
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #0f172a;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.06);
  }

  .app-header .ghost:hover,
  .app-header .ghost:focus-visible {
    background: #ffffff;
    border-color: rgba(59, 130, 246, 0.4);
    color: #0f172a;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
  }

  .auth-guest-note {
    color: rgba(15, 23, 42, 0.85);
  }

  .user-menu {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    padding: var(--space-3);
    color: #fff;
  }

  .header-top {
    gap: var(--space-4);
  }

  /* .brand styling moved to components.css @media (max-width: 640px) for better control */

  /* All .brand, .brand img, .brand-title, .brand-name styling moved to components.css for consistency */

  .header-top-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.25rem;
    padding: 0 !important;
  }

  .header-coupon-button {
    width: 100%;
    border-radius: 18px;
    min-height: 54px;
    font-size: 1rem;
    box-shadow: 0 22px 40px rgba(15, 23, 42, 0.25);
  }

  .header-actions {
    display: grid;
    gap: 0.25rem;
  }

  .header-actions-primary {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 0.25rem;
  }

  .header-actions-primary > * {
    min-height: 56px;
    border-radius: 16px;
    font-weight: 600;
  }

  .header-metrics {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-3);
  }

  .header-metrics .metric-card {
    border-radius: 20px;
    padding: var(--space-4);
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.15);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  }

  .header-metrics .metric-subtext,
  .header-metrics .metric-progress-text {
    color: rgba(15, 23, 42, 0.7);
  }

  .header-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
    padding: var(--space-3);
  }

  .header-tab {
    width: 100%;
    border-radius: 14px;
    padding: 0.75rem 1rem;
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
  }

  .header-tab.is-active {
    background: #ffffff;
    color: #0f172a;
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
  }
}
