/* ============================================================
   MonTech · Biblioteca de componentes
   Todo componente usa exclusivamente tokens de tokens.css
   ============================================================ */

/* ---------- Tarjeta ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  overflow: hidden;
}

.card__head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5) var(--s-3);
}
.card__head h3 { font-size: var(--fs-15); font-weight: 600; letter-spacing: -0.01em; }
.card__head p { font-size: var(--fs-12); color: var(--text-muted); margin-top: 1px; }
.card__head .u-right { margin-left: auto; }
.card__body { padding: var(--s-5); }
.card__head + .card__body { padding-top: var(--s-2); }
.card__head + .card__body--flush { padding-top: 0; border-top: 1px solid var(--border); }
.card__body--tight { padding: var(--s-3) var(--s-4); }
.card__body--flush { padding: 0; }
/* una tabla (que ya trae su propia tarjeta) dentro de una tarjeta sin relleno: sin doble borde */
.card__body--flush > .card, .card__body--flush > div > .card:only-child { border: 0; border-radius: 0; box-shadow: none; }
.card__foot {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-12);
  color: var(--text-muted);
  display: flex; align-items: center; gap: var(--s-3);
}

/* ---------- KPI ---------- */
.kpi {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--sh-1);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color var(--t), box-shadow var(--t);
}
.kpi:hover { border-color: var(--border-strong); }
/* el título absorbe la diferencia de altura: si uno ocupa dos renglones,
   las cifras de toda la fila siguen a la misma altura */
.kpi__top { display: flex; align-items: flex-start; gap: var(--s-2); flex: 1 0 auto; }
.kpi__label { flex: 1 1 auto; min-width: 0; font-size: var(--fs-14); font-weight: 600; color: var(--text-primary); letter-spacing: -0.005em; }
.kpi__icon { flex: 0 0 auto; color: var(--kpi-accent, var(--brand)); margin-top: 1px; }
.kpi__icon svg { width: 18px; height: 18px; }
.kpi__row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px var(--s-2); margin-top: var(--s-3); }
.kpi__value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi__value small { font-size: var(--fs-14); font-weight: 600; color: var(--text-muted); margin-left: 3px; letter-spacing: 0; }
.kpi__meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); font-size: var(--fs-12); color: var(--text-muted); }
.kpi__delta {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px 7px 2px 5px;
  border-radius: var(--r-full); font-size: var(--fs-11); font-weight: 700; font-variant-numeric: tabular-nums;
}
.kpi__delta svg { width: 12px; height: 12px; }
.kpi__delta--up { color: var(--ok-ink); background: var(--ok-soft); }
.kpi__delta--down { color: var(--danger-ink); background: var(--danger-soft); }
.kpi__delta--flat { color: var(--neutral-ink); background: var(--neutral-soft); }
.kpi__spark { margin-left: auto; width: 96px; flex: 0 1 96px; min-width: 56px; align-self: flex-end; }
.kpi__spark svg { width: 100%; height: auto; }
/* Con subgrid, título, cifra y nota comparten renglón con las tarjetas
   vecinas: si un título ocupa dos líneas (pasa mucho en el teléfono),
   las cifras de toda la fila siguen a la misma altura. */
