/* Huella Municipal v2, "Territorio vivo". Tokens y componentes documentados en DESIGN.md */
@font-face { font-family: 'Unbounded'; font-style: normal; font-weight: 500; font-display: swap; src: url('fonts/unbounded-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Unbounded'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/unbounded-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Onest'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/onest-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Onest'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/onest-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Onest'; font-style: normal; font-weight: 700 800; font-display: swap; src: url('fonts/onest-latin-700-normal.woff2') format('woff2'); }

:root {
  /* Marca */
  --anil: #1B1F6B; --anil-deep: #0F1147; --niebla: #EEF0FB; --mango: #FFC531;
  --guacamaya: #E5213F; --selva: #06866A; --cielo: #3D8BFF; --tinta: #14163F;

  /* Roles. Los nombres antiguos se conservan: las páginas de módulos los usan. */
  --bg: var(--niebla);
  --surface: #fff;
  --surface-2: #E3E6F7;
  --ink: var(--tinta);
  --ink-2: #4A4E7A;
  --line: #D5D9F0;
  --line-strong: #8387B5;
  --brand: var(--anil);
  --brand-ink: #fff;
  --brand-soft: #DFE2F8;
  --accent: var(--mango);
  --accent-soft: #FFF4D2;
  --ok: #056B55;   --ok-soft: #E2F5EF;
  --warn: #7A5200; --warn-soft: #FFF4D2;
  --crit: #C8102E; --crit-soft: #FDE8EB;
  --info: #1D5FC4; --info-soft: #E6F0FF;
  --on-dark: #fff;
  --on-dark-2: #C5C9EE;

  /* Forma: el radio crece con la jerarquía */
  --radius-xs: 6px; --radius-sm: 10px; --radius: 16px; --radius-lg: 24px;
  --shadow: 0 1px 2px rgba(15,17,71,.06), 0 6px 20px -8px rgba(15,17,71,.16);
  --shadow-float: 0 2px 6px rgba(15,17,71,.18), 0 18px 44px -12px rgba(15,17,71,.45);

  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Unbounded', 'Onest', system-ui, sans-serif;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --rail-w: 264px;
  --bar-h: 84px; /* alto reservado por la barra flotante pública */
  --dock-h: 84px;
  --contour: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='360' fill='none' stroke='%233D8BFF' stroke-opacity='.2'%3E%3Cpath d='M-20 60C40 20 90 50 150 34s130-30 230 16'/%3E%3Cpath d='M-20 104c60-34 112-6 176-20s120-24 224 18'/%3E%3Cpath d='M-20 150c50-26 96 4 152-6 34-6 60-30 104-26 46 4 84 30 144 22'/%3E%3Cpath d='M-20 214c70 30 124-2 190 14s130 24 210-14'/%3E%3Cpath d='M-20 262c80 26 150 2 220 14s120 12 180-12'/%3E%3Cpath d='M-20 316c60 18 130-8 200 4s130 20 200-6'/%3E%3C/svg%3E");
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 96px; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.55; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; overflow-x: clip; min-height: 100dvh; display: flex; flex-direction: column; }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--info); text-underline-offset: 3px; }
a:hover { color: var(--anil); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; text-wrap: balance; overflow-wrap: break-word; }
h1 { font-family: var(--font-display); font-size: clamp(1.4rem, 1.1rem + 1.5vw, 2.1rem); font-weight: 700; letter-spacing: -.02em; color: var(--anil-deep); }
h2 { font-family: var(--font-display); font-size: clamp(1rem, .95rem + .3vw, 1.2rem); font-weight: 500; letter-spacing: -.01em; color: var(--anil-deep); }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 1em; text-wrap: pretty; }
:focus-visible { outline: 3px solid var(--anil); outline-offset: 2px; border-radius: var(--radius-xs); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sprite { position: absolute; }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Barra flotante pública */
.topbar { position: sticky; top: 10px; z-index: 40; width: min(1180px, calc(100% - 24px)); margin: 10px auto 0; }
.topbar__in { position: relative; display: flex; align-items: center; gap: 8px; min-height: 64px; padding: 8px 10px 8px 14px; color: var(--on-dark); background-color: var(--anil-deep); background-image: var(--contour); background-size: 360px; border-radius: 20px; box-shadow: var(--shadow-float); }
.topbar :focus-visible, .rail :focus-visible, .dock :focus-visible { outline-color: var(--mango); }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--on-dark); text-decoration: none; font-family: var(--font-display); font-weight: 700; font-size: .92rem; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { color: var(--on-dark); }
.brand img { border-radius: 10px; }
.nav { display: flex; gap: 2px; margin-left: 20px; }
.nav__trigger { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 10px 0 14px; color: var(--on-dark-2); background: transparent; border: 0; border-radius: 12px; font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; transition: background-color .15s ease, color .15s ease; }
.nav__trigger .ico { width: 16px; height: 16px; transition: transform .2s var(--ease-out); }
.nav__trigger[aria-expanded="true"] { color: var(--on-dark); background: rgba(255,255,255,.12); }
.nav__trigger[aria-expanded="true"] .ico { transform: rotate(180deg); }
.nav__trigger.is-here { color: var(--mango); }
.topbar__cta { margin-left: 10px; }
.topbar__login { margin-left: auto; min-height: 42px; padding: 0 16px; color: #fff; background: transparent; border: 1.5px solid rgba(255,255,255,.45); }
.topbar__login:hover, .topbar__login[aria-current] { background: rgba(255,255,255,.12); border-color: #fff; }
.topbar__search { margin-left: auto; }

/* Mega menú: los paneles comparten celda para que el contenedor no salte de alto */
.mega { position: absolute; top: calc(100% + 8px); left: 0; right: 0; display: grid; padding: 10px; background-color: var(--anil-deep); background-image: var(--contour); background-size: 360px; border-radius: var(--radius-lg); box-shadow: var(--shadow-float); opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.985); transform-origin: top center; transition: opacity .15s ease, transform .2s var(--ease-out), visibility 0s linear .2s; }
.mega.is-open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.mega__panel { grid-area: 1 / 1; display: grid; grid-template-columns: minmax(200px, 3fr) 7fr; gap: 16px; align-items: start; padding: 14px; visibility: hidden; opacity: 0; transform: translateX(8px); transition: opacity .15s ease, transform .2s var(--ease-out), visibility 0s linear .15s; }
.mega__panel.is-on { visibility: visible; opacity: 1; transform: none; transition-delay: 0s; }
.mega__lead { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1.1rem; line-height: 1.35; color: var(--on-dark); }
.mega__links { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 6px; }
.mega__link { display: flex; align-items: flex-start; gap: 12px; height: 100%; padding: 12px; color: var(--on-dark); text-decoration: none; border-radius: 14px; transition: background-color .15s ease; }
.mega__link .ico { color: var(--mango); margin-top: 1px; }
.mega__link b { display: block; font-weight: 700; }
.mega__link small { display: block; color: var(--on-dark-2); font-size: .85rem; line-height: 1.35; }
.mega__link:hover, .mega__link:focus-visible, .mega__link[aria-current] { color: var(--on-dark); background: rgba(255,255,255,.1); }

/* Riel lateral con sesión */
.rail { position: fixed; inset: 0 auto 0 0; z-index: 35; width: var(--rail-w); display: none; flex-direction: column; gap: 10px; padding: 14px 12px; color: var(--on-dark); background-color: var(--anil-deep); background-image: var(--contour); background-size: 360px; transition: width .2s var(--ease-out); }
.rail__top { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 44px; padding-left: 4px; }
.rail__search { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 10px; color: var(--on-dark-2); background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 12px; font: inherit; font-size: .92rem; text-align: left; cursor: pointer; transition: background-color .15s ease, color .15s ease; }
.rail__search span { flex: 1; white-space: nowrap; overflow: hidden; }
.rail__search kbd { font: inherit; font-size: .75rem; font-weight: 600; padding: 2px 6px; background: rgba(255,255,255,.12); border-radius: var(--radius-xs); white-space: nowrap; }
.rail__nav { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 12px; margin: 2px -4px; padding: 2px 4px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.rail__group { display: grid; gap: 2px; }
.rail__label { margin: 0; padding: 4px 10px; font-family: var(--font); font-size: .78rem; font-weight: 600; letter-spacing: 0; color: var(--on-dark-2); white-space: nowrap; }
.rail__link { position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 10px; color: var(--on-dark-2); font-weight: 600; font-size: .94rem; text-decoration: none; white-space: nowrap; border-radius: 12px; transition: background-color .15s ease, color .15s ease; }
.rail__link > * { position: relative; z-index: 1; }
.rail__link::before { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--mango); opacity: 0; transform: scaleX(.9); transform-origin: left; transition: opacity .15s ease, transform .2s var(--ease-out); }
.rail__link[aria-current]::before { opacity: 1; transform: none; view-transition-name: rail-mark; }
.rail__link[aria-current] { color: var(--tinta); }
.rail__user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px 2px 8px; border-top: 1px solid rgba(255,255,255,.14); }
.rail__who { min-width: 0; display: grid; line-height: 1.25; }
.rail__who b, .rail__who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail__who small { color: var(--on-dark-2); font-size: .8rem; }
.navbtn { display: inline-flex; align-items: center; gap: 8px; min-width: 44px; min-height: 44px; justify-content: center; padding: 0 12px; color: var(--on-dark-2); background: transparent; border: 0; border-radius: 12px; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; transition: background-color .15s ease, color .15s ease, transform .12s ease; }
.navbtn--icon { padding: 0; }
.navbtn:active { transform: scale(.94); }
.rail__user .navbtn { padding: 0 10px; }

