/**
 * Prebuild Frontend Styles
 *
 * Grid-Layout für Prebuild-Übersicht
 *
 * @package ProductBuilder
 * @since 2.6.0
 */

/* ========================================
   Reset & Base Styles
   ======================================== */

/* Reset für mögliche Theme-Konflikte */
.pb-prebuilds-grid * {
    box-sizing: border-box;
}

/* Verstecke Prebuild-Posts die vom Theme angezeigt werden */
.post-type-archive-pb_prebuild .pb-prebuilds-grid ~ article.pb_prebuild,
.post-type-archive-pb_prebuild .pb-prebuilds-grid ~ .post.pb_prebuild,
body:has(.pb-prebuilds-grid) article.type-pb_prebuild:not(.pb-prebuild-card),
body:has(.pb-prebuilds-grid) .post.type-pb_prebuild:not(.pb-prebuild-card) {
    display: none !important;
}

/* Fix: Ignoriere zusätzliche Wrapper die vom Theme/Page Builder kommen */
.pb-prebuilds-grid > div:not(.pb-prebuild-card):not(.pb-modal) {
    display: contents; /* Wrapper wird "durchsichtig" für das Grid */
}

/* Sicherstellen dass Container volle Breite nutzt */
.entry-content .pb-prebuilds-grid,
.page-content .pb-prebuilds-grid,
.post-content .pb-prebuilds-grid,
article .pb-prebuilds-grid {
    width: 100%;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}

/* ========================================
   Prebuild Wrapper & Controls
   ======================================== */

.pb-prebuilds-wrapper {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 20px;
}

