/* ==== Desktop: Trigger rechts mittig andocken ==== */
@media (min-width: 821px) {
  #elboy-calc-widget #trigger {
    position: fixed;
    top: 50%;
    right: 0;
    bottom: auto;
    left: auto;
    transform: translate(var(--tx), -50%);
    border-radius: 4px 0 0 4px;
  }
  #elboy-calc-widget #trigger span.label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
  }
}

/* ==== Mobile & Tablet (bis 820px) ==== */
@media (max-width: 820px) {
  #elboy-calc-widget {
    --site-offset: 0px;
    font-size: 16px;
  }

  #elboy-calc-widget .btn {
    padding: 12px 14px;
    border-radius: 10px;
    font-weight: 800;
  }

  #elboy-calc-widget #drawer {
    top: env(safe-area-inset-top, 0px);
    right: 0;
    bottom: 0;
    width: 100vw;
    border-left: none;
    border-radius: 0;
    box-shadow: none;
  }

  #elboy-calc-widget #backdrop {
    top: 0;
  }

  /* Patch: zusätzlicher Offset unter globalem Header */
  #elboy-calc-widget .topbar {
    position: sticky;
    top: 0;
    padding: 10px 12px;
    background: #2c65ab;
    gap: 10px;
    margin-top: 60px; /* PATCH */
  }

  #elboy-calc-widget .topbar .brand img {
    height: 26px;
  }

  #elboy-calc-widget .layout {
    display: block;
    padding: 8px;
  }

  #elboy-calc-widget .sidebar {
    display: block !important;
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
    margin: 0 0 8px 0;
    border-radius: 10px;
    padding: 10px;
  }

  #elboy-calc-widget .powered {
    position: static;
    margin-top: 10px;
  }

  #elboy-calc-widget .filters {
    position: sticky;
    top: 48px;
    z-index: 30;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
  }

  #elboy-calc-widget .chip-group {
    display: block;
    overflow: auto;
    white-space: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  #elboy-calc-widget .chip {
    display: inline-flex;
    margin-right: 8px;
    margin-bottom: 6px;
  }

  #elboy-calc-widget .search {
    height: 44px;
  }

  #elboy-calc-widget #grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin: 4px 0 0;
  }

  #elboy-calc-widget .card {
    grid-template-columns: 72px 1fr;
    padding: 10px 8px;
  }

  #elboy-calc-widget .thumb {
    width: 72px;
    height: 72px;
  }

  #elboy-calc-widget .form {
    margin-top: 10px;
    border-radius: 12px;
    padding: 10px;
  }

  #elboy-calc-widget .form-grid {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  #elboy-calc-widget .form-grid .visual {
    grid-column: 1 / -1;
    order: -1;
  }

  #elboy-calc-widget label {
    font-size: 0.9rem;
  }

  #elboy-calc-widget input,
  #elboy-calc-widget select,
  #elboy-calc-widget textarea {
    height: auto;
    min-height: 44px;
  }

  #elboy-calc-widget .ral-group {
    gap: 6px;
  }

  #elboy-calc-widget .btn.block {
    width: 100%;
  }

  #elboy-calc-widget .sel-visual .img {
    min-height: clamp(180px, 36vh, 320px);
  }

  /* Preiszeile sticky am Fuß */
  #elboy-calc-widget #form > div[style*="margin-top:10px"] {
    position: sticky;
    bottom: calc(env(safe-area-inset-bottom, 8px));
    padding-bottom: env(safe-area-inset-bottom, 8px);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #fff 40%);
    z-index: 20;
  }

  #elboy-calc-widget #calc {
    flex: 1;
  }

  #elboy-calc-widget #price {
    font-size: 1.1rem;
    font-weight: 800;
  }

  #elboy-calc-widget #contactSection {
    grid-template-columns: 1fr;
  }

  /* ===== Ebene 2: RAL-Modal ===== */
  #elboy-calc-widget #ralModal .dlg {
    width: 100vw;
    left: 0;
    right: 0;
    margin: 0;
    top: 0;
    max-height: 100vh;
    border-radius: 0;
    background: #fff;
    box-shadow: 0 32px 72px rgba(0, 0, 0, 0.45);
  }

  /* Patch: zusätzlicher Offset */
  #elboy-calc-widget #ralModal header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 5;
    margin-top: 60px; /* PATCH */
  }

  #elboy-calc-widget #ralModal .body {
    background: #fff;
  }

  #elboy-calc-widget .ral-split {
    display: block;
  }

  /* Farbraster: sichtbarer Rahmen + Scrollbars + Scroll-Shadows */
  #elboy-calc-widget .ral-grid {
    height: 42vh;
    overflow: auto;
    padding: 8px;
    border: 1px solid #e6e9ef;
    border-radius: 12px;
    background: #fff;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
  }
  #elboy-calc-widget .ral-grid::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }
  #elboy-calc-widget .ral-grid::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
  }
  #elboy-calc-widget .ral-grid::-webkit-scrollbar-track {
    background: transparent;
  }
  #elboy-calc-widget .ral-grid::before,
  #elboy-calc-widget .ral-grid::after {
    content: "";
    position: sticky;
    left: 0;
    right: 0;
    height: 10px;
    display: block;
    pointer-events: none;
    z-index: 2;
  }
  #elboy-calc-widget .ral-grid::before {
    top: 0;
    box-shadow: inset 0 8px 8px -8px rgba(0, 0, 0, 0.25);
  }
  #elboy-calc-widget .ral-grid::after {
    bottom: 0;
    box-shadow: inset 0 -8px 8px -8px rgba(0, 0, 0, 0.22);
  }

  .rightcol {
    height: auto;
    display: flex;
    flex-direction: column;
  }

  .rightcol .pv-info {
    order: -2;
    margin-bottom: 10px;
  }

  .rightcol .scene-toolbar {
    order: -1;
  }

  .rightcol .scene {
    display: none;
  }

  #elboy-calc-widget #previewBtn {
    width: 100%;
  }

  /* ===== Ebene 3: Preview-Modal ===== */
  #elboy-calc-widget #previewModal .dlg {
    width: 100vw;
    left: 0;
    right: 0;
    margin: 0;
    top: 0;
    max-height: 100vh;
    border-radius: 0;
  }

  /* Patch: zusätzlicher Offset */
  #elboy-calc-widget #previewModal header {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 5;
    margin-top: 60px; /* PATCH */
  }

  #elboy-calc-widget #previewModal .scene {
    height: 52vh;
    overflow: visible;
  }

  #elboy-calc-widget .player-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 8px;
  }

  #elboy-calc-widget .player-row {
    gap: 6px;
  }

  #elboy-calc-widget .player-btn {
    padding: 8px 10px;
    font-weight: 600;
    border-radius: 10px;
  }

  #elboy-calc-widget .player-drop {
    left: 8px;
    right: 8px;
    bottom: 64px;
    max-width: none;
    z-index: 1000;
    border-radius: 12px;
    padding: 8px;
  }

  /* Close-Button: Icon-only (✕) */
  #elboy-calc-widget #plClose {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    position: relative;
    text-indent: -9999px;
    overflow: hidden;
    font-size: 0;
  }
  #elboy-calc-widget #plClose::before {
    content: "\2715";
    font-size: 18px;
    line-height: 1;
    text-indent: 0;
  }

  /* Bestätigungs-Popup */
  #elboy-calc-widget #mailResultModal .dlg.centered {
    width: 92vw;
  }

  /* Mobile Trigger unten rechts (bestehend lassen) */
  #elboy-calc-widget #trigger {
    top: auto;
    bottom: 14px;
    right: 14px;
    transform: none;
    border-radius: 999px;
    gap: 6px;
    padding: 10px 12px;
  }
  #elboy-calc-widget #trigger span.label {
    writing-mode: initial;
  }
}

/* ==== Mobile Landscape Feinschliff ==== */
@media (max-width: 820px) and (orientation: landscape) {
  #elboy-calc-widget .filters {
    top: 44px;
  }

  #elboy-calc-widget .sel-visual .img {
    min-height: clamp(140px, 42vh, 260px);
  }

  #elboy-calc-widget #previewModal .scene {
    height: 56vh;
  }
}
