/*!
 * calculator-mobile.css — Mobile-only rules for the Rechner.
 *
 * RULES:
 * 1. Every rule MUST be inside one of these two blocks:
 *      @media (max-width: 767px)                         -> Phones
 *      @media (min-width: 768px) and (max-width: 1023px) -> iPad portrait
 * 2. NEVER add rules that apply at >= 1024px. Desktop is governed by calculator.css.
 * 3. Cap !important usage at 5 occurrences in this file. Justify each with a comment.
 *
 * Loaded AFTER calculator.css so cascade order favors mobile.
 */

/* ============================================================
   PHONE — Foundations (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  /* Prevent horizontal scroll caused by overflowing children */
  .pv-rechner-wrap {
    overflow-x: clip;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* iOS Safari auto-zooms inputs with font-size < 16px on focus.
     This rule prevents that across all interactive form fields. */
  .pv-rechner-wrap input[type="text"],
  .pv-rechner-wrap input[type="number"],
  .pv-rechner-wrap input[type="email"],
  .pv-rechner-wrap input[type="tel"],
  .pv-rechner-wrap input[type="search"],
  .pv-rechner-wrap select,
  .pv-rechner-wrap textarea {
    font-size: 16px;
  }

  /* Tap target floor: 44x44 minimum (Apple HIG / WCAG 2.5.5). */
  .pv-rechner-wrap button,
  .pv-rechner-wrap a.pv-btn-next,
  .pv-rechner-wrap a.pv-btn-back,
  .pv-rechner-wrap .pv-btn-next,
  .pv-rechner-wrap .pv-btn-back,
  .pv-rechner-wrap .pv-btn-submit {
    min-height: 44px;
  }

  .pv-rechner-wrap input[type="checkbox"],
  .pv-rechner-wrap input[type="radio"] {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
  }

  /* Respect iPhone home-indicator safe area */
  .pv-rechner-wrap {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}

/* ============================================================
   IPAD PORTRAIT — Foundations (768px - 1023px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-rechner-wrap input[type="text"],
  .pv-rechner-wrap input[type="number"],
  .pv-rechner-wrap input[type="email"],
  .pv-rechner-wrap input[type="tel"],
  .pv-rechner-wrap input[type="search"],
  .pv-rechner-wrap select,
  .pv-rechner-wrap textarea {
    font-size: 16px;
  }

  .pv-rechner-wrap button,
  .pv-rechner-wrap a.pv-btn-next,
  .pv-rechner-wrap a.pv-btn-back,
  .pv-rechner-wrap .pv-btn-next,
  .pv-rechner-wrap .pv-btn-back,
  .pv-rechner-wrap .pv-btn-submit {
    min-height: 40px;
  }
}

/* ============================================================
   PHONE — Stepper + Step 1 form (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  /* Step container padding */
  .pv-rechner-wrap .pv-step {
    padding: 20px 16px;
    border-radius: var(--radius-lg);
  }

  .pv-rechner-wrap .pv-step h2 {
    font-size: 22px;
    line-height: 1.25;
    margin-bottom: 18px;
  }

  /* Stepper — 3 pills horizontal, all visible */
  .pv-rechner-wrap .pv-progress {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    margin-bottom: 20px;
  }

  .pv-rechner-wrap .pv-progress-step {
    padding: 10px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pv-rechner-wrap .pv-progress-step.active {
    font-size: 12px;
    font-weight: 700;
  }

  /* Form fields */
  .pv-rechner-wrap .pv-field {
    margin-bottom: 16px;
  }

  .pv-rechner-wrap .pv-field label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
  }

  .pv-rechner-wrap .pv-field input[type="text"],
  .pv-rechner-wrap .pv-field input[type="number"],
  .pv-rechner-wrap .pv-field input[type="email"],
  .pv-rechner-wrap .pv-field input[type="tel"],
  .pv-rechner-wrap .pv-field select {
    width: 100%;
    height: 52px;
    padding: 14px 16px;
    border-radius: var(--radius);
    box-sizing: border-box;
  }

  /* Help text under fields */
  .pv-rechner-wrap .pv-field-help,
  .pv-rechner-wrap .pv-hint,
  .pv-rechner-wrap [id$="-hint"] {
    font-size: 12px;
    line-height: 1.45;
    margin-top: 4px;
  }

  /* Google Places autocomplete dropdown — rendered at <body> level */
  body > .pac-container {
    max-width: calc(100vw - 32px);
    font-size: 14px;
    z-index: 99999;
  }

  body > .pac-container .pac-item {
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.4;
  }
}

