/* ============================================================
   Grupo Dimar - componentes compartidos (ADR-020)
   Los valores viven en assets/css/tokens.css.
   Solo se animan transform y opacity; las micro-transiciones de
   color/fondo/borde duran <=150 ms y se desactivan con reduced-motion.
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1200px; margin: 0 auto; }

h1, h2, h3 { color: var(--color-text); line-height: var(--leading-tight); margin-bottom: var(--space-4); }
h1 { font-size: var(--text-xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
h3 { font-size: var(--text-md); font-weight: var(--weight-semibold); }

.ag-main h2, .section-card h2 { position: relative; padding-left: var(--space-3); }
.ag-main h2::before, .section-card h2::before {
  content: ''; position: absolute; left: 0; top: 50%; width: 3px; height: 16px;
  border-radius: 2px; background: var(--champan-500); transform: translateY(-50%);
}

a { color: var(--color-brand-text); }

:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* ---------- Iconos ---------- */
.ag-icon {
  width: var(--icon-md); height: var(--icon-md); flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: middle;
}
.ag-icon--sm { width: var(--icon-sm); height: var(--icon-sm); }
.ag-icon--lg { width: var(--icon-lg); height: var(--icon-lg); }

/* ---------- Skip-link ---------- */
.ag-skip {
  position: fixed; top: 8px; left: 8px; z-index: calc(var(--z-header) + 1);
  padding: var(--space-3) var(--space-4); background: var(--color-surface); color: var(--color-brand-text);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-2);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); text-decoration: none;
  transform: translateY(-150%);
}
.ag-skip:focus { transform: translateY(0); }
html.theme-ready .ag-skip { transition: transform var(--dur-fast) var(--ease-standard); }
.ag-main:focus { outline: none; }

/* ---------- Shell ---------- */
.ag-shell { display: block; }
.ag-main { display: block; min-width: 0; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-6) var(--gutter); }
.ag-shell--single .ag-main { max-width: 1120px; }

/* ---------- Cabecera ---------- */
.ag-header, .topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  column-gap: var(--space-4); padding: 0 var(--gutter); margin: 0;
  background: var(--color-surface); border-bottom: 1px solid var(--color-border);
  position: relative; z-index: var(--z-header);
}
.ag-brand { display: flex; align-items: center; gap: var(--space-3); min-height: var(--header-h); order: 1; }
.ag-brand__logo { height: 40px; aspect-ratio: 969 / 424; width: auto; flex: none; color: var(--color-logo); display: block; }
.ag-brand__title { font-size: var(--text-md); font-weight: var(--weight-bold); margin: 0; letter-spacing: 0; }
.ag-brand__prefix {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.ag-header__actions { display: flex; align-items: center; gap: var(--space-2); order: 2; margin-left: auto; }
.nav-links {
  display: flex; align-items: center; gap: var(--space-1); order: 3; flex: 1 0 100%;
  min-height: 44px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
  margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter);
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-link {
  display: inline-flex; align-items: center; flex: none; white-space: nowrap; scroll-snap-align: start;
  min-height: 40px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-pill);
  color: var(--color-text-muted); text-decoration: none; font-size: var(--text-sm); font-weight: var(--weight-medium);
}
.nav-link[hidden] { display: none; }
.nav-link.active, .nav-link[aria-current="page"] {
  background: var(--color-brand-soft); color: var(--color-brand-text); font-weight: var(--weight-semibold);
}
.nav-link:active { transform: translateY(1px); background: var(--color-hover); }
@media (pointer: coarse) { .nav-link { min-height: var(--touch-min); } }
html.theme-ready .nav-link { transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) {
  .nav-link:hover { background: var(--color-hover); color: var(--color-text); }
  .nav-link.active:hover, .nav-link[aria-current="page"]:hover { color: var(--color-brand-text); }
}

