/* Paleta del logo: verde petróleo #114745, verde coche #498C82, mostaza #D69C26, rojo #BC4527 */
:root{
  --teal:#498C82; --teal-strong:#1F5F59; --teal-soft:#E1EDE9; --on-teal:#FBF6EA;
  --petrol:#114745; --on-petrol:#FBF6EA; --mustard:#D69C26; --red:#B8401F;
  --ink:#114745; --amber:#D69C26;
  --bg:#F6F1E6; --surface:#FFFCF5; --surface-2:#F1EADB; --surface-3:#E7DECB;
  --text:#1D2A28; --muted:#696556; --line:#E3D9C4;
  --side:#FFFCF5; --side-text:#5E5A4D; --side-strong:#1D2A28; --side-hover:#F1EADB; --side-active:#E1EDE9; --side-line:#E3D9C4;
  --ok:#2E7D57; --ok-soft:#E2F2EA; --warn:#8A5B00; --warn-soft:#FBEFCF; --bad:#A8361A; --bad-soft:#F9E3DC; --idle:#6B6A63; --idle-soft:#ECE7DC;
  --shadow:0 1px 2px rgba(17,71,69,.05),0 2px 10px rgba(17,71,69,.06);
  --r:12px;
  --display:"Nunito",system-ui,-apple-system,"Segoe UI",sans-serif;
  --cond:"Barlow Condensed","Arial Narrow",system-ui,sans-serif;
  --body:"Nunito",system-ui,-apple-system,"Segoe UI",sans-serif;
  color-scheme:light;
}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){
  color-scheme:dark;
  --teal:#6FB0A5; --teal-strong:#9BD0C6; --teal-soft:#1C3532; --on-teal:#0D1716;
  --petrol:#E2A93A; --on-petrol:#1B1406; --mustard:#E2A93A; --red:#EE7A58;
  --bg:#0D1716; --surface:#142321; --surface-2:#1B2D2B; --surface-3:#233936;
  --text:#EFE8D8; --muted:#A3ADA6; --line:#26403C;
  --side:#0A1312; --side-text:#9FB0AB; --side-strong:#EFE8D8; --side-hover:#142321; --side-active:#1B2D2B; --side-line:#1D302D;
  --ok:#6FCF9B; --ok-soft:#173226; --warn:#F2C14E; --warn-soft:#2E2510; --bad:#F28B82; --bad-soft:#3A1A18; --idle:#A3ABB7; --idle-soft:#23272D;
  --shadow:0 1px 2px rgba(0,0,0,.35);
}}
:root[data-theme="dark"]{
  color-scheme:dark;
  --teal:#6FB0A5; --teal-strong:#9BD0C6; --teal-soft:#1C3532; --on-teal:#0D1716;
  --petrol:#E2A93A; --on-petrol:#1B1406; --mustard:#E2A93A; --red:#EE7A58;
  --bg:#0D1716; --surface:#142321; --surface-2:#1B2D2B; --surface-3:#233936;
  --text:#EFE8D8; --muted:#A3ADA6; --line:#26403C;
  --side:#0A1312; --side-text:#9FB0AB; --side-strong:#EFE8D8; --side-hover:#142321; --side-active:#1B2D2B; --side-line:#1D302D;
  --ok:#6FCF9B; --ok-soft:#173226; --warn:#F2C14E; --warn-soft:#2E2510; --bad:#F28B82; --bad-soft:#3A1A18; --idle:#A3ABB7; --idle-soft:#23272D;
  --shadow:0 1px 2px rgba(0,0,0,.35);
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.5 var(--body);-webkit-font-smoothing:antialiased}
button,input,select,textarea{font:inherit;color:inherit}
a{color:var(--teal-strong)}
:focus-visible{outline:3px solid var(--teal);outline-offset:2px;border-radius:6px}
h1,h2,h3{font-family:var(--display);font-weight:800;margin:0;text-wrap:balance;letter-spacing:-.01em;line-height:1.2}
h1{font-size:26px} h2{font-size:19px} h3{font-size:16px}
[hidden]{display:none!important}
.boot{display:grid;place-items:center;height:100%;color:var(--muted)}
.muted{color:var(--muted)}
.small{font-size:13px}
.num{font-variant-numeric:tabular-nums}
.eyebrow{font:700 13px/1.2 var(--cond);letter-spacing:.1em;text-transform:uppercase;color:var(--red)}