/* ============================================================
   IPAD — Stepper + Step 1 form (768-1023px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-rechner-wrap .pv-step {
    padding: 32px 28px;
  }

  .pv-rechner-wrap .pv-progress {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 10px;
    margin-bottom: 24px;
  }

  .pv-rechner-wrap .pv-progress-step {
    padding: 12px 14px;
    font-size: 13px;
  }
}

/* ============================================================
   PHONE — Step 2: 3D Canvas + Roof Segment List (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  /* 3D canvas: 60vh on phone, with sane min/max */
  .pv-rechner-wrap #pv-3d-canvas-container {
    height: 60vh;
    min-height: 320px;
    max-height: 500px;
    width: 100%;
    margin: 12px 0 16px;
    border-radius: var(--radius);
    overflow: hidden;
  }

  /* Canvas itself: disable browser default touch behaviors so
     Three.js OrbitControls can handle pan/pinch without page scroll fighting */
  .pv-rechner-wrap #pv-3d-canvas-container canvas {
    touch-action: none;
    width: 100% !important; /* !important: Three.js sometimes inlines width=0 during resize */
    height: 100% !important; /* !important: same as above */
    display: block;
  }

  /* API preview wrapper */
  .pv-rechner-wrap #pv-api-preview {
    background: linear-gradient(135deg, rgba(252, 211, 77, 0.06), rgba(245, 158, 11, 0.04));
    border: 1.5px solid rgba(252, 211, 77, 0.3);
    border-radius: var(--radius-lg);
    padding: 16px 14px;
    margin: 12px 0;
  }

  .pv-rechner-wrap #pv-api-preview h4 {
    font-size: 16px;
    margin: 0 0 12px;
  }

  /* Roof segment list */
  .pv-rechner-wrap #pv-api-dach-liste {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius);
    padding: 8px;
  }

  /* Sticky header with "Alle markieren / Keine markieren" buttons */
  .pv-rechner-wrap #pv-api-dach-liste-buttons {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    gap: 8px;
    padding: 8px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    margin-bottom: 8px;
  }

  .pv-rechner-wrap #pv-api-dach-liste-buttons button {
    flex: 1;
    min-height: 44px;
    font-size: 13px;
    padding: 10px 12px;
  }

  /* Scrollable list of segments */
  .pv-rechner-wrap #pv-api-dach-liste-scroll {
    max-height: 280px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px;
  }

  /* Custom scrollbar */
  .pv-rechner-wrap #pv-api-dach-liste-scroll::-webkit-scrollbar {
    width: 6px;
  }

  .pv-rechner-wrap #pv-api-dach-liste-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
  }

  .pv-rechner-wrap #pv-api-dach-liste-scroll::-webkit-scrollbar-thumb {
    background: var(--gold, var(--pv-gold, #d4af37));
    border-radius: 3px;
  }

  /* Individual segment cards */
  .pv-rechner-wrap .pv-api-dach-item {
    min-height: 56px;
    padding: 12px 14px;
    margin-bottom: 6px;
    border-radius: var(--radius);
    background: rgba(30, 30, 30, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    cursor: pointer;
  }

  .pv-rechner-wrap .pv-api-dach-item.pv-segment-selected {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.25), rgba(212, 175, 55, 0.15));
    border: 2px solid var(--gold, var(--pv-gold, #d4af37));
  }

  .pv-rechner-wrap .pv-api-dach-item .dach-badge {
    justify-self: start;
  }
}

/* ============================================================
   IPAD — Step 2: 3D Canvas split-view (768-1023px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-rechner-wrap #pv-3d-canvas-container {
    height: 50vh;
    min-height: 360px;
    max-height: 520px;
  }

  .pv-rechner-wrap #pv-api-dach-liste-scroll {
    max-height: 360px;
  }

  .pv-rechner-wrap .pv-api-dach-item {
    min-height: 48px;
    padding: 10px 12px;
  }
}

/* ============================================================
   PHONE — Step 3: Result Cards + CTAs (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  /* Result grid: single column on phone */
  .pv-rechner-wrap .pv-result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .pv-rechner-wrap .pv-result-card {
    padding: 20px 18px;
    border-radius: var(--radius-lg);
  }

  .pv-rechner-wrap .pv-result-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
  }

  .pv-rechner-wrap .pv-result-label {
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text-secondary);
  }

  /* Disclaimer box */
  .pv-rechner-wrap .pv-disclaimer {
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.55;
    margin: 16px 0 24px;
    gap: 10px;
  }

  /* CTA buttons (Konfigurator + Montage) — they use inline styles for full-width
     but we tune typography for phone */
  .pv-rechner-wrap #pv-to-konfigurator,
  .pv-rechner-wrap #pv-to-montage {
    font-size: 16px;
    padding: 16px 20px;
    min-height: 52px;
  }

  .pv-rechner-wrap #pv-to-konfigurator svg,
  .pv-rechner-wrap #pv-to-montage svg {
    width: 18px;
    height: 18px;
  }
}