#btn-dark-toggle {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  width: var(--touch-min); height: var(--touch-min); min-height: var(--touch-min); flex: 0 0 var(--touch-min); padding: 0; margin: 0;
  background: transparent; border: 0; border-radius: var(--radius-md); color: var(--color-text-muted);
  font-size: var(--text-md); line-height: 1;
}
@media (pointer: coarse) { a.compras-ver-detalle { display: inline-flex; align-items: center; min-height: var(--touch-min); } }
#btn-dark-toggle:active { background: var(--color-hover); color: var(--color-text); }
@media (hover: hover) and (pointer: fine) {
  #btn-dark-toggle:hover { background: var(--color-hover); color: var(--color-text); }
}

@media (max-width: 639px) {
  #btn-logout { width: var(--touch-min); min-width: var(--touch-min); padding: 0; gap: 0; }
  .ag-btn__label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
}

@media (min-width: 768px) {
  .ag-header, .topbar {
    position: sticky; top: 0; flex-wrap: nowrap; min-height: var(--header-h);
    background: var(--glass-bg); -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
  }
  .ag-brand__prefix { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; white-space: normal; }
  .ag-brand__title { font-size: var(--text-lg); }
  .nav-links { order: 2; flex: 0 1 auto; min-height: 0; margin: 0 0 0 var(--space-6); padding: 0; overflow: visible; }
  .ag-header__actions { order: 3; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ag-header, .topbar { background: var(--color-surface); }
}
@media (prefers-reduced-transparency: reduce) {
  .ag-header, .topbar { background: var(--color-surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (min-width: 1024px) {
  .ag-brand__logo { height: 36px; }
}

/* ---------- Botones ---------- */
button, .btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: var(--space-2) var(--space-5); margin-right: var(--space-1);
  border: 1px solid transparent; border-radius: var(--radius-md);
  background: var(--color-brand); color: var(--color-on-brand);
  font-family: inherit; font-size: var(--text-md); font-weight: var(--weight-semibold); line-height: 1.2;
  cursor: pointer;
}
@media (pointer: coarse) { button, .btn-primary { min-height: var(--touch-min); } }
button:active { transform: translateY(1px); background: var(--color-brand-hover); }
html.theme-ready button { transition: background-color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) { button:hover { background: var(--color-brand-hover); } }
button:disabled, button[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
@media (hover: hover) and (pointer: fine) { button:disabled:hover { background: var(--color-brand); } }

.btn-secondary, #btn-logout, #confirm-cancel, #btn-descargar-csv {
  background: transparent; border-color: var(--color-border-strong); color: var(--color-brand-text);
}
.btn-secondary:active, #btn-logout:active, #confirm-cancel:active, #btn-descargar-csv:active { background: var(--color-hover); }
@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover, #btn-logout:hover, #confirm-cancel:hover, #btn-descargar-csv:hover { background: var(--color-hover); }
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--color-brand-text); }
.btn-ghost:active { background: var(--color-hover); }
@media (hover: hover) and (pointer: fine) { .btn-ghost:hover { background: var(--color-hover); } }
.btn-danger { background: var(--color-danger-solid); color: var(--color-on-danger-solid); }
.btn-danger:active { background: var(--color-danger-solid); filter: brightness(0.92); }
@media (hover: hover) and (pointer: fine) { .btn-danger:hover { background: var(--color-danger-solid); filter: brightness(0.92); } }

button[aria-busy="true"]::before {
  content: ''; width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: ag-spin 800ms linear infinite;
}
@keyframes ag-spin { to { transform: rotate(360deg); } }

/* ---------- Formularios ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="color"]),
select, textarea {
  min-height: var(--touch-min); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text);
  font-family: inherit; font-size: 16px; line-height: 1.3;
}
select[multiple] { min-height: 0; }
.filtro-etiqueta { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
input::placeholder, textarea::placeholder { color: var(--color-text-subtle); opacity: 1; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--color-brand-text); }
html.theme-ready input, html.theme-ready select, html.theme-ready textarea { transition: border-color var(--dur-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) {
  input:hover, select:hover, textarea:hover { border-color: var(--color-text-muted); }
}
input:focus, select:focus, textarea:focus { border-color: var(--color-focus); }
input[type="date"]:focus-within { outline: 2px solid var(--color-focus); outline-offset: 2px; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; background: var(--color-sunken); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--color-danger); }
label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }

#form-container { background: var(--color-surface); padding: var(--space-5); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); margin-bottom: var(--space-5); border: 1px solid var(--color-border); }
#form-container label { display: block; margin-bottom: var(--space-3); color: var(--color-text); }
#form-container input[type="text"], #form-container input[type="url"], #form-container input[type="number"] { width: 100%; margin-top: var(--space-1); }
#form-container input[type="checkbox"] { margin-left: var(--space-1); }
#btn-nuevo { margin-bottom: var(--space-5); }

.filtros-row {
  display: grid; grid-template-columns: 1fr; gap: var(--space-4); align-items: end; margin-bottom: var(--space-6); padding: var(--space-5);
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); border: 1px solid var(--color-border);
}
.filtros-row label, .filtros-row .filtro-campo { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-text); }
.filtros-row input, .filtros-row select { width: 100%; }
.filtros-row button { margin: 0; width: 100%; white-space: nowrap; }
@media (min-width: 768px) { .filtros-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .filtros-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); } .filtros-row button { width: auto; } .filtros-row > :first-child { grid-column: span 2; } }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
}
.table-wrap:focus-visible { outline-offset: -2px; }
table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--color-border); }
.table-wrap table { border: 0; border-radius: 0; }
th, td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--color-border); font-size: var(--text-sm); color: var(--color-text); font-variant-numeric: tabular-nums; }
th { background: var(--color-sunken); font-weight: var(--weight-semibold); color: var(--color-text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-caps); }
tbody tr:last-child td { border-bottom: 0; }
html.theme-ready tbody tr { transition: background-color var(--dur-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) { tbody tr:hover { background: var(--color-hover); } }

/* Cabeceras de tabla fijas (inmovilizar fila): el contenedor con scroll es .table-wrap (o .mp-tabla-envoltorio); ver docs/cabeceras_tabla_sticky.md */
.table-wrap, .mp-tabla-envoltorio {
  overflow: auto;
  max-height: max(20rem, calc(100vh - var(--header-h) - 48px - var(--space-8)));
  max-height: max(20rem, calc(100dvh - var(--header-h) - 48px - var(--space-8)));
}
.table-wrap table, .mp-tabla-envoltorio table { border-collapse: separate; border-spacing: 0; overflow: visible; }
.table-wrap thead th, .mp-tabla-envoltorio thead th { position: sticky; top: 0; z-index: 2; background-color: var(--color-sunken); }
.mp-tabla-envoltorio thead tr:first-child th:first-child { border-top-left-radius: var(--radius-lg); }
.mp-tabla-envoltorio thead tr:first-child th:last-child { border-top-right-radius: var(--radius-lg); }
@media (max-width: 768px) {
  .table-wrap:has(.compras-locales-resumen, .compras-margen-tabla) { max-height: none; overflow-x: auto; overflow-y: visible; }
  .compras-locales-resumen thead th, .compras-margen-tabla thead th { position: static; }
}

/* ---------- Navegacion por pestanas ---------- */
.ag-nav { position: sticky; top: 0; z-index: var(--z-nav); background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.tabs {
  display: flex; gap: var(--space-1); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; padding: 0 var(--gutter);
  background:
    linear-gradient(to right, var(--color-surface) 30%, transparent) left center / 24px 100% no-repeat local,
    linear-gradient(to left, var(--color-surface) 30%, transparent) right center / 24px 100% no-repeat local,
    linear-gradient(to right, var(--color-border), transparent) left center / 12px 100% no-repeat scroll,
    linear-gradient(to left, var(--color-border), transparent) right center / 12px 100% no-repeat scroll;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex; align-items: center; gap: var(--space-2); flex: 0 0 auto; position: relative;
  min-height: 48px; padding: 0 var(--space-4); margin: 0; white-space: nowrap; scroll-snap-align: center;
  background: transparent; color: var(--color-text-muted); border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  font-size: var(--text-md); font-weight: var(--weight-medium);
}
.tab-btn:active { transform: translateY(1px); background: var(--color-hover); }
.tab-btn:focus-visible { outline-offset: -2px; }
.tab-btn.active { color: var(--color-brand-text); font-weight: var(--weight-semibold); border-bottom-color: var(--color-brand-text); background: transparent; }
html.theme-ready .tab-btn { transition: background-color var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard); }
@media (hover: hover) and (pointer: fine) {
  .tab-btn:hover { background: var(--color-hover); color: var(--color-text); }
  .tab-btn.active:hover { color: var(--color-brand-text); background: var(--color-hover); }
}
@media (min-width: 768px) { .ag-nav { top: var(--header-h); } }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: ag-panel-in var(--dur-base) var(--ease-out) both; }
@keyframes ag-panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (min-width: 1024px) {
  .ag-shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-areas: "header header" "nav main"; align-items: start; }
  .ag-shell > .ag-header, .ag-shell > .topbar { grid-area: header; }
  .ag-shell > .ag-nav {
    grid-area: nav; align-self: stretch; position: relative; top: auto; height: auto; min-height: calc(100vh - var(--header-h)); min-height: calc(100dvh - var(--header-h));
    overflow: visible; border-bottom: 0; border-right: 1px solid var(--color-border); padding: var(--space-4) var(--space-3);
  }
  .ag-shell > .ag-nav .tabs {
    position: sticky; top: calc(var(--header-h) + var(--space-4)); flex-direction: column; padding: 0; background: none; scroll-snap-type: none; gap: var(--space-1);
    max-height: calc(100vh - var(--header-h) - var(--space-8)); max-height: calc(100dvh - var(--header-h) - var(--space-8)); overflow-x: hidden; overflow-y: auto;
  }
  .ag-shell > .ag-nav .tab-btn { width: 100%; min-height: 44px; justify-content: flex-start; border-bottom: 0; border-radius: var(--radius-md); gap: var(--space-3); }
  .ag-shell > .ag-nav .tab-btn.active { background: var(--color-brand-soft); }
  .ag-shell > .ag-nav .tab-btn.active::before {
    content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--color-brand-text);
  }
  .ag-shell > .ag-main { grid-area: main; }
  .ag-shell--single { display: block; }
  .ag-shell--single > .ag-nav { position: sticky; top: var(--header-h); height: auto; min-height: 0; align-self: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--color-border); padding: 0; }
  .ag-shell--single > .ag-nav .tabs { position: static; max-height: none; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0 var(--gutter); }
  .ag-shell--single > .ag-nav .tab-btn { width: auto; border-bottom: 3px solid transparent; border-radius: 0; min-height: 48px; }
  .ag-shell--single > .ag-nav .tab-btn.active { background: transparent; border-bottom-color: var(--color-brand-text); }
  .ag-shell--single > .ag-nav .tab-btn.active::before { content: none; }
}

