/* Signup Step 4 — list + detail panel (shared by wizard + demo) */

.sg-wrap {
    transition: max-width 0.25s ease;
}

body.sg-on-services .sg-wrap,
body.sg-on-step4 .sg-wrap,
.s4d-wrap {
    max-width: 1100px;
}

.s4d-demo-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--sg-muted);
    border: 1px solid var(--sg-border);
    background: var(--sg-surface-2);
    padding: 0.28rem 0.6rem;
    border-radius: 999px;
}

.s4d-banner {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--sg-border);
    background: color-mix(in srgb, var(--sg-surface) 88%, #38bdf8);
    color: var(--sg-text);
    font-size: 0.86rem;
    line-height: 1.55;
}

.s4d-banner > i {
    margin-top: 0.15rem;
    color: var(--sg-blue);
    flex-shrink: 0;
}

.s4d-banner strong {
    display: block;
    color: var(--sg-dark);
    font-size: 0.92rem;
    margin-bottom: 0.15rem;
}

.s4d-banner span { color: var(--sg-muted); }

/* Toolbar */
.s4d-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    margin: 0.85rem 0 0.95rem;
}

.s4d-search { position: relative; }

.s4d-search > i {
    position: absolute;
    right: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sg-muted);
    pointer-events: none;
}

.s4d-search input {
    width: 100%;
    border: 1.5px solid var(--sg-border);
    background: var(--sg-input-bg);
    color: var(--sg-dark);
    border-radius: 12px;
    padding: 0.72rem 2.4rem 0.72rem 0.9rem;
    font: inherit;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.s4d-search input:focus {
    border-color: color-mix(in srgb, var(--sg-dark) 35%, var(--sg-border));
}

.s4d-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.s4d-filter {
    border: 1px solid var(--sg-border);
    background: transparent;
    color: var(--sg-muted);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.4rem 0.78rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    min-height: 36px;
}

.s4d-filter:hover {
    color: var(--sg-dark);
    border-color: color-mix(in srgb, var(--sg-dark) 25%, var(--sg-border));
}

.s4d-filter.is-active {
    background: var(--sg-btn-bg);
    color: var(--sg-btn-fg);
    border-color: transparent;
}

.s4d-toolbar__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}

.s4d-count {
    margin-right: auto;
    font-size: 0.78rem;
    color: var(--sg-muted);
    font-weight: 600;
}

/* Layout */
.s4d-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: start;
}

@media (min-width: 900px) {
    .s4d-layout {
        grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
        gap: 1.15rem;
    }
}

.s4d-list-pane { min-width: 0; }

.s4d-loading,
.s4d-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    padding: 2.2rem 1rem;
    color: var(--sg-muted);
    text-align: center;
}

.s4d-loading i {
    font-size: 1.4rem;
    animation: s4dSpin 0.9s linear infinite;
}

@keyframes s4dSpin {
    to { transform: rotate(-360deg); }
}

.s4d-empty i {
    font-size: 1.6rem;
    opacity: 0.7;
}

.s4d-board { min-width: 0; }

/* Group accordion */
.s4d-group {
    --s4d-accent: #64748b;
    margin-bottom: 0.65rem;
    border: 1px solid var(--sg-border);
    border-radius: 14px;
    background: var(--sg-surface);
    overflow: hidden;
}

.s4d-group__head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.78rem 0.85rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: right;
    cursor: pointer;
    position: relative;
    min-height: 52px;
}

.s4d-group__head::before {
    content: '';
    position: absolute;
    right: 0;
    top: 0.55rem;
    bottom: 0.55rem;
    width: 3px;
    border-radius: 3px;
    background: var(--s4d-accent);
    opacity: 0.85;
}

.s4d-group__icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: color-mix(in srgb, var(--s4d-accent) 14%, transparent);
    color: var(--s4d-accent);
    font-size: 0.95rem;
}

.s4d-group__titles {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
}

