/* Componentes reutilizables. */

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-4); border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) { background: #f0f3f7; border-color: var(--ink-300); }
/* El ámbar identifica la acción principal. El resto de botones son neutros. */
.btn--primary { background: var(--action); border-color: var(--action); color: var(--ink-950); font-weight: 600; }
.btn--primary:hover:not(:disabled) { background: var(--action-hover); border-color: var(--action-hover); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover:not(:disabled) { background: rgba(6, 43, 75, 0.06); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn--block { width: 100%; }

/* Iconos */
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* Etiquetas */
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--s-2);
  border-radius: 999px; font-size: var(--fs-xs); font-weight: 500; background: var(--info-soft); color: var(--info);
  white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag--demo { background: var(--signal-soft); color: #7a4310; }
.tag--ok { background: var(--positive-soft); color: var(--positive); }
.tag--warn { background: var(--signal-soft); color: #8a4a12; }
.tag--bad { background: var(--negative-soft); color: var(--negative); }
.tag--neutral { background: #eef1f5; color: var(--ink-600); }

/* Formularios */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field__label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-800); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: var(--negative); }
.input, .select {
  height: 40px; width: 100%; padding: 0 var(--s-3); border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); font-size: var(--fs-sm);
}
.input:focus, .select:focus { outline: none; border-color: var(--info); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--negative); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* Barra de filtros */
.filters { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end; }
.filters .field { min-width: 160px; flex: 0 1 200px; }
.filters .field--search { flex: 1 1 260px; }
.filters .field__label { font-size: var(--fs-xs); color: var(--text-muted); }
.segmented {
  display: inline-flex; background: #eaeef3; border-radius: var(--r-sm); padding: 3px; gap: 2px; flex-wrap: wrap;
}
.segmented button {
  border: 0; background: transparent; height: 30px; padding: 0 var(--s-3); border-radius: 4px;
  font-size: var(--fs-sm); color: var(--ink-600);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(7, 22, 42, 0.12); }

/* Tablas. En pantallas angostas las filas pasan a tarjetas con etiqueta,
   así ninguna columna queda cortada. Las matrices anchas usan .table-wrap--scroll. */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 12px var(--s-4); text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td.num, .table th.num { white-space: nowrap; }
.table thead th { font-weight: 600; color: var(--ink-600); background: #f7f9fc; position: sticky; top: 0; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f9fbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .muted { color: var(--text-muted); }
.table-foot { padding: var(--s-3) var(--s-4); font-size: var(--fs-xs); color: var(--text-muted); border-top: 1px solid var(--line); }
.table-wrap--scroll .table { min-width: 560px; }
.table-wrap--scroll .table th, .table-wrap--scroll .table td { white-space: nowrap; }

@container (max-width: 560px) {
  .table-wrap:not(.table-wrap--scroll) { border: 0; background: transparent; overflow: visible; }
  .table-wrap:not(.table-wrap--scroll) .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap:not(.table-wrap--scroll) .table,
  .table-wrap:not(.table-wrap--scroll) .table tbody { display: grid; gap: var(--s-3); }
  .table-wrap:not(.table-wrap--scroll) .table tr {
    display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-2) 0;
  }
  .table-wrap:not(.table-wrap--scroll) .table td {
    display: grid; grid-template-columns: minmax(96px, 38%) minmax(0, 1fr); gap: var(--s-3); align-items: center;
    border-bottom: 0; padding: 8px var(--s-4); text-align: left;
  }
  .table-wrap:not(.table-wrap--scroll) .table td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--fs-xs); }
  .table-wrap:not(.table-wrap--scroll) .table td.num { text-align: left; }
  .table-wrap:not(.table-wrap--scroll) .table tbody tr:hover td { background: transparent; }
  .table-wrap:not(.table-wrap--scroll) .table-foot { border-top: 0; padding-inline: 0; }
}

