/* Base y layout de la aplicación. */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

.skip-link {
  position: absolute; left: var(--s-4); top: -60px; z-index: 100;
  background: var(--ink-900); color: #fff; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
}
.skip-link:focus { top: var(--s-4); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Shell: menú lateral + cabecera + contenido ---------- */
.shell { min-height: 100%; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--ink-900); color: var(--text-on-ink);
  display: flex; flex-direction: column; padding: var(--s-5) var(--s-4); gap: var(--s-5);
}
/* Marca: el logo oficial se muestra sin recolorear, sobre una placa blanca. */
.brand-plate { display: block; background: #fff; border-radius: var(--r-md); padding: 10px 14px; text-decoration: none; }
.brand-plate img { display: block; width: 100%; height: auto; max-width: 180px; margin: 0 auto; }
.brand-plate--login { display: inline-block; padding: 14px 20px; }
.brand-plate--login img { max-width: 220px; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center;
}
.brand__sub { font-size: var(--fs-xs); color: var(--text-on-ink-muted); }
.brand__sub--block { margin-top: calc(var(--s-3) * -1); padding: 0 var(--s-2); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__group { margin-top: var(--s-4); }
.nav__title { font-size: var(--fs-xs); color: var(--text-on-ink-muted); padding: 0 var(--s-3) var(--s-2); }
.nav__link {
  display: flex; align-items: center; gap: var(--s-3); padding: 8px var(--s-3);
  border-radius: var(--r-sm); color: var(--text-on-ink); text-decoration: none; font-size: var(--fs-sm);
  transition: background-color 0.15s ease;
}
.nav__link:hover { background: rgba(255, 255, 255, 0.07); }
.nav__link[aria-current="page"] { background: rgba(255, 255, 255, 0.12); color: #fff; box-shadow: inset 3px 0 0 #7db8e8; }
.nav__link .icon { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav__link--sub { padding-left: 38px; font-size: var(--fs-sm); color: var(--text-on-ink-muted); }
.nav__link--sub[aria-current="page"] { color: #fff; }

.sidebar__foot { margin-top: auto; font-size: var(--fs-xs); color: var(--text-on-ink-muted); padding: 0 var(--s-3); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  background: rgba(245, 247, 250, 0.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s-4); padding: 0 var(--gutter);
}
.topbar__crumb { font-size: var(--fs-sm); color: var(--text-muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--s-2); position: relative; }
.topbar__mobile-brand { display: none; }

.demo-banner {
  background: var(--signal-soft); color: #7a4310; border-bottom: 1px solid #efd4b2;
  font-size: var(--fs-sm); padding: 6px var(--gutter);
}
.demo-banner strong { font-weight: 600; }

.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-6) var(--gutter) var(--s-7); }
.content > * + * { margin-top: var(--s-5); }

/* ---------- Navegación móvil ---------- */
.bottom-nav { display: none; }

@media (max-width: 880px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar__mobile-brand { display: flex; align-items: center; gap: var(--s-2); }
  .topbar__crumb { display: none; }
  .content { padding-bottom: 96px; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--ink-900);
    display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    background: none; border: 0; color: var(--text-on-ink-muted); text-decoration: none;
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; border-radius: var(--r-sm);
  }
  .bottom-nav [aria-current="page"] { color: #fff; }
  .bottom-nav .icon { width: 20px; height: 20px; }
}

/* ---------- Encabezado de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.page-head__title { font-family: var(--font-display); font-size: var(--fs-2xl); line-height: 1.1; font-weight: 500; letter-spacing: -0.02em; }
.page-head__lede { color: var(--text-muted); margin-top: var(--s-2); max-width: 62ch; }
.page-head__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* Franja KPI: filetes verticales en lugar de tarjetas */
.kpi-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.kpi { padding: var(--s-5); min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--line); }
.kpi__label { font-size: var(--fs-sm); color: var(--text-muted); }
.kpi__value { font-family: var(--font-display); font-size: var(--fs-kpi); line-height: 1.1; margin-top: var(--s-2); font-weight: 500; }
.kpi__delta { font-size: var(--fs-sm); margin-top: var(--s-2); color: var(--text-muted); }
.kpi__delta--up { color: var(--positive); }
.kpi__delta--down { color: var(--negative); }
.kpi__delta--warn { color: var(--signal); }

@media (max-width: 1180px) {
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(odd) { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--line); }
}
@media (max-width: 880px) {
  .kpi { padding: var(--s-4); }
}

/* Dos columnas: gráfico principal + lectura lateral */
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--s-5); align-items: stretch; }
.split > * { min-width: 0; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-5); }
@media (max-width: 1180px) { .split { grid-template-columns: minmax(0, 1fr); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); min-width: 0; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
.panel__title { font-size: var(--fs-md); font-weight: 600; }
.panel__note { font-size: var(--fs-sm); color: var(--text-muted); }

/* Grid de módulos (selector visual) */
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s-4); }

/* Responsive helpers */
.hide-sm { display: initial; }
@media (max-width: 880px) { .hide-sm { display: none !important; } }

/* Cada panel y el contenido son contenedores: las tablas se adaptan al espacio real, no solo a la pantalla. */
.panel, .content { container-type: inline-size; }

/* Dos paneles iguales: en pantallas medianas se apilan; en monitores grandes van lado a lado. */
.split-even { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-5); align-items: start; }
.split-even > * { min-width: 0; }
@media (min-width: 1500px) { .split-even { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
