:root {
  --plano: #f3f6f8; --blanco: #fff; --tinta: #07294e; --pizarra: #3e4f5e; --azul: #146ea6; --azul-claro: #1988cd;
  --linea: #d5dee5; --borde: #728496; --error: #b42318; --error-fondo: #fdf1f0; --ok: #1d7a46; --ok-fondo: #ecf8f0;
  --aviso: #8a5a00; --aviso-fondo: #fff7e6; --sel: #eef5fb;
  --fuente: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--fuente); font-size: 14px; color: var(--pizarra); background: var(--plano); }
h1, h2, h3 { color: var(--tinta); font-weight: 650; margin: 0 0 .6rem; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; margin-top: 1.4rem; } h3 { font-size: .95rem; }
a { color: var(--azul); }
.barra { position: sticky; top: 0; z-index: 5; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; padding: .5rem 1rem; background: var(--tinta); color: #d6e2ec; }
.marca { display: flex; gap: .5rem; align-items: center; color: #fff; font-size: 1.05rem; }
#tabs { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
#tabs button { background: transparent; color: #d6e2ec; border: 0; padding: .45rem .65rem; border-radius: 6px; cursor: pointer; font: inherit; }
#tabs button[aria-current="page"] { background: rgb(255 255 255 / .14); color: #fff; }
#tabs button:hover { color: #fff; }
.derecha { display: flex; gap: .75rem; align-items: center; }
.periodo input { margin-left: .3rem; padding: .25rem .4rem; border-radius: 6px; border: 1px solid transparent; font: inherit; }
main { max-width: 1280px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.cargando { color: var(--pizarra); }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .7rem; }
.tarjeta { background: var(--blanco); border: 1px solid var(--linea); border-radius: 10px; padding: .8rem .9rem; }
.tarjeta .t { font-size: .78rem; color: var(--pizarra); }
.tarjeta .v { font-size: 1.25rem; color: var(--tinta); font-weight: 650; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.tarjeta .n { font-size: .75rem; margin-top: .2rem; }
.tarjeta .chip { white-space: normal; }
.panel { background: var(--blanco); border: 1px solid var(--linea); border-radius: 10px; padding: 1rem; margin-top: 1rem; overflow-x: auto; }
.fila { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.espacio { flex: 1; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--linea); vertical-align: top; }
th { color: var(--tinta); font-weight: 600; background: var(--plano); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--sel); }
tfoot td { font-weight: 650; color: var(--tinta); }
button, .btn { font: inherit; padding: .45rem .8rem; border-radius: 7px; border: 1px solid var(--azul); background: var(--azul); color: #fff; cursor: pointer; text-decoration: none; display: inline-block; }
button.sec, .btn.sec { background: var(--blanco); color: var(--azul); }
button.peligro { background: var(--error); border-color: var(--error); }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--azul-claro); outline-offset: 2px; }
.chip { display: inline-block; padding: .05rem .45rem; border-radius: 99px; font-size: .75rem; background: var(--plano); border: 1px solid var(--linea); white-space: nowrap; }
.chip.ok { background: var(--ok-fondo); color: var(--ok); border-color: #b7dfc6; }
.chip.alto { background: var(--error-fondo); color: var(--error); border-color: #f3c2bd; }
.chip.medio { background: var(--aviso-fondo); color: var(--aviso); border-color: #f0d9a8; }
.avisos { list-style: none; padding: 0; margin: 0; } .avisos li { padding: .35rem 0; border-bottom: 1px solid var(--linea); }
dialog { border: 0; border-radius: 12px; padding: 0; width: min(720px, 96vw); box-shadow: 0 20px 60px rgb(7 41 78 / .3); }
dialog form { padding: 1.2rem; }
dialog::backdrop { background: rgb(7 41 78 / .35); }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .7rem; margin: .8rem 0; }
.campo label { display: block; font-size: .78rem; color: var(--tinta); margin-bottom: .2rem; font-weight: 600; }
.campo input, .campo select, .campo textarea { width: 100%; padding: .45rem .5rem; border: 1px solid var(--borde); border-radius: 7px; font: inherit; background: var(--blanco); color: var(--tinta); }
.campo input[readonly] { background: var(--plano); border-color: var(--linea); color: var(--pizarra); }
.campo.ancho { grid-column: 1 / -1; }
.ayuda { font-size: .78rem; color: var(--pizarra); }
#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--tinta); color: #fff; padding: .6rem 1rem; border-radius: 8px; display: none; z-index: 50; max-width: 90vw; }
#toast.error { background: var(--error); }
.entrar { max-width: 380px; margin: 8vh auto; background: var(--blanco); border: 1px solid var(--linea); border-radius: 12px; padding: 1.5rem; }
.entrar input { width: 100%; padding: .5rem; margin: .3rem 0 .8rem; border: 1px solid var(--borde); border-radius: 7px; font: inherit; }
.entrar button { width: 100%; margin-top: .3rem; }
.sep { text-align: center; color: var(--borde); margin: .8rem 0; font-size: .8rem; }
.filtro { padding: .4rem .5rem; border: 1px solid var(--borde); border-radius: 7px; font: inherit; min-width: 220px; }
pre.txt { font-size: .75rem; overflow-x: auto; background: var(--plano); padding: .6rem; border-radius: 8px; }
@media (max-width: 720px) { .barra { gap: .5rem; } .derecha { width: 100%; justify-content: space-between; } }

/* ---------- celular y tablet angosta ---------- */
.menu { display: none; }
@media (max-width: 760px) {
  body { font-size: 15px; }
  .barra { position: sticky; flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }
  .marca span { display: none; }
  .periodo { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: .35rem; }
  .periodo span { display: none; }
  .periodo input { margin: 0; width: 100%; min-height: 40px; font-size: 16px; }
  .menu { display: inline-block; flex: 0 1 auto; background: rgb(255 255 255 / .14); border-color: transparent; color: #fff; min-height: 40px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #tabs, .derecha { display: none; }
  body.menu-abierto #tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; width: 100%; padding: .4rem 0 .2rem; }
  body.menu-abierto #tabs button { text-align: left; padding: .7rem .75rem; background: rgb(255 255 255 / .06); min-height: 44px; }
  body.menu-abierto .derecha { display: flex; width: 100%; justify-content: space-between; padding: .3rem 0 .2rem; font-size: .85rem; }
  main { padding: .9rem .75rem 4rem; }
  h1 { font-size: 1.15rem; }
  .fila { gap: .45rem; }
  .fila > .espacio { flex-basis: 100%; height: 0; }
  .fila > h1 { margin-bottom: .2rem; }
  .filtro { min-width: 0; flex: 1; font-size: 16px; min-height: 42px; }
  button, .btn { min-height: 42px; }
  .tarjetas { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
  .tarjeta { min-width: 0; overflow-wrap: anywhere; }
  .tarjeta .chip, .avisos .chip { white-space: normal; }
  .tarjeta { padding: .65rem .7rem; }
  .tarjeta .v { font-size: 1.05rem; }
  .panel { padding: .75rem; border-radius: 9px; }

  /* tablas como fichas */
  table.fichas, table.fichas tbody, table.fichas tfoot, table.fichas tr, table.fichas td { display: block; width: 100%; }
  table.fichas thead { display: none; }
  table.fichas tr { border: 1px solid var(--linea); border-radius: 9px; padding: .45rem .6rem; margin-bottom: .55rem; background: var(--blanco); }
  table.fichas tfoot tr { background: var(--plano); }
  table.fichas td { display: flex; justify-content: space-between; gap: .75rem; border: 0; padding: .22rem 0; text-align: right; }
  table.fichas td::before { content: attr(data-label); color: var(--pizarra); font-weight: 600; text-align: left; flex-shrink: 0; max-width: 45%; }
  table.fichas td:not([data-label])::before { content: none; }
  table.fichas td.vacia { display: none; }
  table.fichas td:first-child { font-weight: 650; color: var(--tinta); }
  table.fichas td[colspan] { justify-content: flex-start; text-align: left; }
  .panel:has(table.fichas) { background: transparent; border: 0; padding: 0; }
  .avisos li { font-size: .9rem; }

  /* formularios a pantalla completa */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog form { padding: 1rem .9rem 0; min-height: 100%; display: flex; flex-direction: column; }
  .campos { grid-template-columns: 1fr; gap: .6rem; }
  .campo input, .campo select, .campo textarea { font-size: 16px; min-height: 44px; }
  .pie { position: sticky; bottom: 0; margin: auto -.9rem 0; padding: .7rem .9rem calc(.7rem + env(safe-area-inset-bottom)); background: var(--blanco); border-top: 1px solid var(--linea); }
  .pie > .espacio { flex-basis: auto; height: auto; flex: 1; }
  #ml select, #ml input { width: 100%; font-size: 16px; min-height: 40px; }
  .entrar { margin: 4vh auto; }
  .entrar input { font-size: 16px; min-height: 44px; }
}