/* ---------- Tarjeta KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.kpi-row > .kpi-card { grid-column: span 12; }
@media (min-width: 560px) {
  .kpi-row > .kpi-card { grid-column: span 6; }
  .kpi-row > .kpi-card:last-child:nth-child(odd) { grid-column: span 12; }
}
/* Reparto sin tarjeta huerfana: 5 = 3+2, 4 = 2+2 (4 en fila desde 1280), 2 = 2, 3 = 3, 6 = 3+3. */
@media (min-width: 768px) {
  .kpi-row > .kpi-card, .kpi-row > .kpi-card:last-child:nth-child(odd) { grid-column: span 4; }
  .kpi-row:has(> .kpi-card:nth-child(5):last-child) > .kpi-card:nth-child(n+4),
  .kpi-row:has(> .kpi-card:nth-child(4):last-child) > .kpi-card,
  .kpi-row:has(> .kpi-card:nth-child(2):last-child) > .kpi-card { grid-column: span 6; }
}
@media (min-width: 1280px) {
  .kpi-row:has(> .kpi-card:nth-child(4):last-child) > .kpi-card { grid-column: span 3; }
}
.kpi-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); min-width: 0;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-1); text-align: left; container-type: inline-size;
}
.kpi-card::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none;
}
.kpi-card .kpi-icon {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none;
  border-radius: var(--radius-md); background: var(--color-brand-soft); color: var(--color-brand-text);
}
.kpi-card .label { font-size: var(--text-label); font-weight: var(--weight-medium); color: var(--color-text-muted); line-height: var(--leading-snug); }
.kpi-card .value {
  display: block; max-width: 100%; font-size: clamp(1.375rem, 11cqw, var(--text-kpi)); font-weight: var(--weight-bold); line-height: var(--leading-tight);
  color: var(--color-text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.kpi-card:active { background: var(--color-surface-2); }
@media (hover: hover) and (pointer: fine) {
  html.theme-ready .kpi-card { transition: transform var(--dur-fast) var(--ease-standard); }
  html.theme-ready .kpi-card::after { transition: opacity var(--dur-fast) var(--ease-standard); }
  .kpi-card:hover { transform: translateY(-2px); }
  .kpi-card:hover::after { opacity: 1; }
}

#locales-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-5); }
.local-card { background: var(--color-surface); border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow-1); border: 1px solid var(--color-border); }
.local-card h3 { margin-bottom: var(--space-3); }
.local-card p { margin: var(--space-1) 0; color: var(--color-text-muted); font-size: var(--text-sm); }
.sync-status { font-size: var(--text-xs); color: var(--color-text-muted); }

.section-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-6); box-shadow: var(--shadow-1); }
@media (min-width: 640px) { .section-card { padding: var(--space-6); } }