.pb-prebuilds-controls {
    margin-bottom: 30px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.pb-prebuilds-sort {
    min-width: 250px;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
    background: white;
    border: 2px solid #ced4da;
    border-radius: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    cursor: pointer;
}

.pb-prebuilds-sort:focus {
    outline: none;
    border-color: #2271b1;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1), 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pb-prebuilds-sort:hover {
    border-color: #2271b1;
    box-shadow: 0 2px 10px rgba(34, 113, 177, 0.15);
}

/* ========================================
   Grid Container
   ======================================== */

.pb-prebuilds-grid {
    display: grid !important;
    gap: 30px;
    margin: 0 !important;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
    grid-template-columns: repeat(3, 1fr) !important; /* Default: 3 Spalten */
    grid-auto-rows: auto;
    justify-items: stretch;
    align-items: start;
}

/* Spalten-Layout */
.pb-prebuilds-grid[data-columns="1"] {
    grid-template-columns: repeat(3, 1fr) !important; /* Fix: Force 3 columns even if data-columns="1" */
}

.pb-prebuilds-grid[data-columns="2"] {
    grid-template-columns: repeat(2, 1fr) !important;
}

.pb-prebuilds-grid[data-columns="3"] {
    grid-template-columns: repeat(3, 1fr) !important;
}

.pb-prebuilds-grid[data-columns="4"] {
    grid-template-columns: repeat(4, 1fr) !important;
}

/* Responsive */
@media (max-width: 1200px) {
    .pb-prebuilds-grid[data-columns="4"] {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 900px) {
    .pb-prebuilds-grid[data-columns="3"],
    .pb-prebuilds-grid[data-columns="4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 600px) {
    .pb-prebuilds-grid {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }
}

/* Extra: Force für sehr breite Bildschirme */
@media (min-width: 1400px) {
    .pb-prebuilds-grid[data-columns="3"] {
        grid-template-columns: repeat(3, minmax(300px, 1fr)) !important;
    }
}

/* ========================================
   Prebuild Card
   ======================================== */

.pb-prebuild-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    max-width: 100%;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

.pb-prebuild-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    border-color: #2271b1;
}

/* ========================================
   Card Image
   ======================================== */

.pb-card-image {
    position: relative;
    width: 100%;
    padding-top: 75%; /* 4:3 Aspect Ratio */
    background: #f5f5f5;
    overflow: hidden;
}

.pb-card-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.pb-prebuild-card:hover .pb-card-image img {
    transform: scale(1.05);
}

.pb-card-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.pb-card-image-placeholder .dashicons {
    font-size: 64px;
    color: rgba(255,255,255,0.5);
    width: 64px;
    height: 64px;
}

/* ========================================
   Badges
   ======================================== */

.pb-card-badges {
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
}

.pb-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.pb-badge-featured {
    background: rgba(255, 193, 7, 0.95);
    color: #1a1a1a;
}

.pb-badge-shipping {
    background: rgba(76, 175, 80, 0.95);
    color: #fff;
}

.pb-badge-stock {
    background: rgba(255, 152, 0, 0.95);
    color: #fff;
}

.pb-badge-out {
    background: rgba(244, 67, 54, 0.95);
    color: #fff;
}

/* ========================================
   Card Content
   ======================================== */

.pb-card-content {
    padding: 24px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.pb-card-title {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 700;
    color: #1a1a1a;
    line-height: 1.3;
}

.pb-card-excerpt {
    margin: 0 0 20px;
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    flex: 1;
}

/* ========================================
   Performance-Stufen Tabs
   ======================================== */

.pb-card-variations {
    margin-bottom: 20px;
}

.pb-variations-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.pb-variation-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pb-variation-tab {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    background: #f5f5f5;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.pb-variation-tab:hover {
    background: #e8f4fd;
    border-color: #68b3d4;
}

.pb-variation-tab.active {
    background: #e5f5fa;
    border-color: #2271b1;
    box-shadow: 0 2px 8px rgba(34, 113, 177, 0.15);
}

.pb-var-name {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
}

.pb-var-badge {
    font-size: 10px;
    color: #666;
    text-align: center;
    line-height: 1.3;
}

/* ========================================
   Preis
   ======================================== */

.pb-card-price {
    margin-bottom: 20px;
    padding: 16px;
    background: linear-gradient(135deg, #f0f6fc 0%, #e5f5fa 100%);
    border-radius: 8px;
    text-align: center;
}

.pb-price-label {
    display: block;
    font-size: 11px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.pb-price-amount {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: #2271b1;
    line-height: 1;
}

/* ========================================
   Action Buttons
   ======================================== */

.pb-card-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pb-btn {
    padding: 14px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    width: 100%;
}

.pb-btn-primary {
    background: #2271b1;
    color: #fff;
}

.pb-btn-primary:hover {
    background: #135e96;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.3);
}

.pb-btn-secondary {
    background: #fff;
    color: #2271b1;
    border: 2px solid #2271b1;
}

.pb-btn-secondary:hover {
    background: #f0f6fc;
    transform: translateY(-1px);
}

.pb-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ========================================
   Loading State
   ======================================== */

.pb-btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.pb-btn.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: pb-spin 0.6s linear infinite;
}

@keyframes pb-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Empty State
   ======================================== */

.pb-no-prebuilds {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    font-size: 16px;
}

/* ========================================
   Dark Mode Support (Optional)
   ======================================== */

@media (prefers-color-scheme: dark) {
    .pb-prebuild-card {
        background: #1e1e1e;
        border-color: #333;
    }

    /* Titel mit hoher Spezifität für bessere Sichtbarkeit */
    .pb-prebuild-card .pb-card-title,
    .pb-card-title {
        color: #fff !important;
    }

    /* Alle Links in Cards sollten hell sein */
    .pb-prebuild-card a,
    .pb-prebuild-card a:visited {
        color: #68b3d4;
    }

    .pb-prebuild-card a:hover {
        color: #8ec9e8;
    }

    .pb-card-excerpt,
    .pb-variations-label,
    .pb-var-badge {
        color: #aaa;
    }

    .pb-variation-tab {
        background: #2a2a2a;
        border-color: transparent;
    }

    .pb-variation-tab:hover {
        background: #333;
        border-color: #68b3d4;
    }

    .pb-variation-tab.active {
        background: #2d3e50;
        border-color: #68b3d4;
    }

    .pb-var-name {
        color: #fff;
    }

    .pb-card-price {
        background: linear-gradient(135deg, #2a3a4a 0%, #243443 100%);
    }

    .pb-price-amount {
        color: #68b3d4;
    }

    .pb-btn-secondary {
        background: #1e1e1e;
        border-color: #444;
        color: #68b3d4;
    }

    .pb-btn-secondary:hover {
        background: #2a2a2a;
        border-color: #68b3d4;
    }
}

/* ========================================
   MODAL
   ======================================== */

.pb-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
}

.pb-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.pb-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pb-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    color: #333;
}

.pb-modal-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: rotate(90deg);
}

/* Modal Header */
.pb-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 30px;
    padding: 30px 30px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.pb-modal-header-left {
    flex: 1;
}

.pb-modal-header-right {
    flex-shrink: 0;
}

.pb-modal-header h2 {
    margin: 0 0 15px;
    font-size: 28px;
    color: #1a1a1a;
}

.pb-modal-image-container {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 3px solid #2271b1;
}

.pb-modal-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pb-modal-variations {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pb-modal-variation-tab {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.pb-modal-variation-tab:hover {
    background: #e8f4fd;
    border-color: #68b3d4;
}

.pb-modal-variation-tab.active {
    background: #e5f5fa;
    border-color: #2271b1;
    color: #2271b1;
}

/* Modal Body */
.pb-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.pb-modal-loading {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.pb-modal-loaded {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.pb-modal-col h3 {
    margin: 0 0 20px;
    font-size: 20px;
    color: #1a1a1a;
    border-bottom: 2px solid #2271b1;
    padding-bottom: 10px;
}

/* Case Overview */
.pb-modal-case-setup {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.pb-case-section {
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    border-left: 4px solid #2271b1;
}

.pb-case-section:last-child {
    margin-bottom: 0;
}

.pb-case-section h5 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #2271b1;
    font-weight: 600;
}

.pb-case-section ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.pb-case-section li {
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 14px;
    color: #333;
    line-height: 1.5;
}

.pb-case-section li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.pb-case-section li strong {
    color: #1a1a1a;
    font-weight: 600;
}

.pb-case-section p {
    margin: 0;
    font-size: 14px;
    color: #333;
    line-height: 1.6;
}

/* Case Diagram Styles */
.pb-case-diagram {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
    margin-bottom: 15px;
}

.pb-case-slot {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

.pb-case-slot-top {
    grid-column: 1 / 4;
}

.pb-case-slot-front {
    grid-column: 3;
    grid-row: 2;
}

.pb-case-slot-side {
    grid-column: 2;
    grid-row: 2;
}

.pb-case-slot-rear {
    grid-column: 1;
    grid-row: 2;
}

.pb-case-slot-bottom {
    grid-column: 1 / 4;
    grid-row: 3;
}

.pb-case-slot-midplate {
    display: none; /* Midplate ausblenden */
}

.slot-empty {
    background: #f8f9fa;
    border-color: #dee2e6;
    opacity: 0.6;
}

.slot-occupied {
    background: #d4edda;
    border-color: #28a745;
}

.slot-aio-occupied {
    background: #cce5ff;
    border-color: #2271b1;
}

.slot-label {
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #666;
}

.slot-status-icon {
    font-size: 20px;
    line-height: 1;
}

.slot-status-text {
    font-size: 11px;
    font-weight: 600;
    color: #333;
}

.slot-detail {
    font-size: 12px;
    color: #666;
    font-weight: 500;
    margin-top: 4px;
}

.pb-case-section ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.pb-case-section ul li {
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 13px;
    color: #333;
}

.pb-case-section ul li:last-child {
    border-bottom: none;
}

/* Hinweis-Box */
.pb-case-hint {
    margin-top: 20px;
    padding: 15px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    color: #856404;
}

.pb-case-hint svg {
    color: #ffc107;
}

.pb-case-hint strong {
    color: #856404;
}

@media (max-width: 600px) {
    .pb-case-diagram {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .pb-case-slot-top,
    .pb-case-slot-bottom,
    .pb-case-slot-front,
    .pb-case-slot-side,
    .pb-case-slot-rear,
    .pb-case-slot-midplate {
        grid-column: 1;
        grid-row: auto;
    }

    .pb-case-slot {
        min-height: 80px;
    }

    .pb-case-hint {
        font-size: 12px;
        padding: 12px;
    }
}

/* Component Search */
.pb-modal-search-wrapper {
    margin-bottom: 20px;
}

.pb-modal-search {
    width: 100%;
    padding: 12px 18px 12px 44px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat left 14px center;
    background-size: 18px 18px;
    border: 2px solid #ced4da;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.pb-modal-search:focus {
    outline: none;
    border-color: #2271b1;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232271b1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat left 14px center;
    background-size: 18px 18px;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1), 0 1px 6px rgba(0, 0, 0, 0.1);
}

.pb-modal-search:hover {
    border-color: #2271b1;
    box-shadow: 0 2px 8px rgba(34, 113, 177, 0.12);
}

.pb-modal-search::placeholder {
    color: #999;
    font-weight: 400;
}

/* Component List */
.pb-modal-steps {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.pb-modal-step {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
}

.pb-modal-step h4 {
    margin: 0 0 10px;
    font-size: 16px;
    color: #2271b1;
    font-weight: 600;
}

.pb-modal-product-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.pb-modal-product {
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
}

.pb-modal-product:last-child {
    border-bottom: none;
}

.pb-modal-product-name {
    font-size: 14px;
    color: #333;
}

/* Modal Footer */
.pb-modal-footer {
    padding: 20px 30px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.pb-modal-price {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.pb-modal-price-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pb-modal-price-amount {
    font-size: 28px;
    font-weight: 700;
    color: #2271b1;
}

.pb-modal-add-to-cart {
    padding: 14px 30px;
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pb-modal-add-to-cart:hover {
    background: #135e96;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.3);
}

.pb-modal-add-to-cart.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.pb-modal-add-to-cart.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid #fff;
    border-right-color: transparent;
    border-radius: 50%;
    animation: pb-spin 0.6s linear infinite;
}

.pb-modal-add-to-cart.success {
    background: #4caf50;
}

/* Responsive Modal */
@media (max-width: 900px) {
    .pb-modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .pb-modal-loaded {
        grid-template-columns: 1fr;
    }

    .pb-modal-header {
        flex-direction: column;
        gap: 20px;
        padding: 20px 20px 15px;
    }

    .pb-modal-header h2 {
        font-size: 22px;
    }

    .pb-modal-image-container {
        width: 100%;
        max-width: 300px;
        height: 180px;
        align-self: center;
    }

    .pb-modal-body {
        padding: 20px;
    }

    .pb-modal-footer {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }

    .pb-modal-price {
        text-align: center;
    }

    .pb-modal-add-to-cart {
        width: 100%;
    }

    .pb-modal-search {
        padding: 10px 16px 10px 40px;
        font-size: 13px;
        background-size: 16px 16px;
        background-position: left 12px center;
    }
}