@supports (grid-template-rows: subgrid) {
  .grid > .kpi { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 0; }
  .grid > .kpi > * { align-self: start; }
}
@media (max-width: 860px) {
  /* En tableta y teléfono van de a dos por fila, para no hacer una columna eterna */
  .grid:has(> .kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid:has(> .kpi) > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .grid:has(> .kpi) { gap: var(--s-3); }
  .kpi { padding: var(--s-4); }
  .kpi__label { font-size: var(--fs-13); }
  .kpi__icon svg { width: 16px; height: 16px; }
  .kpi__row { margin-top: var(--s-2); }
  .kpi__value { font-size: var(--fs-24); overflow-wrap: break-word; }
  .kpi__value small { display: inline-block; }   /* la unidad baja entera si no cabe */
  .card__body--flush > .grid:has(> .kpi) { padding: var(--s-3); margin-bottom: 0; }
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 16px;
  border-radius: var(--r); border: 1px solid transparent;
  font-size: var(--fs-13); font-weight: 600; white-space: nowrap; letter-spacing: -0.005em;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), filter var(--t-fast);
  background: var(--bg-surface); color: var(--text-primary);
}
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--brand);
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 86%, #fff) 0%, var(--brand) 100%);
  border-color: var(--brand-hover); color: #fff;
  box-shadow: 0 1px 2px rgba(16, 35, 39, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn--primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn--primary:focus-visible { box-shadow: 0 0 0 3px var(--brand-ring); outline: none; }
.btn--navy { background: var(--mt-navy-900); border-color: var(--mt-navy-900); color: #fff; }
.btn--navy:hover:not(:disabled) { background: var(--mt-navy-800); }
.btn--ghost { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border); box-shadow: var(--sh-1); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-muted); border-color: var(--border-strong); }
.btn--soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn--soft:hover:not(:disabled) { background: var(--brand-ring); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(1.06); }
.btn--ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn--ok:hover:not(:disabled) { filter: brightness(1.06); }
.btn--sm { height: 32px; padding: 0 12px; font-size: var(--fs-12); border-radius: var(--r-sm); }
.btn--sm svg { width: 14px; height: 14px; }
.btn--lg { height: 46px; padding: 0 22px; font-size: var(--fs-14); }
.btn--block { width: 100%; }
/* en el encabezado de cada página los botones van a tamaño normal */
.page-head__actions .btn--sm { height: 36px; padding: 0 14px; font-size: var(--fs-13); border-radius: var(--r); }
.page-head__actions .btn--sm svg { width: 15px; height: 15px; }
.btn--icon { width: 38px; padding: 0; }

/* ---------- Insignias / etiquetas ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: var(--fs-11); font-weight: 600; letter-spacing: 0;
  background: var(--neutral-soft); color: var(--neutral-ink);
  white-space: nowrap; line-height: 1.6;
}
.badge svg { width: 12px; height: 12px; }
.badge--ok { background: var(--ok-soft); color: var(--ok-ink); }
.badge--warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge--danger { background: var(--danger-soft); color: var(--danger-ink); }
.badge--info { background: var(--info-soft); color: var(--info-ink); }
.badge--brand { background: var(--brand-soft); color: var(--brand-ink); }
.badge--gold { background: var(--mt-gold-100); color: var(--warn-ink); }
.badge--solid { background: var(--brand); color: #fff; }
.badge--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-secondary); }
.badge--lg { padding: 4px 12px; font-size: var(--fs-12); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: 0 0 auto; }

/* ---------- Avatar ---------- */
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-full);
  display: grid; place-items: center; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--info-ink);
  font-size: var(--fs-12); font-weight: 700; letter-spacing: -0.01em;
}
.avatar--sm { width: 26px; height: 26px; font-size: 10px; }
.avatar--lg { width: 52px; height: 52px; font-size: var(--fs-16); }
.avatar--brand { background: var(--brand-soft); color: var(--brand-ink); }
.avatar--navy { background: var(--mt-navy-900); color: #fff; }

/* ---------- Tabla ---------- */
.tbl-wrap { width: 100%; overflow-x: auto; }
.tbl { width: 100%; font-size: var(--fs-13); }
.tbl thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-surface);
  text-align: left; font-size: var(--fs-11); font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted);
  padding: 11px var(--s-4); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl thead th:first-child, .tbl tbody td:first-child { padding-left: var(--s-5); }