/* ---------- Badges ---------- */
.badge, .sem-badge {
  display: inline-block; padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: var(--weight-semibold); border: 1px solid transparent;
}

/* ---------- Alertas ---------- */
.error, #error-msg, #login-error {
  color: var(--color-danger); background: var(--color-danger-bg); border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); font-size: var(--text-sm); line-height: var(--leading-snug);
}
.aviso-coste, .sin-datos-horarios, .clima-sin-datos {
  background: var(--color-warning-bg); border: 1px solid var(--color-warning-border); color: var(--color-warning);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); margin-top: var(--space-3); font-size: var(--text-sm); line-height: var(--leading-normal);
}
.clima-sin-datos { background: var(--color-info-bg); border-color: var(--color-info-border); color: var(--color-info); }

/* ---------- Toast ---------- */
#toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-2); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3); min-width: 240px; max-width: 380px;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); border-left: 4px solid var(--color-info-solid);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: var(--leading-snug); box-shadow: var(--shadow-3);
  opacity: 0; transform: translateY(8px); pointer-events: auto;
  transition: opacity var(--dur-fast) var(--ease-in);
}
.toast::before {
  content: 'i'; display: inline-flex; align-items: center; justify-content: center; flex: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--color-info-solid); color: var(--color-on-info-solid); font-size: var(--text-xs); font-weight: var(--weight-bold); line-height: 1;
}
.toast.show { opacity: 1; transform: translateY(0); transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out); }
.toast.toast-success { border-left-color: var(--color-success-solid); }
.toast.toast-success::before { content: '\2713'; background: var(--color-success-solid); color: var(--color-on-success-solid); }
.toast.toast-error { border-left-color: var(--color-danger-solid); }
.toast.toast-error::before { content: '\2715'; background: var(--color-danger-solid); color: var(--color-on-danger-solid); }
.toast.toast-info { border-left-color: var(--color-info-solid); }
.toast.show::before { animation: ag-pop var(--dur-base) var(--ease-pop) both; }
@keyframes ag-pop { from { transform: scale(0.6); } to { transform: scale(1); } }

