:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --ok: #157f3b;   --ok-bg: #e5f5ea;
  --warn: #9a6200; --warn-bg: #fff4dc;
  --bad: #b42318;  --bad-bg: #fde9e7;
  --info: #175cd3; --info-bg: #e7f0ff;
  --example: #7a3fc6; --example-bg: #f2eafd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b2029; --text: #e6e9ef; --muted: #98a2b3; --line: #2c3340;
    --brand: #6d95ff; --brand-ink: #0b1020; --brand-soft: #1f2a44;
    --ok: #6fd593; --ok-bg: #173523; --warn: #f2c25b; --warn-bg: #3a2e12; --bad: #ff8a80; --bad-bg: #42201d;
    --info: #8db4ff; --info-bg: #1b2a48; --example: #c9a5ff; --example-bg: #2d2140;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; }
h2 { font-size: 1.08rem; margin: 0 0 .75rem; }
h3 { font-size: .98rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Barra superior y navegación */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.client-switch select { font-weight: 600; min-width: 12rem; }
.user { margin-left: auto; display: flex; align-items: center; gap: .75rem; white-space: nowrap; }
.user form { margin: 0; }
.nav-toggle { display: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: .25rem .6rem; font-size: 1.1rem; }
.shell { display: flex; min-height: calc(100vh - 52px); }
.sidebar { width: 240px; flex: none; padding: .75rem .5rem 2rem; border-right: 1px solid var(--line); background: var(--surface); position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1rem .6rem .25rem; font-weight: 700; }
.nav-item { display: block; padding: .38rem .6rem; border-radius: 7px; color: var(--text); }
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.main { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; max-width: 1280px; }

/* Cabecera de página */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.ref { margin: 0; color: var(--muted); font-size: .85rem; }
.intro { background: var(--brand-soft); border-left: 3px solid var(--brand); padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; font-size: .92rem; }
.code { font-family: ui-monospace, Consolas, monospace; background: var(--bg); border: 1px solid var(--line); padding: .05rem .4rem; border-radius: 6px; font-size: .95rem; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.card.narrow { max-width: 520px; }
.card.danger { border-color: var(--bad-bg); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }

/* Botones y controles */
.btn { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .45rem .85rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .42rem .55rem; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; padding: 0; accent-color: var(--brand); vertical-align: -2px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: .88rem; }
label > input, label > select, label > textarea { margin-top: .25rem; font-weight: 400; }
.stack { display: grid; gap: .75rem; }

/* Formularios de registro */
fieldset.card { padding-top: .4rem; }
legend { font-weight: 700; padding: 0 .4rem; font-size: 1rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .8rem 1rem; }
.field.wide { grid-column: 1 / -1; }
.field.is-check label { font-weight: 500; display: flex; gap: .5rem; align-items: flex-start; }
.field.is-check { align-self: center; }
.help { display: block; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.error { display: block; color: var(--bad); font-size: .82rem; margin-top: .2rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.req { color: var(--bad); }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--line); }
.child-table { margin-top: 1rem; }
.child-table h3 { margin-top: .25rem; }
.child-table td input { min-width: 140px; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; }
.is-check { display: flex; gap: .5rem; align-items: center; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; padding: .75rem; }
.filters label { min-width: 150px; flex: 0 1 180px; }
.filters label.grow { flex: 1 1 240px; }
.filter-actions { display: flex; gap: .4rem; }

/* Tablas */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border-radius: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: var(--bg); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr:hover { background: var(--bg); }
.table.compact td, .table.compact th { padding: .35rem .45rem; }
.table .num, .num { text-align: right; white-space: nowrap; width: 1%; }
.row-void td { color: var(--muted); text-decoration: line-through; }
.row-void td a, .row-void td .badge { text-decoration: none; }
.row-example { background: var(--example-bg); }
.row-total td { border-top: 2px solid var(--text); }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .75rem; }
.pager a { padding: .25rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.pager a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* Insignias */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.b-example { background: var(--example-bg); color: var(--example); margin-left: .35rem; }

/* Mensajes */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .6rem; font-size: .92rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

/* Detalle */
.detail { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .6rem 1.25rem; margin: 0; }
.detail .wide { grid-column: 1 / -1; }
.detail dt { font-size: .78rem; color: var(--muted); font-weight: 600; }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.next-steps { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.hist { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.hist > li { padding: .4rem 0; border-bottom: 1px solid var(--line); }

/* Tablero */
.steps { margin: 0; padding-left: 1.2rem; display: grid; gap: .45rem; }
.deliverable { display: grid; grid-template-columns: auto 1fr; gap: .1rem .6rem; padding: .75rem; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--surface); }
.deliverable:hover { text-decoration: none; border-color: var(--brand); }
.deliverable .check { grid-row: span 2; font-size: 1.2rem; color: var(--warn); }
.deliverable.done { background: var(--ok-bg); }
.deliverable.done .check { color: var(--ok); }
.deliverable small { color: var(--muted); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem 1.25rem; }
.counts .nav-group { margin-left: 0; }
.count-row { display: flex; justify-content: space-between; padding: .2rem 0; color: var(--text); border-bottom: 1px dashed var(--line); }
.checks { display: grid; gap: .4rem; }
.check-item { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; }
.check-item summary { cursor: pointer; font-weight: 600; }
.check-item.has-issues { border-color: var(--warn); }
.check-item .check { display: inline-block; width: 1.2rem; text-align: center; }

/* Acceso */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: min(420px, 100%); display: grid; gap: .8rem; }

/* Responsivo */
@media (max-width: 960px) {
  .nav-toggle { display: block; }
  .sidebar { position: fixed; left: 0; top: 52px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .main { padding: 1rem 16px 3rem; }
  .brand { display: none; }
  .client-switch select { min-width: 0; max-width: 45vw; }
}

/* Impresión de fichas */
@media print {
  .topbar, .sidebar, .no-print, .form-actions, .flash, .nav-toggle { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #999; break-inside: avoid; }
  .row-example { background: #f3f3f3; }
  a { color: #000; }
}
.is-print .topbar, .is-print .sidebar, .is-print .no-print { display: none !important; }
.is-print .main { max-width: 900px; margin: 0 auto; }
.multi { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .25rem; }
.multi label { font-weight: 400; display: flex; gap: .3rem; align-items: center; }
