:root{
  --bg:#EEF0EE; --surface:#FFFFFF; --surface-2:#F6F7F5; --ink:#1B2124; --muted:#5A6569; --line:#D3D8D6;
  --accent:#1E5A86; --accent-ink:#FFFFFF; --accent-soft:#E2ECF4;
  --warn:#8F5500; --warn-soft:#FBEFD8; --ok:#2B6A3C; --ok-soft:#E0EFE3; --bad:#A1322B; --bad-soft:#F8E2DF;
  --bar:#16384F; --bar-ink:#EAF1F6; --bar-muted:#A9BFCE;
  --f-display:"Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-body:"IBM Plex Sans", "Segoe UI", Roboto, Arial, sans-serif;
  --f-mono:"IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    color-scheme:dark;
    --bg:#111518; --surface:#192024; --surface-2:#1F272B; --ink:#E4E9EB; --muted:#98A4A9; --line:#2E383D;
    --accent:#86B8E0; --accent-ink:#0B1A25; --accent-soft:#1B3040;
    --warn:#E9B45C; --warn-soft:#33270F; --ok:#84C897; --ok-soft:#15291B; --bad:#F09088; --bad-soft:#3A1B18;
    --bar:#0C1C27; --bar-ink:#E4E9EB; --bar-muted:#8FA6B5;
  }
}
:root[data-theme="dark"]{
  color-scheme:dark;
  --bg:#111518; --surface:#192024; --surface-2:#1F272B; --ink:#E4E9EB; --muted:#98A4A9; --line:#2E383D;
  --accent:#86B8E0; --accent-ink:#0B1A25; --accent-soft:#1B3040;
  --warn:#E9B45C; --warn-soft:#33270F; --ok:#84C897; --ok-soft:#15291B; --bad:#F09088; --bad-soft:#3A1B18;
  --bar:#0C1C27; --bar-ink:#E4E9EB; --bar-muted:#8FA6B5;
}
*{box-sizing:border-box}
[hidden]:not([hidden=until-found i]){display:none!important}
body{background:var(--bg); color:var(--ink); font-family:var(--f-body); font-size:14px; line-height:1.45; margin:0}
h1,h2,h3{font-family:var(--f-display); text-wrap:balance; margin:0}
.shell{max-width:1380px; margin:0 auto; padding-inline:16px}
button{font:inherit; cursor:pointer; border-radius:6px; border:1px solid var(--line); background:var(--surface-2); color:var(--ink); padding:7px 12px; font-weight:500}
button:hover{border-color:var(--accent)}
button.primary{background:var(--accent); color:var(--accent-ink); border-color:var(--accent); font-weight:600}
button.primary:hover{filter:brightness(1.08)}
button.ghost{background:transparent}
button.danger{color:var(--bad)}
button.sm{padding:5px 10px; font-size:13px}
button[disabled]{opacity:.5; cursor:not-allowed}
button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--accent); outline-offset:1px}
input[type=text],input[type=search],select{font:inherit; color:var(--ink); background:var(--surface-2); border:1px solid var(--line); border-radius:6px; padding:7px 9px; width:100%; min-width:0}
label,.lbl{font-size:11.5px; font-weight:600; letter-spacing:.05em; text-transform:uppercase; color:var(--muted)}
.hint{color:var(--muted); font-size:12.5px}
.mono{font-family:var(--f-mono); font-variant-numeric:tabular-nums}

