/* ── Modal overlay ──────────────────────────────────────────────────────── */

#dyson-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
}

body.dyson-modal-open {
    overflow: hidden;
}

#dyson-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    cursor: pointer;
}

/* ── Modal box ──────────────────────────────────────────────────────────── */

#dyson-modal-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(660px, calc(100% - 32px));
    max-height: 85vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 10px;
    padding: 32px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .22);
}

#dyson-modal-title {
    margin: 0 0 6px;
    font-size: 1.3rem;
    padding-right: 32px; /* clearance for close btn */
}

.dyson-modal-subtitle {
    margin: 0 0 20px;
    color: #666;
    font-size: .9rem;
}

#dyson-modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: #555;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background .15s;
}

#dyson-modal-close:hover {
    background: #f0f0f0;
    color: #000;
}

/* ── Breadcrumb nav ──────────────────────────────────────────────────────── */

.dyson-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eee;
}

.dyson-breadcrumb {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.dyson-breadcrumb li {
    display: flex;
    align-items: center;
}

.dyson-breadcrumb li + li::before {
    content: '›';
    margin-right: 4px;
    color: #aaa;
}

.dyson-breadcrumb-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    font-size: .85rem;
    color: #4933D1;
    cursor: pointer;
    border-radius: 3px;
    text-decoration: underline;
}

.dyson-breadcrumb-btn:hover {
    background: #f0eeff;
}

.dyson-breadcrumb-current {
    font-size: .85rem;
    font-weight: 600;
    color: #333;
}

.dyson-btn-text {
    background: none;
    border: none;
    padding: 2px 4px;
    font-size: .82rem;
    color: #888;
    cursor: pointer;
    white-space: nowrap;
}

.dyson-btn-text:hover {
    color: #333;
    text-decoration: underline;
}

/* ── Option buttons ──────────────────────────────────────────────────────── */

.dyson-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.dyson-option-btn {
    display: block;
    width: 100%;
    padding: 12px 14px;
    background: #f7f7f7;
    border: 2px solid #e0e0e0;
    border-radius: 7px;
    font-size: .95rem;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .1s;
}

.dyson-option-btn:hover {
    border-color: #4933D1;
    background: #f0eeff;
    transform: translateY(-1px);
}

.dyson-option-btn:active {
    transform: translateY(0);
}

/* Wariant z obrazkami (root kategorie) */
.dyson-options--images {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}

.dyson-option-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 0 12px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 16px;
    cursor: pointer;
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s, transform .15s;
    text-align: center;
}

.dyson-option-card:hover {
    border-color: #4933D1;
    box-shadow: 0 4px 14px rgba(73, 51, 209, .15);
    transform: translateY(-2px);
}

.dyson-option-card:active {
    transform: translateY(0);
}

.dyson-option-card__img-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f5f7fa;
}

.dyson-option-card__img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .3s ease;
}

.dyson-option-card:hover .dyson-option-card__img-wrap img {
    transform: scale(1.05);
}

.dyson-option-card__name {
    font-size: .82rem;
    font-weight: 600;
    color: #222;
    line-height: 1.2;
    padding: 0 8px;
}

/* ── Modal: lista urządzeń ───────────────────────────────────────────────── */

#dyson-devices-grid {
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: 16px;
}

.dyson-modal-device-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.dyson-modal-device-card {
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, .11);
    border-radius: 20px;
    overflow: hidden;
    background: #fff;
    transition: box-shadow .15s;
    height: 100%;
}

/* Kwadratowe zdjęcie – takie samo jak w zakładce konta */
.dyson-modal-device-card .dyson-device-img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f5f7fa;
}

.dyson-modal-device-card .dyson-device-img-wrap img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dyson-modal-device-card .dyson-device-info {
    padding: 8px 10px 4px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.dyson-modal-device-card .dyson-device-model {
    font-size: .88rem;
    font-weight: 700;
    color: #111;
    line-height: 1.2;
}

.dyson-modal-device-card .dyson-device-path {
    font-size: .7rem;
    color: #888;
    line-height: 1.3;
}

.dyson-modal-remove-btn {
    margin: 8px 12px 12px;
    align-self: center;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: .78rem !important;
    line-height: 1.2 !important;
    background: #d60000 !important;
    color: #fff !important;
    border-radius: 25px !important;
    padding: 10px 30px !important;
    border-color: #d60000 !important;
    transition: background .15s !important;
}

.dyson-modal-remove-btn::before {
    content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6l-1 14H6L5 6'/%3E%3Cpath d='M9 6V4h6v2'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
    display: inline-flex;
    align-items: center;
    line-height: 0;
}

.dyson-modal-remove-btn:hover {
    background: #b00000 !important;
    border-color: #b00000 !important;
}

.dyson-modal-footer {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 4px;
    flex-wrap: wrap;
}

.dyson-modal-compat-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    border-radius: 50px;
    border: 1.5px solid #2e7d32;
    background: #f1faf1;
    color: #2e7d32;
    font-size: .85rem;
    font-weight: 700;
    text-decoration: none;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}

