/* ============================================
   Schillig Konfigurator - Shared Styles
   ============================================ */

:root {
    --accent: #108474;
    --accent-hover: #0d6b5e;
    --accent-light: rgba(16, 132, 116, 0.1);
    --primary: #1a1a1a;
    --text: #333;
    --text-light: #666;
    --bg: #fff;
    --bg-alt: #f8f7f5;
    --border: #e5e5e5;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    overflow-x: hidden;
    color: var(--text);
}

/* Header */
.header {
    background: #fff;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-left a { text-decoration: none; }

.logo img { height: 26px; }

.header-breadcrumb {
    font-size: 13px;
    color: var(--text-light);
}

.header-breadcrumb a {
    color: var(--text-light);
    text-decoration: none;
}

.header-breadcrumb a:hover { color: var(--accent); }

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.header-right a {
    color: var(--text);
    text-decoration: none;
}

.header-right a:hover { color: var(--accent); }

/* Main Layout */
.container {
    display: flex;
    height: calc(100vh - 52px);
}

/* 3D Viewer */
.viewer-container {
    flex: 1;
    background: linear-gradient(135deg, #eaeaea 0%, #f8f8f8 100%);
    position: relative;
}

model-viewer {
    width: 100%;
    height: 100%;
    --poster-color: transparent;
}

model-viewer::part(default-progress-bar) {
    background-color: var(--accent);
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.loading-overlay.active { opacity: 1; pointer-events: all; }

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #eee;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-size: 13px;
    color: var(--text-light);
}

/* Viewer Info */
.viewer-info {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(255,255,255,0.95);
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.viewer-info h2 { font-size: 16px; margin-bottom: 3px; }
.viewer-info p { font-size: 12px; color: var(--text-light); }

/* Dimension Toggle */
.dimension-toggle {
    position: absolute;
    top: 16px;
    left: 16px;
    background: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    z-index: 10;
}

.dimension-toggle:hover { background: #f5f5f5; }
.dimension-toggle.active { background: var(--accent); color: #fff; }
.dimension-toggle.active .dim-icon { stroke: #fff; }

.dim-icon {
    width: 16px; height: 16px;
    stroke: #333; fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Dimension Info */
.dimension-info {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.95);
    padding: 14px 18px;
    border-radius: var(--radius);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s;
    pointer-events: none;
    z-index: 10;
}

.dimension-info.visible { opacity: 1; transform: translateY(0); }
.dimension-info h4 { font-size: 12px; color: var(--text-light); margin-bottom: 8px; text-transform: uppercase; }
.dimension-info table { font-size: 13px; }
.dimension-info td { padding: 3px 0; }
.dimension-info td:first-child { color: var(--text-light); padding-right: 14px; }
.dimension-info td:last-child { font-weight: 600; text-align: right; }

.dimension-hotspot {
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.dimension-hotspot.visible { opacity: 1; }

/* Sidebar */
.sidebar {
    width: 340px;
    background: #fff;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-content {
    padding: 20px;
    flex: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: #fff;
    position: sticky;
    bottom: 0;
}

/* Sections */
.section { margin-bottom: 24px; }

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-light);
    margin-bottom: 12px;
    font-weight: 600;
}

/* Product Selector */
.product-tabs {
    margin-bottom: 12px;
}

.product-group-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    margin: 12px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.product-group-header:first-child { margin-top: 0; }

.product-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 4px;
}

.product-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.product-card:hover { border-color: var(--accent); background: var(--accent-light); }
.product-card.active { border-color: var(--accent); border-width: 2px; background: var(--accent-light); }
.product-card.no-3d { opacity: 0.35; cursor: not-allowed; }

.product-card-icon {
    width: 100%;
    height: 53px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.product-card-icon img {
    max-width: 100%;
    max-height: 53px;
    object-fit: contain;
}

.product-card-icon.no-icon {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
}

.product-card.active .product-card-icon.no-icon { color: var(--accent); }

.product-card-dims {
    font-size: 9px;
    color: #888;
    margin-top: 1px;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}


.product-card-label {
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Material Type Tabs (Stoff/Leder) */
.material-type-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.material-type-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
}

.material-type-tab:not(:last-child) { border-right: 1px solid var(--border); }
.material-type-tab:hover { background: var(--bg-alt); }
.material-type-tab.active { background: var(--accent); color: #fff; }

/* Material Group Tabs */
.material-group-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.material-group-tab {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
}

.material-group-tab:hover { border-color: var(--accent); }
.material-group-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Color Swatches */
.color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.color-swatch {
    aspect-ratio: 1;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: visible;
}

.color-swatch:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 10;
}

.color-swatch.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 132, 116, 0.3);
}

.color-swatch .tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 20;
}

.color-swatch:hover .tooltip { opacity: 1; }

/* Foot Swatches */
.foot-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.foot-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
    transition: all 0.2s;
    background-size: cover;
    background-position: center;
}

.foot-swatch:hover { transform: scale(1.1); z-index: 10; }
.foot-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(16, 132, 116, 0.3); }
.foot-swatch .tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 20;
}
.foot-swatch:hover .tooltip { opacity: 1; }

