/* 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 {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-4);
  }

  .brand-title {
    align-items: center;
    text-align: center;
  }

  .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: var(--space-5);
    padding: var(--space-6);
    border-radius: 32px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: linear-gradient(160deg, #0ea5e9 0%, #2563eb 52%, #7c3aed 100%);
    box-shadow: 0 32px 60px rgba(15, 23, 42, 0.25);
  }

  .app-header .auth-bar,
  .app-header .header-top-actions,
  .app-header .header-metrics,
  .app-header .header-tabs {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 24px;
    padding: var(--space-4);
    backdrop-filter: blur(18px);
    box-shadow: 0 24px 40px rgba(15, 23, 42, 0.22);
  }

  .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: rgba(15, 23, 42, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.32);
    color: #fff;
    box-shadow: none;
  }

  .app-header .ghost:hover,
  .app-header .ghost:focus-visible {
    background: rgba(15, 23, 42, 0.25);
    color: #fff;
  }

  .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 {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4);
    border-radius: 26px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.72));
    box-shadow: 0 26px 46px rgba(15, 23, 42, 0.2);
    color: var(--color-neutral-900);
  }

  .brand img {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    padding: 0.5rem;
    background: rgba(37, 99, 235, 0.12);
    border: 2px solid rgba(37, 99, 235, 0.4);
  }

  .brand-title {
    display: grid;
    gap: 0.35rem;
    text-align: left;
  }

  .brand-name {
    margin: 0;
    font-size: clamp(1.6rem, 5.4vw, 2.15rem);
    font-weight: 700;
    letter-spacing: -0.018em;
    color: #0f172a;
    background: linear-gradient(132deg, #0f172a 0%, #1d4ed8 40%, #38bdf8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 14px 28px rgba(15, 23, 42, 0.28);
  }

  .brand-name span {
    color: var(--color-accent-600);
    background: linear-gradient(132deg, #fbbf24 0%, #f97316 45%, #fb7185 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .brand .tagline {
    margin: 0;
    color: rgba(15, 23, 42, 0.72);
    font-size: 0.95rem;
    line-height: 1.45;
  }

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

  .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: var(--space-3);
  }

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

  .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: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 44px rgba(15, 23, 42, 0.22);
  }

  .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;
    box-shadow: 0 18px 32px rgba(15, 23, 42, 0.18);
  }

  .header-tab.is-active {
    background: #fff;
    color: var(--color-neutral-900);
    box-shadow: 0 22px 40px rgba(15, 23, 42, 0.22);
  }
}
