:root {
  --bg: #f3f6fc; --surface: #ffffff; --surface-2: #e9eef8;
  --ink: #0e1a33; --ink-2: #43506b; --ink-3: #5f6b84; --line: #dce3f0;
  --accent: #1564e6; --accent-ink: #ffffff;
  --brand: #0a1a3a; --brand-raised: #13285a; --brand-line: #1f3566; --brand-ink-2: #a9b8d6;
  --red: #b8291d; --red-bg: #fde9e6; --amber: #8a5300; --amber-bg: #fff2d6;
  --green: #17703d; --green-bg: #e1f5e8; --blue: #2563c9; --blue-bg: #e3ecfb;
  --radius: 14px; --shadow: 0 1px 2px rgba(18,22,26,.06), 0 2px 8px rgba(18,22,26,.05);
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071022; --surface: #0f1a30; --surface-2: #16243f; --ink: #eaf0fb; --ink-2: #adb9d0; --ink-3: #7c89a4;
    --line: #22314f; --brand: #060d1c; --brand-raised: #112142; --brand-line: #182a4d;
    --red: #ff6b5c; --red-bg: #3a1714; --amber: #ffb547; --amber-bg: #352510;
    --green: #4ad584; --green-bg: #112d1d; --blue: #7aa7ff; --blue-bg: #15233d; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #071022; --surface: #0f1a30; --surface-2: #16243f; --ink: #eaf0fb; --ink-2: #adb9d0; --ink-3: #7c89a4;
  --line: #22314f; --brand: #060d1c; --brand-raised: #112142; --brand-line: #182a4d;
  --red: #ff6b5c; --red-bg: #3a1714; --amber: #ffb547; --amber-bg: #352510;
  --green: #4ad584; --green-bg: #112d1d; --blue: #7aa7ff; --blue-bg: #15233d; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- estructura: menú lateral en escritorio, barra abajo en el celular ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
.side { background: var(--brand); color: #fff; padding: 16px 12px; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px; }
.side nav { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.side a.nav { color: var(--brand-ink-2); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500; }
.side a.nav.on, .side a.nav:hover { background: var(--brand-raised); color: #fff; }
.side .pie { margin-top: auto; font-size: 13px; color: var(--brand-ink-2); display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.side .pie button { background: none; border: 1px solid var(--brand-line); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
main.cont { padding: 24px; max-width: 1100px; width: 100%; }
.top { display: none; }
.bottom { display: none; }
@media (max-width: 820px) {
  .layout { display: block; }
  .side { display: none; }
  .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--brand); color: #fff;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px; position: sticky; top: 0; z-index: 5; }
  .top button.salir { background: none; border: 1px solid var(--brand-line); color: #fff; border-radius: 8px; padding: 4px 10px; }
  main.cont { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .bottom { display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom a { text-align: center; padding: 10px 2px 8px; font-size: 12px; color: var(--ink-3); text-decoration: none; font-weight: 600; }
  .bottom a.on { color: var(--accent); }
}

/* ---------- selector de módulos ---------- */
.mod { position: relative; }
.mod-btn { display: flex; align-items: center; gap: 6px; background: none; border: 0; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.mod-btn:hover { background: var(--brand-raised); }
.mod-nombre { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 6px; display: flex; align-items: center; gap: 8px; }
.mod img.logo, .mod-btn img.logo { width: 24px; height: 24px; }
.mod-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; z-index: 20; }
.mod-op { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
a.mod-op:hover { background: var(--surface-2); }
.mod-op.on { color: var(--accent); font-weight: 700; }
.mod-ini { width: 20px; height: 20px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

/* ---------- piezas ---------- */
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.lista { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: start; text-decoration: none; color: inherit; }
a.item:hover { border-color: var(--accent); }
.item .tit { font-weight: 600; color: var(--ink); text-decoration: none; }
.item .tit:hover { color: var(--accent); }
.item a.sub { text-decoration: none; }
.item .sub { color: var(--ink-3); font-size: 13px; grid-column: 1 / -1; display: flex; gap: 6px 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 500; font-size: 14px; }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip .n { margin-left: 4px; opacity: .7; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-gris { background: var(--surface-2); color: var(--ink-2); }
.b-azul { background: var(--blue-bg); color: var(--blue); }
.b-ambar { background: var(--amber-bg); color: var(--amber); }
.b-verde { background: var(--green-bg); color: var(--green); }
.b-rojo { background: var(--red-bg); color: var(--red); }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.peligro { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
dl.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.datos dt { color: var(--ink-3); }
dl.datos dd { margin: 0; overflow-wrap: anywhere; }
label.campo { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 11px; font-size: 15px; min-width: 0; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
form.form { display: grid; gap: 12px; }
.fotos { display: flex; gap: 8px; flex-wrap: wrap; }
.fotos a img { width: 104px; height: 104px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; background: var(--surface-2); }
.persona { border-top: 1px solid var(--line); padding: 10px 0; }
.persona:first-child { border-top: 0; padding-top: 0; }
.vacio { text-align: center; color: var(--ink-3); padding: 28px 12px; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th { text-align: left; color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabla td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla td.der, .tabla th.der { text-align: right; }
.scroll { overflow-x: auto; }
.barra { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.barra > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.barra.lleno > span { background: var(--green); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--ink-3); font-size: 13px; }
.aviso { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px); }
#toast.ver { opacity: 1; }
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(7,16,34,.5); }
.login { min-height: 100dvh; display: grid; place-items: center; background: var(--brand); padding: 16px; }
.login .card { width: min(380px, 100%); }