/* Foot Form Tabs */
.foot-form-tabs {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.foot-form-tab {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    text-align: left;
}

.foot-form-tab:hover { border-color: var(--accent); background: var(--accent-light); }
.foot-form-tab.active { border-color: var(--accent); background: var(--accent); color: #fff; }

.foot-form-tab img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 4px;
    background: #f5f5f5;
    flex-shrink: 0;
}

.foot-form-tab.active img { background: rgba(255,255,255,0.2); }

/* Current Selection */
.current-selection {
    background: var(--bg-alt);
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.current-selection h4 { font-size: 11px; color: var(--text-light); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.current-selection .value { font-size: 14px; font-weight: 500; }

/* Price Section */
.price-section {
    background: var(--primary);
    color: #fff;
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 12px;
}

.price-section .label { font-size: 11px; opacity: 0.7; margin-bottom: 4px; }
.price-section .price { font-size: 26px; font-weight: bold; }
.price-section .note { font-size: 10px; opacity: 0.5; margin-top: 4px; }

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
    display: block;
}

.btn + .btn { margin-top: 8px; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* Info Box */
.info-box {
    background: #fff8e6;
    border: 1px solid #ffe58f;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 11px;
    color: #8a6d3b;
    margin-top: 16px;
}

/* Back Link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 16px;
}

.back-link:hover { color: var(--accent); }

/* Separator */
.separator {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* No Model State */
.no-model-message {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-light);
}

.no-model-message svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.3; }
.no-model-message p { font-size: 14px; }

/* Responsive */
@media (max-width: 900px) {
    .container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 52px);
    }

    .viewer-container {
        height: 45vh;
        min-height: 280px;
        flex: none;
    }

    .sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        overflow-y: visible;
        height: auto;
    }

    .sidebar-footer {
        position: static;
    }

    .color-grid { grid-template-columns: repeat(6, 1fr); }
    .foot-grid { grid-template-columns: repeat(8, 1fr); }

    .header-breadcrumb { display: none; }
}

@media (max-width: 480px) {
    .header { padding: 10px 16px; }
    .sidebar-content { padding: 16px; }
    .color-grid { grid-template-columns: repeat(5, 1fr); }
}


/* ═══════════════════════════════════════════════════════
   COMPOSITION / ZUSAMMENSTELLUNG
   ═══════════════════════════════════════════════════════ */

/* Mode Toggle */
.composition-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 4px;
}
.comp-mode-btn {
    flex: 1;
    padding: 9px 8px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    transition: all .2s;
    text-align: center;
}
.comp-mode-btn.active {
    background: var(--accent);
    color: #fff;
}
.comp-mode-btn:not(.active):hover {
    background: var(--bg-alt);
}