@media (hover: hover) and (pointer: fine) {
  .nav__trigger:hover { color: var(--on-dark); background: rgba(255,255,255,.1); }
  .navbtn:hover { color: var(--on-dark); background: rgba(255,255,255,.12); }
  .rail__search:hover { color: var(--on-dark); background: rgba(255,255,255,.14); }
  .rail__link:not([aria-current]):hover { color: var(--on-dark); background: rgba(255,255,255,.1); }
  .btn:hover { background: var(--surface-2); color: var(--ink); }
  .btn--primary:hover { background: var(--anil-deep); color: #fff; }
  .btn--accent:hover { background: #F5B400; color: var(--tinta); }
  .btn--danger:hover { background: #A50D26; color: #fff; }
  .btn--ghost:hover { background: var(--brand-soft); color: var(--anil); }
  .pet:has(a):hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(15,17,71,.08), 0 16px 32px -12px rgba(15,17,71,.32); }
  .pager a:hover { background: var(--surface-2); }
  .table tbody tr:hover { background: #F6F7FE; }
  .cmdk__opt:hover { background: var(--niebla); }
}

/* Riel contraído: solo íconos, la etiqueta aparece como globo */
.rail-min { --rail-w: 76px; }
.rail-min .rail__top { flex-direction: column; padding: 0; }
.rail-min .rail__top .brand span, .rail-min .rail__search span, .rail-min .rail__search kbd, .rail-min .rail__who { display: none; }
.rail-min .rail__search { justify-content: center; padding: 0; }
.rail-min .rail__label { height: 1px; padding: 0; margin: 4px 10px; overflow: hidden; color: transparent; background: rgba(255,255,255,.18); }
.rail-min .rail__link { justify-content: center; padding: 0; }
.rail-min .rail__link > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rail-min .rail__nav { overflow: visible; }
.rail-min .rail__link::after { content: attr(data-label); position: absolute; left: calc(100% + 12px); top: 50%; z-index: 5; padding: 6px 10px; color: var(--on-dark); background: var(--tinta); border-radius: var(--radius-sm); font-size: .85rem; white-space: nowrap; box-shadow: var(--shadow-float); opacity: 0; pointer-events: none; transform: translate(-4px, -50%); transition: opacity .12s ease, transform .15s var(--ease-out); }
.rail-min .rail__link:hover::after, .rail-min .rail__link:focus-visible::after { opacity: 1; transform: translate(0, -50%); }
.rail-min .rail__user { justify-content: center; padding: 8px 0 0; }
.rail-min .rail__user .navbtn { padding: 0; }
.rail-min .rail__user .navbtn span { display: none; }

/* Dock móvil */
.dock { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 35; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2px; padding: 6px; color: var(--on-dark-2); background: var(--anil-deep); border-radius: 22px; box-shadow: var(--shadow-float); view-transition-name: dock; }
.dock__item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-width: 0; min-height: 54px; padding: 4px 2px; color: inherit; background: transparent; border: 0; border-radius: 16px; font: inherit; font-size: .72rem; font-weight: 600; line-height: 1.15; text-align: center; text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s ease, color .15s ease; }
.dock__item > * { position: relative; z-index: 1; }
.dock__item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock__item:hover { color: var(--on-dark); }
.dock__item:active { transform: scale(.94); }
.dock__item[aria-current] { color: var(--tinta); }
.dock__item[aria-current]::before { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--mango); view-transition-name: dock-mark; }

/* Hoja deslizable y paleta: diálogos nativos */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(15,17,71,.55); animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: 86dvh; margin: 0; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-float); transform: translateY(100%); transition: transform .26s var(--ease-out); }
.sheet.is-open { transform: translateY(var(--drag, 0)); }
.sheet.is-drag { transition: none; }
.sheet__grip { position: sticky; top: 0; z-index: 1; display: grid; place-items: center; height: 28px; margin: 0 -16px; background: var(--surface); cursor: grab; touch-action: none; }
.sheet__grip span { width: 44px; height: 5px; background: var(--line-strong); border-radius: 3px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet__head .rail__who small { color: var(--ink-2); }
.sheet .navbtn { color: var(--ink-2); }
.sheet__body { display: grid; gap: 14px; }
.sheet__label { margin: 0 0 6px; font-family: var(--font); font-size: .85rem; font-weight: 600; letter-spacing: 0; color: var(--ink-2); }
.sheet__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.sheet__link { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; color: var(--ink); background: var(--niebla); border-radius: 14px; font-weight: 600; font-size: .92rem; line-height: 1.2; text-decoration: none; }
.sheet__link .ico { color: var(--anil); }
.sheet__link:hover { color: var(--ink); background: var(--surface-2); }
.sheet__link[aria-current] { color: var(--tinta); background: var(--mango); }
.sheet__link[aria-current] .ico { color: var(--tinta); }
.sheet__body form .navbtn { width: 100%; color: var(--crit); background: var(--crit-soft); }

.cmdk { position: fixed; top: 12dvh; width: min(560px, calc(100% - 24px)); max-height: 70dvh; margin: 0 auto; padding: 0; overflow: hidden; background: var(--surface); border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-float); opacity: 0; transform: translateY(-8px) scale(.98); transition: opacity .14s ease, transform .18s var(--ease-out); }
.cmdk[open] { display: flex; flex-direction: column; }
.cmdk.is-open { opacity: 1; transform: none; }
.cmdk__field { display: flex; align-items: center; gap: 10px; padding: 6px 16px; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.cmdk__field input, .cmdk__field input:focus { min-height: 50px; padding: 0; border: 0; border-radius: 0; box-shadow: none; outline: none; background: transparent; font-size: 1.05rem; }
.cmdk__field input::-webkit-search-cancel-button { display: none; }
.cmdk__list { flex: 1; overflow-y: auto; padding: 8px; }
.cmdk__opt { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 6px 10px; color: var(--ink); font-weight: 600; text-decoration: none; border-radius: 12px; }
.cmdk__opt .ico { color: var(--anil); }
.cmdk__opt span { flex: 1; }
.cmdk__opt small { color: var(--ink-2); font-weight: 400; font-size: .82rem; }
.cmdk__opt[aria-selected="true"] { color: var(--on-dark); background: var(--anil); }
.cmdk__opt[aria-selected="true"] .ico { color: var(--mango); }
.cmdk__opt[aria-selected="true"] small { color: var(--on-dark-2); }
.cmdk__opt[hidden] { display: none; }
.cmdk__none { margin: 0; padding: 0 18px; color: var(--ink-2); }
.cmdk__none:not(:empty) { padding: 6px 18px 20px; }

/* Contenedor */
.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 16px 64px; }
.main--wide { max-width: none; padding: 0; }
.has-rail .main--wide { padding: 24px 16px 64px; }
.foot { color: var(--ink-2); background: var(--surface); box-shadow: 0 -1px 0 var(--line); }
.foot__in { max-width: 1180px; margin: 0 auto; padding: 18px 16px; display: flex; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap; font-size: .875rem; }
.foot__links { display: flex; gap: 4px 16px; flex-wrap: wrap; }
.foot a { display: inline-flex; align-items: center; min-height: 24px; color: var(--ink-2); }
.foot a:hover { color: var(--anil); }
.is-bare .foot { display: none; }

