*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    min-height: 100vh;
}

.container {
    width: 95%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

header { margin-bottom: 2rem; }
header h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
header h1 span { color: #6366f1; }
header p { color: #6b7280; margin-top: 0.4rem; font-size: 0.95rem; }

.card {
    background: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6366f1;
    margin-bottom: 1rem;
}

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.82rem; font-weight: 600; color: #374151; }

.field input,
.field select,
.field textarea {
    padding: 0.55rem 0.75rem;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    background: #fafafa;
    transition: border-color 0.15s, box-shadow 0.15s;
    color: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
    background: #fff;
}

.field textarea { resize: vertical; min-height: 88px; }

.hint { font-size: 0.8rem; color: #9ca3af; margin-top: 0.25rem; }

/* ── Furniture selection area ──────────────────────────── */
#furniture-section {
    background: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    margin-bottom: 1.25rem;
}

.load-btn {
    padding: 0.65rem 1.25rem;
    background: #f5f3ff;
    color: #6366f1;
    border: 1.5px solid #c7d2fe;
    border-radius: 9px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.load-btn:hover:not(:disabled) { background: #ede9fe; border-color: #6366f1; }
.load-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.load-btn.icon-mode {
    padding: 0.4rem 0.7rem;
    font-size: 1.2rem;
    line-height: 1;
    border-radius: 8px;
    min-width: unset;
}

.furniture-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.furniture-header .card-title { margin-bottom: 0; }
.furniture-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ── Filter Section ────────────────────────────────────── */
#filter-section {
    background: #fafafa;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
}

/* Range Slider Styling */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: #e5e7eb;
    border-radius: 3px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
    background: #d1d5db;
}

#selection-count {
    font-size: 0.82rem;
    color: #6b7280;
}
#selection-count span {
    font-weight: 700;
    color: #6366f1;
}

#furniture-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.85rem;
}

.furniture-card {
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #fafafa;
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
    user-select: none;
}
.furniture-card:hover { border-color: #a5b4fc; box-shadow: 0 2px 8px rgba(99,102,241,.1); }
.furniture-card.selected {
    border-color: #6366f1;
    background: #f5f3ff;
    box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}

.furniture-card img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.furniture-card-body { padding: 0.55rem 0.7rem 0.7rem; }
.furniture-card-name {
    font-size: 0.83rem;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.3;
    margin-bottom: 0.2rem;
}
.furniture-card-dims { font-size: 0.73rem; color: #6b7280; margin-bottom: 0.15rem; }
.furniture-card-price {
    font-size: 0.78rem;
    font-weight: 600;
    color: #6366f1;
    margin-bottom: 0.5rem;
}

.select-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #9ca3af;
}
.furniture-card.selected .select-indicator {
    color: #6366f1;
}
.select-indicator-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: #fff;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}
.furniture-card.selected .select-indicator-dot {
    background: #6366f1;
    border-color: #6366f1;
}

.generate-btn {
    width: 100%;
    padding: 0.95rem 1.5rem;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    border: none;
    border-radius: 11px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    letter-spacing: -0.01em;
    box-shadow: 0 4px 14px rgba(99,102,241,.35);
}
.generate-btn:hover:not(:disabled) { opacity: 0.92; }
.generate-btn:active:not(:disabled) { transform: scale(0.99); }
.generate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Loading indicator ────────────────────────────────── */
#loading { display: none; text-align: center; padding: 3.5rem 1rem; }
#loading p { color: #6b7280; font-size: 0.92rem; line-height: 1.6; }

.spinner {
    width: 52px;
    height: 52px;
    border: 4px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin: 0 auto 1.25rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result ───────────────────────────────────────────── */
#result { margin-top: 0.5rem; padding-top: 1rem; }
#result-gemini { margin-top: 0.5rem; padding-top: 2rem; }
.result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.75rem;
    max-width: 1200px;
    margin: 0.5rem auto 0;
}
.result-image img {
    width: 100%;
    max-height: calc(60vh - 5rem);
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    display: block;
}
.result-image p {
    font-size: 0.8rem;
    color: #6b7280;
    text-align: center;
    margin-top: 0.5rem;
    font-weight: 500;
}
.gemini-select-btn {
    display: block;
    width: 100%;
    margin-top: 0.6rem;
    padding: 0.45rem 0.75rem;
    background: #f5f3ff;
    border: 1.5px solid #c4b5fd;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6366f1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.gemini-select-btn:hover { background: #ede9fe; border-color: #a78bfa; }
.gemini-select-btn.active { background: #6366f1; color: #fff; border-color: #6366f1; }
.result-image.gemini-selected { outline: 2.5px solid #6366f1; border-radius: 12px; }
#result-gemini .gemini-result-wrapper {
    width: 100%;
    margin: 0.5rem 0 0;
    display: flex;
    justify-content: center;
}
#result-gemini .gemini-result-image {
    width: auto;
    max-width: min(100%, 1200px);
}
#result-gemini .result-image img {
    aspect-ratio: unset;
    width: auto;
    max-width: 100%;
    max-height: 80vh;
    margin: 0 auto;
    object-fit: contain;
    border-radius: 14px;
}
.debug-collapsible {
    margin-top: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    padding: 0.65rem 0.8rem;
}
.debug-collapsible summary {
    cursor: pointer;
    font-size: 0.84rem;
    color: #4b5563;
    font-weight: 600;
    user-select: none;
}
.debug-collapsible[open] summary {
    margin-bottom: 0.8rem;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    #furniture-list { grid-template-columns: repeat(2, 1fr); }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .result-grid { grid-template-columns: 1fr; }
    header h1 { font-size: 1.6rem; }
}

/* ── Dynamische Button Zentrierung ────────────────────── */
.furniture-header.initial-center {
    justify-content: center;
    padding: 2rem 0;
}
.furniture-header.initial-center .furniture-header-right {
    width: 100%;
    justify-content: center;
}
.furniture-header.initial-center .load-btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border-radius: 12px;
}