.s4d-group__title {
    display: block;
    margin: 0;
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--sg-dark);
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.s4d-group__sub {
    display: block;
    margin: 0;
    font-size: 0.72rem;
    color: var(--sg-muted);
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.s4d-group__meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.s4d-group__count {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--sg-muted);
    background: var(--sg-surface-2);
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
}

.s4d-group__chev {
    color: var(--sg-muted);
    transition: transform 0.25s ease;
    font-size: 0.85rem;
}

.s4d-group.is-open .s4d-group__chev {
    transform: rotate(180deg);
}

.s4d-group__body {
    display: none;
    border-top: 1px solid var(--sg-border);
}

.s4d-group.is-open .s4d-group__body {
    display: block;
}

.s4d-group__hint {
    margin: 0;
    padding: 0.55rem 0.85rem;
    font-size: 0.74rem;
    line-height: 1.45;
    color: var(--sg-muted);
    background: color-mix(in srgb, var(--s4d-accent) 8%, transparent);
    border-bottom: 1px solid var(--sg-border);
}

/* Service rows */
.s4d-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.65rem;
    align-items: center;
    padding: 0.72rem 0.85rem;
    border-bottom: 1px solid color-mix(in srgb, var(--sg-border) 70%, transparent);
    cursor: pointer;
    transition: background 0.18s ease;
    user-select: none;
}

.s4d-row:last-child { border-bottom: 0; }

.s4d-row:hover {
    background: color-mix(in srgb, var(--sg-surface-2) 70%, transparent);
}

.s4d-row.is-selected {
    background: color-mix(in srgb, var(--sg-dark) 5%, var(--sg-surface));
}

html[data-sg-theme="dark"] .s4d-row.is-selected {
    background: rgba(255, 255, 255, 0.04);
}