/* Móvil: el dock reemplaza riel y menú */
@media (max-width: 899.98px) {
  body:not(.is-bare) { padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom)); }
  .topbar__in { min-height: 58px; padding: 6px 8px 6px 10px; border-radius: 18px; }
  .nav, .mega, .topbar .topbar__cta { display: none; }
  .brand { font-size: .85rem; }
}
@media (min-width: 900px) {
  .dock, .sheet { display: none; }
  .has-rail { padding-left: var(--rail-w); transition: padding-left .2s var(--ease-out); }
  .has-rail .topbar { display: none; }
  .has-rail .rail { display: flex; }
  .has-rail .main { padding: 32px clamp(20px, 3vw, 44px) 64px; }
  .has-rail .main:not(.main--wide) { max-width: 1240px; }
  html:has(.has-rail) { scroll-padding-top: 16px; }
}

/* Encabezado de página */
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.pagehead > div:first-child { min-width: 0; max-width: 100%; }
.pagehead h1 { margin-bottom: .3em; }
.pagehead p { color: var(--ink-2); margin: 0; }

/* Tarjetas y rejillas */
.card { min-width: 0; background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card__title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card__title > * { margin-bottom: 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }

/* Indicadores: el primero de cada rejilla lleva el peso visual */
.stat { min-width: 0; background: var(--surface); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.stat__label { font-size: .875rem; color: var(--ink-2); font-weight: 600; }
.stat__value { font-family: var(--font-display); font-size: clamp(1.5rem, 1.3rem + .8vw, 2rem); font-weight: 700; line-height: 1.1; margin-top: 6px; color: var(--anil-deep); font-variant-numeric: tabular-nums; letter-spacing: -.02em; overflow-wrap: anywhere; }
.grid > .stat:first-child { color: var(--on-dark); background-color: var(--anil-deep); background-image: var(--contour); background-size: 300px; }
.grid > .stat:first-child .stat__label { color: var(--on-dark-2); }
.grid > .stat:first-child .stat__value { color: var(--mango); }
.stat.stat--alert, .grid > .stat--alert:first-child { color: #fff; background: var(--crit); background-image: none; }
.grid > .stat.stat--alert .stat__label, .stat.stat--alert .stat__label { color: #fff; }
.grid > .stat.stat--alert .stat__value, .stat.stat--alert .stat__value { color: #fff; }

/* Botones */
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 0; background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); font: inherit; font-weight: 700; font-size: .95rem; line-height: 1.2; text-align: center; text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color .15s ease, color .15s ease, box-shadow .15s ease, transform .12s ease; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--anil); color: var(--brand-ink); box-shadow: none; }
.btn--accent { background: var(--mango); color: var(--tinta); box-shadow: none; }
.btn--danger { background: var(--crit); color: #fff; box-shadow: none; }
.btn--ghost { background: transparent; color: var(--anil); box-shadow: none; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; border-radius: var(--radius-sm); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::after { content: ''; position: absolute; width: 18px; height: 18px; border: 2px solid var(--ink-2); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn--primary[aria-busy="true"]::after, .btn--danger[aria-busy="true"]::after { border-color: #fff; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Formularios */
.form { display: grid; gap: 16px; }
.form > * { min-width: 0; }
.form--2 { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); align-items: start; }
.form--2 > :is(fieldset, .alert, p, .check, .btn, .form__actions), .form--2 > .field:has(textarea, input[type=file]), .form--2 > div:not(.field):has(> .btn) { grid-column: 1 / -1; }
.page-narrow { max-width: 520px; margin-inline: auto; }
.page-form { max-width: 780px; margin-inline: auto; }
.main > :where(.form, .card:has(> .form):not(:has(.tablewrap))) { max-width: 780px; }
.main > .page-narrow.card { max-width: 520px; }
.main > .page-form, .main > .page-narrow { margin-inline: auto; }
.field > label.check, .field > .check { font-weight: 400; }
.form legend { padding: 0; }
.form fieldset:not(.tiles) > legend { padding: 0 6px; }
input[type=date], input[type=time], input[type=datetime-local] { height: 47px; }
.form--2 > .field:has(> .btn) { grid-column: 1 / -1; justify-items: start; }
.form--2 > .field:has(> .btn--block) { justify-items: stretch; }
.filterbar { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 16px; padding: 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.filterbar .field { flex: 1 1 220px; }
.juris { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.juris details { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.juris details:last-child { border-bottom: 0; }
.juris summary { min-height: 28px; font-weight: 700; cursor: pointer; }
.juris details > .check { margin: 8px 0; }
.juris__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 700; font-size: .9rem; }
.field .hint { font-size: .85rem; color: var(--ink-2); }
.field .error { font-size: .875rem; color: var(--crit); font-weight: 600; }
.input, input:where(:not([type=checkbox],[type=radio],[type=file],[type=hidden],[type=range],[type=color],[type=submit],[type=button])), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); transition: border-color .15s ease, box-shadow .15s ease;
}
::placeholder { color: #5D6190; opacity: 1; }
textarea { min-height: 120px; resize: vertical; }
select { appearance: none; padding-right: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%231B1F6B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
select[multiple] { padding-right: 12px; background-image: none; }
input[type=file] { width: 100%; min-height: 46px; padding: 6px; font: inherit; font-size: .9rem; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }
input[type=file]::file-selector-button { min-height: 32px; margin-right: 12px; padding: 0 14px; font: inherit; font-weight: 600; color: var(--anil); background: var(--niebla); border: 0; border-radius: 6px; cursor: pointer; }
.field:has(> .error) :is(input, select, textarea) { border-color: var(--crit); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--anil); box-shadow: 0 0 0 3px rgba(27,31,107,.28); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.check input { flex: none; width: 20px; height: 20px; margin-top: 2px; accent-color: var(--anil); }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
.pin { letter-spacing: .5em; font-size: 1.3rem; text-align: center; max-width: 220px; }

/* Tablas */
.tablewrap { position: relative; overflow-x: auto; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--niebla); vertical-align: middle; }
.table th { font-size: .85rem; font-weight: 600; color: var(--ink-2); background: #F6F7FE; border-bottom-color: var(--line); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .12s ease; }

/* Etiquetas */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--radius-xs); font-size: .8rem; font-weight: 700; white-space: nowrap; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--crit { background: var(--crit-soft); color: var(--crit); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--mute { background: var(--surface-2); color: var(--ink-2); }

/* Alertas */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 600; border-left: 4px solid; animation: alert-in .24s var(--ease-out); }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } }
.alert--ok { background: var(--ok-soft); color: var(--ok); border-color: var(--selva); }
.alert--warn { background: var(--warn-soft); color: var(--warn); border-color: var(--mango); }
.alert--err { background: var(--crit-soft); color: var(--crit); border-color: var(--guacamaya); }
.alert--info { background: var(--info-soft); color: var(--info); border-color: var(--cielo); }

/* Tarjeta de animal (vitrina, listas) */
.pet { min-width: 0; background: var(--surface); border-radius: 22px; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .2s var(--ease-out), box-shadow .2s ease; }
.pet__img { aspect-ratio: 4/3; object-fit: cover; width: 100%; background: var(--surface-2); outline: 1px solid rgba(15,17,71,.08); outline-offset: -1px; }
.pet__body { padding: 14px 16px 16px; display: grid; gap: 6px; flex: 1; }
.pet__name { font-weight: 700; font-size: 1.12rem; color: var(--anil-deep); }
.pet__meta { font-size: .88rem; color: var(--ink-2); }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery img { aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); }

/* Lista de definición (fichas) */
.dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0; }
.dl dt { color: var(--ink-2); font-weight: 600; font-size: .9rem; }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* Línea de tiempo: curva de nivel con hitos */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 18px 20px; }
.timeline li::before { content: ''; position: absolute; left: -8px; top: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--anil); }
.timeline li:first-child::before { background: var(--mango); }

