:root {
            --primary: #2563eb;
            --primary-hover: #1d4ed8;
            --secondary: #64748b;
            --danger: #ef4444;
            --success: #22c55e;
            --bg-gray: #f1f5f9;
            --surface: #ffffff;
            --border: #e2e8f0;
            --seat-empty: #e2e8f0;
            --seat-filled: #dbeafe;
            --seat-hover: #bfdbfe;
            --text-main: #1e293b;
        }

        * { box-sizing: border-box; }
        body { margin: 0; font-family: 'Segoe UI', system-ui, sans-serif; height: 100vh; display: flex; flex-direction: column; color: var(--text-main); overflow: hidden; }
        
        /* Layout */
        header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.5rem 1rem; display: flex; justify-content: space-between; align-items: center; height: 60px; z-index: 10; }
        .header-info { display: flex; gap: 1rem; align-items: center; }
        .header-inputs input { border: none; border-bottom: 1px dashed #cbd5e1; font-weight: bold; color: var(--text-main); font-size: 1rem; width: 150px; text-align: center; }
        .header-inputs input:focus { outline: none; border-bottom: 1px solid var(--primary); }

        .main-container { display: flex; flex: 1; height: calc(100vh - 60px); }
        
        /* Sidebar */
        aside { width: 380px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; z-index: 5; box-shadow: 2px 0 5px rgba(0,0,0,0.05); }
        .panel-section { padding: 1rem; border-bottom: 1px solid var(--border); }
        .panel-title { font-weight: 600; margin-bottom: 0.75rem; display: flex; justify-content: space-between; align-items: center; color: var(--secondary); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; }
        #structure-panel { display: flex; flex-direction: column; gap: 0.6rem; }
        .room-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem; background: #fff; display: flex; flex-direction: column; gap: 0.4rem; transition: border-color 0.2s, box-shadow 0.2s; }
        .room-card.active { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15); }
        .room-header { display: flex; align-items: center; gap: 0.4rem; }
        .room-name { flex: 1; text-align: left; border: none; background: transparent; font-weight: 600; color: var(--text-main); cursor: pointer; padding: 0.2rem 0.1rem; border-radius: 4px; }
        .room-name:hover, .room-name:focus-visible { background: #eef2ff; color: var(--primary); outline: none; }
        .room-actions { display: flex; gap: 0.2rem; }
        .room-actions .icon-btn { padding: 0.1rem 0.35rem; border-radius: 4px; }
        .structure-panel .panel-title { color: var(--text-main); text-transform: none; letter-spacing: 0; }
        .structure-panel .panel-title span { font-size: 1rem; font-weight: 600; }
        .structure-header-actions { display: flex; gap: 0.3rem; }
        .class-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
        .class-chip { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0 2rem 0 0.9rem; height: 36px; border-radius: 8px; border: 1px solid #93c5fd; background: #dbeafe; color: #1e3a8a; cursor: pointer; font-size: 0.9rem; font-weight: 600; transition: all 0.2s; box-shadow: 0 3px 10px rgba(59, 130, 246, 0.22); position: relative; }
        .class-chip.active { border-color: #1d4ed8; background: #2563eb; color: #ffffff; box-shadow: 0 6px 14px rgba(37, 99, 235, 0.35); }
        .class-chip:hover { background: #bfdbfe; border-color: #60a5fa; }
        .class-chip .chip-actions { display: flex; gap: 0.15rem; opacity: 0; transition: opacity 0.2s; position: absolute; right: 0.4rem; }
        .class-chip:hover .chip-actions { opacity: 1; }
        .class-chip .icon-btn { padding: 0.15rem 0.35rem; font-size: 0.75rem; border-radius: 4px; color: inherit; }
        .chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
        .empty-structure { padding: 0.4rem 0.6rem; border-radius: 6px; border: 1px dashed var(--border); color: #94a3b8; font-size: 0.85rem; background: #f8fafc; }
        
        /* Tabs */
        .tabs { display: flex; gap: 5px; margin-bottom: 10px; border-bottom: 1px solid var(--border); }
        .tab { padding: 5px 10px; cursor: pointer; font-size: 0.85rem; color: var(--secondary); border-bottom: 2px solid transparent; }
        .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: bold; }
        .tab-content { display: none; }
        .tab-content.active { display: block; }

        /* Workspace */
        #workspace-wrapper { flex: 1; position: relative; background: var(--bg-gray); overflow: auto; display: flex; flex-direction: column; }

        /* Workspace Tabs */
        .workspace-tabs {
            display: flex;
            background: var(--surface);
            border-bottom: 2px solid var(--border);
            padding: 0 1rem;
            flex-shrink: 0;
        }
        .workspace-tab {
            padding: 0.75rem 1.5rem;
            cursor: pointer;
            font-size: 0.95rem;
            font-weight: 500;
            color: var(--secondary);
            border-bottom: 3px solid transparent;
            margin-bottom: -2px;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .workspace-tab:hover {
            color: var(--primary);
            background: rgba(37, 99, 235, 0.05);
        }
        .workspace-tab.active {
            color: var(--primary);
            border-bottom-color: var(--primary);
            font-weight: 600;
            background: rgba(37, 99, 235, 0.08);
        }

        /* Affichage conditionnel selon la vue active */
        .view-class, .view-group { transition: opacity 0.2s ease; }
        body.view-group .view-class { display: none !important; }
        body.view-class .view-group { display: none !important; }
        body.view-class .view-class { display: block !important; }
        body.view-group .view-group { display: block !important; }

        #workspace { 
            width: 2500px; height: 2000px; 
            background-color: var(--bg-gray);
            /* Grid CSS pattern */
            background-image: linear-gradient(#cbd5e1 1px, transparent 1px), linear-gradient(90deg, #cbd5e1 1px, transparent 1px);
            background-size: 20px 20px; 
            position: relative; 
            transform-origin: 0 0;
        }

        /* Objects */
        .obj { position: absolute; background: var(--surface); border: 2px solid var(--secondary); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); cursor: grab; user-select: none; transition: box-shadow 0.2s, border-color 0.2s; display: flex; flex-direction: column; border-radius: 4px; }
        .obj:active { cursor: grabbing; }
        .obj.selected { border-color: var(--primary); z-index: 100; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2); }
        
        .obj-teacher { width: 140px; height: 80px; background: #f8fafc; align-items: center; justify-content: center; font-weight: bold; color: var(--secondary); position: relative; cursor: move; }
        .obj-board { width: 300px; height: 20px; background: #334155; border: none; color: white; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; position: relative; cursor: move; }
        .obj-rect { background: #f8fafc; border: 2px dashed #94a3b8; justify-content: center; align-items: center; padding: 6px; cursor: move; }
        .obj-remove { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; background: var(--danger); color: white; border-radius: 50%; display: none; align-items: center; justify-content: center; cursor: pointer; font-size: 12px; font-weight: bold; z-index: 10; }
        .obj:hover .obj-remove { display: flex; }
        .obj-table { height: 100px; padding: 5px; justify-content: space-between; cursor: move; }
        .obj-table.double { width: 160px; }
        .obj-table.single { width: 80px; }

        .table-label { text-align: center; font-size: 0.7rem; color: #94a3b8; margin-bottom: 2px; cursor: move; }
        .seats-container { display: flex; gap: 5px; flex: 1; height: 100%; }
        .rect-label { font-size: 0.8rem; font-weight: 600; color: #475569; text-align: center; width: 100%; outline: none; cursor: text; word-break: break-word; }
        .rect-label:focus { outline: 2px solid rgba(37, 99, 235, 0.4); border-radius: 4px; padding: 2px; background: white; }
        .resize-handle { position: absolute; right: 2px; bottom: 2px; width: 14px; height: 14px; background: #94a3b8; border-radius: 3px; cursor: nwse-resize; opacity: 0; }
        .obj:hover .resize-handle { opacity: 1; }
        
        .seat { 
            flex: 1; background: var(--seat-empty); border-radius: 4px; border: 1px dashed #cbd5e1; 
            display: flex; flex-direction: column; align-items: center; justify-content: center; 
            text-align: center; padding: 2px; transition: background 0.2s; position: relative; overflow: hidden;
        }
        .seat.drag-over { background: var(--seat-hover); border-style: solid; border-color: var(--primary); }
        .seat.filled { background: var(--seat-filled); border-style: solid; border-color: #93c5fd; }
        
        .seat-name { font-size: 0.8rem; font-weight: 500; word-break: normal; overflow-wrap: normal; white-space: normal; hyphens: none; pointer-events: none; line-height: 1.1; }
        .seat-meta { font-size: 0.65rem; color: #64748b; font-weight: bold; pointer-events: none; margin-top: 2px; display: flex; gap: 4px; }
        .seat-action { position: absolute; top: 0px; width: 16px; height: 16px; font-size: 10px; display: none; align-items: center; justify-content: center; cursor: pointer; z-index: 5; }
        .seat-remove { right: 0px; background: var(--danger); color: white; border-bottom-left-radius: 4px; }
        .seat:hover .seat-action { display: flex; }

        /* UI Elements */
        button { background: var(--surface); border: 1px solid var(--border); padding: 0.4rem 0.6rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem; transition: all 0.2s; color: var(--text-main); white-space: nowrap; }
        button:hover { background: #f8fafc; border-color: #cbd5e1; }
        button.primary { background: var(--primary); color: rgba(7, 43, 2, 0.774); border-color: var(--primary); }
        button.primary:hover { background: var(--primary-hover); }
        button.danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
        button.icon-btn { padding: 2px 5px; font-size: 0.75rem; color: #64748b; border:none; background:none; }
        button.icon-btn:hover { background: #f1f5f9; color: var(--primary); }
        
        input, select, textarea { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; margin-bottom: 0.5rem; width: 100%; }
        textarea { resize: vertical; min-height: 80px; font-family: monospace; font-size: 0.8rem; }

        .student-item {
            padding: 0.4rem; background: white; border: 1px solid var(--border); margin-bottom: 0.3rem; border-radius: 4px;
            display: flex; justify-content: space-between; align-items: center; cursor: grab;
        }
        .student-item.placed { opacity: 0.6; background: #f8fafc; border-style:dashed; }
        .student-controls { display: none; gap: 2px; }
        .student-item:hover .student-controls { display: flex; }
        .student-checkbox { cursor: pointer; width: 16px; height: 16px; accent-color: var(--primary); }
        
        .badge { padding: 2px 6px; border-radius: 10px; font-size: 0.65rem; font-weight: bold; color: white; min-width: 18px; text-align: center; display: inline-block; }
        .badge.M { background-color: #3b82f6; }
        .badge.F { background-color: #ec4899; }
        .badge.lvl-1 { background-color: #ef4444; }
        .badge.lvl-2 { background-color: #f59e0b; }
        .badge.lvl-3 { background-color: #10b981; }

        .toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: nowrap; overflow-x: auto; }
        .toolbar-group { display: flex; gap: 0.5rem; align-items: center; flex-wrap: nowrap; }
        .toolbar button,
        .toolbar .button {
            border-radius: 8px;
            padding: 0 0.9rem;
            height: 40px;
            min-width: 140px;
            font-weight: 700;
            background: #2563eb;
            color: #ffffff;
            border: 1px solid #1d4ed8;
            box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
            transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s, border-color 0.2s;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.4rem;
        }
        .toolbar button:hover,
        .toolbar .button:hover {
            background: #1d4ed8;
            border-color: #1e40af;
            box-shadow: 0 6px 16px rgba(30, 64, 175, 0.35);
            transform: translateY(-1px);
        }
        .toolbar button:focus-visible,
        .toolbar .button:focus-visible {
            outline: 2px solid rgba(37, 99, 235, 0.45);
            outline-offset: 2px;
        }
        .toolbar .button { display: inline-flex; align-items: center; }
        .toolbar button.primary { background: #0ea5e9; border-color: #0284c7; box-shadow: 0 6px 14px rgba(14, 165, 233, 0.35); }
        .toolbar button.primary:hover { background: #0284c7; border-color: #0369a1; }
        .toolbar button.dark { background: #0f172a; border-color: #0f172a; box-shadow: 0 6px 14px rgba(15, 23, 42, 0.4); }
        .toolbar button.dark:hover { background: #1e293b; border-color: #1e293b; }
        
        /* Modal */
        .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; display: none; align-items: center; justify-content: center; }
        .modal.active { display: flex; }
        .modal-content { background: white; padding: 2rem; border-radius: 8px; width: 400px; max-width: 90%; box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
        .form-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
        .form-row label { font-size: 0.9rem; font-weight: 500; }
        .form-row input, .form-row select { width: 60%; margin-bottom: 0; }

        .status-box { margin-top: 1rem; padding: 0.75rem; border-radius: 4px; font-size: 0.85rem; line-height: 1.4; display: none; }
        .status-box.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
        .status-box.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
        
        #toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
        .toast { padding: 10px 15px; border-radius: 6px; background: #334155; color: white; box-shadow: 0 4px 6px rgba(0,0,0,0.1); opacity: 0; transform: translateY(20px); transition: all 0.3s; font-size: 0.9rem; }
        .toast.show { opacity: 1; transform: translateY(0); }
        
        .config-block { background: #f1f5f9; padding: 10px; border-radius: 4px; margin-bottom: 10px; }
        
        /* Loading Overlay */
        #loader { position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(255,255,255,0.8); z-index:3000; display:none; justify-content:center; align-items:center; flex-direction:column; }
        .spinner { width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 10px; }
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
        /* Ajoutez ceci au CSS existant */
        .full-width { width: 100%; }
        .small { padding: 2px 8px; font-size: 0.8rem; }
        .mt-2 { margin-top: 0.5rem; }
        .dark { background: #334155; color: rgba(207, 12, 12, 0.877); border-color: #334155; }
        .separator { border-left: 1px solid #e2e8f0; padding-left: 1rem; margin-left: 1rem; }
        .header-inputs input { width: 140px; }
        .tab.active { border-bottom: 2px solid #2563eb; color: #2563eb; font-weight: 600; }
        .tab { padding: 5px 10px; cursor: pointer; color: #64748b; }
        .tabs { display: flex; gap: 10px; border-bottom: 1px solid #e2e8f0; margin-bottom: 10px; }
        .tab-content { display: none; }
        .tab-content.active { display: block; }

        /* PDF Preview Modal */
        .modal-pdf-content { width: 700px; max-width: 95%; }
        #pdf-preview-container {
            background: #e2e8f0;
            border-radius: 4px;
            padding: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 300px;
            max-height: 50vh;
            overflow: auto;
        }
        #pdf-preview-canvas {
            max-width: 100%;
            max-height: 100%;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            background: white;
        }

        /* Mode export PDF - sans grille */
        #workspace.export-mode {
            background-image: none !important;
            background-color: white !important;
        }
        #workspace.export-mode .obj-remove { display: none !important; }
        #workspace.export-mode .seat-action { display: none !important; }

        /* Aide Pronote */
        .modal-help-content { width: 900px; max-width: 95%; max-height: 85vh; overflow: auto; }
        .modal-help-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
        .modal-help-header h2 { margin: 0; font-size: 1.2rem; }
        .help-intro { margin: 0 0 1rem 0; color: #475569; }
        .help-steps { display: grid; gap: 1rem; }
        .help-step { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 0.75rem; }
        .help-step-title { font-weight: 600; margin-bottom: 0.5rem; color: #1e293b; }
        .help-step img { width: 33%; max-width: 360px; height: auto; border-radius: 6px; border: 1px solid #e2e8f0; display: block; margin: 0.5rem auto 0; }
        .help-footer { display: flex; justify-content: flex-end; margin-top: 1rem; }
