:root {
    /* Color Palette - Business Hub Modern Dark */
    --bg-primary: #0f1115;
    --bg-secondary: #1a1d23;
    --bg-tertiary: #252a33;
    --accent-primary: #3b82f6;
    --accent-secondary: #2563eb;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2e3540;
    --glass-bg: rgba(26, 29, 35, 0.8);
    --glass-border: rgba(255, 255, 255, 0.05);

    --sidebar-width: 380px;
    --radius-lg: 16px;
    --radius-md: 10px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

h1,
h2,
h3 {
    font-family: 'Outfit', sans-serif;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logo {
    height: 40px;
    object-fit: contain;
    align-self: flex-start;
}

.sidebar h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.control-group h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.input-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-field label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

input,
select {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

input:focus,
select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Actions */
.actions {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 16px;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.5);
}

.secondary-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.btn-secondary,
.btn-outline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
}

.btn-outline:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

/* Viewer Section */
.viewer-container {
    flex: 1;
    position: relative;
    background: radial-gradient(circle at center, #1e293b, #0f172a);
}

#three-container {
    width: 100%;
    height: 100%;
}

.viewer-controls {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: 50px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.control-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.control-btn:hover {
    background-color: var(--accent-primary);
    transform: scale(1.1);
}

.control-btn svg {
    transition: var(--transition);
}

/* Modal AR */
.ar-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.ar-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.ar-modal-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 95%;
    min-height: 400px;
    text-align: center;
    position: relative;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
}

model-viewer {
    width: 100%;
    height: 400px;
    background-color: #1e293b;
    border-radius: var(--radius-md);
    margin-top: 20px;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
}

#qr-container {
    background: white;
    padding: 16px;
    border-radius: var(--radius-md);
    margin: 20px auto;
    width: fit-content;
}

/* Loader */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    gap: 20px;
}

.loader-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Modular Sections UI */
.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-icon-add {
    background: transparent;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    transition: var(--transition);
    padding: 4px;
    border-radius: 50%;
}

.btn-icon-add:hover {
    background: rgba(59, 130, 246, 0.1);
    transform: rotate(90deg);
}

.sections-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 12px;
    border-radius: var(--radius-md);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.section-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-remove-section {
    color: #ef4444;
    cursor: pointer;
    padding: 2px;
    font-size: 1.2rem;
    line-height: 1;
}

.section-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: center;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-field input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.empty-state {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 20px 0;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.empty-state.hidden {
    display: none;
}

/* ── New Column-Based Configurator UI ──────────────────────────────────── */

/* Sidebar subtitle */
.sidebar-subtitle {
    font-size: 0.72rem;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
    margin-top: -8px;
}

/* Step badge */
.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: -4px;
}

/* Step hint text */
.step-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: -8px;
}

/* Columns count stepper */
.cols-field label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}



.cols-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.stepper-btn {
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.stepper-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}

.cols-stepper input {
    flex: 1;
    border: none;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-radius: 0;
    text-align: center;
    padding: 8px 0;
    font-size: 1rem;
    font-weight: 700;
    background: var(--bg-secondary);
}

/* Column cards list */
.columns-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.column-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    animation: slideIn 0.25s ease;
    transition: border-color 0.2s;
}

.column-card:hover {
    border-color: rgba(59, 130, 246, 0.4);
}

.column-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border-color);
}

.column-icon {
    color: var(--accent-primary);
    display: flex;
    align-items: center;
}

.column-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.column-width-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.12);
    padding: 2px 7px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}

.column-fields {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.column-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--bg-secondary);
    padding: 6px 8px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    transition: var(--transition);
}

.column-field:hover {
    border-color: var(--border-color);
}

.column-field.dragging {
    opacity: 0.5;
    border-color: var(--accent-primary);
}

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.drag-handle:active {
    cursor: grabbing;
}

.column-field label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    flex: 1;
    cursor: pointer;
    user-select: none;
}

/* Mini quantity stepper */
.mini-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.mini-btn {
    background: var(--bg-secondary);
    border: none;
    color: var(--text-primary);
    width: 28px;
    height: 28px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mini-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}

.mini-val {
    min-width: 28px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    padding: 4px 2px;
    background: var(--bg-tertiary);
}

/* LED Toggle switch */
.toggle-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0 2px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    border-radius: 24px;
    transition: 0.3s;
}

.slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked+.slider {
    background: var(--accent-primary);
}