/* Vacío */
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); background-image: var(--contour); background-position: center; border-radius: var(--radius); }

/* Accesibilidad: saltar al contenido */
.skip { position: fixed; left: 8px; top: -60px; z-index: 100; background: var(--mango); color: var(--tinta); padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700; }
.skip:focus { top: 8px; color: var(--tinta); }

/* Esqueletos de carga: las imágenes muestran un brillo hasta que cargan (app.js quita .is-loading) */
.skel, img.is-loading { background: linear-gradient(90deg, var(--surface-2) 25%, #F6F7FE 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skel 1.3s ease infinite; }
.skel-line { height: 12px; border-radius: var(--radius-xs); margin: 8px 0; }
.skel-line--short { width: 55%; }
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Indicador de navegación lenta (red móvil): barra superior mientras carga la siguiente página */
.navprogress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--guacamaya); z-index: 200; transition: width 8s cubic-bezier(.1,.7,.2,1); }
.navprogress.is-on { width: 85%; }

/* Paginación */
.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 20px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); text-decoration: none; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; transition: background-color .15s ease; }
.pager [aria-current="page"] { background: var(--anil); color: #fff; }

/* Transición entre vistas: el riel queda quieto y el marcador activo viaja */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  .rail { view-transition-name: rail; }
  .topbar { view-transition-name: topbar; }
  ::view-transition-group(*) { animation-duration: .22s; animation-timing-function: var(--ease-out); }
  ::view-transition-old(root) { animation: .12s ease-out both vt-out; }
  ::view-transition-new(root) { animation: .2s var(--ease-out) both vt-in; }
  ::view-transition-old(rail), ::view-transition-new(rail), ::view-transition-old(topbar), ::view-transition-new(topbar), ::view-transition-old(dock), ::view-transition-new(dock) { animation: none; mix-blend-mode: normal; }
  ::view-transition-old(rail), ::view-transition-old(topbar), ::view-transition-old(dock) { display: none; }
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }
}
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after, ::backdrop { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  .skel, img.is-loading { animation: none; }
}

/* Impresión (carnet, actas) */
@media print {
  .topbar, .rail, .dock, .sheet, .cmdk, .navprogress, .foot, .no-print, .btn { display: none !important; }
  body, .has-rail { background: #fff; padding: 0 !important; display: block; }
  .main, .has-rail .main { padding: 0; max-width: none; }
  .card, .stat, .pet, .tablewrap { box-shadow: none; border: 1px solid #ccc; }
}
