/*!
 * dach-zeichnen.css — UI for the Dach-Zeichnen feature.
 * Loaded only on pages with the rechner shortcode.
 * Cap on !important: 3 (justify each).
 */

#pv-zeichnen-host {
  margin: 24px 0;
}

#pv-zeichnen-host[hidden] { display: none; }

.pv-zeichnen-overlay {
  background: var(--bg-surface, #181818);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 12px;
  overflow: hidden;
}

.pv-zeichnen-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}

.pv-z-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  min-height: 40px;
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pv-z-btn:hover {
  background: rgba(212, 175, 55, 0.1);
  border-color: rgba(212, 175, 55, 0.7);
}

.pv-z-confirm {
  background: var(--gold-gradient, linear-gradient(135deg, #d4af37, #f0c947));
  color: #000;
  border-color: transparent;
  margin-left: auto;
}

.pv-z-confirm:hover {
  filter: brightness(1.1);
}

.pv-zeichnen-canvas {
  width: 100%;
  height: 480px;
  background: #1a1a1a;
}

.pv-zeichnen-error {
  padding: 32px;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 15px;
}

.pv-zeichnen-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(212, 175, 55, 0.2);
}

.pv-z-metric {
  text-align: center;
}

.pv-z-metric-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 4px;
}

.pv-z-metric-value {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--pv-gold, #d4af37);
}

@media (max-width: 767px) {
  .pv-zeichnen-canvas {
    height: 60vh;
    min-height: 320px;
  }
  .pv-z-btn {
    min-height: 44px;
    padding: 10px 14px;
  }
  .pv-z-metric-value {
    font-size: 16px;
  }
}

/* Touch device: boost the small overlay vertex handles for tap target */
@media (hover: none) and (pointer: coarse) {
  /* !important: overrides Google Maps inline styles on overlay handles. #1 of cap 3. */
  #pv-zeichnen-host .gm-style div[role="button"] {
    min-width: 24px !important;
    min-height: 24px !important;
  }
}

/* Canvas — disable browser default touch behavior so polygon edits don't fight page scroll */
.pv-zeichnen-canvas {
  touch-action: none;
}

/* Scroll-escape strips above and below canvas */
.pv-zeichnen-scroll-escape {
  height: 12px;
  background: transparent;
  touch-action: pan-y;
}

/* The overlay needs position:relative so toast can absolute-position inside */
.pv-zeichnen-overlay {
  position: relative;
}

/* Toast (fades in via animation) */
.pv-zeichnen-toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: pv-z-toast-in 0.2s ease-out;
}

.pv-zeichnen-toast--error {
  background: rgba(220, 53, 69, 0.95);
  color: #fff;
}

.pv-zeichnen-toast--warn {
  background: rgba(245, 158, 11, 0.95);
  color: #1a1a1a;
}

.pv-zeichnen-toast--info {
  background: rgba(15, 15, 15, 0.95);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(212, 175, 55, 0.4);
}