/* ---------- Layout ---------- */
.shell{display:grid;grid-template-columns:240px 1fr;min-height:100%}
.side{background:var(--side);color:var(--side-text);border-right:1px solid var(--side-line);position:sticky;top:0;height:100vh;display:flex;flex-direction:column;padding:16px 12px;gap:4px}
.logo{display:block;line-height:0;align-self:flex-start;margin:0 4px 18px}
.logo img{height:50px;width:auto}
.navlink{display:flex;align-items:center;gap:12px;padding:9px 10px;border-radius:10px;color:var(--side-text);text-decoration:none;font-weight:700;border:0;background:none;cursor:pointer;width:100%;text-align:left}
.navlink svg{width:20px;height:20px;flex:none}
.navlink:hover{color:var(--side-strong);background:var(--side-hover)}
.navlink[aria-current="page"]{color:var(--side-strong);background:var(--side-active)}
.navlink[aria-current="page"] svg{color:var(--teal-strong)}
.side .grow{flex:1}
.me{display:flex;gap:10px;align-items:center;padding:10px;border-top:1px solid var(--side-line);margin-top:8px}
.me .av{width:34px;height:34px;border-radius:50%;background:var(--teal-soft);color:var(--teal-strong);display:grid;place-items:center;font-weight:800;flex:none}
.me b{display:block;color:var(--side-strong);font-size:14px;line-height:1.2}
.me span{font-size:12px}
.main{min-width:0;padding:28px 32px 48px;max-width:1180px;width:100%}
.mtop,.mnav{display:none}

@media (max-width:860px){
  .shell{grid-template-columns:1fr}
  .side{display:none}
  .mtop{display:flex;position:sticky;top:0;z-index:20;background:var(--side);border-bottom:1px solid var(--side-line);align-items:center;gap:10px;padding:10px 16px;padding-top:calc(10px + env(safe-area-inset-top,0px))}
  .mtop .logo{margin:0}
  .mtop .logo img{height:40px}
  .mtop .who{margin-left:auto;color:var(--side-text);font-size:12px;text-align:right;line-height:1.25}
  .mtop .who b{color:var(--side-strong);display:block;font-size:13px}
  .main{padding:18px 16px calc(96px + env(safe-area-inset-bottom,0px))}
  .mnav{display:grid;grid-template-columns:repeat(5,1fr);position:fixed;left:0;right:0;bottom:0;z-index:30;background:var(--side);
    padding:6px 6px calc(6px + env(safe-area-inset-bottom,0px));border-top:1px solid var(--side-line)}
  .mnav button{background:none;border:0;color:var(--side-text);display:flex;flex-direction:column;align-items:center;gap:2px;font-size:11px;font-weight:700;padding:6px 2px;cursor:pointer;min-height:52px}
  .mnav button svg{width:22px;height:22px}
  .mnav .ico{display:grid;place-items:center;width:42px;height:26px;border-radius:13px}
  .mnav button[aria-current="page"]{color:var(--side-strong)}
  .mnav button[aria-current="page"] .ico{background:var(--petrol);color:var(--on-petrol)}
}

/* ---------- Page header ---------- */
.ph{display:flex;align-items:flex-end;justify-content:space-between;gap:12px 16px;flex-wrap:wrap;margin-bottom:20px}
.ph .actions{display:flex;gap:8px;flex-wrap:wrap}
.stack{display:grid;gap:16px}
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px;align-items:start}