/* Composition Panel */
.composition-panel {
    background: #f7f7f7;
    border-bottom: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.viewer-container.has-composition {
    display: flex;
    flex-direction: column;
}
.viewer-container.has-composition .composition-panel {
    display: block;
    height: 55%;
    min-height: 260px;
}
.viewer-container.has-composition model-viewer {
    height: auto;
    flex: 1;
    min-height: 180px;
}

/* Toolbar */
.composition-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.composition-toolbar .comp-dim {
    font-weight: 400;
    color: var(--text-light);
    margin-left: auto;
}
.comp-clear-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text-light);
    font-size: 11px;
    cursor: pointer;
    transition: all .2s;
}
.comp-clear-btn:hover {
    background: #fee;
    border-color: #e55;
    color: #c33;
}

/* Canvas — Grid Background + Drag Area */
.composition-canvas {
    width: 100%;
    height: calc(100% - 40px);
    overflow: hidden;
    position: relative;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    background-color: #fafafa;
    background-image:
        linear-gradient(rgba(0,0,0,.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,.05) 1px, transparent 1px);
    background-size: var(--grid-px, 15px) var(--grid-px, 15px);
}

.comp-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #bbb;
    font-size: 13px;
    line-height: 1.5;
    pointer-events: none;
}
.comp-empty svg { margin-bottom: 12px; }
.comp-empty p { margin: 0; }

/* Composed Elements */
.comp-element {
    position: absolute;
    cursor: grab;
    border: 2px solid rgba(0,0,0,.1);
    border-radius: 4px;
    background: rgba(255,255,255,.65);
    transition: border-color .15s, box-shadow .15s;
    overflow: visible;
    touch-action: none;
}
.comp-element:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px rgba(16,132,116,.18);
    z-index: 10;
}
.comp-element.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(16,132,116,.12);
    z-index: 11;
}
.comp-element.dragging {
    cursor: grabbing;
    opacity: 0.8;
    z-index: 100 !important;
    box-shadow: 0 8px 30px rgba(0,0,0,.22);
    transition: none;
}
.comp-element img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    display: block;
}
.comp-element-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8e8e8;
    color: var(--text-light);
    font-size: 11px;
    font-weight: 600;
    border-radius: 2px;
}

/* Label below element */
.comp-element-label {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-light);
    pointer-events: none;
}

/* Remove button */
.comp-element-remove {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e55;
    color: #fff;
    border: 2px solid #fff;
    font-size: 14px;
    line-height: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 15;
    padding: 0;
}
.comp-element:hover .comp-element-remove {
    display: flex;
}

/* Magnetic Snap Indicator */
.snap-indicator {
    position: absolute;
    background: #0c6;
    z-index: 50;
    pointer-events: none;
    border-radius: 2px;
    opacity: 0.7;
    box-shadow: 0 0 8px rgba(0,204,102,.5);
}

/* Sidebar Composition List */
.comp-element-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.comp-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-alt);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
}
.comp-list-item:hover { background: #eef; }
.comp-list-item.active {
    background: rgba(16,132,116,.06);
    border-color: var(--accent);
}
.comp-list-item img {
    width: 40px;
    height: 26px;
    object-fit: contain;
    flex-shrink: 0;
}
.comp-list-item-info { flex: 1; min-width: 0; }
.comp-list-item-code { font-weight: 600; color: var(--text); }
.comp-list-item-title {
    color: var(--text-light);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.comp-list-item-remove {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 16px;
    padding: 0 2px;
    flex-shrink: 0;
    transition: color .15s;
}
.comp-list-item-remove:hover { color: #e55; }

/* Disabled product cards */
.product-card.comp-disabled {
    opacity: .3;
    pointer-events: none;
}

/* Count label */
.comp-element-count {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 900px) {
    .viewer-container.has-composition .composition-panel {
        height: 35vh;
        min-height: 200px;
    }
    .viewer-container.has-composition model-viewer {
        min-height: 160px;
    }
}