.tbl thead th:last-child, .tbl tbody td:last-child { padding-right: var(--s-5); }
.tbl thead th.is-sortable { cursor: pointer; user-select: none; }
.tbl thead th.is-sortable:hover { color: var(--text-primary); }
.tbl thead th .sort-ind { display: inline-block; margin-left: 4px; opacity: 0.4; font-size: 8px; vertical-align: 1px; }
.tbl thead th.is-sorted { color: var(--text-primary); }
.tbl thead th.is-sorted .sort-ind { opacity: 1; color: var(--brand); }
.tbl tbody td { padding: 13px var(--s-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--bg-muted); }
.tbl tbody tr.is-clickable { cursor: pointer; }
.tbl tbody tr.is-selected { background: var(--brand-soft); }
.tbl tbody tr.row-danger { background: var(--danger-soft); }
.tbl tbody tr.row-danger:hover { background: var(--danger-soft); filter: brightness(0.985); }
.tbl tbody tr.row-warn { background: var(--warn-soft); }
.tbl tbody tr.row-warn:hover { background: var(--warn-soft); filter: brightness(0.985); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .tight { width: 1%; white-space: nowrap; }

@media (max-width: 640px) {
  .tbl thead th, .tbl tbody td,
  .tbl thead th:first-child, .tbl tbody td:first-child,
  .tbl thead th:last-child, .tbl tbody td:last-child { padding-left: 10px; padding-right: 10px; }
  .tbl thead th { letter-spacing: 0.04em; }
}
@media (max-width: 640px) {
  /* En el teléfono cada renglón de la tabla es una ficha: la primera columna
     arriba y el resto en dos columnas con su título encima */
  .tbl--fichas thead { display: none; }
  .tbl--fichas, .tbl--fichas tbody { display: block; }
  .tbl--fichas tbody tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2) var(--s-3);
    padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border);
  }
  .tbl--fichas tbody tr:last-child { border-bottom: 0; }
  .tbl--fichas tbody td,
  .tbl--fichas tbody td:first-child,
  .tbl--fichas tbody td:last-child { display: block; padding: 0; border: 0; min-width: 0; overflow-wrap: anywhere; }
  .tbl--fichas tbody td:first-child { grid-column: 1 / -1; }
  .tbl--fichas tbody td[data-titulo]:not(:first-child)::before {
    content: attr(data-titulo); display: block; margin-bottom: 1px;
    font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted);
  }
  .tbl--fichas .num { text-align: left; }
  .tbl--fichas .tight { width: auto; white-space: normal; }
  .tbl--fichas tbody td:empty { display: none; }
}

.tbl-empty { padding: var(--s-8) var(--s-5); text-align: center; color: var(--text-muted); }
.tbl-empty svg { width: 40px; height: 40px; margin: 0 auto var(--s-3); opacity: 0.4; }

.tbl-foot {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border);
  font-size: var(--fs-12); color: var(--text-muted);
}
.tbl-foot:empty { display: none; }
.tbl-foot b { color: var(--text-secondary); font-weight: 600; }
.pager { display: flex; gap: 4px; margin-left: auto; }
.pager button {
  min-width: 32px; height: 32px; padding: 0 9px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg-surface);
  font-size: var(--fs-12); font-weight: 600; color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.pager button:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text-primary); background: var(--bg-muted); }
.pager button.is-active { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-12); font-weight: 600; color: var(--text-secondary); }
.field > label .req { color: var(--danger); }
.field__hint { font-size: var(--fs-11); color: var(--text-muted); }

.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: var(--fs-13); outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--text-muted); }
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select {
  -webkit-appearance: none; appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a888b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--bg-inset); color: var(--text-muted); cursor: not-allowed; }
.input.is-error, .select.is-error { border-color: var(--danger); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }

/* Contraseña con botón para verla */
.clave { position: relative; display: block; }
.clave > input[type] { padding-right: 44px; }
.clave > input::-ms-reveal { display: none; }
.clave__ver {
  position: absolute; top: 0; right: 0; bottom: 0; width: 42px;
  display: grid; place-items: center; padding: 0;
  background: none; border: 0; border-radius: 0 var(--r) var(--r) 0;
  color: var(--text-muted); cursor: pointer;
}
.clave__ver:hover, .clave__ver[aria-pressed="true"] { color: var(--brand); }
.clave__ver:focus-visible { outline: 2px solid var(--brand); outline-offset: -3px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.form-grid .col-span, .grid > .col-span { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

.check { display: flex; align-items: flex-start; gap: var(--s-2); cursor: pointer; font-size: var(--fs-13); }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--brand); cursor: pointer; }


/* ---------- Segmentos / filtros ---------- */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-inset); border-radius: var(--r);
}
.segmented button {
  padding: 6px 13px; border: none; background: transparent; border-radius: var(--r-sm);
  font-size: var(--fs-12); font-weight: 600; color: var(--text-secondary);
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast); white-space: nowrap;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button.is-active { background: var(--bg-surface); color: var(--text-primary); box-shadow: 0 1px 2px rgba(16, 35, 39, 0.1), 0 0 0 1px var(--border); }
.segmented button:disabled { cursor: not-allowed; opacity: .6; }
.segmented button:disabled:hover { color: var(--text-secondary); }
@media (max-width: 640px) {
  /* si no caben, se deslizan de lado en vez de salirse de la pantalla */
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { padding: 7px 11px; }
}

.chips { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--r-full);
  border: 1px solid var(--border); background: var(--bg-surface);
  font-size: var(--fs-12); font-weight: 600; color: var(--text-secondary);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }
.chip__count { font-size: 10px; padding: 1px 6px; border-radius: var(--r-full); background: var(--bg-inset); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.chip.is-active .chip__count { background: var(--bg-surface); color: var(--brand-ink); }

.toolbar {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--border); background: var(--bg-surface);
}
.searchbox { position: relative; flex: 0 1 300px; }
.searchbox input { height: 36px; padding-left: 36px; border-radius: var(--r-full); border-color: var(--border); }
.searchbox svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-muted); pointer-events: none; }
@media (max-width: 640px) {
  .toolbar { padding: var(--s-3) var(--s-4); }
  .searchbox { flex: 1 1 100%; }
}

/* ---------- Barra de progreso / medidor ---------- */
.meter { height: 6px; border-radius: var(--r-full); background: var(--bg-inset); overflow: hidden; position: relative; }
.meter__fill { height: 100%; border-radius: var(--r-full); background: var(--brand); transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1); }
.meter__fill--ok { background: var(--ok); }
.meter__fill--warn { background: var(--warn); }
.meter__fill--danger { background: var(--danger); }
.meter__fill--info { background: var(--info); }

/* ---------- Avisos en línea ---------- */
.note {
  display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  border-radius: var(--r); border: 1px solid var(--border);
  background: var(--bg-muted); font-size: var(--fs-13);
}
.note svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.note b { display: block; margin-bottom: 2px; font-weight: 600; }
.note--danger { background: var(--danger-soft); border-color: transparent; color: var(--danger-ink); }
.note--warn { background: var(--warn-soft); border-color: transparent; color: var(--warn-ink); }
.note--ok { background: var(--ok-soft); border-color: transparent; color: var(--ok-ink); }
.note--info { background: var(--info-soft); border-color: transparent; color: var(--info-ink); }
.note--brand { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }

/* ---------- Línea de tiempo / actividad ---------- */
.timeline { position: relative; padding-left: var(--s-6); }
.timeline::before {
  content: ""; position: absolute; left: 11px; top: 6px; bottom: 6px;
  width: 1px; background: var(--border-strong);
}
.tl-item { position: relative; padding: 0 0 var(--s-5) 0; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: -18px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg-surface); border: 2px solid var(--brand);
}
.tl-item__time { font-size: var(--fs-11); color: var(--text-muted); font-weight: 600; }
.tl-item__title { font-size: var(--fs-13); font-weight: 600; margin-top: 1px; }
.tl-item__body { font-size: var(--fs-12); color: var(--text-secondary); margin-top: 2px; }

