:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1d2733;
  --muted: #5e6b78;
  --border: #d8dee5;
  --primary: #1f4e79;
  --primary-dark: #163a5a;
  --ok: #1e7b45;
  --warn: #8a5a00;
  --err: #b3261e;
  --radius: 8px;
}
* { box-sizing: border-box; }
/* El atributo hidden debe ganar a reglas como `label { display: block }` */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h1 small { font-size: .9rem; font-weight: normal; color: var(--muted); }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1rem 0 .4rem; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.break { word-break: break-all; }
.pre { white-space: pre-wrap; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  background: var(--primary-dark); color: #fff; padding: .7rem 1.25rem;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.brand span { font-weight: 400; opacity: .8; }
.topbar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar nav a, .topbar .link { color: #fff; text-decoration: none; }
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 420px; margin: 3rem auto; }
.card.highlight { border-color: var(--primary); }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.btn {
  display: inline-block; background: var(--primary); color: #fff; border: 0; border-radius: 6px;
  padding: .55rem 1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn-primary { padding: .75rem 1.6rem; font-size: 1rem; }
.btn-secondary { background: #e7ecf1; color: var(--text); }
.btn-secondary:hover { background: #d9e0e7; }
.btn-small { padding: .35rem .7rem; font-size: .9rem; }
.topbar .btn-small { background: #fff; color: var(--primary-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
form.inline { display: inline; margin: 0; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .7rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; font: inherit; font-weight: normal;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e6; border-color: var(--primary); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.choice-row { display: flex; gap: 2.5rem; flex-wrap: wrap; }
.choice { display: inline-flex; align-items: center; gap: .4rem; font-weight: normal; margin-right: 1rem;
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .8rem; cursor: pointer; }
.choice input { width: auto; margin: 0; }
.choice:has(input:checked) { border-color: var(--primary); background: #eaf2fa; }
.req { color: var(--err); text-decoration: none; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 .6rem; }
.field-error { display: block; color: var(--err); font-size: .82rem; font-weight: 600; margin-top: .2rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; margin: 0; }
.search { display: flex; gap: .5rem; }
.search input { margin: 0; min-width: 260px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grid-detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
@media (max-width: 800px) {
  .grid-2, .grid-3, .grid-detail { grid-template-columns: 1fr; }
}

.party-info { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; margin: .3rem 0 0; font-size: .9rem; }
.party-info dt { color: var(--muted); }
.party-info dd { margin: 0; }
.kv { display: grid; grid-template-columns: 190px 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv.small { grid-template-columns: 90px 1fr; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: .4rem; } }

.qr-card { text-align: center; }
.qr svg { width: 100%; max-width: 240px; height: auto; border: 1px solid var(--border); }
.url { word-break: break-all; font-size: .8rem; }

.stats { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.4rem; min-width: 180px; }
.stat-num { display: block; font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: #f0f3f6; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table .actions a { margin-right: .5rem; }
.row-current { background: #f2f8ee; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .45rem; border-radius: 999px; background: #e1f0e6; color: var(--ok); vertical-align: middle; }
.badge-v { background: #e3ecf5; color: var(--primary); }
.badge-old { background: #f6ecd9; color: var(--warn); }

.alert { border-radius: 6px; padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-success { background: #e8f5ed; border-color: #b5dcc3; color: var(--ok); }
.alert-error { background: #fdecea; border-color: #f2b8b5; color: var(--err); }
.alert-warning { background: #fff5e0; border-color: #f0d18a; color: var(--warn); }
.alert-info { background: #eaf2fa; border-color: #b9d3ec; color: var(--primary-dark); }

/* Plantillas GALLINA / BAÑERA */
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.label-like { display: block; font-weight: 600; font-size: .9rem; }
.computed { margin: .25rem 0 .7rem; padding: .5rem .6rem; background: #f0f3f6; border-radius: 6px; }
.carga { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.carga-col { border: 1px solid var(--border); border-radius: 6px; padding: .6rem .8rem 0; }
.carga-col h4 { margin: 0 0 .5rem; font-size: .85rem; color: var(--primary); }
details.card > summary { cursor: pointer; list-style-position: inside; }
.inline-h { display: inline; }
h4 { font-size: .9rem; margin: .9rem 0 .3rem; }
.table-compact th, .table-compact td { padding: .3rem .45rem; }
.vehiculos { margin: 0; padding-left: 1.2rem; }
@media (max-width: 600px) { .carga { grid-template-columns: 1fr; } }
