/* BMW Parts Viewer — Shared Stylesheet */

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333333;
    padding: 20px;
    padding-bottom: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.header {
    background: linear-gradient(135deg, #0066b3 0%, #003d6b 100%);
    padding: 1rem 2rem;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: white;
    flex-shrink: 0;
}
.header-logo img {
    height: 48px;
    border-radius: 4px;
    filter: brightness(0) invert(1);
}
.header h1 {
    font-size: 2em;
    color: white;
    margin: 0;
    flex: 1;
    text-align: center;
}
.header p {
    opacity: 0.9;
    font-size: 1.1em;
    color: white;
    text-align: center;
    margin-top: 5px;
}

/* ── Cart Icon ── */
.cart-icon-btn {
    position: relative;
    background: rgba(255,255,255,0.2);
    border: 2px solid white;
    border-radius: 5px;
    padding: 8px 14px;
    cursor: pointer;
    color: white;
    font-size: 1.3em;
    line-height: 1;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    width: 140px;
    justify-content: center;
}
.cart-icon-btn:hover { background: rgba(255,255,255,0.35); }
.cart-badge {
    position: absolute;
    top: -7px; right: -7px;
    background: white;
    color: #0066b3;
    font-size: 0.65em;
    font-weight: bold;
    width: 18px; height: 18px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.cart-badge.visible { opacity: 1; }
.cart-badge.bump { animation: badge-bump 0.3s ease; }
@keyframes badge-bump {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.5); }
    100% { transform: scale(1); }
}