/* ---------- Components ---------- */
.card{background:var(--surface);border-radius:var(--r);box-shadow:var(--shadow);border:1px solid var(--line)}
.card-h{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:14px 16px;border-bottom:1px solid var(--line)}
.card-b{padding:16px}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;border:1px solid transparent;border-radius:10px;padding:9px 14px;
  font-weight:800;cursor:pointer;text-decoration:none;min-height:40px;white-space:nowrap;font-size:14px}
.btn svg{width:18px;height:18px;flex:none}
.btn-primary{background:var(--petrol);color:var(--on-petrol)}
.btn-primary:hover{filter:brightness(.94)}
.btn-ghost{background:var(--surface);border-color:var(--line);color:var(--text)}
.btn-ghost:hover{background:var(--surface-2)}
.btn-danger{background:var(--bad-soft);color:var(--bad)}
.btn-sm{min-height:32px;padding:5px 10px;font-size:13px}
.btn:disabled{opacity:.5;cursor:default}
.icon-btn{border:0;background:none;color:var(--muted);width:34px;height:34px;border-radius:8px;display:inline-grid;place-items:center;cursor:pointer;flex:none}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.icon-btn svg{width:18px;height:18px}

.pill{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:800;padding:2px 9px;border-radius:999px;white-space:nowrap}
.pill::before{content:"";width:6px;height:6px;border-radius:50%;background:currentColor}
.pill.ok{background:var(--ok-soft);color:var(--ok)}
.pill.warn{background:var(--warn-soft);color:var(--warn)}
.pill.bad{background:var(--bad-soft);color:var(--bad)}
.pill.idle{background:var(--idle-soft);color:var(--idle)}
.pill.teal{background:var(--teal-soft);color:var(--teal-strong)}
.badge-new{display:inline-block;background:#D69C26;color:#114745;border:1.5px solid #114745;font:700 11px/1.2 var(--cond);letter-spacing:.08em;padding:0 5px;border-radius:5px}
.role{font-size:12px;font-weight:800;padding:2px 9px;border-radius:6px;background:var(--surface-3);color:var(--text)}
.role.admin{background:var(--petrol);color:var(--on-petrol)}
.role.profesor{background:var(--teal-soft);color:var(--teal-strong)}
.role.gestion{background:var(--warn-soft);color:var(--warn)}

.bar{height:8px;border-radius:8px;background:var(--surface-3);overflow:hidden;min-width:60px}
.bar i{display:block;height:100%;background:var(--teal);border-radius:8px}
.progress-cell{display:grid;grid-template-columns:1fr 40px;align-items:center;gap:8px}

/* KPI */
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-bottom:16px}
.kpi{padding:16px}
.kpi .v{font-family:var(--cond);font-weight:700;font-size:42px;line-height:1.1;font-variant-numeric:tabular-nums}
.kpi .l{color:var(--muted);font-size:13px;font-weight:700}
.list{display:grid}
.list > *{padding:10px 16px;border-top:1px solid var(--line);display:flex;gap:10px;align-items:center;justify-content:space-between}
.list > *:first-child{border-top:0}
.list a{text-decoration:none;color:var(--text)}
.list a:hover{background:var(--surface-2)}
.empty{padding:22px 16px;color:var(--muted);text-align:center}

/* Forms */
.form{display:grid;gap:14px}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.row3{display:grid;grid-template-columns:repeat(3,1fr);gap:14px}
@media (max-width:620px){.row2,.row3{grid-template-columns:1fr}}
.field{display:grid;gap:5px}
.field > span{font-weight:800;font-size:13px}
.field small{color:var(--muted);font-size:12px}
.input,select.input,textarea.input{width:100%;border:1px solid var(--line);border-radius:10px;padding:9px 11px;background:var(--surface);min-height:40px}
textarea.input{min-height:90px;resize:vertical;line-height:1.5}
.input:focus{outline:2px solid var(--teal);border-color:transparent}
.check{display:flex;gap:10px;align-items:center;font-weight:700;cursor:pointer}
.check input{width:18px;height:18px;accent-color:var(--teal)}
.form-error{background:var(--bad-soft);color:var(--bad);padding:10px 12px;border-radius:10px;font-weight:700;font-size:14px}
.form-actions{display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap;align-items:center}
.form-actions .left{margin-right:auto}