.dyson-modal-compat-btn:hover {
    background: #e0f4e0;
    border-color: #1b5e20;
    color: #1b5e20;
}

.dyson-modal-compat-btn .dyson-badge-check {
    width: 18px;
    height: 18px;
    font-size: .7rem;
}

#dyson-modal-close-btn {
    margin-left: auto;
    border-radius: 25px;
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */

.dyson-loading {
    text-align: center;
    color: #888;
    padding: 20px 0;
    font-style: italic;
}

/* ── Success screen ──────────────────────────────────────────────────────── */

#dyson-modal-success {
    text-align: center;
    padding: 8px 0;
}

.dyson-success-icon {
    width: 54px;
    height: 54px;
    line-height: 54px;
    border-radius: 50%;
    background: #1a9e3f;
    color: #fff;
    font-size: 1.5rem;
    margin: 0 auto 14px;
}

.dyson-success-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 18px;
    flex-wrap: wrap;
}

.dyson-btn {
    padding: 10px 30px;
    border-radius: 25px;
    border: 2px solid #ccc;
    background: #f7f7f7;
    cursor: pointer;
    font-size: .9rem;
    transition: background .15s, border-color .15s, transform .15s, box-shadow .15s;
}

.dyson-btn:hover {
    background: #eee;
}

.dyson-btn.dyson-btn-primary {
    background: #4933D1;
    border-color: #4933D1;
    color: #fff;
    border-radius: 25px;
}

.dyson-btn.dyson-btn-primary:hover {
    background: #5c44e8;
    border-color: #5c44e8;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(73, 51, 209, .35);
}

/* ── Product badge ───────────────────────────────────────────────────────── */

/*
 * li.product needs position: relative (most themes do this already).
 * The badge is rendered before the thumbnail in DOM, so with absolute
 * positioning it visually overlays the image (same technique as WC sale badge).
 */
.dyson-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 5px 0 4px;
    padding: 4px 12px 4px 8px;
    border-radius: 50px;
    border: 1.5px solid #2e7d32;
    background: #f1faf1;
    color: #2e7d32;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: .05em;
    text-decoration: none;
    cursor: pointer;
}

.dyson-badge:hover {
    background: #e0f4e0;
    border-color: #1b5e20;
    color: #1b5e20;
}

.dyson-badge-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2e7d32;
    color: #fff;
    font-size: .65rem;
    font-weight: 900;
    flex-shrink: 0;
    line-height: 1;
}

/* ── My Account: device grid ─────────────────────────────────────────────── */

.dyson-my-devices h3 {
    margin-top: 0;
}

.dyson-device-grid {
    list-style: none;
    margin: 0 0 20px;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.dyson-device-card {
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, .11);
    border-radius: 20px;
    overflow: hidden;
    background: #fff;
    transition: box-shadow .15s;
    height: 100%;
}

.dyson-device-card:hover {
    box-shadow: 0 3px 12px rgba(0, 0, 0, .1);
}

/* Kwadratowe zdjęcie kategorii */
.dyson-device-img-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f5f7fa;
}

