:root {
  --bg: #000000;
  --surface: #181818;
  --surface-2: #1F1F1F;
  --border: #2A2A2A;
  --border-strong: #3A3A3A;
  --text: #EDEDED;
  --muted: #A0A0A0;
  --faint: #6E6E6E;
  --accent: #3CCFB4;
  --accent-hover: #5ADBC4;
  --accent-ink: #00201A;
  --danger: #F07171;
  --warn: #E8B85C;
  --info: #7AA7F5;
  --radius: 10px;
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; }
body { overflow-x: hidden; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
i.ph { font-size: 1.15em; vertical-align: -0.15em; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; padding: 4px 10px 18px; color: var(--text); }
.brand i { color: var(--accent); font-size: 1.4rem; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav a.active i { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.who { padding: 4px 10px 10px; font-size: .85rem; overflow-wrap: anywhere; }
.topbar { display: none; }
.main { flex: 1; min-width: 0; padding: 32px; max-width: 1100px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 12px; font-size: .9rem; }

@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar { display: none; position: fixed; inset: 56px 0 0 0; width: auto; height: auto; z-index: 30; border-right: none; border-top: 1px solid var(--border); overflow-y: auto; }
  .shell.menu-open .sidebar { display: flex; }
  .sidebar .brand { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 31; }
  .topbar .brand { padding: 0; }
  .main { padding: 20px 16px 48px; }
}

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row-card { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text); }
a.row-card:hover { border-color: var(--border-strong); text-decoration: none; background: var(--surface-2); }
.row-main { min-width: 0; flex: 1 1 220px; }
.row-main .title { font-weight: 500; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #4a4a4a; background: #262626; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.sm { height: 32px; padding: 0 10px; font-size: .88rem; }
.btn.block { width: 100%; }
.icon-btn { width: 38px; padding: 0; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 500; border: 1px solid var(--border-strong); color: var(--muted); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.s-abierto, .badge.warn { color: var(--warn); border-color: #4a3d22; }
.badge.s-asignado, .badge.info { color: var(--info); border-color: #2a3a57; }
.badge.s-en_curso { color: #B79AF5; border-color: #3b2f57; }
.badge.s-resuelto, .badge.ok, .badge.s-aprobado { color: var(--accent); border-color: #1e4a42; }
.badge.s-cancelado, .badge.off { color: var(--faint); }
.badge.err { color: var(--danger); border-color: #522; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: transparent; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; }
.chip.on { background: var(--surface-2); color: var(--text); border-color: #555; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .88rem; font-weight: 500; }
.field .hint { font-size: .8rem; color: var(--faint); }
.field .err { font-size: .82rem; color: var(--danger); display: none; }
.field.invalid .err { display: block; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
input, select, textarea { width: 100%; max-width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 11px; font: inherit; min-height: 38px; }
textarea { min-height: 110px; resize: vertical; }
textarea.md { min-height: 260px; font-family: var(--mono); font-size: .88rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline-offset: 0; outline-width: 1px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }
.form-error { color: var(--danger); font-size: .88rem; display: none; padding: 10px 12px; border: 1px solid #522; border-radius: 8px; background: #1a0f0f; }
.form-error.show { display: block; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters > * { flex: 1 1 180px; width: auto; }

/* Modal */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; flex-wrap: wrap; }
.secret { font-family: var(--mono); font-size: 1.15rem; letter-spacing: .04em; background: var(--bg); border: 1px dashed var(--border-strong); border-radius: 8px; padding: 12px; overflow-wrap: anywhere; text-align: center; }

/* Estados */
.empty { text-align: center; padding: 40px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }
.empty i { font-size: 2rem; color: var(--faint); display: block; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.sk { background: var(--surface-2); border-radius: 6px; animation: pulse 1.4s ease-in-out infinite; }
.sk-row { height: 64px; border-radius: var(--radius); }
.sk-line { height: 14px; margin: 8px 0; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.error-box { padding: 16px; border: 1px solid #522; border-radius: var(--radius); color: var(--danger); }

/* Auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px 24px; }
.auth .brand { padding: 0 0 20px; justify-content: center; font-size: 1.3rem; }
.auth h1 { font-size: 1.25rem; margin-bottom: 6px; }

/* Progreso */
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.lesson-item { display: flex; align-items: center; gap: 12px; }
.lesson-num { width: 28px; height: 28px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border-strong); font-size: .82rem; color: var(--muted); }
.lesson-num.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Markdown */
.md-body { overflow-wrap: anywhere; }
.md-body > * + * { margin-top: .8em; }
.md-body h1 { font-size: 1.35rem; } .md-body h2 { font-size: 1.15rem; } .md-body h3 { font-size: 1rem; }
.md-body ul, .md-body ol { padding-left: 1.4em; margin-bottom: 0; }
.md-body code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md-body pre { background: var(--bg); border: 1px solid var(--border); padding: 12px; border-radius: 8px; overflow-x: auto; max-width: 100%; }
.md-body pre code { background: none; padding: 0; }
.md-body blockquote { border-left: 3px solid var(--border-strong); margin-left: 0; padding-left: 12px; color: var(--muted); }
.md-body hr { border: none; border-top: 1px solid var(--border); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); padding: 10px 16px; border-radius: 8px; display: none; z-index: 100; max-width: calc(100vw - 32px); font-size: .9rem; }
#toast.show { display: block; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 28px 0 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; background: var(--surface); }
td { background: var(--bg); }
tr:last-child td { border-bottom: none; }
.total { font-size: 1.4rem; font-weight: 600; }