/* Search / filters */
.toolbar{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:14px}
.search{display:flex;align-items:center;gap:8px;background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:0 10px;flex:1;min-width:220px}
.search input{border:0;background:none;outline:none;flex:1;padding:9px 0;min-width:0}
.search svg{width:18px;height:18px;color:var(--muted)}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:5px 12px;font-weight:700;font-size:13px;cursor:pointer}
.chip[aria-pressed="true"]{background:var(--petrol);border-color:var(--petrol);color:var(--on-petrol)}

/* Table */
.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse}
th{text-align:left;font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;padding:10px 14px;border-bottom:1px solid var(--line);white-space:nowrap}
td{padding:11px 14px;border-bottom:1px solid var(--line);vertical-align:middle}
tbody tr{cursor:pointer}
tbody tr:hover{background:var(--surface-2)}
tbody tr:last-child td{border-bottom:0}
td .name{font-weight:800}
td .sub{color:var(--muted);font-size:13px}
@media (max-width:760px){
  .rtable thead{display:none}
  .rtable tr{display:grid;grid-template-columns:1fr auto;gap:4px 10px;padding:12px 14px;border-bottom:1px solid var(--line)}
  .rtable td{padding:0;border:0}
  .rtable td[data-hide]{display:none}
  .rtable td.full{grid-column:1/-1}
}