@keyframes pv-z-toast-in {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.pv-z-spacer {
  flex: 1 1 auto;
}

.pv-z-btn.pv-z-active {
  background: rgba(212, 175, 55, 0.2);
  border-color: var(--pv-gold, #d4af37);
  color: var(--pv-gold, #d4af37);
}

.pv-z-btn .pv-z-icon {
  margin-right: 6px;
  font-size: 13px;
}

.pv-z-cancel {
  border-color: rgba(220, 53, 69, 0.4);
  color: rgba(220, 53, 69, 0.9);
}

.pv-z-cancel:hover {
  background: rgba(220, 53, 69, 0.1);
  border-color: rgba(220, 53, 69, 0.7);
}

@media (max-width: 600px) {
  .pv-zeichnen-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .pv-z-btn {
    flex-shrink: 0;
    padding: 10px 12px;
  }
  .pv-z-btn .pv-z-label {
    display: none; /* icon-only on small phones */
  }
  .pv-z-btn .pv-z-icon {
    font-size: 16px;
    margin: 0;
  }
  .pv-z-btn[data-action="cancel"] .pv-z-label,
  .pv-z-btn[data-action="confirm"] .pv-z-label {
    display: inline; /* keep labels for primary actions */
  }
}

/* Per-section "Zeichnen" button — sits absolutely positioned in the
   bottom-right of each .pv-dach-section card (Step 1) */
.pv-dach-section {
  position: relative;
}

.pv-zeichnen-card-btn {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(212, 175, 55, 0.10);
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 8px;
  color: var(--pv-gold, #d4af37);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 2;
}

/* iOS Safari fix: ensure clicks on inner <svg>/<span> route to the button */
.pv-zeichnen-card-btn * {
  pointer-events: none;
}

.pv-zeichnen-card-btn:hover {
  background: rgba(212, 175, 55, 0.22);
  border-color: var(--pv-gold, #d4af37);
  transform: translateY(-1px);
}

.pv-zeichnen-card-btn--saved {
  background: rgba(76, 175, 80, 0.12);
  border-color: rgba(76, 175, 80, 0.5);
  color: #6fcc73;
}

@media (max-width: 600px) {
  .pv-zeichnen-card-btn {
    position: static;
    margin-top: 12px;
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
  }
}

/* ============================================================
   PHONE + IPAD PORTRAIT — Full-screen modal
   Matches the same breakpoint pattern as konfigurator-v2-mobile.css:
     phones (max-width: 767px) AND iPad portrait (768-1023, portrait)
   On iPad landscape + desktop, host stays inline (no override needed).
   ============================================================ */
@media (max-width: 767px),
       (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
  /* Body scroll lock while modal is open */
  body.pv-zeichnen-open {
    overflow: hidden;
  }

  /* Disable the inline-card height animation on mobile — it fights with
     position:fixed/inset:0 fullscreen mode and clips the modal. */
  .pv-zeichnen-host-inline {
    animation: none;
    margin: 0;
    border-radius: 0;
    overflow: visible;
  }

  /* The host becomes a fullscreen overlay — works for both
     legacy #pv-zeichnen-host and per-section .pv-zeichnen-host-inline */
  #pv-zeichnen-host:not([hidden]),
  .pv-zeichnen-host-inline:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 9999;
    margin: 0;
    background: var(--bg-surface, #181818);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Inner overlay fills the modal */
  #pv-zeichnen-host .pv-zeichnen-overlay,
  .pv-zeichnen-host-inline .pv-zeichnen-overlay {
    border-radius: 0;
    border: 0;
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* Toolbar sticks at top */
  #pv-zeichnen-host .pv-zeichnen-toolbar,
  .pv-zeichnen-host-inline .pv-zeichnen-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(0, 0, 0, 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }

  /* Canvas grows to fill */
  #pv-zeichnen-host .pv-zeichnen-canvas,
  .pv-zeichnen-host-inline .pv-zeichnen-canvas {
    flex: 1 1 auto;
    height: auto;
    min-height: 60vh;
  }

  /* Metrics sticks at bottom */
  #pv-zeichnen-host .pv-zeichnen-metrics,
  .pv-zeichnen-host-inline .pv-zeichnen-metrics {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: rgba(0, 0, 0, 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0));
  }
}

/* Confirm-button validation states */
.pv-z-btn.pv-z-confirm.pv-z-confirm-error {
  background: linear-gradient(135deg, rgba(220, 53, 69, 0.7), rgba(220, 53, 69, 0.5));
  cursor: not-allowed;
}

.pv-z-btn.pv-z-confirm.pv-z-confirm-warn {
  background: linear-gradient(135deg, #f0ad4e, #ec971f);
}

/* ============================================================
   PER-SECTION INLINE HOST — appears below its parent dach-section
   when "Bearbeiten" is clicked; collapsed when not active.
   ============================================================ */
.pv-zeichnen-host-inline {
  margin: 16px 0 8px;
  border-radius: 12px;
  overflow: hidden;
  animation: pv-z-host-in 0.25s ease-out;
}

.pv-zeichnen-host-inline[hidden] {
  display: none;
}

@keyframes pv-z-host-in {
  from { opacity: 0; transform: translateY(-8px); max-height: 0; }
  to { opacity: 1; transform: translateY(0); max-height: 800px; }
}

/* When the inline editor host is OPEN inside a section, hide the
   "Bearbeiten" entry-button (it would overlap the map and is redundant
   while the editor is already showing). */
.pv-dach-section:has(.pv-zeichnen-host-inline:not([hidden])) .pv-zeichnen-card-btn {
  display: none;
}

/* Hindernis-Button — red accent so users associate it with "exclude/remove" */
.pv-z-btn.pv-z-obstacle {
  border-color: rgba(239, 68, 68, 0.5);
  color: rgba(239, 68, 68, 0.95);
}

.pv-z-btn.pv-z-obstacle:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.85);
}

/* Hindernis-löschen Button — only visible while an obstacle is selected */
.pv-z-btn.pv-z-obstacle-delete {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.7);
  color: #fff;
}

.pv-z-btn.pv-z-obstacle-delete:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 1);
}

/* Hide Google Maps' drag-undo arrow that appears next to a draggable polygon
   after it's been moved (the small "↶" white pill). User has the toolbar
   "Zurücksetzen" button for that purpose, the inline arrow is redundant. */
#pv-zeichnen-host .gm-style div[role="button"][title*="Rückgängig"],
#pv-zeichnen-host .gm-style div[role="button"][title*="Undo"],
#pv-zeichnen-host .gm-style div[aria-label*="Rückgängig"],
#pv-zeichnen-host .gm-style div[aria-label*="Undo"],
.pv-zeichnen-host-inline .gm-style div[role="button"][title*="Rückgängig"],
.pv-zeichnen-host-inline .gm-style div[role="button"][title*="Undo"],
.pv-zeichnen-host-inline .gm-style div[aria-label*="Rückgängig"],
.pv-zeichnen-host-inline .gm-style div[aria-label*="Undo"] {
  display: none !important;
}