/* ============================================================
   IPAD — Step 3: 2-column result grid (768-1023px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-rechner-wrap .pv-result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* 5 cards in 2 columns => 3 rows; last card spans both columns */
  .pv-rechner-wrap .pv-result-card:last-child {
    grid-column: span 2;
  }

  .pv-rechner-wrap .pv-result-value {
    font-size: 26px;
  }
}

/* ============================================================
   PHONE — Lead Form (max-width: 767px)
   ============================================================ */
@media (max-width: 767px) {
  .pv-rechner-wrap .pv-lead-form {
    padding: 20px 16px;
    margin-top: 24px;
    border-radius: var(--radius-lg);
  }

  .pv-rechner-wrap .pv-lead-form h3 {
    font-size: 19px;
    line-height: 1.25;
    margin: 0 0 18px;
    gap: 10px;
  }

  .pv-rechner-wrap .pv-lead-form h3::before {
    font-size: 22px;
  }

  .pv-rechner-wrap .pv-lead-form p {
    font-size: 14px;
    line-height: 1.55;
    margin-bottom: 18px;
  }

  .pv-rechner-wrap .pv-lead-form .pv-field {
    margin-bottom: 14px;
  }

  .pv-rechner-wrap .pv-lead-form input[type="text"],
  .pv-rechner-wrap .pv-lead-form input[type="email"],
  .pv-rechner-wrap .pv-lead-form input[type="tel"],
  .pv-rechner-wrap .pv-lead-form select {
    width: 100%;
    height: 52px;
    padding: 14px 16px;
    box-sizing: border-box;
  }

  .pv-rechner-wrap .pv-lead-form textarea {
    width: 100%;
    min-height: 96px;
    padding: 14px 16px;
    box-sizing: border-box;
  }

  /* Checkbox + label layout */
  .pv-rechner-wrap .pv-lead-form label.pv-checkbox-label,
  .pv-rechner-wrap .pv-lead-form .pv-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
    line-height: 1.5;
  }

  .pv-rechner-wrap .pv-lead-form input[type="checkbox"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    margin-top: 1px;
  }

  /* Submit button */
  .pv-rechner-wrap .pv-lead-form .pv-btn-submit,
  .pv-rechner-wrap #pv-btn-submit {
    width: 100%;
    height: 56px;
    font-size: 16px;
  }
}

/* ============================================================
   IPAD — Lead Form (768-1023px)
   ============================================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  .pv-rechner-wrap .pv-lead-form {
    padding: 32px 28px;
  }
}

/* ============================================================
   PHONE + IPAD — Cloudflare Turnstile native compact mode
   Combined to minimize !important budget. Desktop CSS uses
   scaleX(0.40) hack on iframe + fixed 300px width with !important;
   we must override those. Wrapper max-width override also needs
   !important because desktop sets max-width: none !important.
   ============================================================ */
@media (max-width: 1023px) {
  .pv-rechner-wrap .pv-lead-form .cf-turnstile,
  .pv-rechner-wrap #pv-turnstile-widget {
    max-width: 320px !important; /* !important: overrides desktop max-width: none !important on .cf-turnstile */
    margin: 12px 0;
    width: auto;
  }

  .pv-rechner-wrap .pv-lead-form .cf-turnstile iframe,
  .pv-rechner-wrap #pv-turnstile-widget iframe {
    transform: none !important; /* !important: overrides desktop scaleX(0.40) !important hack */
    width: auto !important;     /* !important: overrides desktop width: 300px !important */
  }
}