.switch input:checked+.slider::before {
    transform: translateX(18px);
}

/* btn-primary flex layout for icon */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* input-field label with icon */
.input-field label svg {
    vertical-align: middle;
    opacity: 0.7;
}

/* ── Mobile Tab Bar (hidden on desktop) ──────────────────────────────── */
.mobile-tab-bar {
    display: none;
}

/* ── CSS variable for mobile viewport height (set by JS) ─────────────── */
:root {
    --mobile-vh: 100vh;
}

/* ── Mobile Responsiveness — Tab-based layout ────────────────────────── */
@media (max-width: 900px) {

    /* Fixed bottom navigation bar — with iOS safe area support */
    .mobile-tab-bar {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 500;
        height: 64px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
    }

    .mobile-tab {
        -webkit-box-flex: 1;
        -ms-flex: 1;
        flex: 1;
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -ms-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: center;
        -ms-flex-align: center;
        align-items: center;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        justify-content: center;
        gap: 4px;
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 0.6rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.6px;
        cursor: pointer;
        -webkit-transition: color 0.2s ease;
        transition: color 0.2s ease;
        padding: 8px 4px;
        font-family: 'Inter', sans-serif;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-tab.active {
        color: var(--accent-primary);
    }

    .mobile-tab svg {
        -webkit-transition: -webkit-transform 0.2s ease;
        transition: transform 0.2s ease;
        -ms-flex-negative: 0;
        flex-shrink: 0;
    }

    .mobile-tab.active svg {
        -webkit-transform: scale(1.15);
        transform: scale(1.15);
    }

    /* Body & container: fixed height, no page scroll */
    body {
        overflow: hidden;
        height: 100vh;
        height: var(--mobile-vh);
    }

    .app-container {
        position: relative;
        display: block;
        /* Fallback puis CSS var injectée par JS pour iOS */
        height: calc(100vh - 64px);
        height: calc(var(--mobile-vh) - 64px);
        overflow: hidden;
        width: 100%;
    }

    /* Viewer: always full area, animates out when config is shown */
    .viewer-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        -webkit-transition: opacity 0.3s ease, -webkit-transform 0.3s ease;
        transition: opacity 0.3s ease, transform 0.3s ease;
        -webkit-transform-origin: center center;
        transform-origin: center center;
    }

    .viewer-container.mobile-hidden {
        opacity: 0;
        pointer-events: none;
        -webkit-transform: scale(0.96);
        transform: scale(0.96);
    }

    /* Sidebar: slides in from the right as a full panel */
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        /* height auto + min-height = pas de limite, scroll naturel */
        height: auto;
        min-height: 100%;
        border-right: none;
        border-top: none;
        box-shadow: none;
        padding: 20px 20px 32px;
        /* Scroll sur la sidebar elle-même */
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 2;
        -webkit-transform: translateX(100%);
        transform: translateX(100%);
        -webkit-transition: -webkit-transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        gap: 20px;
        /* iOS momentum scroll */
        -webkit-overflow-scrolling: touch;
        /* Empêche le flex container de comprimer ses enfants */
        -webkit-box-align: start;
        -ms-flex-align: start;
        align-items: stretch;
    }

    /* Les sections ne se rétrécissent JAMAIS — elles définissent leur hauteur naturelle */
    .sidebar > * {
        -ms-flex-negative: 0;
        flex-shrink: 0;
        width: 100%;
    }

    .sidebar.mobile-active {
        -webkit-transform: translateX(0);
        transform: translateX(0);
    }

    /* Viewer controls positioning */
    .viewer-controls {
        bottom: 12px;
        padding: 8px 10px;
        gap: 8px;
    }

    .control-btn {
        width: 40px;
        height: 40px;
    }

    .control-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Grid adjustments */
    .input-grid {
        grid-template-columns: 1fr 1fr !important;
        width: 100% !important;
    }

    .secondary-actions {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .btn-primary,
    .btn-secondary,
    .btn-outline {
        padding: 14px;
        font-size: 0.9rem;
    }

    .columns-list,
    .control-group {
        width: 100%;
        overflow-x: hidden;
    }
}

@media (max-width: 480px) {
    .input-grid {
        grid-template-columns: 1fr !important;
    }

    .sidebar-header h1 {
        font-size: 1.2rem;
    }

    .column-field label {
        font-size: 0.7rem;
    }

    .stepper-btn {
        width: 32px;
        height: 32px;
    }
}