/* Temario */
.temas{display:grid;gap:12px}
.tema{overflow:hidden}
.tema-h{display:flex;align-items:center;gap:10px;padding:10px 12px}
.handle{cursor:grab;color:var(--muted);width:28px;height:34px;display:grid;place-items:center;flex:none;border-radius:6px;touch-action:none}
.handle:hover{background:var(--surface-2)}
.handle svg{width:16px;height:16px}
.tcode{font-family:var(--cond);font-weight:700;width:40px;height:40px;border-radius:50%;border:4px solid var(--teal);display:grid;place-items:center;font-size:16px;flex:none;font-variant-numeric:tabular-nums}
.tema-h .t{flex:1;min-width:0}
.tema-h .t b{display:block;font-size:16px;line-height:1.25}
.tema-h .t span{font-size:13px;color:var(--muted)}
.tema-h .tools{display:flex;gap:2px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
.collapse svg{transition:transform .2s}
.tema.closed .collapse svg{transform:rotate(-90deg)}
.tema.closed .vlist{display:none}
.vlist{border-top:1px solid var(--line);min-height:44px;background:var(--surface-2)}
.vlist:empty::after{content:"Arrastra aquí un vídeo o crea uno nuevo";display:block;padding:12px 16px;color:var(--muted);font-size:13px}
.vrow{display:flex;align-items:center;gap:10px;padding:7px 12px;background:var(--surface);border-bottom:1px solid var(--line)}
.vrow:last-child{border-bottom:0}
.vrow img{width:72px;height:40px;object-fit:cover;border-radius:6px;background:var(--surface-3);flex:none}
.vrow .t{flex:1;min-width:0}
.vrow .t b{font-weight:700;display:block;line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.vrow .t span{font-size:12px;color:var(--muted)}
.vrow .code{font-weight:800;color:var(--teal-strong);font-variant-numeric:tabular-nums}
.vrow.hidden-v{opacity:.6}
.sortable-ghost{opacity:.35}
.sortable-chosen{box-shadow:0 6px 20px rgba(0,0,0,.15)}
@media (max-width:620px){.vrow img{display:none}.tema-h .tools .btn{display:none}}

/* YouTube preview in form */
.yt-preview{display:grid;grid-template-columns:140px 1fr;gap:12px;align-items:center;padding:10px;border-radius:10px;background:var(--surface-2)}
.yt-preview img{width:140px;aspect-ratio:16/9;object-fit:cover;border-radius:8px;max-width:100%}
.yt-preview b{display:block;line-height:1.3}
@media (max-width:480px){.yt-preview{grid-template-columns:1fr}.yt-preview img{width:100%}}

/* Student detail */
.info{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px 18px}
.info div span{display:block;font-size:12px;color:var(--muted);font-weight:700}
.info div b{font-weight:700;word-break:break-word}
.tprog{display:grid;gap:4px;padding:10px 16px;border-top:1px solid var(--line)}
.tprog:first-child{border-top:0}
.tprog summary{display:grid;grid-template-columns:1fr 140px 52px;gap:12px;align-items:center;cursor:pointer;list-style:none}
.tprog summary::-webkit-details-marker{display:none}
.tprog ul{margin:8px 0 4px;padding:0;list-style:none;display:grid;gap:4px;font-size:14px}
.tprog li{display:flex;gap:8px;justify-content:space-between}
.tprog li.no{color:var(--muted)}
@media (max-width:560px){.tprog summary{grid-template-columns:1fr 70px 44px}}
.note{padding:12px 16px;border-top:1px solid var(--line)}
.note:first-child{border-top:0}
.note p{margin:4px 0 0;white-space:pre-wrap}

/* Credentials */
.cred{display:grid;gap:8px;background:var(--surface-2);border-radius:12px;padding:14px}
.cred div{display:flex;justify-content:space-between;gap:10px;align-items:center}
.cred code{font:700 16px/1.3 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;user-select:all;word-break:break-all}

/* Dialog */
dialog{border:0;border-radius:16px;padding:0;width:min(640px,calc(100vw - 24px));max-height:calc(100vh - 24px);background:var(--surface);color:var(--text);box-shadow:0 20px 60px rgba(0,0,0,.3)}
dialog::backdrop{background:rgba(10,13,12,.55)}
.dlg-h{display:flex;justify-content:space-between;align-items:center;padding:16px 18px;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--surface);z-index:1}
.dlg-b{padding:18px}
@media (max-width:620px){dialog{width:100vw;max-width:100vw;margin:auto 0 0;border-radius:16px 16px 0 0;max-height:92vh}}

/* Login */
.auth{min-height:100vh;min-height:100dvh;display:grid;place-items:center;padding:24px 16px;background:var(--bg)}
.auth .card{width:min(420px,100%);padding:26px}
.auth .logo{margin:0 auto 14px;align-self:center}
.auth .logo img{height:auto;width:170px}
.auth h1{margin-bottom:4px}

.toast{position:fixed;left:50%;bottom:calc(24px + env(safe-area-inset-bottom,0px));transform:translate(-50%,20px);background:#114745;color:#FBF6EA;
  padding:10px 16px;border-radius:12px;font-weight:700;font-size:14px;opacity:0;transition:all .2s;z-index:100;pointer-events:none;max-width:90vw}
.toast.on{opacity:1;transform:translate(-50%,0)}
.toast.err{background:var(--bad)}
@media (max-width:860px){.toast{bottom:calc(84px + env(safe-area-inset-bottom,0px))}}
.log{font-size:14px}
.log .when{color:var(--muted);font-size:12px;white-space:nowrap}
.perm-table td,.perm-table th{padding:8px 10px;text-align:center}
.perm-table td:first-child,.perm-table th:first-child{text-align:left}
@media (prefers-reduced-motion:reduce){*{transition:none!important}}

/* Selector de tema */
.theme-seg{display:grid;grid-template-columns:repeat(3,1fr);gap:2px;background:var(--side-hover);padding:3px;border-radius:10px;margin:6px 0 4px}
.theme-seg button{border:0;background:none;border-radius:8px;padding:6px 2px;font-size:12px;font-weight:700;color:var(--side-text);cursor:pointer}
.theme-seg button[aria-checked="true"]{background:var(--side);color:var(--side-strong);box-shadow:var(--shadow)}
