<x-filament-panels::page>
    <div id="generator-orar-wrapper">
        <div id="generator-app"></div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
    <style>
        #generator-orar-wrapper * { box-sizing: border-box; }
        #generator-orar-wrapper { font-family: Arial, sans-serif; color: #222; font-size: 15px; }
        .go-tabs { display: flex; gap: 3px; flex-wrap: wrap; margin-bottom: 0; }
        .go-tab { padding: 9px 14px; border: 1px solid #ccc; border-bottom: none; border-radius: 7px 7px 0 0; cursor: pointer; font-size: 12px; background: #e2e6ee; color: #555; user-select: none; transition: background .15s; }
        .go-tab.active { background: #fff; color: #1a3c6e; font-weight: 700; border-color: #bbb; }
        .go-tab:hover:not(.active) { background: #d0d8ee; }
        .go-panel { display: none; background: #fff; border: 1px solid #bbb; border-radius: 0 8px 8px 8px; padding: 26px; }
        .go-panel.active { display: block; }
        .go-section-title { font-size: 16px; font-weight: 700; color: #1a3c6e; margin-bottom: 16px; }
        .go-card { background: #f7f9fc; border: 1px solid #dde3ee; border-radius: 8px; padding: 16px; margin-bottom: 14px; }
        .go-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
        .go-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
        #generator-orar-wrapper label { font-size: 13px; color: #555; display: block; margin-bottom: 4px; }
        #generator-orar-wrapper input[type=text], #generator-orar-wrapper input[type=number],
        #generator-orar-wrapper input[type=time], #generator-orar-wrapper select {
            width: 100%; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; background: #fff; color: #222;
        }
        .go-checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; }
        .go-checkbox-group label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #333; margin: 0; }
        .go-toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
        .go-toggle-row > label { margin: 0; font-size: 14px; font-weight: 700; color: #1a3c6e; cursor: pointer; }
        .go-card-cond { background: #f0f4ff; border: 1px solid #c4d4f4; border-radius: 8px; padding: 14px; margin-bottom: 10px; }
        .go-card-cond-mat { background: #f4fff0; border: 1px solid #b8e0b0; border-radius: 8px; padding: 14px; margin-bottom: 10px; }
        .go-cond-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid #c8d8f0; }
        .go-cond-body-mat { margin-top: 10px; padding-top: 10px; border-top: 1px solid #b8d8b0; }
        .go-cond-desc { font-size: 12px; color: #888; margin-bottom: 6px; }
        .go-add-btn { border: 1.5px dashed #aaa; border-radius: 6px; padding: 9px; width: 100%; background: transparent; color: #555; font-size: 13px; cursor: pointer; margin-top: 8px; }
        .go-add-btn:hover { background: #eef2ff; color: #1a3c6e; }
        .go-item-row { display: flex; align-items: center; gap: 8px; background: #eef2ff; border-radius: 6px; padding: 8px 12px; border: 1px solid #ccd8f0; margin-bottom: 7px; }
        .go-item-row-mat { display: flex; align-items: center; gap: 8px; background: #eefce8; border-radius: 6px; padding: 8px 12px; border: 1px solid #b8d8b0; margin-bottom: 7px; }
        .go-item-row span, .go-item-row-mat span { flex: 1; font-size: 13px; }
        .go-del-btn { background: transparent; border: none; color: #aaa; cursor: pointer; font-size: 17px; padding: 0 3px; }
        .go-del-btn:hover { color: #c0392b; }
        .go-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #dce8ff; color: #1a3c6e; font-weight: 700; }
        .go-badge-label { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e0f0e8; color: #1a6e3c; font-weight: 700; margin-left: 6px; }
        .go-gen-btn { width: 100%; padding: 13px; background: #1a3c6e; border: none; border-radius: 8px; font-size: 15px; font-weight: 700; color: #fff; cursor: pointer; margin-top: 18px; }
        .go-gen-btn:hover { background: #14305a; }
        .go-save-btn { padding: 10px 24px; background: #27ae60; border: none; border-radius: 6px; color: #fff; font-size: 14px; font-weight: 700; cursor: pointer; margin-right: 8px; }
        .go-save-btn:hover { background: #219150; }
        .go-dl-btn { padding: 8px 18px; background: #27ae60; border: none; border-radius: 6px; color: #fff; font-size: 13px; font-weight: 700; cursor: pointer; }
        .go-dl-btn:hover { background: #219150; }
        .go-regen-btn { padding: 8px 18px; background: #1a3c6e; border: none; border-radius: 6px; color: #fff; font-size: 13px; font-weight: 700; cursor: pointer; margin-right: 8px; }
        .go-result-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
        .go-result-tab { padding: 6px 14px; border: 1px solid #ccc; border-radius: 6px; cursor: pointer; font-size: 13px; background: #f0f0f0; color: #555; }
        .go-result-tab.active { background: #1a3c6e; color: #fff; border-color: #1a3c6e; font-weight: 700; }
        .go-result-section { display: none; }
        .go-result-section.active { display: block; }
        table.go-orar { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 500px; }
        table.go-orar th { background: #1a3c6e; color: #fff; padding: 8px 10px; border: 1px solid #14305a; text-align: center; font-weight: 700; }
        table.go-orar td { padding: 7px 9px; border: 1px solid #ddd; text-align: center; vertical-align: middle; }
        table.go-orar td.go-ora-label { background: #eef2ff; font-weight: 700; font-size: 12px; color: #1a3c6e; white-space: nowrap; }
        .go-cell-mat { font-weight: 700; color: #222; font-size: 12px; }
        .go-cell-prof { color: #777; font-size: 11px; margin-top: 2px; }
        .go-cell-consec { background: #e8f4ff !important; }
        .go-empty-cell { color: #ccc; font-size: 11px; }
        .go-warn-box { font-size: 13px; color: #a05800; background: #fff8e6; border: 1px solid #f0d080; border-radius: 6px; padding: 10px 14px; margin-bottom: 12px; }
        table.go-orar td.go-interactive { cursor: pointer; transition: background .15s, box-shadow .15s; }
        table.go-orar td.go-interactive:hover { background: #f0f4ff !important; }
        table.go-orar td.go-selected { background: #dbeafe !important; box-shadow: inset 0 0 0 2px #3b82f6; }
        table.go-orar td.go-conflict { background: #fee2e2 !important; }
        .go-swap-hint { font-size: 12px; color: #3b82f6; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px; padding: 8px 14px; margin-bottom: 12px; display: none; }
        .go-swap-hint.visible { display: block; }
        .go-conflict-list { font-size: 12px; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; padding: 8px 14px; margin-bottom: 12px; }
        .go-undo-btn { padding: 6px 14px; background: #f59e0b; border: none; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 700; cursor: pointer; margin-left: 8px; }
        .go-undo-btn:hover { background: #d97706; }
        .go-tip { font-size: 12px; color: #888; background: #fffbea; border: 1px solid #f0e060; border-radius: 5px; padding: 8px 12px; margin-bottom: 12px; }
        .go-group-title { font-size: 14px; font-weight: 700; color: #1a3c6e; margin: 22px 0 10px; padding-top: 18px; border-top: 2px solid #e8eef8; }
        @media (max-width: 640px) { .go-row2,.go-row3 { grid-template-columns: 1fr; } .go-panel { padding: 14px; } }
    </style>

    <script>
    document.addEventListener('DOMContentLoaded', function() {
        var dbClase = @json($this->getClaseData());
        var dbProfesori = @json($this->getProfesoriData());

        // State
        var clase = dbClase.map(function(c) { return {name: c.name, elevi: c.elevi}; });
        var profesori = dbProfesori;
        var materiiData = {};
        dbClase.forEach(function(c) {
            materiiData[c.name] = c.materii.map(function(m) {
                return {materie: m.materie, prof: m.prof, ore: m.ore};
            });
        });

        var puRules=[], ivRules=[], saRules=[];
        var nuRules=[], difRules=[], mcRules=[];

        // Build UI
        var container = document.getElementById('generator-app');
        container.innerHTML = buildHTML();

        // Init
        goSwitchTab(0);
        renderClase();
        renderProfesori();

        // --- Tab nav ---
        window.goSwitchTab = function(idx) {
            container.querySelectorAll('.go-tab').forEach(function(t,i){ t.classList.toggle('active', i===idx); });
            container.querySelectorAll('.go-panel').forEach(function(p,i){ p.classList.toggle('active', i===idx); });
            if (idx===3) renderMateriiTab();
        };

        window.goToggleCond = function(id) {
            var cb = document.getElementById(id+'-on');
            document.getElementById('cond-'+id+'-body').style.display = cb.checked ? 'block' : 'none';
        };

        // --- Clase ---
        function renderClase() {
            document.getElementById('go-clase-list').innerHTML = clase.map(function(c,i){
                return '<div class="go-item-row"><span><strong>'+c.name+'</strong></span><span class="go-badge">'+c.elevi+' elevi</span><button class="go-del-btn" onclick="goDelClasa('+i+')">×</button></div>';
            }).join('');
        }
        window.goAddClasa = function() {
            var n = document.getElementById('go-clasa-name').value.trim();
            var e = document.getElementById('go-clasa-elevi').value;
            if (!n) return alert('Introdu denumirea clasei.');
            if (clase.find(function(c){ return c.name===n; })) return alert('Clasa există deja.');
            clase.push({name:n, elevi:e||'?'});
            document.getElementById('go-clasa-name').value=''; document.getElementById('go-clasa-elevi').value='';
            renderClase();
        };
        window.goDelClasa = function(i){ clase.splice(i,1); renderClase(); };

        // --- Profesori ---
        function renderProfesori() {
            document.getElementById('go-prof-list').innerHTML = profesori.map(function(p,i){
                return '<div class="go-item-row"><span><strong>'+p.name+'</strong> — '+p.materie+'</span><button class="go-del-btn" onclick="goDelProf('+i+')">×</button></div>';
            }).join('');
        }
        window.goAddProfesor = function() {
            var n = document.getElementById('go-prof-name').value.trim();
            var m = document.getElementById('go-prof-materie').value.trim();
            if (!n||!m) return alert('Completează numele și materia.');
            profesori.push({name:n, materie:m, indisponibil:[]});
            document.getElementById('go-prof-name').value=''; document.getElementById('go-prof-materie').value='';
            renderProfesori();
        };
        window.goDelProf = function(i){ profesori.splice(i,1); renderProfesori(); };

        // --- Materii ---
        function renderMateriiTab() {
            var con = document.getElementById('go-materii-container');
            if (!clase.length){ con.innerHTML='<p style="color:#aaa">Adaugă mai întâi clase.</p>'; return; }
            var html='';
            clase.forEach(function(c){
                html+='<div class="go-card"><p style="font-weight:700;font-size:14px;color:#1a3c6e;margin-bottom:10px">Clasa '+c.name+'</p>';
                var mat=materiiData[c.name]||[];
                if(!mat.length) html+='<p style="font-size:13px;color:#aaa;margin-bottom:8px">Nicio materie adăugată.</p>';
                mat.forEach(function(m,mi){
                    html+='<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;background:#fff;border:1px solid #e0e0e0;border-radius:6px;padding:7px 12px">';
                    html+='<span style="flex:1;font-size:13px"><strong>'+m.materie+'</strong> — '+m.prof+'</span>';
                    html+='<input type="number" min="1" max="12" value="'+m.ore+'" style="width:52px" onchange="goUpdateOre(\''+c.name.replace(/'/g,"\\'")+'\','+mi+',this.value)">';
                    html+='<span style="font-size:12px;color:#888">ore/săpt</span>';
                    html+='<button class="go-del-btn" onclick="goDelMaterie(\''+c.name.replace(/'/g,"\\'")+'\','+mi+')">×</button></div>';
                });
                if(profesori.length){
                    var opts=profesori.map(function(p){ return '<option value="'+p.name+'|'+p.materie+'">'+p.materie+' — '+p.name+'</option>'; }).join('');
                    html+='<div style="display:flex;gap:8px;margin-top:6px"><select id="go-sel-'+c.name+'" style="flex:1;font-size:13px">'+opts+'</select>';
                    html+='<button class="go-add-btn" style="margin:0;width:auto;padding:7px 14px" onclick="goAddMaterie(\''+c.name.replace(/'/g,"\\'")+'\')">+ Adaugă</button></div>';
                }
                html+='</div>';
            });
            con.innerHTML=html;
        }
        window.goAddMaterie = function(cn){
            var sel=document.getElementById('go-sel-'+cn); if(!sel) return;
            var parts=sel.value.split('|');
            if(!materiiData[cn]) materiiData[cn]=[];
            if(materiiData[cn].some(function(m){ return m.materie===parts[1]; })) return alert('Materie deja existentă.');
            materiiData[cn].push({materie:parts[1], prof:parts[0], ore:3});
            renderMateriiTab();
        };
        window.goUpdateOre = function(cn,mi,v){ if(materiiData[cn]) materiiData[cn][mi].ore=Math.max(1,parseInt(v)||1); };
        window.goDelMaterie = function(cn,mi){ if(materiiData[cn]) materiiData[cn].splice(mi,1); renderMateriiTab(); };

        // --- Conditii ---
        window.goAddPU = function(){
            var p=document.getElementById('go-pu-prof').value.trim(), t=document.getElementById('go-pu-tip').value;
            if(!p) return alert('Introdu numele profesorului.');
            puRules.push({prof:p, tip:t}); document.getElementById('go-pu-prof').value=''; renderPU();
        };
        function renderPU(){ document.getElementById('go-pu-list').innerHTML=puRules.map(function(r,i){ return '<div class="go-item-row"><span><strong>'+r.prof+'</strong> — '+({'prima':'fără prima oră','ultima':'fără ultima oră','ambele':'fără prima & ultima'}[r.tip])+'</span><button class="go-del-btn" onclick="goDelPU('+i+')">×</button></div>'; }).join(''); }
        window.goDelPU = function(i){ puRules.splice(i,1); renderPU(); };

        window.goAddIV = function(){
            var p=document.getElementById('go-iv-prof').value.trim();
            var mn=parseInt(document.getElementById('go-iv-min').value), mx=parseInt(document.getElementById('go-iv-max').value);
            if(!p) return alert('Introdu numele.'); if(mn>=mx) return alert('Interval invalid.');
            ivRules.push({prof:p,min:mn,max:mx}); document.getElementById('go-iv-prof').value=''; renderIV();
        };
        function renderIV(){ document.getElementById('go-iv-list').innerHTML=ivRules.map(function(r,i){ return '<div class="go-item-row"><span><strong>'+r.prof+'</strong> — ore '+r.min+' până la '+r.max+'</span><button class="go-del-btn" onclick="goDelIV('+i+')">×</button></div>'; }).join(''); }
        window.goDelIV = function(i){ ivRules.splice(i,1); renderIV(); };

        window.goAddSA = function(){
            var a=document.getElementById('go-sala-a').value.trim(), b=document.getElementById('go-sala-b').value.trim(), s=document.getElementById('go-sala-n').value.trim()||'Sală';
            if(!a||!b) return alert('Introdu ambii profesori.');
            saRules.push({profA:a,profB:b,sala:s}); document.getElementById('go-sala-a').value=''; document.getElementById('go-sala-b').value=''; renderSA();
        };
        function renderSA(){ document.getElementById('go-sa-list').innerHTML=saRules.map(function(r,i){ return '<div class="go-item-row"><span><strong>'+r.profA+'</strong> & <strong>'+r.profB+'</strong> — '+r.sala+'</span><button class="go-del-btn" onclick="goDelSA('+i+')">×</button></div>'; }).join(''); }
        window.goDelSA = function(i){ saRules.splice(i,1); renderSA(); };

        window.goAddNU = function(){
            var m=document.getElementById('go-nu-mat').value.trim(); if(!m) return alert('Introdu materia.');
            nuRules.push({materie:m}); document.getElementById('go-nu-mat').value=''; renderNU();
        };
        function renderNU(){ document.getElementById('go-nu-list').innerHTML=nuRules.map(function(r,i){ return '<div class="go-item-row-mat"><span><strong>'+r.materie+'</strong> — niciodată în ultima oră</span><button class="go-del-btn" onclick="goDelNU('+i+')">×</button></div>'; }).join(''); }
        window.goDelNU = function(i){ nuRules.splice(i,1); renderNU(); };

        window.goAddDif = function(){
            var m=document.getElementById('go-dif-mat').value.trim(), p=parseInt(document.getElementById('go-dif-pana').value);
            if(!m) return alert('Introdu materia.');
            difRules.push({materie:m,pana:p}); document.getElementById('go-dif-mat').value=''; renderDif();
        };
        function renderDif(){ document.getElementById('go-dif-list').innerHTML=difRules.map(function(r,i){ return '<div class="go-item-row-mat"><span><strong>'+r.materie+'</strong> — maxim până la ora '+r.pana+'</span><button class="go-del-btn" onclick="goDelDif('+i+')">×</button></div>'; }).join(''); }
        window.goDelDif = function(i){ difRules.splice(i,1); renderDif(); };

        window.goAddMC = function(){
            var m=document.getElementById('go-mc-mat').value.trim(); if(!m) return alert('Introdu materia.');
            mcRules.push({materie:m}); document.getElementById('go-mc-mat').value=''; renderMC();
        };
        function renderMC(){ document.getElementById('go-mc-list').innerHTML=mcRules.map(function(r,i){ return '<div class="go-item-row-mat"><span><strong>'+r.materie+'</strong> — ore consecutive</span><button class="go-del-btn" onclick="goDelMC('+i+')">×</button></div>'; }).join(''); }
        window.goDelMC = function(i){ mcRules.splice(i,1); renderMC(); };

        // --- Time helpers ---
        function getOreTimes(nrOre){
            var start=document.getElementById('go-ora-start').value||'08:00';
            var dur=parseInt(document.getElementById('go-dur-ora').value);
            var pm=parseInt(document.getElementById('go-pauza-mica').value)||10;
            var pM=parseInt(document.getElementById('go-pauza-mare').value)||20;
            var pmD=parseInt(document.getElementById('go-pauza-mare-dupa').value)||3;
            var parts=start.split(':'), cur=parseInt(parts[0])*60+parseInt(parts[1]);
            var times=[];
            for(var i=0;i<nrOre;i++){
                var h=Math.floor(cur/60),m=cur%60;
                var s=(h<10?'0':'')+h+':'+(m<10?'0':'')+m;
                cur+=dur;
                var h2=Math.floor(cur/60),m2=cur%60;
                var e=(h2<10?'0':'')+h2+':'+(m2<10?'0':'')+m2;
                times.push({display: s+' – '+e, start: s, end: e});
                if(i<nrOre-1) cur+=((i+1===pmD)?pM:pm);
            }
            return times;
        }

        function getZile(){
            var z=[];
            container.querySelectorAll('#go-zile-check input:checked').forEach(function(cb){ z.push(cb.value); });
            return z;
        }

        function getCond(){
            return {
                maxZi: document.getElementById('go-maxzi-on').checked,
                maxZiVal: parseInt(document.getElementById('go-maxzi-val').value)||3,
                primaUltima: document.getElementById('go-pu-on').checked, puRules: puRules,
                interval: document.getElementById('go-iv-on').checked, ivRules: ivRules,
                sala: document.getElementById('go-sa-on').checked, saRules: saRules,
                consec: document.getElementById('go-consec-on').checked,
                consecVal: parseInt(document.getElementById('go-consec-val').value)||3,
                echilibru: document.getElementById('go-echilibru-on').checked,
                echilibruVal: parseInt(document.getElementById('go-echilibru-val').value)||1,
                nUltima: document.getElementById('go-nu-on').checked, nuRules: nuRules,
                dificile: document.getElementById('go-dif-on').checked, difRules: difRules,
                mconsec: document.getElementById('go-mc-on').checked, mcRules: mcRules
            };
        }

        function countConsec(occ,pn,zi,idx){ var a=occ[pn][zi],cnt=0,j=idx-1; while(j>=0&&a[j]){cnt++;j--;} j=idx+1; while(j<a.length&&a[j]){cnt++;j++;} return cnt; }
        function countZiProf(occ,pn,zi){ return occ[pn][zi].filter(Boolean).length; }
        function hasConflictSala(rules,op,pn,zi,si,cond){
            if(!cond.sala) return false;
            return rules.some(function(r){ var o=(r.profA===pn)?r.profB:(r.profB===pn?r.profA:null); if(!o||!op[o]) return false; return op[o][zi]&&op[o][zi][si]!==null; });
        }

        // --- Main generator ---
        window.goGenerar = function(){
            _undoStack = [];
            var zile=getZile(), nrOre=parseInt(document.getElementById('go-ore-zi').value), cond=getCond(), warnings=[];
            if(!clase.length||!zile.length){ document.getElementById('go-rezultat').innerHTML='<p style="color:#aaa;padding:20px;text-align:center">Adaugă clase și zile.</p>'; return; }

            var orare={}, orareProf={}, profOcc={}, oreMZi={};
            clase.forEach(function(c){ orare[c.name]={}; oreMZi[c.name]={}; zile.forEach(function(z){ orare[c.name][z]=new Array(nrOre).fill(null); oreMZi[c.name][z]={}; }); });
            profesori.forEach(function(p){ orareProf[p.name]={}; profOcc[p.name]={}; zile.forEach(function(z){ orareProf[p.name][z]=new Array(nrOre).fill(null); profOcc[p.name][z]=new Array(nrOre).fill(false); }); });

            clase.forEach(function(c){
                var materii=(materiiData[c.name]||[]).slice();
                materii.sort(function(a,b){
                    var aP=0,bP=0;
                    if(cond.dificile&&difRules.find(function(r){ return r.materie.toLowerCase()===a.materie.toLowerCase(); })) aP-=2;
                    if(cond.mconsec&&mcRules.find(function(r){ return r.materie.toLowerCase()===a.materie.toLowerCase(); })) aP-=1;
                    if(cond.dificile&&difRules.find(function(r){ return r.materie.toLowerCase()===b.materie.toLowerCase(); })) bP-=2;
                    if(cond.mconsec&&mcRules.find(function(r){ return r.materie.toLowerCase()===b.materie.toLowerCase(); })) bP-=1;
                    return aP-bP;
                });

                materii.forEach(function(m){
                    var ramas=m.ore;
                    var profObj=profesori.find(function(p){ return p.name===m.prof; });
                    var difRule=cond.dificile?difRules.find(function(r){ return r.materie.toLowerCase()===m.materie.toLowerCase(); }):null;
                    var isNU=cond.nUltima&&nuRules.some(function(r){ return r.materie.toLowerCase()===m.materie.toLowerCase(); });
                    var isConsec=cond.mconsec&&mcRules.some(function(r){ return r.materie.toLowerCase()===m.materie.toLowerCase(); });
                    var puRule=cond.primaUltima?puRules.find(function(r){ return r.prof.toLowerCase()===m.prof.toLowerCase(); }):null;
                    var ivRule=cond.interval?ivRules.find(function(r){ return r.prof.toLowerCase()===m.prof.toLowerCase(); }):null;

                    var slots=[];
                    zile.forEach(function(z){ for(var i=0;i<nrOre;i++){
                        if(difRule&&(i+1)>difRule.pana) continue;
                        if(isNU&&i===nrOre-1) continue;
                        if(puRule){ if(puRule.tip==='prima'&&i===0) continue; if(puRule.tip==='ultima'&&i===nrOre-1) continue; if(puRule.tip==='ambele'&&(i===0||i===nrOre-1)) continue; }
                        if(ivRule&&((i+1)<ivRule.min||(i+1)>ivRule.max)) continue;
                        slots.push({z:z,i:i});
                    }});

                    function canPlace(z,i){
                        if(orare[c.name][z][i]!==null) return false;
                        if(profObj&&profObj.indisponibil&&profObj.indisponibil.indexOf(z)>=0) return false;
                        if(profOcc[m.prof]&&profOcc[m.prof][z]&&profOcc[m.prof][z][i]) return false;
                        if(hasConflictSala(saRules,orareProf,m.prof,z,i,cond)) return false;
                        if(cond.maxZi&&countZiProf(profOcc,m.prof,z)>=cond.maxZiVal) return false;
                        if(cond.consec&&countConsec(profOcc,m.prof,z,i)>=cond.consecVal) return false;
                        return true;
                    }
                    function place(z,i,consec){
                        orare[c.name][z][i]={materie:m.materie,prof:m.prof,consec:consec||false};
                        profOcc[m.prof][z][i]=true;
                        orareProf[m.prof][z][i]={clasa:c.name,materie:m.materie};
                        oreMZi[c.name][z][m.materie]=(oreMZi[c.name][z][m.materie]||0)+1;
                        ramas--;
                    }

                    if(isConsec){
                        var zR=zile.slice().sort(function(){return Math.random()-0.5;});
                        zR.forEach(function(z){ for(var i=0;i<nrOre-1&&ramas>=2;i++){
                            if(!slots.some(function(s){return s.z===z&&s.i===i;})||!slots.some(function(s){return s.z===z&&s.i===i+1;})) continue;
                            if(!canPlace(z,i)||!canPlace(z,i+1)) continue;
                            if(cond.maxZi&&countZiProf(profOcc,m.prof,z)+2>cond.maxZiVal) continue;
                            if(cond.echilibru&&((oreMZi[c.name][z][m.materie]||0)+2>cond.echilibruVal*2)) continue;
                            place(z,i,true); place(z,i+1,true);
                        }});
                    }

                    if(ramas>0){
                        if(cond.echilibru) slots.sort(function(a,b){ var cA=oreMZi[c.name][a.z][m.materie]||0,cB=oreMZi[c.name][b.z][m.materie]||0; return cA!==cB?cA-cB:Math.random()-0.5; });
                        else slots.sort(function(){return Math.random()-0.5;});
                        slots.forEach(function(s){ if(ramas<=0) return; if(!canPlace(s.z,s.i)) return;
                            if(cond.echilibru&&(oreMZi[c.name][s.z][m.materie]||0)>=cond.echilibruVal) return;
                            place(s.z,s.i);
                        });
                    }
                    if(ramas>0) warnings.push('Clasa '+c.name+' — '+m.materie+': '+ramas+' oră/ore neplanificată(e).');
                });
            });

            // Compactare: elimină golurile din orar (copiii nu au ore libere)
            clase.forEach(function(c){
                zile.forEach(function(z){
                    var filled = orare[c.name][z].filter(function(cell){ return cell !== null; });
                    for(var i=0;i<nrOre;i++){
                        orare[c.name][z][i] = i < filled.length ? filled[i] : null;
                    }
                });
            });
            // Reconstruiește orarul profesorilor după compactare
            profesori.forEach(function(p){
                zile.forEach(function(z){ orareProf[p.name][z]=new Array(nrOre).fill(null); });
            });
            clase.forEach(function(c){
                zile.forEach(function(z){
                    for(var i=0;i<nrOre;i++){
                        var cell=orare[c.name][z][i];
                        if(cell && cell.prof && orareProf[cell.prof]){
                            orareProf[cell.prof][z][i]={clasa:c.name,materie:cell.materie};
                        }
                    }
                });
            });

            var times=getOreTimes(nrOre);
            window._goOrare=orare; window._goOrareProf=orareProf; window._goZile=zile; window._goNrOre=nrOre; window._goTimes=times;
            renderRezultat(orare,orareProf,zile,nrOre,times,warnings);
        };

        function renderTabel(orarZile,zile,nrOre,times,isProf,clasaName){
            var html='<div style="overflow-x:auto;margin-top:6px"><table class="go-orar"><thead><tr><th style="min-width:85px">Ora</th>';
            zile.forEach(function(z){html+='<th>'+z+'</th>';});
            html+='</tr></thead><tbody>';
            for(var i=0;i<nrOre;i++){
                html+='<tr><td class="go-ora-label">Ora '+(i+1)+'<br><span style="font-weight:400;font-size:11px">'+times[i].display+'</span></td>';
                zile.forEach(function(z){
                    var cell=orarZile&&orarZile[z]&&orarZile[z][i];
                    var interClass = (!isProf && clasaName) ? ' go-interactive' : '';
                    var dataAttr = (!isProf && clasaName) ? ' data-clasa="'+clasaName+'" data-zi="'+z+'" data-ora="'+i+'"' : '';
                    if(cell){
                        var cls = (!isProf&&cell.consec) ? ' go-cell-consec' : '';
                        html+='<td class="'+cls+interClass+'"'+dataAttr+'><div class="go-cell-mat">'+cell.materie+'</div><div class="go-cell-prof">'+(isProf?'Cls. '+cell.clasa:cell.prof)+'</div></td>';
                    } else {
                        html+='<td class="'+interClass+'"'+dataAttr+'><span class="go-empty-cell">—</span></td>';
                    }
                });
                html+='</tr>';
            }
            html+='</tbody></table></div>';
            return html;
        }

        var _swapSelected = null;
        var _undoStack = [];

        function checkAllConflicts(){
            var conflicts = [];
            var zile = window._goZile, nrOre = window._goNrOre;
            zile.forEach(function(zi){
                for(var i=0;i<nrOre;i++){
                    var profsAtSlot = {};
                    clase.forEach(function(c){
                        var cell = window._goOrare[c.name] && window._goOrare[c.name][zi] && window._goOrare[c.name][zi][i];
                        if(cell && cell.prof){
                            if(!profsAtSlot[cell.prof]) profsAtSlot[cell.prof] = [];
                            profsAtSlot[cell.prof].push(c.name);
                        }
                    });
                    Object.keys(profsAtSlot).forEach(function(prof){
                        if(profsAtSlot[prof].length > 1){
                            conflicts.push(prof + ' — ' + zi + ', ora ' + (i+1) + ' (clase: ' + profsAtSlot[prof].join(', ') + ')');
                        }
                    });
                }
            });
            return conflicts;
        }

        function rebuildOrareProf(){
            var zile = window._goZile, nrOre = window._goNrOre;
            var orareProf = {};
            profesori.forEach(function(p){
                orareProf[p.name] = {};
                zile.forEach(function(z){ orareProf[p.name][z] = new Array(nrOre).fill(null); });
            });
            clase.forEach(function(c){
                zile.forEach(function(z){
                    for(var i=0;i<nrOre;i++){
                        var cell = window._goOrare[c.name] && window._goOrare[c.name][z] && window._goOrare[c.name][z][i];
                        if(cell && cell.prof && orareProf[cell.prof]){
                            orareProf[cell.prof][z][i] = {clasa:c.name, materie:cell.materie};
                        }
                    }
                });
            });
            window._goOrareProf = orareProf;
        }

        function renderRezultat(orare,orareProf,zile,nrOre,times,warnings){
            _swapSelected = null;
            var html='';
            if(warnings.length) html+='<div class="go-warn-box">⚠️ '+warnings.join('<br>⚠️ ')+'</div>';

            var conflicts = checkAllConflicts();
            if(conflicts.length) html+='<div class="go-conflict-list">⚠️ Conflicte profesor:<br>' + conflicts.join('<br>') + '</div>';

            html+='<div class="go-swap-hint" id="go-swap-hint">Selectează o altă celulă pentru a face schimbul, sau click pe aceeași celulă pentru a anula.</div>';
            html+='<div style="margin-bottom:14px">'
                +'<button class="go-save-btn" onclick="goSalveaza()"'+(conflicts.length?' disabled style="opacity:0.5;cursor:not-allowed" title="Rezolvă conflictele mai întâi"':'')+'>💾 Salvează orarul în catalog</button>'
                +'<button class="go-regen-btn" onclick="goGenerar()">🔄 Regenerează</button>'
                +'<button class="go-dl-btn" onclick="goDownloadExcel()">⬇ Excel</button>'
                +(_undoStack.length ? '<button class="go-undo-btn" onclick="goUndo()">↩ Anulează ultimul schimb</button>' : '')
                +'</div>';
            html+='<div class="go-tip">💡 Click pe o celulă din orar pentru a o selecta, apoi click pe altă celulă pentru a face schimbul. Conflictele de profesor sunt detectate automat.</div>';
            html+='<div class="go-result-tabs">';
            clase.forEach(function(c,i){ html+='<div class="go-result-tab'+(i===0?' active':'')+'" onclick="goSwitchResult(\'c'+i+'\',this)">'+c.name+'</div>'; });
            if(profesori.length) html+='<div class="go-result-tab" onclick="goSwitchResult(\'profs\',this)">Profesori</div>';
            html+='</div>';
            clase.forEach(function(c,i){ html+='<div class="go-result-section'+(i===0?' active':'')+'" id="go-rs-c'+i+'">'+renderTabel(orare[c.name],zile,nrOre,times,false,c.name)+'</div>'; });
            if(profesori.length){
                html+='<div class="go-result-section" id="go-rs-profs">';
                profesori.forEach(function(p){ html+='<p style="font-size:14px;font-weight:700;color:#1a3c6e;margin:14px 0 5px">'+p.name+' — '+p.materie+'</p>'+renderTabel(orareProf[p.name],zile,nrOre,times,true,null)+'<hr style="border:none;border-top:1px solid #e0e0e0;margin:14px 0">'; });
                html+='</div>';
            }
            document.getElementById('go-rezultat').innerHTML=html;
            attachSwapHandlers();
        }

        function attachSwapHandlers(){
            container.querySelectorAll('td.go-interactive').forEach(function(td){
                td.addEventListener('click', function(){
                    var clasa = this.dataset.clasa;
                    var zi = this.dataset.zi;
                    var ora = parseInt(this.dataset.ora);

                    if(!_swapSelected){
                        _swapSelected = {clasa:clasa, zi:zi, ora:ora, el:this};
                        this.classList.add('go-selected');
                        document.getElementById('go-swap-hint').classList.add('visible');
                    } else if(_swapSelected.clasa === clasa && _swapSelected.zi === zi && _swapSelected.ora === ora){
                        _swapSelected.el.classList.remove('go-selected');
                        _swapSelected = null;
                        document.getElementById('go-swap-hint').classList.remove('visible');
                    } else if(_swapSelected.clasa === clasa){
                        var src = _swapSelected;
                        var cellA = window._goOrare[clasa][src.zi][src.ora];
                        var cellB = window._goOrare[clasa][zi][ora];

                        _undoStack.push({
                            clasa: clasa,
                            zi1: src.zi, ora1: src.ora, cell1: cellA ? JSON.parse(JSON.stringify(cellA)) : null,
                            zi2: zi, ora2: ora, cell2: cellB ? JSON.parse(JSON.stringify(cellB)) : null
                        });

                        window._goOrare[clasa][src.zi][src.ora] = cellB;
                        window._goOrare[clasa][zi][ora] = cellA;

                        rebuildOrareProf();
                        renderRezultat(window._goOrare, window._goOrareProf, window._goZile, window._goNrOre, window._goTimes, []);
                    } else {
                        _swapSelected.el.classList.remove('go-selected');
                        _swapSelected = {clasa:clasa, zi:zi, ora:ora, el:this};
                        this.classList.add('go-selected');
                    }
                });
            });
        }

        window.goUndo = function(){
            if(!_undoStack.length) return;
            var last = _undoStack.pop();
            window._goOrare[last.clasa][last.zi1][last.ora1] = last.cell1;
            window._goOrare[last.clasa][last.zi2][last.ora2] = last.cell2;
            rebuildOrareProf();
            renderRezultat(window._goOrare, window._goOrareProf, window._goZile, window._goNrOre, window._goTimes, []);
        };

        window.goSwitchResult = function(id,el){
            container.querySelectorAll('.go-result-tab').forEach(function(b){b.classList.remove('active');});
            container.querySelectorAll('.go-result-section').forEach(function(s){s.classList.remove('active');});
            document.getElementById('go-rs-'+id).classList.add('active');
            el.classList.add('active');
        };

        // --- Save to DB ---
        window.goSalveaza = function(){
            if(!window._goOrare) return alert('Generează orarul mai întâi.');
            var conflicts = checkAllConflicts();
            if(conflicts.length) return alert('Există conflicte de profesor! Rezolvă-le înainte de salvare.');
            var slots=[];
            var zile=window._goZile, nrOre=window._goNrOre, times=window._goTimes;
            Object.keys(window._goOrare).forEach(function(clasa){
                zile.forEach(function(zi){
                    for(var i=0;i<nrOre;i++){
                        var cell=window._goOrare[clasa][zi][i];
                        if(cell){
                            slots.push({
                                clasa: clasa,
                                materie: cell.materie,
                                zi: zi,
                                ora_index: i,
                                ora_inceput: times[i].start,
                                ora_sfarsit: times[i].end
                            });
                        }
                    }
                });
            });
            @this.call('salveazaOrar', slots);
        };

        // --- Excel download ---
        window.goDownloadExcel = function(){
            if(!window._goOrare) return;
            var wb=XLSX.utils.book_new(), zile=window._goZile, nrOre=window._goNrOre, times=window._goTimes;
            clase.forEach(function(c){
                var orar=window._goOrare[c.name], rows=[['Ora / Zi'].concat(zile)];
                for(var i=0;i<nrOre;i++){ var row=['Ora '+(i+1)+' ('+times[i].display+')']; zile.forEach(function(z){ var cell=orar&&orar[z]&&orar[z][i]; row.push(cell?cell.materie+'\n'+cell.prof:''); }); rows.push(row); }
                var ws=XLSX.utils.aoa_to_sheet(rows); ws['!cols']=[{wch:24}].concat(zile.map(function(){return{wch:20};}));
                XLSX.utils.book_append_sheet(wb,ws,'Cls '+c.name);
            });
            profesori.forEach(function(p){
                var orar=window._goOrareProf[p.name], rows=[['Ora / Zi'].concat(zile)];
                for(var i=0;i<nrOre;i++){ var row=['Ora '+(i+1)+' ('+times[i].display+')']; zile.forEach(function(z){ var cell=orar&&orar[z]&&orar[z][i]; row.push(cell?cell.materie+' (Cls '+cell.clasa+')':''); }); rows.push(row); }
                var ws=XLSX.utils.aoa_to_sheet(rows); ws['!cols']=[{wch:24}].concat(zile.map(function(){return{wch:20};}));
                XLSX.utils.book_append_sheet(wb,ws,p.name.substring(0,28));
            });
            XLSX.writeFile(wb,'orar_scoala.xlsx');
        };

        function buildHTML(){
            return '<div class="go-tabs">'
                +'<div class="go-tab active" onclick="goSwitchTab(0)">1. Date generale</div>'
                +'<div class="go-tab" onclick="goSwitchTab(1)">2. Clase</div>'
                +'<div class="go-tab" onclick="goSwitchTab(2)">3. Profesori</div>'
                +'<div class="go-tab" onclick="goSwitchTab(3)">4. Materii & ore</div>'
                +'<div class="go-tab" onclick="goSwitchTab(4)">5. Condiții speciale</div>'
                +'<div class="go-tab" onclick="goSwitchTab(5)">6. Orar generat</div>'
                +'</div>'

                // Panel 1
                +'<div class="go-panel active" id="go-panel-0"><p class="go-section-title">Configurare generală</p><div class="go-card">'
                +'<div class="go-row2"><div><label>Număr de ore pe zi</label><select id="go-ore-zi"><option>5</option><option selected>6</option><option>7</option><option>8</option></select></div>'
                +'<div><label>Zile de școală</label><div class="go-checkbox-group" id="go-zile-check">'
                +'<label><input type="checkbox" value="Luni" checked> Luni</label>'
                +'<label><input type="checkbox" value="Marți" checked> Marți</label>'
                +'<label><input type="checkbox" value="Miercuri" checked> Miercuri</label>'
                +'<label><input type="checkbox" value="Joi" checked> Joi</label>'
                +'<label><input type="checkbox" value="Vineri" checked> Vineri</label>'
                +'</div></div></div>'
                +'<div class="go-row2"><div><label>Ora de început</label><input type="time" id="go-ora-start" value="08:00"></div>'
                +'<div><label>Durata orei</label><select id="go-dur-ora"><option value="45">45 min</option><option value="50" selected>50 min</option><option value="60">60 min</option></select></div></div>'
                +'<div class="go-row3"><div><label>Pauza mică (min)</label><input type="number" id="go-pauza-mica" value="10" min="5" max="20"></div>'
                +'<div><label>Pauza mare (min)</label><input type="number" id="go-pauza-mare" value="20" min="10" max="40"></div>'
                +'<div><label>Pauza mare după ora nr.</label><select id="go-pauza-mare-dupa"><option>2</option><option selected>3</option><option>4</option></select></div></div>'
                +'</div><button class="go-gen-btn" onclick="goSwitchTab(1)">Următorul pas →</button></div>'

                // Panel 2 - Clase
                +'<div class="go-panel" id="go-panel-1"><p class="go-section-title">Clase (preîncărcate din catalog)</p><div class="go-card">'
                +'<div class="go-row2"><div><label>Denumire clasă</label><input type="text" id="go-clasa-name" placeholder="ex: 5A"></div>'
                +'<div><label>Număr elevi</label><input type="number" id="go-clasa-elevi" placeholder="28" min="1"></div></div>'
                +'<button class="go-add-btn" onclick="goAddClasa()">+ Adaugă clasă</button></div>'
                +'<div id="go-clase-list"></div>'
                +'<button class="go-gen-btn" onclick="goSwitchTab(2)">Următorul pas →</button></div>'

                // Panel 3 - Profesori
                +'<div class="go-panel" id="go-panel-2"><p class="go-section-title">Profesori (preîncărcați din catalog)</p><div class="go-card">'
                +'<div class="go-row2"><div><label>Nume profesor</label><input type="text" id="go-prof-name" placeholder="ex: Ion Popescu"></div>'
                +'<div><label>Materia</label><input type="text" id="go-prof-materie" placeholder="ex: Matematică"></div></div>'
                +'<button class="go-add-btn" onclick="goAddProfesor()">+ Adaugă profesor</button></div>'
                +'<div id="go-prof-list"></div>'
                +'<button class="go-gen-btn" onclick="goSwitchTab(3)">Următorul pas →</button></div>'

                // Panel 4 - Materii
                +'<div class="go-panel" id="go-panel-3"><p class="go-section-title">Materii & ore pe săptămână</p>'
                +'<div class="go-tip">💡 Materiile și orele sunt preîncărcate din catalog. Poți ajusta orele pe săptămână.</div>'
                +'<div id="go-materii-container"></div>'
                +'<button class="go-gen-btn" onclick="goSwitchTab(4)">Următorul pas →</button></div>'

                // Panel 5 - Conditii
                +'<div class="go-panel" id="go-panel-4"><p class="go-section-title">Condiții speciale</p>'
                +'<p class="go-group-title" style="border-top:none;padding-top:0;margin-top:0">Condiții pentru Profesori</p>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-maxzi-on" onchange="goToggleCond(\'go-maxzi\')"><label for="go-maxzi-on">Maxim X ore pe zi per profesor</label></div>'
                +'<p class="go-cond-desc">Limitează câte ore poate preda un profesor într-o zi.</p>'
                +'<div class="go-cond-body" id="cond-go-maxzi-body" style="display:none"><div class="go-row2"><div><label>Maxim ore/zi</label><select id="go-maxzi-val"><option value="2">2</option><option value="3" selected>3</option><option value="4">4</option><option value="5">5</option></select></div></div></div></div>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-pu-on" onchange="goToggleCond(\'go-pu\')"><label for="go-pu-on">Profesori fără prima / ultima oră</label></div>'
                +'<p class="go-cond-desc">Anumite cadre didactice nu vor fi la prima sau ultima oră.</p>'
                +'<div class="go-cond-body" id="cond-go-pu-body" style="display:none"><div class="go-row2"><div><label>Profesor</label><input type="text" id="go-pu-prof" placeholder="Nume"></div>'
                +'<div><label>Restricție</label><select id="go-pu-tip"><option value="prima">Fără prima oră</option><option value="ultima">Fără ultima oră</option><option value="ambele">Fără prima și ultima</option></select></div></div>'
                +'<button class="go-add-btn" onclick="goAddPU()">+ Adaugă</button><div id="go-pu-list"></div></div></div>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-iv-on" onchange="goToggleCond(\'go-iv\')"><label for="go-iv-on">Profesor predă doar în anumite intervale</label></div>'
                +'<p class="go-cond-desc">Restrânge orele unui profesor la un interval.</p>'
                +'<div class="go-cond-body" id="cond-go-iv-body" style="display:none"><div class="go-row3"><div><label>Profesor</label><input type="text" id="go-iv-prof" placeholder="Nume"></div>'
                +'<div><label>Ora min</label><select id="go-iv-min"><option value="1">1</option><option value="2" selected>2</option><option value="3">3</option><option value="4">4</option></select></div>'
                +'<div><label>Ora max</label><select id="go-iv-max"><option value="4">4</option><option value="5" selected>5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option></select></div></div>'
                +'<button class="go-add-btn" onclick="goAddIV()">+ Adaugă</button><div id="go-iv-list"></div></div></div>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-sa-on" onchange="goToggleCond(\'go-sa\')"><label for="go-sa-on">Sală comună — profesori care nu pot fi simultan</label></div>'
                +'<p class="go-cond-desc">Doi profesori cu aceeași sală nu pot preda simultan.</p>'
                +'<div class="go-cond-body" id="cond-go-sa-body" style="display:none"><div class="go-row3"><div><label>Prof A</label><input type="text" id="go-sala-a"></div>'
                +'<div><label>Prof B</label><input type="text" id="go-sala-b"></div>'
                +'<div><label>Sală</label><input type="text" id="go-sala-n" placeholder="ex: Lab"></div></div>'
                +'<button class="go-add-btn" onclick="goAddSA()">+ Adaugă</button><div id="go-sa-list"></div></div></div>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-consec-on" onchange="goToggleCond(\'go-consec\')"><label for="go-consec-on">Maxim ore consecutive per profesor</label></div>'
                +'<div class="go-cond-body" id="cond-go-consec-body" style="display:none"><div class="go-row2"><div><label>Maxim consecutive</label><select id="go-consec-val"><option value="2">2</option><option value="3" selected>3</option><option value="4">4</option></select></div></div></div></div>'

                +'<div class="go-card-cond"><div class="go-toggle-row"><input type="checkbox" id="go-echilibru-on" onchange="goToggleCond(\'go-echilibru\')"><label for="go-echilibru-on">Echilibrare ore în săptămână</label></div>'
                +'<div class="go-cond-body" id="cond-go-echilibru-body" style="display:none"><div class="go-row2"><div><label>Max ore/materie/zi</label><select id="go-echilibru-val"><option value="1" selected>1</option><option value="2">2</option></select></div></div></div></div>'

                +'<p class="go-group-title">Condiții pentru Materii</p>'

                +'<div class="go-card-cond-mat"><div class="go-toggle-row"><input type="checkbox" id="go-nu-on" onchange="goToggleCond(\'go-nu\')"><label for="go-nu-on">Materie interzisă în ultima oră</label></div>'
                +'<div class="go-cond-body-mat" id="cond-go-nu-body" style="display:none"><div><label>Materie</label><input type="text" id="go-nu-mat" placeholder="ex: Educație fizică"></div>'
                +'<button class="go-add-btn" onclick="goAddNU()">+ Adaugă</button><div id="go-nu-list"></div></div></div>'

                +'<div class="go-card-cond-mat"><div class="go-toggle-row"><input type="checkbox" id="go-dif-on" onchange="goToggleCond(\'go-dif\')"><label for="go-dif-on">Materii dificile doar în primele ore</label></div>'
                +'<div class="go-cond-body-mat" id="cond-go-dif-body" style="display:none"><div class="go-row2"><div><label>Materie</label><input type="text" id="go-dif-mat" placeholder="ex: Matematică"></div>'
                +'<div><label>Maxim până la ora</label><select id="go-dif-pana"><option value="2">2</option><option value="3" selected>3</option><option value="4">4</option><option value="5">5</option></select></div></div>'
                +'<button class="go-add-btn" onclick="goAddDif()">+ Adaugă</button><div id="go-dif-list"></div></div></div>'

                +'<div class="go-card-cond-mat"><div class="go-toggle-row"><input type="checkbox" id="go-mc-on" onchange="goToggleCond(\'go-mc\')"><label for="go-mc-on">2 ore consecutive dintr-o materie</label></div>'
                +'<div class="go-cond-body-mat" id="cond-go-mc-body" style="display:none"><div><label>Materie</label><input type="text" id="go-mc-mat" placeholder="ex: Desen"></div>'
                +'<button class="go-add-btn" onclick="goAddMC()">+ Adaugă</button><div id="go-mc-list"></div></div></div>'

                +'<button class="go-gen-btn" onclick="goSwitchTab(5); goGenerar()">Generează orarul ↗</button></div>'

                // Panel 6
                +'<div class="go-panel" id="go-panel-5"><p class="go-section-title">Orar generat</p><div id="go-rezultat"><p style="color:#aaa;padding:20px;text-align:center">Completează pașii anteriori și apasă „Generează orarul".</p></div></div>';
        }
    });
    </script>
</x-filament-panels::page>
