:root {
  --bg: #f2f4f7;
  --card: #fff;
  --text: #1c2733;
  --muted: #6b7785;
  --line: #e2e6eb;
  --brand: #1f3a5f;
  --brand-2: #2c5282;
  --ok: #2e7d32;
  --warn: #ef6c00;
  --bad: #c62828;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--brand-2); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.bad-text { color: var(--bad); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1f3a5f, #0f2238); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login-logo { font-size: 2.4rem; text-align: center; }
.login-card h1 { text-align: center; font-size: 1.4rem; }
.login-card > p.muted { text-align: center; margin: -6px 0 4px; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 20px 0; background: var(--brand); color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 1.1rem; padding-bottom: 10px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: #cfd9e6; text-decoration: none; padding: 10px 14px; border-radius: 8px 8px 0 0; font-weight: 600; white-space: nowrap; font-size: .95rem; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { background: var(--bg); color: var(--brand); }
.userbox { display: flex; align-items: center; gap: 8px; padding-bottom: 10px; }
.user-chip { color: #fff; text-decoration: none; font-size: .9rem; font-weight: 600; }
.role { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px; vertical-align: middle; }
.role-fiscal { background: #ffe082; color: #5d4300; }
.role-instructor { background: #b3e5fc; color: #01405f; }
.role-sistema { background: #e0e0e0; color: #444; }

.view { max-width: 1240px; margin: 16px auto; padding: 0 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.kicker { margin: 0; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.back { text-decoration: none; font-weight: 600; }
.hint { font-size: .85rem; color: var(--muted); margin: 0 0 8px; }
.notice { background: #e8f0fb; color: #1f3a5f; padding: 10px 12px; border-radius: 8px; font-size: .9rem; margin: 0; }
.notice.warn { background: #fff3e0; color: #8a4500; }
.empty { color: var(--muted); font-size: .92rem; padding: 6px 0; margin: 0; list-style: none; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 14px; border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: #f5f7fa; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn.ghost:hover { background: rgba(255,255,255,.12); }
.btn.ghost.on { background: rgba(255,255,255,.2); }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.block { width: 100%; padding: 12px; }
.icon-btn { border: none; background: none; font-size: 1.6rem; line-height: 1; padding: 4px 10px; cursor: pointer; border-radius: 8px; }
.icon-btn:hover { background: #eef2f6; }

/* ---------- Calendario ---------- */
.layout { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 16px; }
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cal-head h2 { flex: 1; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-bottom: 8px; justify-content: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays span { text-align: center; font-size: .78rem; font-weight: 700; color: var(--muted); padding: 6px 0; }
.grid { gap: 4px; }
.day { min-height: 98px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; overflow: hidden; background: #fff; }
.day:hover, .day:focus-visible { border-color: var(--brand-2); outline: none; }
.day.other { background: #fafbfc; }
.day.other .num { color: #a7b0ba; }
.day .num { font-size: .85rem; font-weight: 700; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.day.today .num { background: var(--brand); color: #fff; }
.day.selected { border: 2px solid var(--brand); padding: 3px; }
.chips { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chip {
  display: block; font-size: .74rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; color: #fff; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { filter: brightness(1.1); text-decoration: underline; }
.chip.done { opacity: .4; text-decoration: line-through; }
.more { font-size: .72rem; color: var(--muted); padding-left: 4px; }

/* ---------- Listas ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card > h3 { margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 8px; padding: 10px 10px 10px 12px; border: 1px solid var(--line); border-left: 5px solid var(--brand); border-radius: 8px; }
.item.done { opacity: .6; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; word-break: break-word; text-decoration: none; color: var(--text); }
a.item-title { color: var(--brand-2); }
a.item-title:hover { text-decoration: underline; }
.item-meta { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.item-desc { font-size: .85rem; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.item-actions { display: flex; gap: 0; align-items: flex-start; flex-shrink: 0; }
.item-actions button { border: none; background: none; cursor: pointer; font-size: 1rem; padding: 5px 6px; border-radius: 6px; }
.item-actions button:hover { background: #eef2f6; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.dot.big { width: 12px; height: 12px; vertical-align: -1px; margin-right: 8px; }
.badge { font-size: .68rem; font-weight: 800; padding: 2px 7px; border-radius: 10px; background: #e8eef5; color: var(--brand); vertical-align: middle; margin-left: 4px; white-space: nowrap; }
.badge.ok { background: #e6f4ea; color: var(--ok); }
.badge.warn { background: #fff3e0; color: #b45300; }
.badge.bad { background: #fdecea; color: var(--bad); }

/* ---------- Buscador y tablas ---------- */
.search input { font-size: 1.05rem; padding: 12px 14px; margin-bottom: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px; border-bottom: 2px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover { background: #f8fafc; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { margin: 2px; }
.audit td { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.act { font-weight: 700; white-space: nowrap; }
.act-plazo { color: #1565c0; } .act-legajo { color: #2e7d32; } .act-inicio, .act-cierre, .act-sesion, .act-sesiones { color: #6a1b9a; }
.act-aviso { color: #ef6c00; } .act-usuario { color: #5d4037; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.filters label { flex: 0 1 180px; }
.filters label.grow { flex: 1 1 220px; }

.datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; margin: 0; }
.datos .wide { grid-column: 1 / -1; }
.datos dt { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.datos dd { margin: 2px 0 0; font-size: 1rem; word-break: break-word; }

/* ---------- Formularios y diálogos ---------- */
dialog { border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 20px)); max-height: calc(100vh - 30px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 20, 35, .5); }
dialog:has(.wide-modal) { width: min(900px, calc(100vw - 20px)); }
.form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.form h3 { margin-top: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: #3a4654; flex: 1; }
input, select, textarea { font: inherit; font-weight: 400; padding: 9px 10px; border: 1px solid #cdd5de; border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input[type=color] { padding: 2px; height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }
.row { display: flex; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; margin: 0; }
legend { font-size: .85rem; font-weight: 700; padding: 0 4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.field-static { background: #f5f7fa; border-radius: 8px; padding: 10px 12px; font-size: .95rem; }
.field-static span { display: block; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.error { color: var(--bad); background: #fdecea; padding: 8px 10px; border-radius: 8px; margin: 0; font-size: .9rem; }

/* ---------- Pop-up ---------- */
.popup { overflow: hidden; width: min(440px, calc(100vw - 20px)); }
.popup-bar { height: 10px; }
.popup-body { padding: 20px; }
.popup-kicker { margin: 0 0 4px; font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.popup h2 { font-size: 1.5rem; }
.popup[open] { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1c2733; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  max-width: calc(100vw - 32px); z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 10px 0; gap: 6px 10px; }
  .brand { order: 1; padding-bottom: 4px; }
  .userbox { order: 2; margin-left: auto; padding-bottom: 4px; }
  .user-chip { font-size: 0; }
  .user-chip .role { font-size: .68rem; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { padding: 9px 11px; font-size: .88rem; }
  .view { padding: 0 8px 30px; margin-top: 10px; gap: 10px; }
  .card { padding: 12px; }
  .day { min-height: 62px; padding: 2px; }
  .day.selected { padding: 1px; }
  .day .num { width: 22px; height: 22px; font-size: .78rem; }
  .chip { font-size: .58rem; padding: 1px 2px; white-space: normal; word-break: break-all; line-height: 1.15; text-overflow: clip; }
  .chips .chip:nth-child(n+3) { display: none; }
  .row { flex-direction: column; gap: 12px; }
  .table.responsive thead { display: none; }
  .table.responsive tr { display: block; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 6px 4px; }
  .table.responsive td { display: flex; gap: 10px; border: none; padding: 4px 8px; }
  .table.responsive td[data-l]::before { content: attr(data-l); flex: 0 0 90px; font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
  .row-actions { text-align: left; flex-wrap: wrap; }
}