/* ---------- Modal de confirmacion ---------- */
#confirm-overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay); display: none; align-items: center; justify-content: center;
  background: var(--color-overlay);
}
@supports ((backdrop-filter: blur(4px)) or (-webkit-backdrop-filter: blur(4px))) {
  #confirm-overlay { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
}
@media (prefers-reduced-transparency: reduce) { #confirm-overlay { -webkit-backdrop-filter: none; backdrop-filter: none; } }
#confirm-overlay.show { display: flex; animation: ag-fade var(--dur-fast) var(--ease-out) both; }
#confirm-box {
  background: var(--color-surface); border-radius: var(--radius-xl); padding: var(--space-6); max-width: 420px;
  width: calc(100% - 2 * var(--gutter)); box-shadow: var(--shadow-3); border: 1px solid var(--color-border);
}
#confirm-overlay.show #confirm-box { animation: ag-rise var(--dur-base) var(--ease-out) both; }
#confirm-msg { font-size: var(--text-md); color: var(--color-text); margin-bottom: var(--space-5); line-height: var(--leading-normal); }
#confirm-buttons { display: flex; gap: var(--space-3); justify-content: flex-end; }
#confirm-buttons button { margin: 0; }
@media (max-width: 639px) {
  #confirm-buttons { flex-direction: column-reverse; }
  #confirm-buttons button { width: 100%; }
  #toast-container { bottom: var(--space-3); left: var(--gutter); right: var(--gutter); }
  .toast { min-width: 0; max-width: 100%; }
}
@keyframes ag-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ag-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Estado vacio ---------- */
tbody > tr > td[colspan]:only-child {
  text-align: center; color: var(--color-text-muted); font-size: var(--text-sm); padding: var(--space-8) var(--space-4);
}
tbody > tr > td[colspan]:only-child::before {
  content: ''; display: block; width: 32px; height: 32px; margin: 0 auto var(--space-3);
  background: var(--color-text-subtle);
  -webkit-mask: url(/assets/icons/empty-inbox.svg) center / contain no-repeat; mask: url(/assets/icons/empty-inbox.svg) center / contain no-repeat;
}
@media (hover: hover) and (pointer: fine) { tbody tr:has(> td[colspan]:only-child):hover { background: transparent; } }