/* Barras de progreso (cumplimiento) */
.meter { height: 6px; border-radius: 99px; background: #e8ecf1; overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; background: var(--positive); border-radius: inherit; }
.meter--warn > span { background: var(--signal); }
.meter--bad > span { background: var(--negative); }

/* Gráficos SVG */
.chart-host { width: 100%; min-width: 0; }
.chart { display: block; max-width: 100%; overflow: visible; }
.chart text { font-family: var(--font-ui); fill: var(--text-muted); font-size: 11px; }
.chart .grid line { stroke: #e7ebf0; }
.chart .axis-label { fill: var(--text-muted); }
.legend { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--ink-600); margin-top: var(--s-3); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 2px; }
.hbar { display: grid; gap: var(--s-3); }
.hbar__row { display: grid; grid-template-columns: minmax(110px, 1fr) 2fr auto; gap: var(--s-3); align-items: center; font-size: var(--fs-sm); }
.hbar__track { height: 10px; background: #e8ecf1; border-radius: 3px; overflow: hidden; }
.hbar__fill { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.hbar__value { font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }

/* Estados: vacío, carga, error, confirmación */
.state {
  display: grid; justify-items: start; gap: var(--s-2); padding: var(--s-6); border-radius: var(--r-md);
  border: 1px dashed var(--line-strong); background: var(--surface); color: var(--text-muted);
}
.state__title { color: var(--text); font-weight: 600; font-size: var(--fs-md); }
.state--error { border-style: solid; border-color: #f0c8c3; background: #fff8f7; }
.state--error .state__title { color: var(--negative); }
.state .btn { margin-top: var(--s-2); }

.skeleton {
  background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 37%, #eef1f5 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm); height: 14px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 60; display: grid; gap: var(--s-2); max-width: 360px; }
@media (max-width: 880px) { .toasts { left: var(--s-4); right: var(--s-4); bottom: 92px; max-width: none; } }
.toast {
  background: var(--ink-900); color: #fff; border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow-pop); font-size: var(--fs-sm); display: flex; gap: var(--s-3); align-items: flex-start;
  animation: toast-in 0.2s ease;
}
.toast--error { background: var(--negative); }
.toast small { display: block; opacity: 0.75; font-size: var(--fs-xs); margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Notificaciones y perfil */
.popover {
  position: absolute; top: calc(100% + 8px); right: 0; width: 340px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-pop); z-index: 40; overflow: hidden;
}
.popover__head { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); font-weight: 600; font-size: var(--fs-sm); display: flex; justify-content: space-between; }
.notif { display: grid; gap: 2px; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.notif:last-child { border-bottom: 0; }
.notif small { color: var(--text-muted); font-size: var(--fs-xs); }
.notif--unread { background: #fbfcfe; }
.menu-item { display: flex; width: 100%; gap: var(--s-2); align-items: center; padding: 10px var(--s-4); background: none; border: 0; text-align: left; font-size: var(--fs-sm); }
.menu-item:hover { background: #f3f6f9; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; position: relative;
}
.icon-btn:hover { background: #f3f6f9; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--ink-800); color: #fff;
  display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 600;
}

/* Módulos (selector) */
.module-card {
  display: grid; gap: var(--s-3); padding: var(--s-5); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); text-decoration: none; color: inherit; min-height: 168px; align-content: start;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.module-card:hover { border-color: var(--ink-300); box-shadow: 0 6px 18px rgba(7, 22, 42, 0.07); }
.module-card__icon { width: 40px; height: 40px; border-radius: var(--r-sm); background: var(--ink-900); color: #fff; display: grid; place-items: center; }
.module-card__title { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 500; }
.module-card__desc { font-size: var(--fs-sm); color: var(--text-muted); }
.module-card--locked { opacity: 0.55; border-style: dashed; cursor: not-allowed; }

/* Asistente */
.assistant-fab {
  position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 35; height: 52px; padding: 0 var(--s-5) 0 var(--s-4);
  border-radius: 999px; border: 0; background: var(--action); color: var(--ink-950); font-weight: 600; font-size: var(--fs-sm);
  display: inline-flex; align-items: center; gap: var(--s-2); box-shadow: 0 10px 24px rgba(201, 112, 28, 0.35);
}
.assistant-fab:hover { background: var(--action-hover); }
@media (max-width: 880px) { .assistant-fab { bottom: 92px; right: var(--s-4); } }

.assistant {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.22s ease;
}
.assistant[data-open="true"] { transform: none; }
.assistant__head { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--s-3); }
.assistant__body { flex: 1; overflow-y: auto; padding: var(--s-5); display: grid; align-content: start; gap: var(--s-4); }
.assistant__foot { border-top: 1px solid var(--line); padding: var(--s-4); display: grid; gap: var(--s-3); }
.bubble { max-width: 88%; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.5; }
.bubble--user { justify-self: end; background: var(--ink-900); color: #fff; border-bottom-right-radius: 3px; }
.bubble--assistant { justify-self: start; background: #f2f5f8; border-bottom-left-radius: 3px; }
.bubble small { display: block; margin-top: 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.suggestions button {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 6px var(--s-3);
  font-size: var(--fs-xs); color: var(--ink-800); text-align: left;
}
.suggestions button:hover { border-color: var(--ink-300); background: #f7f9fb; }
.assistant-scrim { position: fixed; inset: 0; background: rgba(7, 22, 42, 0.32); z-index: 45; }
@media (max-width: 880px) { .assistant { width: 100vw; top: auto; height: 88vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; transform: translateY(100%); } .assistant[data-open="true"] { transform: none; } }

/* Login */
.login {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
}
.login__art { background: var(--ink-900); color: var(--text-on-ink); padding: var(--s-7); display: flex; flex-direction: column; justify-content: space-between; gap: var(--s-6); }
.login__art h1 { font-family: var(--font-display); font-size: clamp(2rem, 3.6vw, 3rem); font-weight: 400; line-height: 1.1; max-width: 16ch; }
.login__art p { color: var(--text-on-ink-muted); max-width: 46ch; }
.login__panel { padding: var(--s-7) var(--s-6); display: flex; align-items: center; background: var(--surface); }
.login__form { width: 100%; max-width: 360px; margin: 0 auto; display: grid; gap: var(--s-4); }
.login__form h2 { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 500; }
.login__warning { font-size: var(--fs-sm); background: var(--signal-soft); color: #7a4310; border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); }
.login__roles { display: grid; gap: var(--s-2); }
@media (max-width: 880px) {
  .login { grid-template-columns: 1fr; }
  .login__art { padding: var(--s-6) var(--gutter); gap: var(--s-4); }
  .login__panel { padding: var(--s-6) var(--gutter); }
}

/* Mapas de calor y nodos de proceso (Logística) */
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.steps__item { padding: var(--s-4); border-left: 1px solid var(--line); min-width: 0; }
.steps__item:first-child { border-left: 0; }
.steps__count { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 500; }
.steps__label { font-size: var(--fs-sm); color: var(--text-muted); }
.steps__item--current { background: #f4f8fb; box-shadow: inset 0 -3px 0 var(--info); }
@media (max-width: 880px) { .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); } .steps__item:nth-child(3) { border-left: 0; } .steps__item:nth-child(n + 3) { border-top: 1px solid var(--line); } }

/* Lista de alertas */
.alerts { display: grid; gap: 0; }
.alert-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.alert-row:last-child { border-bottom: 0; }
.alert-row__mark { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--signal); }
.alert-row__mark--bad { background: var(--negative); }
.alert-row__mark--ok { background: var(--positive); }
.alert-row small { color: var(--text-muted); display: block; font-size: var(--fs-xs); }

.pending-note { font-size: var(--fs-xs); color: var(--text-muted); border: 1px dashed var(--line-strong); border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); }

/* Navegación por páginas del módulo (solo móvil; en PC va en el menú lateral) */
.chips { display: none; }
@media (max-width: 880px) {
  .chips { display: flex; gap: var(--s-2); overflow-x: auto; padding-bottom: var(--s-1); margin: 0 calc(var(--gutter) * -1); padding-inline: var(--gutter); scrollbar-width: none; }
  .chips a {
    flex: none; padding: 6px var(--s-3); border: 1px solid var(--line-strong); border-radius: 999px;
    font-size: var(--fs-sm); color: var(--ink-800); text-decoration: none; background: var(--surface);
  }
  .chips a[aria-current="page"] { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Patrones de dashboard reutilizables ---------- */

/* Filtros globales: período + selectores de dimensión */
.global-filters {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5); display: grid; gap: var(--s-3);
}
.global-filters__row { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: flex-end; }
.global-filters .field { min-width: 150px; flex: 1 1 150px; max-width: 220px; }
.global-filters .field__label { font-size: var(--fs-xs); color: var(--text-muted); }
.global-filters__status { font-size: var(--fs-xs); color: var(--text-muted); display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.period { display: grid; gap: 6px; }
.period .field__label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 500; }
@media (max-width: 720px) {
  .global-filters { padding: var(--s-4); }
  .global-filters .field { max-width: none; flex-basis: calc(50% - var(--s-4)); }
  .period .segmented { width: 100%; }
  .period .segmented button { flex: 1 1 auto; }
}

/* Espacio reservado para un dashboard futuro, con sus estados */
.slot { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); min-width: 0; display: grid; gap: var(--s-3); align-content: start; }
.slot__head { display: flex; justify-content: space-between; gap: var(--s-3); align-items: flex-start; flex-wrap: wrap; }
.slot__title { font-size: var(--fs-md); font-weight: 600; }
.slot__area { min-height: 160px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); display: grid; place-items: center; text-align: center; padding: var(--s-5); color: var(--text-muted); background: #fafbfd; }
.slot__area strong { display: block; color: var(--text); margin-bottom: 4px; }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s-5); }

/* Cumplimiento: texto + color, nunca solo color */
.compliance { display: inline-flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; max-width: 100%; }

/* Indicador pendiente (sin dato conectado) */
.kpi--pending .kpi__value { color: var(--ink-300); }

/* Guía de diseño */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-4); }
.swatch { display: grid; gap: 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.swatch__chip { height: 52px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.swatch strong { color: var(--text); font-size: var(--fs-sm); font-weight: 600; }

/* ---------- Orden por columna y tabla compacta ---------- */
.th-sort {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 0;
  font: inherit; font-weight: 600; color: inherit; cursor: pointer; border-radius: 4px;
}
.th-sort:hover { color: var(--text); }
.th-sort__icon { font-size: 10px; color: var(--ink-300); line-height: 1; }
.th-sort--active, .th-sort--active .th-sort__icon { color: var(--brand); }
.table .num .th-sort { flex-direction: row-reverse; }
.table-wrap--compact .table th, .table-wrap--compact .table td { padding-block: 8px; }
.table-wrap--compact .table { font-size: var(--fs-sm); }

/* Lectura rápida: cifras derivadas de los datos de demostración */
.metric-list { margin: 0; display: grid; gap: var(--s-4); }
.metric-list > div { display: grid; gap: 2px; padding-bottom: var(--s-4); border-bottom: 1px solid var(--line); }
.metric-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.metric-list dt { font-size: var(--fs-sm); color: var(--text-muted); }
.metric-list dd { margin: 0; font-family: var(--font-display); font-size: var(--fs-xl); line-height: 1.2; }
.metric-list dd span { font-family: var(--font-ui); font-size: var(--fs-sm); color: var(--text-muted); margin-left: 6px; }

/* ---------- Usuarios y permisos ---------- */
.module-note {
  font-size: var(--fs-sm); background: var(--signal-soft); color: #6f3d0e; border: 1px solid #efd4b2;
  border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
}
.module-note--ask { background: var(--info-soft); color: var(--ink-900); border-color: #c7dcf0; }
.link { color: var(--brand); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.rule { border: 0; border-top: 1px solid var(--line); margin: var(--s-5) 0; }

.check-list { border: 0; padding: 0; margin: 0; display: grid; gap: var(--s-2); min-width: 0; }
.check-list legend { margin-bottom: var(--s-2); padding: 0; }
.check-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-3); align-items: start;
  padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-sm); background: #fbfcfe; cursor: pointer;
}
.check-item:hover { border-color: var(--ink-300); }
.check-item input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--brand); }
.check-item strong { font-weight: 600; font-size: var(--fs-sm); display: block; }
.check-item small { color: var(--text-muted); font-size: var(--fs-xs); display: block; }
.check-list:disabled .check-item { opacity: 0.6; cursor: not-allowed; }

.scope-line { display: flex; gap: var(--s-3); align-items: flex-start; margin-bottom: var(--s-4); font-weight: 500; }
.scope-line .icon { color: var(--brand); margin-top: 2px; }

.perm-table th, .perm-table td { white-space: nowrap; }
.perm-table td.num { text-align: center; }
.perm-table th.num { text-align: center; }
.perm-table td.perm-pendiente { background: var(--warn-bg, #fff7e0); }
.perm-cambios { margin: 0 0 var(--s-3); padding-left: var(--s-4); }
.perm-cambios .perm-mas { color: var(--ok, #1b6e3c); }
.perm-cambios .perm-menos { color: var(--danger, #a12b2b); }
.perm-table input[type="checkbox"], .perm-compare input { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.perm-table input:disabled { cursor: not-allowed; opacity: 0.45; }
.perm-group th { background: #eef3f8; color: var(--ink-600); font-size: var(--fs-xs); text-align: left; position: static; }
.perm-module { font-weight: 500; text-align: left; background: transparent; position: static; color: var(--text); }
.perm-compare td.num { text-align: center; letter-spacing: 0.04em; font-weight: 500; }
.perm-compare th.num { text-align: center; }

.policy-list { margin: 0; display: grid; gap: var(--s-3); }
.policy-list > div { display: grid; grid-template-columns: minmax(130px, 38%) minmax(0, 1fr); gap: var(--s-3); padding-bottom: var(--s-3); border-bottom: 1px solid var(--line); }
.policy-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.policy-list dt { color: var(--text-muted); font-size: var(--fs-sm); }
.policy-list dd { margin: 0; font-weight: 500; }
@media (max-width: 560px) { .policy-list > div { grid-template-columns: 1fr; gap: 2px; } }

.steps-list { margin: 0 0 var(--s-4); padding-left: var(--s-5); display: grid; gap: var(--s-3); }
.steps-list li::marker { color: var(--brand); font-weight: 700; }

/* Navegación del módulo en pantallas medianas */
.table td a.btn { height: 32px; }

/* Tableros reales dentro del portal: el marco ocupa todo el alto restante de la pantalla; la ÚNICA barra de desplazamiento es la del propio
   tablero (así sus paneles fijos, tablas ampliadas y filtros se comportan como fueron diseñados). */
body:has(.tablero) { overflow: hidden; }
.shell:has(.tablero) .sidebar, .shell:has(.tablero) .main { height: calc(100dvh - var(--banner-h, 0px)); }
.shell:has(.tablero) .main { overflow: hidden; }
.content:has(.tablero) { display: flex; flex-direction: column; flex: 1; min-height: 0; max-width: none; margin: 0; padding: 0; }
.content:has(.tablero) > * + * { margin-top: 0; }
.content:has(.tablero) > .module-note { margin: var(--s-3) var(--gutter); }
.tablero { flex: 1; min-height: 0; display: flex; }
.tablero__marco { flex: 1; width: 100%; height: 100%; border: 0; display: block; background: var(--surface, #fff); }
@media (max-width: 880px) { .content:has(.tablero) { padding-bottom: 64px; } }

/* Submenú de Administración (Equipos comerciales / Usuarios y permisos) */
.nav__subtitle { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-on-ink-muted); padding: var(--s-3) var(--s-3) var(--s-1); }

/* ---------- OPA-IA: panel lateral (superposición: no reduce el espacio de los tableros) ---------- */
.opaia-launcher, .opaia-burbuja {
  display: inline-flex; align-items: center; gap: var(--s-2); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-900); font: 600 var(--fs-sm) var(--font-ui); border-radius: 999px; cursor: pointer;
}
.opaia-launcher { height: 40px; padding: 0 var(--s-3) 0 4px; }
.opaia-launcher:hover, .opaia-burbuja:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(0, 86, 155, 0.18); }
.opaia-launcher img { width: 32px; height: 32px; border-radius: 50%; }
.opaia-burbuja { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 49; height: 56px; padding: 0 var(--s-4) 0 6px; box-shadow: var(--shadow-pop); }
.opaia-burbuja[hidden] { display: none; }
.opaia-burbuja img { width: 44px; height: 44px; border-radius: 50%; }
.opaia {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); z-index: 50; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop);
  transform: translateX(105%); transition: transform 0.22s ease;
}
.opaia[data-estado="abierto"] { transform: none; }
.opaia__head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5); background: var(--ink-900); color: #fff; }
.opaia__avatar { width: 48px; height: 48px; border-radius: 50%; background: #fff; flex: none; }
.opaia__titulos { flex: 1; min-width: 0; display: grid; gap: 2px; }
.opaia__titulos h2 { margin: 0; font: 600 var(--fs-md) var(--font-ui); }
.opaia__estado { font-size: var(--fs-xs); color: var(--action); }
.opaia__btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; display: grid; place-items: center; cursor: pointer; }
.opaia__btn:hover { background: rgba(255, 255, 255, 0.24); }
.opaia__cuerpo { flex: 1; overflow-y: auto; padding: var(--s-6) var(--s-5); display: grid; align-content: start; justify-items: center; gap: var(--s-3); text-align: center; color: var(--text); font-size: var(--fs-sm); line-height: 1.55; }
.opaia__hero { width: 112px; height: 112px; border-radius: 50%; box-shadow: 0 8px 24px rgba(0, 86, 155, 0.25); }
.opaia__lema { margin: 0; font: 600 var(--fs-lg) var(--font-display); color: var(--ink-900); }
.opaia__cuerpo p { margin: 0; max-width: 32ch; }
.opaia__nota { color: var(--text-muted); font-size: var(--fs-xs); }
.opaia__pie { border-top: 1px solid var(--line); padding: var(--s-4); }
.opaia__pie .input { width: 100%; }
@media (max-width: 880px) {
  .opaia { width: 100vw; top: auto; height: min(86dvh, 640px); border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; transform: translateY(105%); }
  .opaia[data-estado="abierto"] { transform: none; }
  .opaia-burbuja { bottom: 76px; right: var(--s-4); }
  .opaia-launcher span { display: none; }
  .opaia-launcher { padding: 0 4px; }
}
@media (prefers-reduced-motion: reduce) { .opaia { transition: none; } }

/* Navegación móvil: se adapta al número de módulos del perfil (hasta 6); si no caben, la barra se desliza (la página no) */
@media (max-width: 880px) {
  .bottom-nav { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(72px, 1fr); overflow-x: auto; scrollbar-width: none; }
  .bottom-nav::-webkit-scrollbar { display: none; }
  .bottom-nav a, .bottom-nav button { white-space: nowrap; }
}


/* ---------- Carga de tableros: esqueleto único (misma estructura y colores para todos los tableros) ---------- */
.tablero { position: relative; }
.tablero__velo { position: absolute; inset: 0; z-index: 3; background: var(--ref-papel, #f3f6fb); overflow: hidden; transition: opacity .22s ease, visibility 0s linear .22s; }
.tablero:is([data-tablero-estado="listo"], [data-tablero-estado="error"]) > .tablero__velo { opacity: 0; visibility: hidden; pointer-events: none; }
.esq { max-width: 1480px; margin: 0 auto; padding: var(--s-5, 20px) var(--gutter, 24px); display: grid; gap: var(--s-4, 16px); }
.esq__cabecera { display: flex; justify-content: space-between; align-items: center; background: var(--surface, #fff); border: 1px solid var(--line, #e3e9f2); border-radius: 18px; padding: 22px 26px; }
.esq__linea { display: block; border-radius: 8px; background: #e6edf6; }
.esq__linea--titulo { width: min(320px, 50%); height: 30px; }
.esq__linea--boton { width: 150px; height: 36px; }
.esq__filtros { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; background: var(--surface, #fff); border: 1px solid var(--line, #e3e9f2); border-radius: 18px; padding: 16px; }
.esq__filtros span { height: 40px; border-radius: 10px; background: #eaf0f8; }
.esq__kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.esq__kpis span { height: 132px; border-radius: 18px; background: var(--surface, #fff); border: 1px solid var(--line, #e3e9f2); }
.esq__grafico { height: 280px; border-radius: 18px; background: var(--surface, #fff); border: 1px solid var(--line, #e3e9f2); }
.esq__linea, .esq__filtros span, .esq__kpis span, .esq__grafico { position: relative; overflow: hidden; }
.esq__linea::after, .esq__filtros span::after, .esq__kpis span::after, .esq__grafico::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .7) 50%, transparent 80%); transform: translateX(-100%); animation: esq-brillo 1.4s ease-in-out infinite; }
@keyframes esq-brillo { to { transform: translateX(100%); } }
.esq__texto { margin: 0; text-align: center; color: var(--text-muted, #5b6b82); font-size: var(--fs-sm, 14px); }
.esq__demora { display: none; margin: 0 auto; max-width: 560px; text-align: center; gap: 8px; justify-items: center; padding: 16px 20px; border-radius: 14px; background: var(--surface, #fff); border: 1px solid var(--line, #e3e9f2); }
.tablero[data-tablero-estado="demora"] .esq__demora { display: grid; }
.tablero[data-tablero-estado="demora"] .esq__texto { display: none; }
.tablero[data-tablero-estado="demora"] .esq__linea::after, .tablero[data-tablero-estado="demora"] .esq__filtros span::after, .tablero[data-tablero-estado="demora"] .esq__kpis span::after, .tablero[data-tablero-estado="demora"] .esq__grafico::after { animation: none; opacity: 0; }
@media (max-width: 880px) { .esq__filtros { grid-template-columns: repeat(2, minmax(0, 1fr)); } .esq__kpis { grid-template-columns: minmax(0, 1fr); } .esq__kpis span { height: 96px; } .esq__linea--boton { display: none; } }
@media (prefers-reduced-motion: reduce) { .esq__linea::after, .esq__filtros span::after, .esq__kpis span::after, .esq__grafico::after { animation: none; opacity: 0; } .tablero__velo { transition: none; } }

/* ---------- Menú lateral contraíble (solo computador y tablet ancha: en celular se usa la barra inferior) ---------- */
.shell { transition: grid-template-columns .2s ease; }
.sidebar { position: relative; z-index: 5; }
.sidebar__cab { display: flex; align-items: center; gap: var(--s-2, 8px); }
.sidebar__cab .brand-plate { flex: 1; min-width: 0; }
.sidebar__toggle { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .06); color: #e9f1fb; cursor: pointer; }
.sidebar__toggle:hover { background: rgba(255, 255, 255, .15); }
.sidebar__toggle:focus-visible, .nav-mini__enlace:focus-visible { outline: 2px solid #7db8e8; outline-offset: 2px; }
.sidebar__toggle .icon { width: 18px; height: 18px; }
.nav-mini { display: none; }
@media (min-width: 881px) {
  .shell[data-colapsado="true"] { --sidebar-w: 76px; }
  .shell[data-colapsado="true"] .sidebar { overflow: visible; padding-left: var(--s-2, 8px); padding-right: var(--s-2, 8px); align-items: center; }
  .shell[data-colapsado="true"] .sidebar__cab { flex-direction: column; gap: var(--s-3, 12px); width: 100%; }
  /* Contraído: no existe una versión compacta OFICIAL del logo, así que se oculta el logo completo (nunca recortado ni deformado) y queda el botón centrado. */
  .shell[data-colapsado="true"] .sidebar .brand-plate { display: none; }
  .shell[data-colapsado="true"] .sidebar__cab { justify-content: center; }
  .shell[data-colapsado="true"] .brand__sub--block, .shell[data-colapsado="true"] .nav, .shell[data-colapsado="true"] .sidebar__foot { display: none; }
  .shell[data-colapsado="true"] .nav-mini { display: flex; flex-direction: column; gap: 4px; width: 100%; }
  .nav-mini__item { position: relative; }
  .nav-mini__enlace { display: grid; place-items: center; width: 100%; height: 44px; border-radius: 10px; color: #e9f1fb; text-decoration: none; }
  .nav-mini__enlace .icon { width: 20px; height: 20px; }
  .nav-mini__enlace:hover { background: rgba(255, 255, 255, .1); }
  .nav-mini__enlace[aria-current] { background: var(--ref-nav-activo, rgba(255, 255, 255, .16)); color: #fff; }
  .nav-mini__flyout { position: absolute; left: 100%; top: 0; padding-left: 10px; display: none; z-index: 60; }
  .nav-mini__item:hover > .nav-mini__flyout, .nav-mini__item:focus-within > .nav-mini__flyout { display: block; }
  .nav-mini__caja { min-width: 214px; background: var(--ref-nav, #0b2a55); border: 1px solid rgba(255, 255, 255, .16); border-radius: 12px; padding: 6px; box-shadow: 0 14px 34px rgba(5, 18, 40, .35); }
  .nav-mini__titulo { padding: 8px 12px 6px; font-size: var(--fs-sm, 14px); font-weight: 600; color: #fff; white-space: nowrap; }
  .nav-mini__caja a { display: block; padding: 8px 12px; border-radius: 8px; color: #cfe0f3; text-decoration: none; font-size: var(--fs-sm, 14px); white-space: nowrap; }
  .nav-mini__caja a:hover, .nav-mini__caja a:focus-visible { background: rgba(255, 255, 255, .1); color: #fff; }
  .nav-mini__caja a[aria-current="page"] { background: var(--ref-nav-sub, rgba(255, 255, 255, .14)); color: #fff; font-weight: 600; }
}
@media (max-width: 880px) { .sidebar__toggle { display: none; } }
@media (prefers-reduced-motion: reduce) { .shell { transition: none; } }

/* Menú: aparición suave al expandir o contraer (sin saltos) */
@keyframes opa-aparece { from { opacity: 0; } to { opacity: 1; } }
.shell[data-colapsado="false"] .sidebar .nav, .shell[data-colapsado="false"] .sidebar .brand-plate, .shell[data-colapsado="false"] .sidebar .sidebar__foot { animation: opa-aparece .22s ease; }
.shell[data-colapsado="true"] .nav-mini { animation: opa-aparece .22s ease; }
.sidebar__toggle, .nav-mini__enlace { transition: background-color .15s ease, border-color .15s ease; }
.sidebar .brand-plate img { height: auto; object-fit: contain; } /* proporciones originales, sin estirar */
@media (prefers-reduced-motion: reduce) { .shell .sidebar .nav, .shell .sidebar .brand-plate, .shell .sidebar .sidebar__foot, .shell .nav-mini { animation: none !important; } }

/* Celular táctil (PWA): campos de 16 px para que iPhone no agrande la pantalla al escribir, y botones de al menos 40 px. En computador no cambia nada. */
@media (max-width: 880px) and (pointer: coarse) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  .input, .select, textarea.input { font-size: 16px; min-height: 44px; }
  .btn, .chips a, .bottom-nav a, .bottom-nav button { min-height: 44px; }
}
