/**
 * KS Grid Builder - Frontend Styles
 */

/* Section */
.ksgb-section {
    width: 100%;
    box-sizing: border-box;
}

/* Separator lines */
.ksgb-separator {
    width: 100%;
}

/* Items shared */
.ksgb-item {
    box-sizing: border-box;
}

/* Overlay for banner type */
.ksgb-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1;
    pointer-events: none;
    border-radius: inherit;
}
.ksgb-item-inner,
.ksgb-item-text-content {
    position: relative;
    z-index: 2;
    width: 100%;
}

/* ============================================================
   Icon Box - centered (default)
   ============================================================ */
.ksgb-type-iconbox .ksgb-icon-wrap {
    margin-bottom: 15px;
}
.ksgb-type-iconbox .ksgb-icon-img {
    object-fit: contain;
}
.ksgb-title {
    margin-bottom: 8px;
    line-height: 1.3;
}
.ksgb-text {
    line-height: 1.6;
}

/* ============================================================
   Icon Box - left (image left, text right)
   ============================================================ */
.ksgb-iconbox-left {
    flex-direction: row !important;
}
.ksgb-iconbox-left .ksgb-icon-left {
    flex: 0 0 auto;
    margin-right: 15px;
}
.ksgb-iconbox-left .ksgb-icon-left .ksgb-icon-img {
    object-fit: contain;
    display: block;
}
.ksgb-iconbox-left .ksgb-item-text-content {
    flex: 1;
    min-width: 0;
    width: auto;
}
.ksgb-iconbox-left .ksgb-title {
    margin-bottom: 4px;
}
.ksgb-iconbox-left .ksgb-text {
    margin-bottom: 0;
}

/* ============================================================
   Card type
   ============================================================ */
.ksgb-type-card {
    overflow: hidden;
}
.ksgb-card-image {
    width: 100%;
    overflow: hidden;
}
.ksgb-card-image img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}
a.ksgb-type-card:hover .ksgb-card-image img {
    transform: scale(1.05);
}

/* ============================================================
   Banner type
   ============================================================ */
.ksgb-type-banner {
    background-size: cover;
    background-position: center;
}
.ksgb-type-banner .ksgb-title,
.ksgb-type-banner .ksgb-text {
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ============================================================
   Button
   ============================================================ */
.ksgb-button {
    display: inline-block;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none !important;
    border: none;
    cursor: pointer;
    margin-top: 12px;
    transition: opacity 0.2s ease;
}
.ksgb-button:hover {
    opacity: 0.85;
}
a.ksgb-item .ksgb-button {
    pointer-events: none;
}

/* ============================================================
   v1.2.0 — Call Form (button -> inline form -> popup)
   ============================================================ */

/* CTA wrap holds button + form. Form replaces button visually
   without shifting layout (button reserves space via min-height
   on the wrap; the inline form fills the same slot).
   v1.3.1: text-align inherits from the item so the trigger button
   follows the item's alignment (e.g. centered in the banner). */
.ksgb-cta-wrap {
    display: inline-block;
    width: 100%;
    max-width: 360px;
    margin-top: 12px;
    text-align: inherit;
    vertical-align: middle;
}

/* When the trigger is inside the wrap, override the .ksgb-button margin
   so it sits flush with the wrap's own margin-top.
   v1.3.2: frachtbedarf button size - 48px tall (14px vertical padding),
   14px/600 text. Only affects the call-form trigger, not other ksgb buttons. */
.ksgb-cta-wrap > .ksgb-button.ksgb-cta-trigger {
    margin-top: 0;
    padding: 14px 24px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
}

/* Hidden attribute handling - keep generic */
.ksgb-cta-wrap [hidden] {
    display: none !important;
}

/* The inline form panel */
.ksgb-cta-form {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 10px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: ksgb-form-in 0.28s ease-out;
}
@keyframes ksgb-form-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ksgb-cta-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 8px;
}
.ksgb-cta-fields input {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    border: 1.5px solid transparent;
    border-radius: 6px;
    background: #ffffff;
    color: #1a1a1a;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}
.ksgb-cta-fields input::placeholder {
    color: #999;
}
.ksgb-cta-fields input:focus {
    border-color: #1a1a1a;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.ksgb-cta-fields input.has-error {
    border-color: #b53d29;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
    animation: ksgb-shake 0.35s ease;
}
@keyframes ksgb-shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    50%      { transform: translateX(4px); }
    75%      { transform: translateX(-2px); }
}

.ksgb-cta-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.ksgb-cta-send {
    flex: 1;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s ease, transform 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    line-height: 1.2;
}
.ksgb-cta-send:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}
.ksgb-cta-send:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}
.ksgb-cta-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ksgb-spin 0.7s linear infinite;
}
.ksgb-cta-send.is-loading .ksgb-cta-spinner {
    display: inline-block;
}
.ksgb-cta-send.is-loading .ksgb-cta-send-label {
    opacity: 0.7;
}
@keyframes ksgb-spin {
    to { transform: rotate(360deg); }
}

.ksgb-cta-cancel {
    flex: 0 0 38px;
    padding: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.55);
    background: transparent;
    color: inherit;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    font-family: inherit;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ksgb-cta-cancel:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.85);
}