.feed { display: flex; flex-direction: column; }
.feed__row {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.feed__row:last-child { border-bottom: none; }
.feed__row:hover { background: var(--bg-muted); }
.feed__row > svg { flex: 0 0 auto; margin-top: 8px; color: var(--text-muted); }
.feed__icon {
  width: 34px; height: 34px; border-radius: var(--r); flex: 0 0 auto;
  display: grid; place-items: center; background: var(--bg-inset); color: var(--text-secondary);
}
.feed__icon svg { width: 16px; height: 16px; }
.feed__icon--ok { background: var(--ok-soft); color: var(--ok); }
.feed__icon--warn { background: var(--warn-soft); color: var(--warn); }
.feed__icon--danger { background: var(--danger-soft); color: var(--danger); }
.feed__icon--brand { background: var(--brand-soft); color: var(--brand); }
.feed__icon--info { background: var(--info-soft); color: var(--info); }
.feed__title { font-size: var(--fs-13); font-weight: 600; }
.feed__meta { font-size: var(--fs-12); color: var(--text-muted); margin-top: 1px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 800;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: var(--s-6);
  animation: fadeIn 160ms ease both;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px);
  background: var(--bg-elevated); border-radius: var(--r-xl); border: 1px solid var(--border);
  box-shadow: var(--sh-3); display: flex; flex-direction: column; overflow: hidden;
  animation: popIn 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.modal--sm { max-width: 420px; }
.modal--lg { max-width: 760px; }
.modal--xl { max-width: 1040px; }
.modal__head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}
.modal__head h3 { font-size: var(--fs-18); font-weight: 700; letter-spacing: -0.015em; }
.modal__head p { font-size: var(--fs-13); color: var(--text-muted); margin-top: 2px; }
.modal__close { margin-left: auto; }
/* botón de cerrar redondo con borde, como en los paneles */
.modal__close, .drawer__head [data-cerrar] {
  width: 34px; height: 34px; border-radius: var(--r-full); border: 1px solid var(--border); align-self: flex-start;
}
.modal__close svg, .drawer__head [data-cerrar] svg { width: 16px; height: 16px; }
.modal__body { padding: var(--s-5); overflow-y: auto; flex: 1 1 auto; }
.modal__body--flush { padding: 0; }
.modal__foot {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.modal__foot .u-right { margin-left: auto; }

/* ---------- Panel lateral (drawer) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 780;
  background: var(--scrim);
  animation: fadeIn 160ms ease both;
}
.drawer {
  position: fixed; top: var(--s-3); right: var(--s-3); bottom: var(--s-3); z-index: 790;
  width: min(720px, calc(100vw - 24px));
  background: var(--bg-elevated); box-shadow: var(--sh-3);
  border-radius: var(--r-xl); border: 1px solid var(--border); overflow: hidden;
  display: flex; flex-direction: column;
  animation: slideInRight 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.drawer--wide { width: min(980px, calc(100vw - 24px)); }
.drawer__head { padding: var(--s-5); border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: var(--s-4); }
.drawer__body { flex: 1 1 auto; overflow-y: auto; padding: var(--s-4) var(--s-5) var(--s-6); }
.drawer__foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: var(--s-5); border-bottom: 1px solid var(--border); padding: 0 var(--s-5); }
.tabs button {
  padding: 13px 0 12px; border: none; background: none;
  font-size: var(--fs-13); font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast); white-space: nowrap;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.is-active { color: var(--text-primary); border-bottom-color: var(--brand); }
.tabs button.is-active .chip__count { background: var(--brand-soft); color: var(--brand-ink); }
.tabpanel { animation: viewIn 200ms ease both; }
@media (max-width: 640px) {
  /* En el teléfono las pestañas se deslizan de lado en vez de salirse de la pantalla */
  .tabs { overflow-x: auto; overflow-y: hidden; gap: var(--s-4); padding: 0 var(--s-3) 1px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
}

@media (max-width: 640px) {
  .modal-backdrop { padding: var(--s-3); }
  .modal { max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); border-radius: var(--r-lg); }
  .modal__head { padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); }
  .modal__body { padding: var(--s-4); }
  .modal__foot { padding: var(--s-3) var(--s-4); flex-wrap: wrap; justify-content: flex-end; }
  .drawer, .drawer--wide { top: 0; right: 0; bottom: 0; width: 100%; border-radius: 0; border: 0; }
  .drawer__head { padding: var(--s-4); }
  .drawer__body { padding: var(--s-4) var(--s-4) var(--s-6); }
  .drawer__foot { padding: var(--s-3) var(--s-4); }
}

/* ---------- Avisos flotantes ---------- */
.toasts {
  position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 950;
  display: flex; flex-direction: column; gap: var(--s-2); width: 380px; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-3);
  animation: slideInRight 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.toast.is-out { animation: fadeOut 240ms ease both; }
.toast__icon {
  width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: var(--r-full); background: var(--brand-soft); color: var(--brand);
}
.toast__icon svg { width: 16px; height: 16px; }
.toast__title { font-size: var(--fs-13); font-weight: 600; margin-top: 5px; }
.toast__msg { font-size: var(--fs-12); color: var(--text-secondary); margin-top: 2px; }
.toast--ok .toast__icon { background: var(--ok-soft); color: var(--ok); }
.toast--warn .toast__icon { background: var(--warn-soft); color: var(--warn); }
.toast--danger .toast__icon { background: var(--danger-soft); color: var(--danger); }
.toast--info .toast__icon { background: var(--info-soft); color: var(--info); }
.toast__close { margin-left: auto; border-radius: var(--r-full); }

@media (max-width: 640px) {
  .toasts { left: var(--s-3); right: var(--s-3); bottom: var(--s-3); width: auto; max-width: none; }
}

/* ---------- Menú contextual ---------- */
.menu {
  position: absolute; z-index: 860; min-width: 210px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: 6px;
  animation: popIn 140ms ease both;
}
.menu__item {
  display: flex; align-items: center; gap: var(--s-3); width: 100%;
  padding: 9px 10px; border-radius: var(--r-sm); border: none; background: none;
  font-size: var(--fs-13); color: var(--text-primary); text-align: left;
}
.menu__item:hover { background: var(--bg-inset); }
.menu__item svg { width: 16px; height: 16px; color: var(--text-muted); flex: 0 0 auto; }
.menu__item--danger { color: var(--danger); }
.menu__item--danger svg { color: var(--danger); }
.menu__sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu__title { font-size: var(--fs-12); font-weight: 600; color: var(--text-muted); padding: 7px 10px 5px; }