.dyson-device-img-wrap img.dyson-device-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Teksty pod zdjęciem */
.dyson-device-info {
    padding: 10px 12px 6px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dyson-device-model {
    font-size: .95rem;
    font-weight: 700;
    color: #111;
    line-height: 1.2;
}

.dyson-device-path {
    font-size: .75rem;
    color: #888;
    line-height: 1.3;
}

/* Przycisk Usuń na dole karty */
.dyson-remove-device {
    margin: 8px 12px 12px;
    align-self: center;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: .78rem !important;
    line-height: 1.2 !important;
    background: #d60000 !important;
    color: #fff !important;
    border-radius: 25px !important;
    padding: 10px 30px !important;
    border-color: #d60000 !important;
    transition: background .15s !important;
}

.dyson-remove-device::before {
    content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6l-1 14H6L5 6'/%3E%3Cpath d='M9 6V4h6v2'/%3E%3Cline x1='10' y1='11' x2='10' y2='17'/%3E%3Cline x1='14' y1='11' x2='14' y2='17'/%3E%3C/svg%3E");
    display: inline-flex;
    align-items: center;
    line-height: 0;
}

.dyson-remove-device:hover {
    background: #b00000 !important;
    border-color: #b00000 !important;
}

.dyson-add-device-btn {
    margin-bottom: 24px;
    display: inline-block;
}

.dyson-accessories-heading {
    margin-top: 60px;
}

.dyson-no-devices-msg {
    color: #666;
    margin-bottom: 12px;
}

/* ── Shortcode: override kolumn pętli WooCommerce ───────────────────────── */

.dyson-compatible-products.dyson-cols-2 .products { --dyson-cols: 2; }
.dyson-compatible-products.dyson-cols-3 .products { --dyson-cols: 3; }
.dyson-compatible-products.dyson-cols-4 .products { --dyson-cols: 4; }
.dyson-compatible-products.dyson-cols-5 .products { --dyson-cols: 5; }
.dyson-compatible-products.dyson-cols-6 .products { --dyson-cols: 6; }

/* Produkty wyrównane do prawej */
.dyson-compatible-products ul.products {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
}

/* Nadpisuje liczbę kolumn niezależnie od motywu */
.dyson-compatible-products[class*="dyson-cols-"] ul.products li.product {
    width: calc(100% / var(--dyson-cols) - 2%) !important;
}

/* ── Shortcode: showcase urządzeń użytkownika ───────────────────────────── */

.dyson-devices-showcase {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: flex-end;
}

/* Szerokość itemu = (100% - suma przerw) / liczba kolumn */
.dyson-devices-showcase--cols-1 .dyson-devices-showcase__item { flex: 0 0 100%; max-width: 100%; }
.dyson-devices-showcase--cols-2 .dyson-devices-showcase__item { flex: 0 0 calc(50% - 8px); max-width: calc(50% - 8px); }
.dyson-devices-showcase--cols-3 .dyson-devices-showcase__item { flex: 0 0 calc(33.333% - 11px); max-width: calc(33.333% - 11px); }
.dyson-devices-showcase--cols-4 .dyson-devices-showcase__item { flex: 0 0 calc(25% - 12px); max-width: calc(25% - 12px); }
.dyson-devices-showcase--cols-5 .dyson-devices-showcase__item { flex: 0 0 calc(20% - 13px); max-width: calc(20% - 13px); }
.dyson-devices-showcase--cols-6 .dyson-devices-showcase__item { flex: 0 0 calc(16.666% - 14px); max-width: calc(16.666% - 14px); }

.dyson-devices-showcase__card {
    display: block;
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    text-decoration: none;
    background: #f5f7fa;
}

.dyson-devices-showcase__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .35s ease;
}

.dyson-devices-showcase__card:hover .dyson-devices-showcase__img {
    transform: scale(1.06);
}

/* Overlay wysuwa się od dołu */
.dyson-devices-showcase__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    padding: 0 16px 18px;
    background: linear-gradient(to top, rgba(0,0,0,.55) 0%, transparent 55%);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .25s ease, transform .25s ease;
}

.dyson-devices-showcase__card:hover .dyson-devices-showcase__overlay {
    opacity: 1;
    transform: translateY(0);
}

.dyson-devices-showcase__name {
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    text-shadow: 0 1px 4px rgba(0,0,0,.4);
}

@media (max-width: 900px) {
    .dyson-devices-showcase--cols-5 .dyson-devices-showcase__item,
    .dyson-devices-showcase--cols-6 .dyson-devices-showcase__item {
        flex: 0 0 calc(33.333% - 11px);
        max-width: calc(33.333% - 11px);
    }
}

@media (max-width: 600px) {
    .dyson-devices-showcase .dyson-devices-showcase__item {
        flex: 0 0 calc(50% - 8px) !important;
        max-width: calc(50% - 8px) !important;
    }
}

/* ── Shortcode CTA (brak urządzenia / niezalogowany) ─────────────────────── */

.dyson-shortcode-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 24px;
    border: 2px dashed #d0c8f8;
    border-radius: 16px;
    background: #faf9ff;
    text-align: center;
}

.dyson-shortcode-cta__text {
    margin: 0;
    color: #555;
    font-size: 1rem;
    max-width: 420px;
    line-height: 1.5;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .dyson-device-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 600px) {
    .dyson-device-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    #dyson-modal-box {
        padding: 20px 16px;
    }

    .dyson-options {
        grid-template-columns: 1fr 1fr;
    }

    .dyson-device-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .dyson-modal-device-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── State-based box visibility ──────────────────────────────────────────── *
 *
 * W page builderze (Elementor, Gutenberg) nadaj kontenerowi jedną z klas:
 *   .dyson-box-guest        → niezalogowany, nieznany użytkownik   → "Załóż konto"
 *   .dyson-box-returning    → niezalogowany, był tu wcześniej      → "Zaloguj się"
 *   .dyson-box-no-devices   → zalogowany, brak urządzeń            → "Dodaj urządzenia"
 *   .dyson-box-has-devices  → zalogowany z urządzeniami            → "Zarządzaj urządzeniami"
 *
 * Plugin ustawia klasę stanu na <body> (np. dyson-state--guest).
 * Boks jest widoczny tylko gdy klasa body pasuje; w pozostałych stanach hidden.
 * ─────────────────────────────────────────────────────────────────────────── */

body:not(.dyson-state--guest)       .dyson-box-guest       { display: none !important; }
body:not(.dyson-state--returning)   .dyson-box-returning   { display: none !important; }
body:not(.dyson-state--no-devices)  .dyson-box-no-devices  { display: none !important; }
body:not(.dyson-state--has-devices) .dyson-box-has-devices { display: none !important; }
