/**
 * Gym Schedule — shared mobile / touch optimizations
 * Linked after base.css on all pages.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Safe-area padding for notched devices */
body {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* iOS: 16px+ inputs avoid focus zoom */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea,
  .auth-field input,
  .ff-input,
  .weight-input,
  .bw-log-input,
  .bw-date-input,
  .bw-weight-input {
    font-size: max(16px, 1rem);
  }
}

/* Minimum touch targets (WCAG 2.5.5) */
@media (max-width: 768px) {
  button,
  .btn,
  .btn-auth,
  .btn-gold,
  .btn-outline,
  .admin-link,
  .back-btn,
  .section-toggle,
  .auth-tab,
  .history-tab,
  .th-tab,
  .toggle-btn,
  .pw-toggle,
  .cls-pin-btn,
  .mute-btn,
  .rest-btn,
  .engage-cta-btn,
  .assign-btn,
  .workout-cta a {
    min-height: 44px;
    touch-action: manipulation;
  }

  a.admin-link,
  a.workout-cta a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Theme toggle — above bottom nav + safe area */
@media (max-width: 768px) {
  #themeToggleBtn {
    min-height: 44px;
    padding: 10px 14px !important;
    font-size: 10px !important;
    right: max(12px, env(safe-area-inset-right, 12px)) !important;
    bottom: max(14px, env(safe-area-inset-bottom, 14px)) !important;
  }

  body.has-member-nav #themeToggleBtn {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Toasts above bottom nav */
@media (max-width: 768px) {
  body.has-member-nav .toast:not(.workout-toast) {
    bottom: auto;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(-120px);
    max-width: min(360px, calc(100% - 24px));
  }

  body.has-member-nav .toast.show:not(.workout-toast) {
    transform: translateX(-50%) translateY(0);
  }

  .workout-toast {
    top: calc(12px + env(safe-area-inset-top, 0px));
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(-120px);
    max-width: calc(100% - 24px);
  }

  .workout-toast.show {
    transform: translateX(-50%) translateY(0);
  }
}

/* Shared headers */
@media (max-width: 768px) {
  header,
  header.gym-header,
  .gym-header {
    padding: 12px 16px !important;
    gap: 8px;
  }

  .header-right,
  .header-left {
    min-width: 0;
  }

  .auth-box {
    margin: 0 16px;
    padding: 32px 24px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }
}

/* ── index.html (public schedule / TV + mobile) ─────────── */
@media (max-width: 767px) {
  :root {
    --px: 16px;
  }

  .gym-name {
    font-size: 1.45rem;
    letter-spacing: 0.08em;
  }

  .gym-tagline {
    font-size: 0.52rem;
    letter-spacing: 0.28em;
  }

  #clock {
    font-size: 1.25rem;
  }

  #date {
    font-size: 0.55rem;
    letter-spacing: 0.14em;
  }

  #countdownBanner {
    gap: 8px;
    padding: 10px var(--px);
  }

  #cdTimer {
    font-size: 1.75rem;
    min-width: 64px;
  }

  #cdClass {
    font-size: 0.88rem;
    text-align: center;
    max-width: 100%;
  }

  .cd-label {
    font-size: 0.52rem;
    letter-spacing: 0.22em;
  }

  .cd-divider {
    height: 16px;
  }

  .class-card {
    padding: 14px var(--px);
  }

  .class-name {
    font-size: 1.25rem;
  }

  .class-desc {
    font-size: 0.72rem;
  }

  .schedule-grid {
    gap: 4px;
  }

  .day-block {
    min-width: 48px;
    padding: 5px 3px;
  }

  .workout-cta a {
    width: 100%;
    justify-content: center;
    padding: 14px 20px;
    font-size: 0.8rem;
  }

  body.has-member-nav[data-member-nav="schedule"] {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  body.has-member-nav[data-member-nav="schedule"] footer {
    margin-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 400px) {
  .cd-divider {
    display: none;
  }

  #countdownBanner {
    flex-direction: column;
    gap: 4px;
  }

  .gym-tagline {
    display: none;
  }
}