/* ---------- Sugerencias al escribir (teléfono) ---------- */
.sug-ancla { position: relative; }
.sug {
  position: absolute; left: 0; right: 0; z-index: 30;
  max-height: 280px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-3); padding: 4px;
}
.sug__op {
  display: flex; align-items: baseline; gap: var(--s-3); min-height: 44px;
  padding: 11px 10px; border-radius: var(--r-sm); cursor: pointer;
  font-size: var(--fs-15); line-height: 1.3; color: var(--text-primary);
}
.sug__op + .sug__op { border-top: 1px solid var(--border); }
.sug__op span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.sug__op small { flex: 0 0 auto; font-size: var(--fs-13); color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sug__op:hover, .sug__op.is-activo { background: var(--bg-inset); }

/* ---------- Panel de notificaciones ---------- */
.notif-panel {
  position: absolute; top: calc(var(--topbar-h) - 4px); right: var(--s-6); z-index: 870;
  width: 400px; max-height: 560px; display: flex; flex-direction: column;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--sh-3);
  animation: popIn 160ms ease both; overflow: hidden;
}
.notif-panel > .card__head { padding-bottom: var(--s-3); border-bottom: 1px solid var(--border); }

/* ---------- Estado vacío ---------- */
.empty { padding: var(--s-8) var(--s-5); text-align: center; }
.empty__icon {
  width: 52px; height: 52px; border-radius: var(--r-full); margin: 0 auto var(--s-4);
  display: grid; place-items: center; background: var(--bg-inset); color: var(--text-muted);
}
.empty__icon svg { width: 24px; height: 24px; }
.empty h4 { font-size: var(--fs-15); font-weight: 600; }
.empty p { font-size: var(--fs-13); color: var(--text-muted); margin-top: var(--s-2); max-width: 380px; margin-inline: auto; }

/* ---------- Gráficas ---------- */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart svg text { font-family: var(--font); }
.chart__legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); }
.chart__legend span { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-12); color: var(--text-secondary); }
.chart__legend i { width: 9px; height: 9px; border-radius: 50%; display: block; flex: 0 0 auto; }
.chart__legend i.is-dash { width: 14px; height: 0; border-radius: 0; border-top: 2px dashed; background: none !important; }
/* guía vertical y puntos que aparecen al pasar el cursor por la línea */
.chart-hot .chart-guide, .chart-hot .chart-pt { opacity: 0; transition: opacity 80ms linear; }
.chart-hot:hover .chart-guide, .chart-hot:hover .chart-pt { opacity: 1; }
.chart-tip {
  position: fixed; z-index: 900; pointer-events: none;
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 8px 11px; font-size: var(--fs-12); line-height: 1.55;
  box-shadow: var(--sh-2); white-space: nowrap; transform: translate(-50%, calc(-100% - 14px));
  font-variant-numeric: tabular-nums;
}
.chart-tip b { color: var(--text-primary); font-weight: 700; }
.chart-tip i { display: inline-block; width: 10px; height: 2px; border-radius: 2px; margin-right: 6px; vertical-align: 3px; }
.chart-tip small { color: var(--text-muted); font-size: var(--fs-11); }

/* ---------- Misceláneos ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: var(--s-2) var(--s-4); font-size: var(--fs-13); }
.kv dt { color: var(--text-muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 600; }

kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border);
  background: var(--bg-muted); font: 600 11px/1.5 var(--font); color: var(--text-secondary);
}

@media print {
  .nav, .topbar, .toasts, .page-head__actions { display: none !important; }
  .app { display: block !important; }
  .view { overflow: visible !important; }
  body { background: #fff; }
}

/* ---------- Barras horizontales (ranking) ---------- */
.chart-hbars { display: flex; flex-direction: column; gap: var(--s-4); }
.hbar__top { display: flex; align-items: baseline; gap: var(--s-3); margin-bottom: 6px; }
.hbar__label { font-size: var(--fs-13); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar__val { margin-left: auto; font-size: var(--fs-13); font-weight: 600; font-variant-numeric: tabular-nums; }
.hbar__track { height: 8px; border-radius: var(--r-full); background: var(--bg-inset); overflow: hidden; }
.hbar__fill { height: 100%; border-radius: var(--r-full); transition: width 700ms cubic-bezier(0.22, 1, 0.36, 1); }
.hbar__sub { font-size: var(--fs-11); color: var(--text-muted); margin-top: 4px; }

/* ---------- Barra de composición ---------- */
.chart-stack { display: flex; gap: 2px; width: 100%; border-radius: var(--r-full); overflow: hidden; background: var(--bg-inset); }
.chart-stack__seg { height: 100%; transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1); }