/* top bar */
.bar{background:var(--bar); color:var(--bar-ink); position:sticky; top:0; z-index:20; padding-top:env(safe-area-inset-top,0px)}
.bar .shell{display:flex; align-items:center; gap:10px 18px; min-height:54px; flex-wrap:wrap; padding-block:8px}
.brand{display:flex; align-items:baseline; gap:10px; min-width:0}
.brand b{font-family:var(--f-display); font-size:17px; font-weight:700; letter-spacing:-.01em}
.brand span{color:var(--bar-muted); font-size:12.5px}
.bar button{background:transparent; color:var(--bar-ink); border-color:color-mix(in srgb, var(--bar-ink) 30%, transparent)}
.bar button:hover{border-color:var(--bar-ink)}
.bar .spacer{flex:1}
.dbstate{display:inline-flex; align-items:center; gap:7px; font-size:12.5px; color:var(--bar-muted); white-space:nowrap}
.dbstate i{width:8px; height:8px; border-radius:50%; background:var(--bar-muted); display:inline-block}
.dbstate[data-s="ok"] i{background:#6FCB8A} .dbstate[data-s="saving"] i{background:#E9B45C} .dbstate[data-s="err"] i{background:#F09088}

.notice{border-radius:8px; padding:10px 14px; display:flex; gap:12px; align-items:center; justify-content:space-between; flex-wrap:wrap; margin-top:16px; border:1px solid var(--line)}
.notice.warn{background:var(--warn-soft); border-color:color-mix(in srgb, var(--warn) 40%, transparent)}
.notice.bad{background:var(--bad-soft); border-color:color-mix(in srgb, var(--bad) 40%, transparent)}

/* list view */
.list-head{display:flex; flex-wrap:wrap; gap:12px 20px; align-items:flex-end; justify-content:space-between; padding-block:22px 16px}
.list-head h1{font-size:26px; font-weight:700; letter-spacing:-.01em}
.list-head p{color:var(--muted); margin:6px 0 0; max-width:68ch}
.list-actions{display:flex; gap:8px; flex-wrap:wrap; align-items:center}
.list-actions input[type=search]{width:240px; max-width:100%}
.cards{display:grid; grid-template-columns:repeat(auto-fill,minmax(330px,1fr)); gap:14px; padding-bottom:60px}
@media (max-width:420px){ .cards{grid-template-columns:minmax(0,1fr)} }
.card{background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:16px; display:flex; flex-direction:column; gap:12px; min-width:0}
.card-top{display:flex; justify-content:space-between; gap:10px; align-items:flex-start}
.card h2{font-size:16.5px; font-weight:600; line-height:1.25; overflow-wrap:anywhere}
.card .sub{color:var(--muted); font-size:12.5px; margin-top:3px; overflow-wrap:anywhere}
.tag{font-family:var(--f-mono); font-size:11px; padding:2px 7px; border-radius:99px; background:var(--accent-soft); color:var(--accent); white-space:nowrap; font-weight:500}
.facts{display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:1px; background:var(--line); border:1px solid var(--line); border-radius:7px; overflow:hidden}
.facts div{background:var(--surface-2); padding:7px 9px; min-width:0}
.facts .v{font-family:var(--f-mono); font-size:15px; font-variant-numeric:tabular-nums; white-space:nowrap}
.facts .k{font-size:10.5px; color:var(--muted); text-transform:uppercase; letter-spacing:.05em}
.range{font-family:var(--f-mono); font-size:12.5px; color:var(--muted)}
.open-row{display:grid; grid-template-columns:1fr 1fr; gap:8px}
.open-row button{padding:9px 10px; text-align:left; display:flex; flex-direction:column; gap:1px; line-height:1.25}
.open-row button small{font-weight:400; font-size:11.5px; opacity:.8}
.card-foot{display:flex; justify-content:space-between; align-items:center; gap:8px; flex-wrap:wrap; border-top:1px solid var(--line); padding-top:10px}
.card-foot .when{font-size:12px; color:var(--muted)}
.card-foot .acts{display:flex; gap:4px; flex-wrap:wrap}
.card-foot .acts button{padding:4px 9px; font-size:12.5px; background:transparent}

.empty{background:var(--surface); border:1px dashed var(--line); border-radius:10px; padding:28px 22px; display:grid; gap:18px; grid-template-columns:minmax(0,1.1fr) minmax(0,1fr); align-items:center}
@media (max-width:760px){ .empty{grid-template-columns:minmax(0,1fr)} }
.empty h2{font-size:19px}
.empty p{color:var(--muted); margin:8px 0 14px; max-width:60ch}
.flow{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:8px; counter-reset:f}
.flow li{counter-increment:f; display:grid; grid-template-columns:28px 1fr; gap:10px; align-items:start; background:var(--surface-2); border:1px solid var(--line); border-radius:8px; padding:9px 11px; font-size:13px}
.flow li::before{content:counter(f); font-family:var(--f-mono); width:24px; height:24px; border-radius:50%; background:var(--accent-soft); color:var(--accent); display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:500}
.flow b{display:block; font-weight:600}
.loading{padding:40px 0; color:var(--muted)}

/* course view */
.course-head{display:flex; flex-wrap:wrap; gap:10px 16px; align-items:center; padding-block:16px 0}
.course-head .name{flex:1 1 320px; min-width:0}
.course-head .name input{font-family:var(--f-display); font-size:22px; font-weight:700; background:transparent; border:1px solid transparent; padding:3px 6px; margin-left:-7px; letter-spacing:-.01em}
.course-head .name input:hover{border-color:var(--line)}
.course-head .name input:focus{background:var(--surface); border-color:var(--accent)}
.course-head .meta{font-size:12.5px; color:var(--muted); padding-left:0}
.course-head select{width:auto}
.tabs{display:flex; gap:0; border-bottom:1px solid var(--line); margin-top:14px; overflow-x:auto}
.tabs button{border:0; border-bottom:3px solid transparent; border-radius:0; background:transparent; padding:10px 16px 9px; font-weight:600; color:var(--muted); white-space:nowrap; display:flex; flex-direction:column; align-items:flex-start; gap:0; line-height:1.25}
.tabs button small{font-weight:400; font-size:11.5px}
.tabs button[aria-selected="true"]{color:var(--ink); border-bottom-color:var(--accent)}
.tool-host{display:block}

/* dialog */
.overlay{position:fixed; inset:0; background:color-mix(in srgb, #0b1115 55%, transparent); z-index:40; display:flex; align-items:flex-start; justify-content:center; overflow:auto; padding:calc(env(safe-area-inset-top,0px) + 40px) 16px 40px}
.dlg{background:var(--surface); border:1px solid var(--line); border-radius:12px; width:100%; max-width:640px; padding:20px; display:flex; flex-direction:column; gap:16px; box-shadow:0 12px 40px rgba(0,0,0,.25)}
.dlg h2{font-size:19px}
.fgrid{display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:12px 14px}
.f{display:flex; flex-direction:column; gap:4px; grid-column:span 3; min-width:0}
.f.w6{grid-column:span 6} .f.w2{grid-column:span 2} .f.w4{grid-column:span 4}
@media (max-width:560px){ .f,.f.w2,.f.w4{grid-column:span 6} }
.base{display:flex; flex-direction:column; gap:8px}
.opt{display:grid; grid-template-columns:20px 1fr; gap:8px; align-items:start; border:1px solid var(--line); border-radius:8px; padding:10px 12px; background:var(--surface-2); cursor:pointer; text-transform:none; letter-spacing:0; font-weight:400; color:var(--ink); font-size:13.5px}
.opt:has(input:checked){border-color:var(--accent); background:var(--accent-soft)}
.opt input{margin-top:3px}
.opt b{font-weight:600}
.opt .more{grid-column:2; margin-top:8px; display:flex; flex-direction:column; gap:6px}
.dlg-foot{display:flex; justify-content:flex-end; gap:8px; flex-wrap:wrap}
.filelist{font-size:12.5px; color:var(--muted)}

.toast{position:fixed; left:50%; transform:translateX(-50%); bottom:calc(env(safe-area-inset-bottom,0px) + 18px); background:var(--ink); color:var(--bg); padding:10px 16px; border-radius:8px; font-size:13.5px; z-index:60; max-width:calc(100% - 32px)}
@media (prefers-reduced-motion: reduce){ *{transition:none!important; animation:none!important} }

/* ---------- servidor: enlaces-botón, avisos, login, usuarios ---------- */
a.btn{display:inline-flex; align-items:center; gap:6px; text-decoration:none; font-weight:500; border-radius:6px; border:1px solid var(--line); background:var(--surface-2); color:var(--ink); padding:7px 12px}
a.btn.sm{padding:5px 10px; font-size:13px}
a.btn.primary{background:var(--accent); color:var(--accent-ink); border-color:var(--accent); font-weight:600; justify-content:center}
.bar a.btn{background:transparent; color:var(--bar-ink); border-color:color-mix(in srgb, var(--bar-ink) 30%, transparent)}
.bar a.btn:hover{border-color:var(--bar-ink)}
.bar .who{color:var(--bar-muted); font-size:12.5px; white-space:nowrap}
.notice.ok{background:var(--ok-soft); border-color:color-mix(in srgb, var(--ok) 40%, transparent)}
.notice .acts{display:flex; gap:8px; flex-wrap:wrap}
input[type=password]{font:inherit; color:var(--ink); background:var(--surface-2); border:1px solid var(--line); border-radius:6px; padding:7px 9px; width:100%; min-width:0}
code{font-family:var(--f-mono); font-size:.92em; background:var(--surface-2); border:1px solid var(--line); border-radius:4px; padding:0 4px}
body.auth{min-height:100vh; display:flex; align-items:flex-start; justify-content:center; padding:calc(env(safe-area-inset-top,0px) + 12vh) 16px 40px}
.auth-box{background:var(--surface); border:1px solid var(--line); border-radius:12px; width:100%; max-width:400px; padding:24px; display:flex; flex-direction:column; gap:14px}
.auth-box h1{font-size:22px; font-weight:700; letter-spacing:-.01em}
.auth-box .notice{margin-top:0}
.auth-box button.primary{padding:10px 12px; font-size:15px}
.auth-form{display:flex; flex-direction:column; gap:12px}
.users{display:flex; flex-direction:column; gap:16px; padding-block:18px 60px}
.panel{background:var(--surface); border:1px solid var(--line); border-radius:10px; padding:18px; display:flex; flex-direction:column; gap:12px; min-width:0}
.panel h2{font-size:17px; font-weight:600}
.tbl-wrap{overflow-x:auto; border:1px solid var(--line); border-radius:8px}
table.data{border-collapse:collapse; width:100%; font-size:13px}
table.data th{font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); text-align:left; font-weight:600; background:var(--surface-2); padding:7px 8px; border-bottom:1px solid var(--line)}
table.data td{padding:6px 8px; border-bottom:1px solid var(--line); vertical-align:middle}
table.data tr:last-child td{border-bottom:0}
form.inline{display:flex; gap:6px; align-items:center; min-width:260px}

/* ---------- FUNDAE ---------- */
.fundae-head{padding:10px 0 9px}
.fundae-head span{display:flex; flex-direction:column; font-weight:600; border-bottom:3px solid var(--accent); padding:0 16px 8px; margin-bottom:-10px}
.fundae-head small{font-weight:400; font-size:11.5px; color:var(--muted)}
.tag.fundae{background:var(--warn-soft); color:var(--warn)}

/* ---------- versión 4: módulos y permisos ---------- */
.tag.ok{background:var(--ok-soft); color:var(--ok)}
.sr-only{position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0}
form.mods{display:flex; flex-wrap:wrap; gap:6px 12px; align-items:center; min-width:220px}
label.chk{display:inline-flex; align-items:center; gap:5px; text-transform:none; letter-spacing:0; font-weight:400; font-size:13px; color:var(--ink)}
table.data select{width:auto}