/* ---------- Esqueletos (aria-busy) ---------- */
[aria-busy="true"] .kpi-card .value,
[aria-busy="true"] .compras-ahorro-valor,
[aria-busy="true"] .clima-corr-card .value {
  position: relative; display: block; width: 60%; min-height: 1em; overflow: hidden; color: transparent;
  background: var(--color-sunken); border-radius: var(--radius-sm); user-select: none;
}
[aria-busy="true"] .kpi-card .value::after,
[aria-busy="true"] .compras-ahorro-valor::after,
[aria-busy="true"] .clima-corr-card .value::after,
[aria-busy="true"] .heatmap-wrap::after,
[aria-busy="true"] .clima-chart-wrap::after,
[aria-busy="true"] [id$="-apexchart"]::after,
[aria-busy="true"] td[colspan]:only-child::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--color-hover), transparent);
  transform: translateX(-100%); animation: ag-shimmer var(--shimmer-dur) linear infinite;
}
@keyframes ag-shimmer { to { transform: translateX(100%); } }
[aria-busy="true"] .heatmap-wrap,
[aria-busy="true"] .clima-chart-wrap,
[aria-busy="true"] [id$="-apexchart"] {
  position: relative; overflow: hidden; min-height: 260px; background: var(--color-sunken); border-radius: var(--radius-lg);
}
[aria-busy="true"] .heatmap-wrap > *,
[aria-busy="true"] .clima-chart-wrap > *,
[aria-busy="true"] [id$="-apexchart"] > * { visibility: hidden; }
@media (min-width: 768px) {
  [aria-busy="true"] .heatmap-wrap, [aria-busy="true"] .clima-chart-wrap, [aria-busy="true"] [id$="-apexchart"] { min-height: 320px; }
}
[aria-busy="true"] tbody > tr > td[colspan]:only-child { position: relative; overflow: hidden; color: transparent; }
[aria-busy="true"] tbody > tr > td[colspan]:only-child::before {
  height: 12px; width: 60%; border-radius: var(--radius-sm); background: var(--color-sunken);
  -webkit-mask: none; mask: none; margin-bottom: 0;
}

/* ---------- Varios ---------- */
.ag-empty { text-align: center; color: var(--color-text-muted); padding: var(--space-8) var(--space-4); }
.ag-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: var(--space-2); background: var(--color-text-subtle); vertical-align: middle; }
.ag-dot--ok { background: var(--color-success-solid); }
.ag-dot--warn { background: var(--color-warning-solid); }
.ag-dot--info { background: var(--color-info-solid); }
.ag-dot--off { background: var(--color-text-subtle); }
.ag-skeleton { position: relative; overflow: hidden; background: var(--color-sunken); border-radius: var(--radius-sm); min-height: 1em; }

/* ---------- Transiciones de tema ---------- */
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: none !important; }