/* ── Cart Drawer ── */
.cart-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
}
.cart-overlay.open { display: block; }
.cart-drawer {
    position: fixed; top: 0; right: -420px;
    width: 420px; max-width: 100vw; height: 100vh;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    z-index: 2001;
    display: flex; flex-direction: column;
    transition: right 0.35s cubic-bezier(0.4,0,0.2,1);
}
.cart-drawer.open { right: 0; }
.cart-drawer-header {
    background: linear-gradient(135deg, #0066b3 0%, #003d6b 100%);
    color: white; padding: 18px 20px;
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.cart-drawer-header h2 { margin: 0; font-size: 1.2em; letter-spacing: 0.05em; }
.cart-close-btn {
    background: none; border: none; color: white;
    font-size: 1.6em; cursor: pointer; line-height: 1;
    padding: 0 4px; transition: opacity 0.2s;
}
.cart-close-btn:hover { opacity: 0.7; }
.cart-drawer-body {
    flex: 1; overflow-y: auto; padding: 16px;
}
.cart-drawer-body::-webkit-scrollbar { width: 6px; }
.cart-drawer-body::-webkit-scrollbar-thumb { background: #0066b3; border-radius: 3px; }
.cart-empty { text-align: center; color: #888; font-style: italic; padding: 60px 20px; }
.cart-line-item {
    display: grid; grid-template-columns: 1fr auto;
    gap: 4px 12px; align-items: start;
    padding: 12px 0; border-bottom: 1px solid #e0e0e0;
}
.cart-item-title  { font-weight: bold; font-size: 0.85em; color: #333; grid-column: 1; }
.cart-item-sku    { font-size: 0.75em; color: #888; grid-column: 1; }
.cart-item-qty-price { font-size: 0.85em; color: #333; grid-column: 1; }
.cart-item-remove {
    grid-column: 2; grid-row: 1 / 4;
    background: none; border: none; color: #bbb;
    font-size: 1.2em; cursor: pointer; align-self: center;
    transition: color 0.2s; padding: 0 4px;
}
.cart-item-remove:hover { color: #0066b3; }
.cart-drawer-footer {
    padding: 16px; border-top: 2px solid #e0e0e0;
    flex-shrink: 0; background: #fafafa;
}
.cart-subtotal {
    display: flex; justify-content: space-between;
    font-weight: bold; font-size: 1em; color: #333;
    margin-bottom: 14px;
}
.cart-checkout-btn {
    display: block; width: 100%;
    background: linear-gradient(135deg, #0066b3 0%, #003d6b 100%);
    color: white; border: none; padding: 14px;
    border-radius: 6px; font-size: 1em; font-weight: bold;
    cursor: pointer; letter-spacing: 0.05em;
    transition: opacity 0.2s; text-align: center;
    text-decoration: none;
}
.cart-checkout-btn:hover { opacity: 0.88; }

/* ── Level 1: Category Grid ── */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 30px;
}
.cat-card {
    background: #ffffff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.3s;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 500;
    font-size: 0.9em;
    line-height: 1.3;
}
.cat-card:hover {
    border-color: #0066b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,102,179,0.2);
    color: #0066b3;
}

/* ── Level 2: Diagram Cards ── */
.diagram-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}
.diagram-card {
    background: #ffffff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
}
.diagram-card:hover {
    border-color: #0066b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,102,179,0.2);
}
.diagram-card h3 { color: #0066b3; font-size: 1em; margin-bottom: 6px; }
.diagram-card .info { color: #666; font-size: 0.85em; }
.diagram-card .thumb {
    width: 100%; max-height: 150px; object-fit: contain;
    border-radius: 4px; margin-bottom: 10px;
}

/* ── Breadcrumb ── */
.breadcrumb {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 20px; font-size: 0.9em;
    color: #666; font-weight: 700; text-transform: uppercase;
}
.breadcrumb a { color: #0066b3; cursor: pointer; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .separator { margin: 0 0.3rem; color: #999; }
.breadcrumb .current { color: #333; font-weight: 600; }

/* ── Level 3: Detail View ── */
.panel-tabs {
    display: flex; gap: 8px; margin-bottom: 15px;
    overflow-x: auto; padding-bottom: 8px;
}
.panel-tab {
    background: #ffffff; border: 2px solid #e0e0e0;
    border-radius: 6px; padding: 8px 14px;
    cursor: pointer; font-size: 0.82em;
    white-space: nowrap; transition: all 0.2s;
}
.panel-tab:hover { border-color: #0066b3; color: #0066b3; }
.panel-tab.active { background: #0066b3; border-color: #0066b3; color: white; }

.fiche-layout { display: grid; grid-template-columns: auto 1fr; gap: 20px; }
.diagram-panel {
    background: white; padding: 20px; border-radius: 8px;
    text-align: center; border: 1px solid #e0e0e0;
}
.diagram-panel img {
    width: auto; height: auto; max-height: 600px; border-radius: 4px;
    cursor: zoom-in; transition: transform 0.2s;
}
.diagram-panel img:hover { transform: scale(1.02); }
.parts-panel {
    background: white; border-radius: 8px;
    border: 1px solid #e0e0e0;
    display: flex; flex-direction: column; overflow: hidden;
}
.parts-header {
    background: #0066b3; color: white;
    padding: 12px 15px; font-weight: 600; font-size: 0.9em;
}
.parts-table-container {
    flex: 1; overflow-y: auto; max-height: 600px; font-size: 0.85em;
}
.parts-table-container::-webkit-scrollbar { width: 8px; }
.parts-table-container::-webkit-scrollbar-track { background: #e0e0e0; border-radius: 4px; }
.parts-table-container::-webkit-scrollbar-thumb { background: #0066b3; border-radius: 4px; }

/* ── Parts Table ── */
.parts-table { width: 100%; border-collapse: collapse; }
.parts-table th, .parts-table td {
    padding: 8px 6px; text-align: left;
    border-bottom: 1px solid #e0e0e0; font-size: 0.9em; white-space: nowrap;
}
.parts-table td:nth-child(3), .parts-table th:nth-child(3) { white-space: normal; width: 99%; }
.parts-table th:nth-child(1), .parts-table td:nth-child(1) { width: 36px; min-width: 36px; }
.parts-table th:nth-child(2), .parts-table td:nth-child(2) { width: 90px; min-width: 90px; }
.parts-table th:nth-child(4), .parts-table td:nth-child(4) { width: 40px; min-width: 40px; }
.parts-table th:nth-child(5), .parts-table td:nth-child(5) { width: 62px; min-width: 62px; }
.parts-table th:nth-child(6), .parts-table td:nth-child(6) { width: 44px; min-width: 44px; text-align: center; }
.parts-table th:nth-child(7), .parts-table td:nth-child(7) { width: 48px; min-width: 48px; }
.parts-table th:nth-child(8), .parts-table td:nth-child(8) { width: 60px; min-width: 60px; padding-left: 16px; }

.parts-table th {
    background: white; color: #0066b3; font-weight: bold;
    border-bottom: 2px solid #0066b3; position: sticky; top: 0;
}
.parts-table tr:hover { background: #0066b3; color: white; }
.parts-table tr:hover .price { color: white; }
.parts-table tr:hover .sku { color: white; }

/* ── Part Notes Tooltip ── */
.parts-table tr[data-note] { position: relative; }
.parts-table tr[data-note]::after {
    content: attr(data-note);
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #003d6b;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.82em;
    white-space: normal;
    max-width: 400px;
    text-align: center;
    pointer-events: none;
    z-index: 9999;
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.15s;
    line-height: 1.4;
}
.parts-table tr[data-note]:hover::after { opacity: 1; }
.parts-table .price { color: #333; font-weight: bold; }
.sku { font-family: 'Courier New', monospace; font-weight: 600; color: #0066b3; cursor: help; }

/* ── Availability Circles ── */
.avail-circle {
    display: inline-block; width: 14px; height: 14px;
    border-radius: 50%; vertical-align: middle;
}
.avail-circle.green  { background: #2e7d32; }
.avail-circle.yellow { background: #f3cd33; }
.avail-circle.red    { background: #cc0000; }
.avail-circle.grey   {
    background: #bbb;
    animation: avail-pulse 1.2s ease-in-out infinite;
}
@keyframes avail-pulse {
    0%, 100% { background: #bbb; box-shadow: 0 0 0 0 rgba(187,187,187,0.7); }
    50%       { background: #ddd; box-shadow: 0 0 0 5px rgba(187,187,187,0); }
}

/* ── Add to Cart Button ── */
.cart-qty-input {
    width: 44px; padding: 3px 4px;
    border: 1px solid #ccc; border-radius: 4px;
    text-align: center; font-size: 0.85em;
}
.add-btn {
    background: #0066b3; color: white; border: none;
    padding: 4px 8px; border-radius: 4px; cursor: pointer;
    font-size: 0.8em; font-weight: bold; white-space: nowrap;
    transition: background 0.2s;
}
.add-btn:hover { background: #004d8a; }
.add-btn.success { background: #2e7d32; cursor: default; }
.add-btn.error { background: #555; cursor: default; }
.parts-table tr:hover .cart-qty-input { border-color: white; }

/* ── Image Modal ── */
.image-modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.85); z-index: 10000;
    cursor: pointer; align-items: center; justify-content: center;
}
.image-modal.active { display: flex; }
.image-modal img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px; }
.image-modal .close-btn { position: absolute; top: 20px; right: 30px; color: white; font-size: 2.5rem; cursor: pointer; }

/* ── Footer ── */
.site-footer {
    background: linear-gradient(135deg, #0066b3 0%, #003d6b 100%);
    color: white;
    text-align: center;
    padding: 2rem;
    margin-top: auto;
    margin-left: -20px; margin-right: -20px;
}
.site-footer p {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}
.site-footer a {
    color: white;
    text-decoration: none;
}
.site-footer a:hover {
    text-decoration: underline;
}
.site-footer .sep {
    opacity: 0.5;
}

.hidden { display: none; }

@media (max-width: 900px) {
    .fiche-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    /* ── Body ── */
    body {
        padding: 0 10px 10px 10px;
    }

    .site-footer {
        margin-left: -10px;
        margin-right: -10px;
    }

    /* ── Header: logo+cart top row, title below ── */
    .header {
        padding: 10px 12px;
        margin-bottom: 16px;
        border-radius: 8px;
    }

    .header-top {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
        gap: 0;
        align-items: center;
    }

    .header-logo {
        grid-column: 1;
        grid-row: 1;
    }

    .header-logo img {
        height: 36px;
    }

    .header h1 {
        grid-column: 1 / -1;
        grid-row: 2;
        font-size: 1.2em;
        text-align: center;
        margin-top: 8px;
        flex: unset;
    }

    .header p {
        font-size: 0.9em;
        text-align: center;
    }

    .cart-icon-btn {
        grid-column: 3;
        grid-row: 1;
        width: auto;
        margin-left: 0;
        padding: 6px 10px;
        font-size: 1em;
    }

    /* ── Panel tabs: wrap to multiple rows ── */
    .panel-tabs {
        flex-wrap: wrap;
        gap: 6px;
    }

    .panel-tab {
        font-size: 0.75em;
        padding: 6px 8px;
        flex: 1 1 auto;
        text-align: center;
        min-width: 80px;
    }

    /* ── Diagram thumbnail selector: 3-col grid ── */
    .section-nav {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        overflow-x: visible;
        overflow-y: auto;
        max-height: 340px;
        padding-bottom: 0;
    }

    .diagram-card {
        width: 100%;
        flex-shrink: unset;
    }

    .diagram-card h3 {
        font-size: 0.7em;
    }

    .diagram-card .thumb {
        max-height: 80px;
    }

    /* ── Diagram image ── */
    .diagram-panel img {
        max-height: 320px;
    }

    /* ── Parts table ── */
    .parts-panel {
        overflow: visible !important;
    }

    .parts-table-container {
        max-height: none !important;
        overflow-y: visible !important;
        overflow-x: hidden !important;
    }

    /* Hide Req (col4) and cart-qty-input (col7) */
    .parts-table th:nth-child(4),
    .parts-table td:nth-child(4),
    .parts-table th:nth-child(7),
    .parts-table td:nth-child(7) {
        display: none !important;
    }

    .parts-table {
        table-layout: fixed !important;
        width: 100% !important;
    }

    .parts-table th, .parts-table td {
        padding: 6px 4px !important;
        font-size: 0.72em !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .parts-table th:nth-child(1), .parts-table td:nth-child(1) { width: 28px !important; min-width: 28px !important; }
    .parts-table th:nth-child(2), .parts-table td:nth-child(2) { width: 70px !important; min-width: 70px !important; }
    .parts-table th:nth-child(3), .parts-table td:nth-child(3) { width: 30% !important; max-width: 30% !important; min-width: unset !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; }
    .parts-table th:nth-child(5), .parts-table td:nth-child(5) { width: 52px !important; min-width: 52px !important; }
    .parts-table th:nth-child(6), .parts-table td:nth-child(6) { width: 36px !important; min-width: 36px !important; }
    .parts-table th:nth-child(8), .parts-table td:nth-child(8) { width: 60px !important; min-width: 60px !important; padding-left: 4px !important; }

    /* ── Breadcrumb ── */
    .breadcrumb {
        flex-wrap: wrap;
        font-size: 0.8em;
    }

    /* ── Cat grid ── */
    .cat-grid {
        grid-template-columns: 1fr 1fr;
    }
}