/* ── Dropdown Slider Styling ──────────────────────────── */
.dropdown-btn {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: #fafafa;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    font-size: 0.92rem;
    font-family: inherit;
    color: inherit;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.dropdown-btn:focus {
    outline: none;
    border-color: #6366f1;
}
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #fff;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 1.25rem 1rem;
    z-index: 10;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    margin-top: 5px;
    right: 0;
}
.dropdown-content.show {
    display: block;
}
/* ── Dropdown UI Erweiterungen für Slider & Checkboxes ──────────────────────────── */
.dropdown-container {
    position: relative;
}
.apply-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.6rem;
    background: #6366f1;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.apply-btn:hover { background: #4f46e5; }

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}
.range-current {
    text-align: center;
    font-weight: 700;
    color: #6366f1;
    margin-top: 0.5rem;
    font-size: 0.95rem;
}

.checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding-right: 0.5rem;
}
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    color: #374151;
}
.checkbox-item input {
    cursor: pointer;
    accent-color: #6366f1;
    width: 16px;
    height: 16px;
}
/* ── Multi-Range Slider Styling (Korrigiert) ──────────────────────────── */
.multi-range-container {
    position: relative;
    width: 100%;
    height: 6px;
    margin: 15px 0;
    background-color: #e5e7eb;
    border-radius: 3px;
}
.multi-range-track {
    position: absolute;
    height: 100%;
    background-color: #6366f1;
    border-radius: 3px;
    z-index: 1;
}

/* WICHTIG: Verhindert, dass die Slider den Rahmen und Hintergrund normaler Textfelder erben */
.field .multi-range-container input[type="range"] {
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
}
.field .multi-range-container input[type="range"]:focus {
    box-shadow: none;
    border: none;
}

.multi-range-container input[type="range"] {
    position: absolute;
    width: 100%;
    height: 6px;
    top: 0;
    left: 0;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    z-index: 2;
    margin: 0;
    outline: none;
}

/* Native Hintergrund-Spur unsichtbar machen */
.multi-range-container input[type="range"]::-webkit-slider-runnable-track {
    background: transparent;
    border: none;
}
.multi-range-container input[type="range"]::-moz-range-track {
    background: transparent;
    border: none;
}

/* Die ziehbaren Griffe (Thumbs) zentrieren und stylen */
.multi-range-container input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    margin-top: -6px; /* (Track Höhe 6px - Thumb Höhe 18px) / 2 = zentriert */
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.multi-range-container input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    height: 18px;
    width: 18px;
    border: none;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}