.s4d-row.is-active-detail {
    box-shadow: inset 3px 0 0 var(--s4d-accent, #64748b);
}

.s4d-row__check {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    border: 1.5px solid var(--sg-border);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    color: transparent;
    background: transparent;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
    font-size: 0.78rem;
}

.s4d-row.is-selected .s4d-row__check {
    background: var(--sg-btn-bg);
    border-color: transparent;
    color: var(--sg-btn-fg);
}

.s4d-row__main { min-width: 0; }

.s4d-row__top {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.s4d-row__icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 0.85rem;
    background: color-mix(in srgb, var(--row-accent, #64748b) 12%, transparent);
    color: var(--row-accent, #64748b);
}

.s4d-row__name {
    font-size: 0.88rem;
    font-weight: 750;
    color: var(--sg-dark);
    line-height: 1.35;
}

.s4d-row__badge {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0.12rem 0.4rem;
    border-radius: 6px;
    background: var(--sg-surface-2);
    color: var(--sg-muted);
    white-space: nowrap;
}

.s4d-row__badge--hot {
    background: color-mix(in srgb, #f59e0b 18%, transparent);
    color: #d97706;
}

html[data-sg-theme="dark"] .s4d-row__badge--hot { color: #fbbf24; }

.s4d-row__badge--smart {
    background: color-mix(in srgb, #38bdf8 18%, transparent);
    color: #0284c7;
}

html[data-sg-theme="dark"] .s4d-row__badge--smart { color: #7dd3fc; }

.s4d-row.is-recommended:not(.is-selected) {
    background: color-mix(in srgb, #38bdf8 6%, var(--sg-surface));
}

.s4d-group__rec {
    background: color-mix(in srgb, #38bdf8 16%, transparent) !important;
    color: #0284c7 !important;
}

html[data-sg-theme="dark"] .s4d-group__rec { color: #7dd3fc !important; }

.sg-svc-smart {
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
    margin: 0 0 0.85rem;
    padding: 0.8rem 0.95rem;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, #38bdf8 28%, var(--sg-border));
    background: color-mix(in srgb, #38bdf8 8%, var(--sg-surface));
    color: var(--sg-text);
    font-size: 0.84rem;
    line-height: 1.5;
}

.sg-svc-smart > i {
    margin-top: 0.12rem;
    color: #38bdf8;
    flex-shrink: 0;
}

.sg-svc-smart strong {
    display: block;
    color: var(--sg-dark);
    font-size: 0.88rem;
    margin-bottom: 0.12rem;
}

.sg-svc-smart span {
    color: var(--sg-muted);
}

.sg-svc-smart[hidden] {
    display: none !important;
}

.s4d-row__badge--dep {
    background: color-mix(in srgb, #ef4444 12%, transparent);
    color: #dc2626;
}

html[data-sg-theme="dark"] .s4d-row__badge--dep { color: #f87171; }

.s4d-row__badge--free {
    background: color-mix(in srgb, #10b981 14%, transparent);
    color: #059669;
}

html[data-sg-theme="dark"] .s4d-row__badge--free { color: #6ee7b7; }

.s4d-row__desc {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--sg-muted);
    max-width: 36em;
}

.s4d-row__side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    flex-shrink: 0;
}

.s4d-row__price {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--sg-dark);
    text-align: left;
    white-space: nowrap;
}

.s4d-row__price.is-free { color: #16a34a; }
html[data-sg-theme="dark"] .s4d-row__price.is-free { color: #4ade80; }

.s4d-row__price small {
    display: block;
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--sg-muted);
    margin-top: 0.1rem;
    white-space: normal;
    max-width: 9.5rem;
    text-align: left;
    line-height: 1.3;
}

.s4d-row__info {
    border: 0;
    background: transparent;
    color: var(--sg-muted);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.28rem 0.4rem;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    min-height: 32px;
}

.s4d-row__info:hover,
.s4d-row.is-active-detail .s4d-row__info {
    color: var(--sg-dark);
    background: var(--sg-surface-2);
}

.s4d-detail-slot {
    display: none;
    min-width: 0;
    min-height: 0;
}

@media (min-width: 900px) {
    /* Sticky breaks inside overflow:hidden ancestors (.sg-card) */
    body.sg-on-services .sg-card {
        overflow: visible;
    }

    .s4d-detail-slot {
        display: block;
        position: sticky;
        top: 1rem;
        align-self: start;
        max-height: calc(100vh - 2rem);
        overflow: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        z-index: 2;
    }

    .s4d-detail-slot > .s4d-detail {
        position: relative;
        top: auto;
        max-height: none;
        overflow: visible;
        transform: none !important;
        visibility: visible !important;
        pointer-events: auto !important;
        box-shadow: none;
    }

    .s4d-detail-slot > .s4d-detail.is-open {
        min-height: 0;
    }
}

/* Detail panel */
.s4d-detail {
    position: relative;
    border: 1px solid var(--sg-border);
    border-radius: 16px;
    background: var(--sg-surface);
    min-height: 220px;
    padding: 1.1rem 1rem 1.15rem;
}

.s4d-detail__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.7rem;
    padding: 2rem 0.75rem;
    color: var(--sg-muted);
    font-size: 0.86rem;
    line-height: 1.55;
    min-height: 200px;
}

.s4d-detail__empty i {
    font-size: 1.75rem;
    opacity: 0.55;
}

.s4d-detail__close {
    display: none;
    position: absolute;
    left: 0.75rem;
    top: 0.75rem;
    width: 40px;
    height: 40px;
    border: 1px solid var(--sg-border);
    border-radius: 10px;
    background: var(--sg-surface-2);
    color: var(--sg-dark);
    cursor: pointer;
    place-items: center;
    z-index: 2;
}

.s4d-detail__hero {
    position: relative;
    margin: 0 0 0.85rem;
    border-radius: 12px;
    overflow: hidden;
    background: var(--sg-surface-2);
    aspect-ratio: 16 / 9;
}

.s4d-detail__hero-ph {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: 2.2rem;
}

.s4d-detail__hero img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.s4d-detail__hero-zoom {
    position: absolute;
    z-index: 2;
    bottom: 0.65rem;
    right: 0.65rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.65rem;
    border: none;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(6px);
}

.s4d-detail__hero-zoom[hidden] { display: none !important; }

.s4d-detail__group {
    margin: 0 0 0.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--sg-muted);
    letter-spacing: 0.02em;
}

.s4d-detail__content h3 {
    margin: 0 0 0.35rem;
    font-size: 1.12rem;
    font-weight: 800;
    color: var(--sg-dark);
    line-height: 1.35;
}

.s4d-detail__price {
    margin: 0 0 0.85rem;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--sg-dark);
}

.s4d-detail__monthly {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--sg-muted);
}

.s4d-detail__highlights {
    list-style: none;
    margin: 0 0 0.95rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.s4d-detail__highlights li {
    display: flex;
    gap: 0.45rem;
    align-items: flex-start;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--sg-text);
}

.s4d-detail__highlights li i {
    color: #16a34a;
    margin-top: 0.12rem;
    flex-shrink: 0;
}

html[data-sg-theme="dark"] .s4d-detail__highlights li i { color: #4ade80; }

.s4d-detail__copy {
    font-size: 0.84rem;
    line-height: 1.75;
    color: var(--sg-text);
    margin-bottom: 1.1rem;
}

.s4d-detail__copy p { margin: 0 0 0.75rem; }
.s4d-detail__copy p:last-child { margin-bottom: 0; }

.s4d-detail__content .sg-btn { width: 100%; }

.s4d-sheet-backdrop {
    display: none;
}

/* —— Narrow phones —— */
@media (max-width: 480px) {
    .s4d-row {
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas:
            "check main"
            "check side";
        gap: 0.35rem 0.65rem;
        padding: 0.8rem 0.75rem;
    }

    .s4d-row__check { grid-area: check; align-self: start; margin-top: 0.15rem; }
    .s4d-row__main { grid-area: main; }
    .s4d-row__side {
        grid-area: side;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    .s4d-row__price small { max-width: none; text-align: right; }

    .s4d-group__sub { display: none; }

    .s4d-filter {
        font-size: 0.74rem;
        padding: 0.36rem 0.65rem;
    }
}

/* —— Mobile sheet —— */
@media (max-width: 899px) {
    .s4d-detail-slot {
        display: none !important;
    }

    .s4d-detail {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 80;
        max-height: min(82vh, 680px);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 18px 18px 0 0;
        transform: translateY(110%);
        transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.28);
        margin: 0;
        visibility: hidden;
        pointer-events: none;
        padding-bottom: calc(1.15rem + env(safe-area-inset-bottom));
    }

    .s4d-detail.is-open {
        transform: translateY(0);
        visibility: visible;
        pointer-events: auto;
    }

    .s4d-detail__close { display: grid; }

    .s4d-detail__content h3 {
        padding-left: 2.75rem;
    }

    .s4d-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 70;
        background: rgba(0, 0, 0, 0.45);
        border: 0;
        padding: 0;
        margin: 0;
        cursor: pointer;
    }

    .s4d-sheet-backdrop[hidden] {
        display: none !important;
    }
}

@media (min-width: 900px) {
    .s4d-sheet-backdrop {
        display: none !important;
    }

    .s4d-detail__close {
        display: none !important;
    }

    /* Undocked body panel before JS mounts into slot */
    body > .s4d-detail:not(.is-docked) {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
        padding: 0;
        margin: -1px;
    }
}

/* Signup mobile full-height: keep step 4 scrollable with sticky actions */
@media (max-width: 720px) {
    .sg-pane--services.is-active .s4d-toolbar,
    .sg-pane--services.is-active .s4d-layout {
        flex-shrink: 0;
    }
}