/* ── workout.html ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .top-bar {
    padding: 12px 16px;
    gap: 8px;
  }

  .top-bar-title {
    font-size: 1.2rem;
    letter-spacing: 0.06em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55vw;
  }

  .top-bar-actions {
    flex-shrink: 0;
    gap: 6px;
  }

  .back-btn {
    padding: 10px 14px;
    font-size: 0.75rem;
  }

  .screen-scroll,
  .screen-scroll-inner {
    padding: 16px !important;
    -webkit-overflow-scrolling: touch;
  }

  .cls-card {
    padding: 16px;
  }

  .cls-card-name {
    font-size: 1.35rem;
  }

  .exercise-row {
    padding: 14px 16px;
    gap: 10px;
  }

  .ex-name {
    font-size: 0.95rem;
  }

  .timer-header {
    padding: 12px 16px;
  }

  #screenTimer .timer-body {
    padding: 8px 16px 12px;
    justify-content: flex-start;
  }

  #screenTimer .timer-ex-name {
    font-size: 1.65rem;
  }

  #screenTimer .timer-ex-reps {
    font-size: 0.85rem;
    margin-top: 0;
  }

  #screenTimer .timer-ex-note {
    font-size: 0.7rem;
    max-width: 100%;
  }

  #screenTimer .timer-display {
    font-size: 3.75rem;
    margin-top: 4px;
  }

  #screenTimer .timer-message {
    font-size: 1.1rem;
    min-height: 1.25rem;
  }

  #screenTimer .timer-state {
    margin-top: 8px;
    font-size: 0.75rem;
  }

  #screenTimer .set-dots {
    margin-top: 8px;
    gap: 8px;
  }

  #screenTimer .weight-input-row {
    margin-top: 4px;
  }

  #screenTimer .rest-config {
    margin-bottom: 10px;
  }

  #screenTimer .timer-controls {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }

  #screenTimer .action-btn {
    padding: 16px;
    font-size: 1.25rem;
    min-height: 52px;
  }

  .rest-btn {
    width: 36px;
    height: 36px;
  }

  .history-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .history-tabs::-webkit-scrollbar {
    display: none;
  }

  .history-tab {
    flex: 0 0 auto;
    min-width: 88px;
    padding: 10px 12px;
    font-size: 0.72rem;
  }

  .export-btn,
  .clear-btn {
    min-height: 44px;
    padding: 10px 14px;
  }

  .builder-overlay .builder-panel,
  .confirm-box {
    width: calc(100% - 24px);
    max-width: 400px;
  }

  .bw-log-row {
    flex-direction: column;
    align-items: stretch;
  }

  .bw-log-input,
  .bw-log-btn {
    width: 100%;
    min-height: 44px;
  }

  .session-stat-row,
  .session-ex-list,
  .session-notes,
  .session-done-btn,
  .session-share-btn {
    max-width: 100%;
  }

  .complete-stats {
    max-width: 100%;
  }

  .complete-btn {
    width: 100%;
    max-width: 100%;
    padding: 14px 20px;
    min-height: 48px;
  }
}

/* ── profile.html ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-nav {
    display: none;
  }

  .header-clock {
    display: none;
  }

  main {
    padding: 20px 16px calc(84px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .bw-log-row {
    flex-direction: column;
    align-items: stretch;
  }

  .bw-date-input,
  .bw-weight-input,
  .bw-unit-toggle,
  .bw-log-row .btn-gold {
    width: 100%;
    min-height: 44px;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn-gold,
  .form-actions .btn-outline {
    width: 100%;
    min-height: 44px;
  }

  footer {
    margin-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── admin.html extras ────────────────────────────────────── */
@media (max-width: 768px) {
  .preview-link,
  .btn-logout {
    min-height: 44px;
    padding: 10px 12px !important;
  }

  .btn-login,
  .btn-save,
  .btn-add,
  .btn-danger {
    min-height: 44px;
  }

  .class-item {
    margin-bottom: 10px;
  }

  .ci-actions button {
    min-height: 44px;
  }
}

/* Horizontal scroll areas — momentum scrolling */
@media (max-width: 768px) {
  .today-cards,
  .tomorrow-cards,
  .schedule-grid,
  .muscle-rail,
  .ex-lib-items,
  .bld-lib-items {
    -webkit-overflow-scrolling: touch;
  }
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