/* ---------- Modo presentación ---------- */
.tour {
  /* Centrada con márgenes automáticos: la animación de entrada usa
     transform y borraría un translateX(-50%). */
  position: fixed; left: 0; right: 0; bottom: var(--s-6); margin-inline: auto;
  z-index: 940; width: min(660px, calc(100vw - 32px));
  background: linear-gradient(160deg, #0c5a63 0%, #00404c 100%); color: #fff;
  border-radius: var(--r-xl); box-shadow: var(--sh-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: popIn 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.tour__num {
  display: inline-block; font-size: var(--fs-11); font-weight: 700; letter-spacing: 0.04em;
  color: #9fe0df; margin-bottom: var(--s-2);
  padding: 2px 9px; border-radius: var(--r-full); background: rgba(255, 255, 255, 0.1);
}
.tour h4 { font-size: var(--fs-18); color: #fff; }
.tour p { font-size: var(--fs-14); color: rgba(255, 255, 255, 0.74); margin-top: var(--s-2); line-height: 1.55; }
.tour__acciones { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-4); }
.tour__acciones .u-right { margin-left: auto; }
.tour .btn--ghost { color: rgba(255, 255, 255, 0.8); border-color: rgba(255, 255, 255, 0.2); background: transparent; box-shadow: none; }
.tour .btn--ghost:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.tour .btn--primary { background: #fff; color: #00404c; border-color: #fff; box-shadow: none; }
.tour .btn--primary:hover { background: #e3f4f4; }
@media (max-width: 640px) { .tour { bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px)); padding: var(--s-4); } }

/* ============================================================
   Pares clave/valor (variante en spans) y secciones del panel lateral
   ============================================================ */
.kv__row { grid-column: 1 / -1; display: grid; grid-template-columns: 150px 1fr; gap: 2px var(--s-4); font-size: var(--fs-13); padding: 7px 0; align-items: baseline; border-bottom: 1px solid var(--border); }
.kv__row:last-child { border-bottom: 0; }
.kv__k { color: var(--text-muted); font-weight: 500; }
.kv__v { font-weight: 600; color: var(--text-primary); }

.drawer__eyebrow { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-muted); font-weight: 600; margin-bottom: 2px; }
.drawer__eyebrow svg { color: var(--brand); }
.drawer__section { margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--border); }
.drawer__stitle { display: flex; align-items: center; gap: 8px; font-size: var(--fs-13); font-weight: 600; margin-bottom: var(--s-3); }
.drawer__stitle svg { color: var(--brand); }
.drawer__stitle .badge { font-weight: 600; }

.select--sm { height: 32px; padding: 0 30px 0 10px; font-size: var(--fs-12); border-radius: var(--r-sm); background-position: right 8px center; }
.tbl--tight th, .tbl--tight td,
.tbl.tbl--tight thead th:first-child, .tbl.tbl--tight tbody td:first-child,
.tbl.tbl--tight thead th:last-child, .tbl.tbl--tight tbody td:last-child { padding: 7px 10px; }

/* ============================================================
   Teléfono y tableta
   ============================================================ */
@media (max-width: 640px) {
  .notif-panel { left: var(--s-2); right: var(--s-2); width: auto; max-height: calc(100dvh - var(--topbar-h) - var(--s-4)); }
  .kv { grid-template-columns: 112px minmax(0, 1fr); }
  .kv__row { grid-template-columns: 112px minmax(0, 1fr); }
  .card__head { padding: var(--s-4) var(--s-4) var(--s-3); }
  .card__body { padding: var(--s-4); }
  .card__head + .card__body { padding-top: var(--s-1); }
  .feed__row { padding: var(--s-3) var(--s-4); }
  .tbl-foot { padding: var(--s-3) var(--s-4); }
}
@media (pointer: coarse) {
  /* El iPhone agranda la pantalla al tocar un campo con letra menor de 16 px
     y no la devuelve sola. Con 16 px no hace ese salto. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { font-size: 16px !important; }
}