.ksgb-cta-error {
    margin-top: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    text-align: left;
}

/* ============================================================
   Success popup (global modal overlay)
   ============================================================ */
.ksgb-popup-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 15, 12, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    animation: ksgb-fade-in 0.2s ease-out;
    /* Allow click-to-close on the backdrop itself */
    cursor: pointer;
}
.ksgb-popup-backdrop[hidden] {
    display: none !important;
}
.ksgb-popup-backdrop.is-leaving {
    animation: ksgb-fade-out 0.25s ease-in forwards;
}
@keyframes ksgb-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes ksgb-fade-out { from { opacity: 1; } to { opacity: 0; } }

.ksgb-popup {
    background: #ffffff;
    color: #1a1a1a;
    border-radius: 14px;
    padding: 32px 36px;
    max-width: 420px;
    width: calc(100% - 32px);
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    animation: ksgb-popup-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: default;
    font-family: inherit;
}
.ksgb-popup-backdrop.is-leaving .ksgb-popup {
    animation: ksgb-popup-out 0.25s ease-in forwards;
}
@keyframes ksgb-popup-in {
    from { opacity: 0; transform: scale(0.85) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes ksgb-popup-out {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.95); }
}

.ksgb-popup-check {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #e9f7ed;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ksgb-check-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}
@keyframes ksgb-check-pop {
    from { transform: scale(0.3); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
.ksgb-popup-check svg {
    width: 32px;
    height: 32px;
    stroke: #2a9d4a;
    stroke-width: 3.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: ksgb-check-draw 0.4s ease-out 0.35s forwards;
}
@keyframes ksgb-check-draw {
    to { stroke-dashoffset: 0; }
}

.ksgb-popup-title {
    margin: 0 0 8px;
    font-size: 19px;
    font-weight: 700;
    color: #1a1a1a;
}
.ksgb-popup-text {
    margin: 0;
    font-size: 15px;
    color: #4a4a4a;
    line-height: 1.45;
}
.ksgb-popup-countdown {
    margin-top: 22px;
    height: 3px;
    background: #f1ece8;
    border-radius: 99px;
    overflow: hidden;
}
.ksgb-popup-countdown > span {
    display: block;
    height: 100%;
    background: #c84630;
    width: 100%;
    transform-origin: left;
    animation: ksgb-countdown 3s linear forwards;
}
@keyframes ksgb-countdown {
    to { transform: scaleX(0); }
}

/* Mobile: full width inputs, popup gets a bit smaller */
@media (max-width: 575px) {
    .ksgb-cta-wrap {
        max-width: 100%;
    }
    .ksgb-popup {
        padding: 24px 22px;
        border-radius: 12px;
    }
    .ksgb-popup-title { font-size: 17px; }
    .ksgb-popup-text  { font-size: 14px; }

    /* v1.3.2 mobile fix: force every banner grid to a single column on phones.
       The per-section inline <style> emits responsive column rules, but the
       desktop repeat(12,1fr) was winning at <=575px, leaving row 2 split into a
       cramped 65px + 294px pair (button next to phone number). Forcing one
       column + full-width items makes the fused banners stack into ONE box. */
    .ksgb-grid {
        grid-template-columns: 1fr !important;
    }
    .ksgb-grid > .ksgb-item {
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }

    /* v1.3.4 mobile fix A: centre the call-to-action button. On desktop the
       button box inherits text-align:right (it sat on the right of the row),
       but stacked on mobile it must be centred like the other banners. */
    .ksgb-grid > .ksgb-item .ksgb-item-inner,
    .ksgb-grid > .ksgb-item .ksgb-cta-wrap {
        text-align: center !important;
    }

    /* v1.3.5 mobile fix: normalise the asymmetric horizontal padding that the
       banners inherit from the desktop side-by-side layout (e.g. 22px 0 22px 30px
       on the button box, 22px 60px 22px 0 on the phone box). That left/right
       imbalance shoves the inner content sideways so text-align:center still
       looks off. Force equal 30px left/right padding on every stacked banner. */
    .ksgb-grid > .ksgb-type-banner {
        padding-left: 30px !important;
        padding-right: 30px !important;
    }

    /* v1.3.4 mobile fix B: kill the hairline between stacked fused banners.
       gap is 0 and there is no border, but the items meet on a fractional
       sub-pixel boundary (DPR 3) so two identical red fills render a faint
       lighter seam. Pulling each banner item up by 1px makes adjacent fills
       overlap so no crack shows. Scoped to banner items only, so transparent
       grids (e.g. icon-box rows) are untouched. */
    .ksgb-grid > .ksgb-type-banner + .ksgb-type-banner {
        margin-top: -1px !important;
    }
}

/* Reduced motion - drop the bouncy animations */
@media (prefers-reduced-motion: reduce) {
    .ksgb-cta-form,
    .ksgb-popup-backdrop,
    .ksgb-popup,
    .ksgb-popup-check,
    .ksgb-popup-check svg,
    .ksgb-popup-countdown > span {
        animation: none !important;
    }
    .ksgb-popup-check svg {
        stroke-dashoffset: 0 !important;
    }
}