/* ---------- Tooltips y leyendas de ApexCharts ---------- */
.apexcharts-tooltip { box-shadow: var(--shadow-2) !important; border-radius: var(--radius-md) !important; font-size: var(--text-sm) !important; }
.apexcharts-legend-text { font-size: var(--text-xs) !important; }
.apexcharts-text { font-family: var(--font-sans) !important; }
.apexcharts-xaxis-label, .apexcharts-yaxis-label, .apexcharts-xaxis-title-text, .apexcharts-yaxis-title-text { fill: var(--chart-axis-label) !important; }
.apexcharts-tooltip.apexcharts-theme-light, .apexcharts-tooltip.apexcharts-theme-dark {
  background: var(--chart-tooltip-bg) !important; color: var(--chart-tooltip-fg) !important; border: 0 !important;
}
.apexcharts-tooltip.apexcharts-theme-light .apexcharts-tooltip-title, .apexcharts-tooltip.apexcharts-theme-dark .apexcharts-tooltip-title {
  background: transparent !important; color: var(--chart-tooltip-fg) !important; border-bottom: 1px solid var(--chart-grid) !important;
}
.apexcharts-xaxistooltip, .apexcharts-yaxistooltip {
  background: var(--chart-tooltip-bg) !important; color: var(--chart-tooltip-fg) !important; border-color: var(--chart-grid) !important;
}
.apexcharts-legend-text { color: var(--color-text-muted) !important; }

/* ---------- Detalle desplegable (compras) ---------- */
.compras-detalle > summary, .compras-umbrales > summary { min-height: var(--touch-min); }

/* ---------- Responsive heredado ---------- */
@media (max-width: 768px) {
  .user-form-row { flex-direction: column; align-items: stretch; }
  .filtros-row label { width: 100%; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
  [aria-busy="true"] .kpi-card .value::after, [aria-busy="true"] .compras-ahorro-valor::after, [aria-busy="true"] .clima-corr-card .value::after,
  [aria-busy="true"] .heatmap-wrap::after, [aria-busy="true"] .clima-chart-wrap::after, [aria-busy="true"] [id$="-apexchart"]::after,
  [aria-busy="true"] td[colspan]:only-child::after { animation: none !important; transform: none; opacity: 0; }
  .hev-dot { animation: none !important; }
  .toast { transform: none; }
  .ag-skip { transform: none; opacity: 0; }
  .ag-skip:focus { opacity: 1; }
  button[aria-busy="true"]::before { animation: none !important; border-style: dotted; border-right-color: currentColor; }
}

/* ---------- Impresion ---------- */
@media print {
  :root, [data-theme="dark"] {
    color-scheme: light;
    --color-bg: #ffffff; --color-surface: #ffffff; --color-surface-2: #ffffff; --color-sunken: #efeae3; --color-hover: #f0ebe6;
    --color-border: #e4ddd3; --color-border-strong: #8c8276; --color-text: #26211c; --color-text-muted: #655c52; --color-text-subtle: #766c60;
    --color-brand-text: #7a6149; --color-logo: #6c5741; --color-brand-soft: #f0ebe6;
    --shadow-1: none; --shadow-2: none; --shadow-3: none;
  }
  body { background: #fff; color: #26211c; min-height: 0; }
  .ag-nav, .nav-links, .ag-header__actions, #filtros-grupo, #toast-container, #confirm-overlay, .ag-skip { display: none !important; }
  .ag-shell { display: block; }
  .ag-header, .topbar { position: static; background: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; border-bottom: 1px solid #e4ddd3; }
  .ag-brand__prefix { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; white-space: normal; }
  .ag-brand__logo { color: var(--champan-800); }
  .ag-main { max-width: none; padding: var(--space-4) 0; }
  *, *::before, *::after { box-shadow: none !important; animation: none !important; transition: none !important; }
  .kpi-card, .table-wrap, tr, .local-card, .section-card { break-inside: avoid; }
  .table-wrap, .mp-tabla-envoltorio { max-height: none; overflow: visible; }
  .table-wrap thead th, .mp-tabla-envoltorio thead th { position: static; }
  .kpi-card::after { display: none; }
  .apexcharts-canvas { max-width: 100% !important; }
}
