/* Mercadex - componentes (docs/spec/30-sistema-diseno.md §4). Solo var(--...), nunca colores en crudo. */

/* 4.1.5 Cabecera de pagina */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-title { font-size: var(--fs-title); font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.page-sub { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); }
.page-actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
@media (max-width: 639px) {
  .page-head { flex-direction: column; }
  .page-actions { width: 100%; }
  .page-actions .btn-primary { width: 100%; }
}

/* 4.2 Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-4); border-radius: var(--radius);
  border: 1px solid transparent; font-weight: var(--fw-medium); font-size: var(--fs-md);
  white-space: nowrap; cursor: pointer; position: relative; text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-out);
}
/* Al pulsar, una escala sutil confirma el toque sin que el boton se mueva de sitio (el "hundirse" de 1 px se
   veia como un salto). */
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
@media (hover: hover) and (pointer: fine) { .btn-primary:hover { background: var(--accent-hover); color: var(--text-on-accent); } }
.btn-primary:active { background: var(--accent-active); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
@media (hover: hover) and (pointer: fine) { .btn-secondary:hover { background: var(--surface-3); color: var(--text); } }
.btn-ghost { background: transparent; color: var(--text-dim); }
@media (hover: hover) and (pointer: fine) { .btn-ghost:hover { background: var(--surface-2); color: var(--text); } }
.btn-danger { background: var(--danger-solid); color: var(--text-on-accent); }
@media (hover: hover) and (pointer: fine) { .btn-danger:hover { color: var(--text-on-accent); filter: brightness(1.08); } }
.btn-link { background: none; border: 0; color: var(--accent-text); padding: 0; height: auto; min-height: var(--touch); }
@media (hover: hover) and (pointer: fine) { .btn-link:hover { text-decoration: underline; color: var(--accent-text); } }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn-menu::after { content: ""; width: 8px; height: 8px; border-right: 1.75px solid currentColor; border-bottom: 1.75px solid currentColor; transform: rotate(45deg) translateY(-2px); }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent-text); border-top-color: transparent; animation: spin .7s linear infinite; }
.btn-primary.is-loading::after { border-color: var(--text-on-accent); border-top-color: transparent; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--control-h); height: var(--control-h);
  border-radius: var(--radius); border: 0; background: transparent; color: var(--text-dim); cursor: pointer; flex: none; position: relative;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-out);
}
.icon-btn:active { transform: scale(.94); }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { background: var(--surface-2); color: var(--text); } }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 639px) {
  .btn, .icon-btn { height: var(--touch); min-height: var(--touch); }
  .icon-btn { width: var(--touch); }
  .btn-sm { height: var(--touch); }
}

/* 4.3 Formularios */
.field { display: flex; flex-direction: column; gap: var(--sp-1); }
.field + .field { margin-top: var(--sp-4); }
.label { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.label .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  height: var(--control-h); padding: 0 var(--sp-3); font-size: var(--fs-base); color: var(--text);
  transition: border-color var(--dur-fast) var(--ease);
}
.textarea { min-height: 120px; resize: vertical; padding: var(--sp-2) var(--sp-3); height: auto; line-height: var(--lh-normal); }
@media (hover: hover) and (pointer: fine) { .input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); } }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--focus); box-shadow: var(--ring-focus); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface); color: var(--text-muted); cursor: not-allowed; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.select {
  appearance: none; padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa1b2' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--sp-3) center; background-size: 18px;
}
.hint { font-size: var(--fs-sm); color: var(--text-dim); margin: 0; }
.error { font-size: var(--fs-sm); color: var(--danger); margin: 0; display: flex; gap: var(--sp-1); align-items: center; }
.error[hidden] { display: none; }
.form-error { margin-bottom: var(--sp-4); }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
.form-grid .field + .field { margin-top: 0; }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-grid .span-2 { grid-column: span 2; } }
.form-section { padding-top: var(--sp-6); }
.form-section + .form-section { border-top: 1px solid var(--border); margin-top: var(--sp-6); }
.form-section-title { font-size: var(--fs-base); font-weight: var(--fw-semibold); margin-bottom: var(--sp-1); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled { opacity: .7; }
.check { display: flex; align-items: center; gap: var(--sp-2); min-height: var(--touch); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.switch { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; min-height: var(--touch); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 44px; height: 24px; border-radius: var(--radius-full); background: var(--surface-3); position: relative; transition: background var(--dur-fast) var(--ease); flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-on-accent); transition: transform var(--dur-fast) var(--ease); }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring-focus); }
.input-money { display: flex; align-items: center; }
.input-money .input-affix { height: var(--control-h); display: inline-flex; align-items: center; padding: 0 var(--sp-3); background: var(--surface-3); border: 1px solid var(--border); border-right: 0; border-radius: var(--radius) 0 0 var(--radius); font-size: var(--fs-sm); color: var(--text-dim); }
.input-money .input { border-radius: 0 var(--radius) var(--radius) 0; }
.input-search { position: relative; }
.input-search .icon { position: absolute; left: var(--sp-3); top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-search .input { padding-left: var(--sp-10); }
.dropzone { display: block; border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-dim); cursor: pointer; }
.dropzone.is-over { border-color: var(--accent-text); color: var(--text); background: var(--accent-soft); }
@media (hover: hover) and (pointer: fine) { .dropzone:hover { border-color: var(--accent-text); color: var(--text); background: var(--accent-soft); } }
.dropzone:focus-within { box-shadow: var(--ring-focus); }
.dropzone .icon { margin: 0 auto var(--sp-2); width: 32px; height: 32px; color: var(--text-muted); }
.dropzone strong { color: var(--accent-text); }

/* 4.4 Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-5); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
/* Titulo de seccion al tamano del cuerpo: la jerarquia la hace el peso, no el tamano (PR 0 de diseno). */
.card-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); display: flex; align-items: center; gap: var(--sp-2); }
.card-actions { display: flex; gap: var(--sp-2); align-items: center; }
.card-foot { border-top: 1px solid var(--border); margin-top: var(--sp-4); padding-top: var(--sp-3); color: var(--text-dim); font-size: var(--fs-sm); }
.card-link { display: block; color: inherit; cursor: pointer; transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-out); }
.card-link:active { transform: scale(.99); }
@media (hover: hover) and (pointer: fine) { .card-link:hover { border-color: var(--border-strong); color: inherit; } }
.card-muted { background: var(--surface-2); border: 0; }
.card-accent { border-left: 3px solid var(--brand); }
@media (max-width: 639px) { .card { padding: var(--sp-4); } }

/* 4.5 KPI */
.kpi-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1024px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.kpi-label { font-size: var(--fs-sm); color: var(--text-dim); }
.kpi-value { font-size: var(--fs-metric); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; line-height: var(--lh-tight); }
.kpi-delta { font-size: var(--fs-sm); display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--text-dim); }
.kpi-delta .icon { width: 14px; height: 14px; }
.kpi-delta.is-up { color: var(--success); }
.kpi-delta.is-down { color: var(--danger); }
.kpi-delta.is-flat { color: var(--text-dim); }
.kpi.is-skeleton .kpi-value { height: 34px; width: 60%; }
@media (max-width: 639px) { .kpi { padding: var(--sp-3) var(--sp-4); } }

/* 4.6 Tablas */
.table-wrap { min-width: 0; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
/* Cabeceras en frase (sin mayusculas ni espaciado): en un panel las etiquetas se leen, no gritan. Filas de 40 px. */
.table th { text-align: left; font-size: var(--fs-sm); color: var(--text-dim); font-weight: var(--fw-medium); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.table td { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); height: 40px; vertical-align: middle; font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) { .table tbody tr:hover { background: var(--surface-3); } }
.table tr[data-href] { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-actions { text-align: right; width: 1%; white-space: nowrap; }
.cell-primary { font-weight: var(--fw-medium); color: var(--text); text-decoration: none; display: block; }
.cell-primary:active { color: var(--accent-text); }
@media (hover: hover) and (pointer: fine) { .cell-primary:hover { color: var(--accent-text); } }
.cell-sub { display: block; font-size: var(--fs-sm); }
.table-toolbar { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.table-toolbar .input-search { flex: 1 1 220px; }
.table-toolbar .count { margin-left: auto; color: var(--text-dim); font-size: var(--fs-sm); }
@media (max-width: 639px) {
  .table thead { position: absolute; clip: rect(0 0 0 0); width: 1px; height: 1px; overflow: hidden; }
  .table, .table tbody { display: block; }
  .table tr { display: block; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-3); background: var(--surface); }
  .table td { display: flex; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-1) 0; border: 0; height: auto; text-align: left; }
  .table td::before { content: attr(data-label); color: var(--text-dim); font-size: var(--fs-sm); flex: none; }
  .table td:first-child::before { display: none; }
  .table td:first-child { display: block; font-size: var(--fs-md); font-weight: var(--fw-medium); }
  .table .num { text-align: right; }
  .table td.col-actions { display: flex; justify-content: flex-start; width: auto; padding-top: var(--sp-2); }
  .table td.col-actions::before { display: none; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar .count { margin-left: 0; }
}

/* 4.7 Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--radius-full); font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap; background: var(--neutral-soft); color: var(--neutral); vertical-align: middle; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge .icon { width: 12px; height: 12px; }
.badge.has-icon::before { display: none; }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge .spinner { width: 10px; height: 10px; border-width: 1.5px; }
.plan-chip { display: inline-flex; align-items: center; height: 24px; padding: 0 var(--sp-3); border-radius: var(--radius-full); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.badge-count { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full); background: var(--danger-solid); color: var(--text-on-accent); font-size: 11px; font-weight: var(--fw-semibold); display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.badge-count[hidden] { display: none; }

/* 4.8 Modales y drawers (dialog nativo) */
.modal, .drawer { border: 0; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop, .drawer::backdrop { background: var(--overlay); }
/* Entrada de dialogos y menus (PR 0 de diseno): 150 ms, fundido + un gesto minimo desde donde nacen, curva de
   salida fuerte. Con @starting-style no hace falta JavaScript; un navegador viejo simplemente los muestra de
   golpe, como antes. Con movimiento reducido --enter-y es 0 y --enter-scale 1: queda solo el fundido. */
.modal, .drawer, .modal::backdrop, .drawer::backdrop { transition: opacity var(--dur-enter) var(--ease-out), transform var(--dur-enter) var(--ease-out); }
@starting-style {
  .modal[open] { opacity: 0; transform: scale(var(--enter-scale)); }
  .drawer-right[open] { opacity: 0; transform: translateX(calc(var(--enter-y) * 2)); }
  .drawer-bottom[open] { opacity: 0; transform: translateY(calc(var(--enter-y) * 2)); }
  .modal[open]::backdrop, .drawer[open]::backdrop { opacity: 0; }
}
.modal { width: min(520px, calc(100vw - 2 * var(--gutter))); max-height: 90dvh; border-radius: var(--radius-lg); margin: auto; }
.modal-lg { width: min(760px, calc(100vw - 2 * var(--gutter))); }
.modal-box { display: flex; flex-direction: column; max-height: 90dvh; margin: 0; }
.modal-head, .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-head h2, .drawer-head h2 { font-size: var(--fs-base); }
.modal-body, .drawer-body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }
.modal-foot, .drawer-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); }
@media (max-width: 639px) { .modal-foot { flex-direction: column-reverse; } .modal-foot .btn { width: 100%; } }
.drawer { max-width: none; max-height: none; }
.drawer-right { width: min(480px, 100vw); height: 100dvh; margin: 0 0 0 auto; border-radius: 0; }
.drawer-right .drawer-box { height: 100dvh; display: flex; flex-direction: column; padding-right: var(--safe-right); padding-top: var(--safe-top); }
.drawer-bottom { width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.drawer-bottom .drawer-box { max-height: 92dvh; display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); }
.drawer-bottom .drawer-box::before { content: ""; width: 40px; height: 4px; border-radius: var(--radius-full); background: var(--border-strong); margin: var(--sp-2) auto 0; flex: none; }
.drawer-box { margin: 0; }

/* 4.9 Toasts */
.toast-region { position: fixed; z-index: var(--z-toast); bottom: calc(var(--sp-4) + var(--safe-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--sp-2); width: min(420px, calc(100vw - 2 * var(--gutter))); pointer-events: none; }
@media (min-width: 1024px) { .toast-region { left: auto; right: var(--sp-6); bottom: var(--sp-6); transform: none; } }
/* El aviso entra con transition + @starting-style (no con @keyframes): si llegan dos seguidos no se reinician. */
.toast { pointer-events: auto; display: flex; gap: var(--sp-3); align-items: flex-start; background: var(--surface-3); border: 1px solid var(--border); border-left: 3px solid var(--info); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-md); transition: opacity var(--dur-enter) var(--ease-out), transform var(--dur-enter) var(--ease-out); }
@starting-style { .toast { opacity: 0; transform: translateY(var(--enter-y)); } }
.toast-success { border-left-color: var(--success); } .toast-success .toast-icon { color: var(--success); }
.toast-error { border-left-color: var(--danger); } .toast-error .toast-icon { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); } .toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }
.toast-icon { flex: none; margin-top: 2px; }
.toast-content { flex: 1 1 auto; min-width: 0; }
.toast-title { font-weight: var(--fw-medium); }
.toast-body { font-size: var(--fs-sm); color: var(--text-dim); margin: 2px 0 0; }
.toast .btn-link { min-height: 0; font-size: var(--fs-sm); margin-top: var(--sp-1); }
.toast .icon-btn { width: 32px; height: 32px; min-height: 0; margin: -6px -8px -6px 0; }

/* 4.10 Empty state */
/* Reemplazo compacto de una grafica que todavia no tiene datos: ocupa poco, explica que va a pasar y
   no deja un lienzo grande vacio (que se lee como "esto no funciona"). */
.chart-empty { display: flex; flex-direction: column; justify-content: center; gap: var(--sp-1); min-height: 92px; padding: var(--sp-4); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.chart-empty-title { margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.chart-empty-text { margin: 0; font-size: var(--fs-sm); }

.empty { text-align: center; padding: var(--sp-12) var(--sp-4); display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
.empty-icon { width: 48px; height: 48px; color: var(--text-muted); margin-bottom: var(--sp-2); }
.empty-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.empty-text { max-width: 420px; }
.empty-actions { margin-top: var(--sp-3); display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; }
.empty-compact { padding: var(--sp-6) var(--sp-2); }
.empty-compact .empty-icon { width: 32px; height: 32px; }

/* 4.11 Skeletons y spinners */
.skeleton { background: var(--surface-2); border-radius: var(--radius-sm); position: relative; overflow: hidden; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent); animation: shimmer 1.4s infinite; }
@media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skeleton-text { height: 14px; width: 80%; margin: var(--sp-2) 0; }
.skeleton-text:nth-child(2n) { width: 65%; }
.skeleton-text:nth-child(3n) { width: 90%; }
.skeleton-title { height: 20px; width: 40%; margin-bottom: var(--sp-3); }
.skeleton-kpi { height: 34px; width: 55%; }
.skeleton-row { height: 52px; margin-bottom: var(--sp-2); border-radius: var(--radius); }
.skeleton-card { height: 140px; border-radius: var(--radius-lg); }
.skeleton-thumb { width: 72px; height: 72px; }
.skeleton-wait { color: var(--text-dim); font-size: var(--fs-sm); margin-top: var(--sp-3); }
.spinner { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent-text); border-top-color: transparent; animation: spin .7s linear infinite; flex: none; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .btn.is-loading::after { animation-duration: 1.5s; } }

/* 4.12 Tabs y segmentado */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 var(--sp-3); height: var(--touch); color: var(--text-dim); font-weight: var(--fw-medium); white-space: nowrap; margin-bottom: -1px; border-radius: var(--radius) var(--radius) 0 0; }
@media (hover: hover) and (pointer: fine) { .tab:hover { color: var(--text); } }
.tab:active { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius); padding: 3px; gap: 2px; height: var(--control-h); }
.segmented button { border: 0; background: transparent; color: var(--text-dim); border-radius: calc(var(--radius) - 3px); padding: 0 var(--sp-3); font-weight: var(--fw-medium); font-size: var(--fs-sm); white-space: nowrap; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease-out); }
.segmented button:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) { .segmented button:hover { color: var(--text); } }
.segmented button[aria-checked="true"] { background: var(--surface-3); color: var(--text); }
@media (max-width: 639px) { .segmented { height: var(--touch); } }

/* 4.13 Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; top: calc(100% + 4px); right: 0; z-index: var(--z-dropdown); min-width: 200px; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: var(--sp-1); margin: 0; list-style: none; transform-origin: top right; transition: opacity var(--dur-enter) var(--ease-out), transform var(--dur-enter) var(--ease-out); }
@starting-style { .dropdown-menu:not([hidden]) { opacity: 0; transform: translateY(calc(var(--enter-y) * -0.5)); } }
.dropdown-menu[hidden] { display: none; }
.dropdown-menu.is-left { right: auto; left: 0; }
.menu-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: var(--touch); padding: 0 var(--sp-3); border: 0; background: none; color: var(--text); text-align: left; border-radius: var(--radius-sm); text-decoration: none; font-size: var(--fs-md); cursor: pointer; }
.menu-item:focus-visible { background: var(--surface-2); color: var(--text); }
@media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--surface-2); color: var(--text); } }
.menu-item:active { background: var(--surface-2); }
.menu-item.is-danger { color: var(--danger); }
.menu-item[aria-checked="true"] { font-weight: var(--fw-medium); }
.menu-item[aria-checked="true"]::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-text); }
.menu-item .avatar { width: 24px; height: 24px; font-size: var(--fs-xs); }
.menu-text { display: block; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.dropdown-sep { border: 0; border-top: 1px solid var(--border); margin: var(--sp-1) 0; }
.avatar-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--control-h); height: var(--control-h); border-radius: var(--radius-full); border: 0; background: transparent; padding: 0; }
@media (hover: hover) and (pointer: fine) { .avatar-btn:hover .avatar { background: var(--accent); color: var(--text-on-accent); } }
.avatar-btn:active .avatar { background: var(--accent); color: var(--text-on-accent); }
.avatar-btn:focus-visible { border-radius: var(--radius-full); }
@media (max-width: 639px) { .avatar-btn { width: var(--touch); height: var(--touch); } }

/* 4.14 Calendario (base; detalle en css/pages/calendario.css) */
.cal-nav { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.cal-nav h2 { flex: 1 1 auto; }
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-day { min-height: 96px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-1) var(--sp-2); font-size: var(--fs-xs); }
.cal-day.is-other { color: var(--text-muted); }
.cal-day.is-today .cal-num { background: var(--accent); color: var(--text-on-accent); border-radius: 50%; }
.cal-num { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; font-weight: var(--fw-medium); }
.cal-chip { display: flex; gap: 4px; align-items: center; font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
@media (max-width: 639px) { .cal-day { min-height: 48px; } .cal-chip span { display: none; } }

/* 4.15 Timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 8px; bottom: 8px; width: 2px; background: var(--border); }
.timeline-day { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-dim); margin: var(--sp-3) 0 var(--sp-2) var(--sp-6); }
.timeline-day:first-child { margin-top: 0; }
.timeline-item { position: relative; padding: 0 0 var(--sp-3) var(--sp-6); font-size: var(--fs-sm); }
.timeline-item::before { content: ""; position: absolute; left: 3px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); border: 2px solid var(--surface); }
.timeline-item.is-system::before { background: var(--brand); }
.timeline-item.is-error::before { background: var(--danger); }
.timeline-item.is-success::before { background: var(--success); }
.timeline-meta { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; color: var(--text-dim); font-size: var(--fs-sm); margin-top: 2px; font-variant-numeric: tabular-nums; }
.timeline-text { overflow-wrap: anywhere; }

/* 4.16 Graficas */
.chart { position: relative; width: 100%; min-width: 0; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-tip { position: absolute; z-index: 2; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3); font-size: var(--fs-xs); box-shadow: var(--shadow-md); pointer-events: none; white-space: nowrap; }
.chart-tip[hidden] { display: none; }
.chart-tip strong { display: block; margin-bottom: 2px; }
.chart-legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--text-dim); margin-top: var(--sp-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-table { margin-top: var(--sp-3); }
.chart-table[hidden] { display: none; }
.chart-axis { fill: var(--text-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.chart-grid line { stroke: var(--chart-grid); }

/* 4.17 Alertas */
.alert { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); border-left: 3px solid var(--info); background: var(--info-soft); }
.alert .icon { flex: none; margin-top: 2px; }
.alert-body { flex: 1 1 auto; min-width: 0; }
.alert-title { font-weight: var(--fw-medium); }
.alert-text { font-size: var(--fs-sm); color: var(--text-dim); margin: 0; }
.alert-actions { flex: none; display: flex; gap: var(--sp-2); }
.alert-info { border-left-color: var(--info); background: var(--info-soft); } .alert-info > .icon { color: var(--info); }
.alert-success { border-left-color: var(--success); background: var(--success-soft); } .alert-success > .icon { color: var(--success); }
.alert-warning { border-left-color: var(--warning); background: var(--warning-soft); } .alert-warning > .icon { color: var(--warning); }
.alert-danger { border-left-color: var(--danger); background: var(--danger-soft); } .alert-danger > .icon { color: var(--danger); }
@media (max-width: 639px) { .alert { flex-wrap: wrap; } .alert-actions { width: 100%; padding-left: 32px; } }

/* 4.18 Avatares y miniaturas */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; font-weight: var(--fw-semibold); font-size: var(--fs-sm); flex: none; overflow: hidden; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 48px; height: 48px; font-size: var(--fs-lg); }
.thumb { object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); flex: none; }
.thumb-48 { width: 48px; height: 48px; } .thumb-72 { width: 72px; height: 72px; } .thumb-120 { width: 120px; height: 120px; }
.thumb-placeholder { display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); }
.thumb-grid { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.thumb-item { position: relative; }
.thumb-item .icon-btn { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; min-height: 0; background: var(--surface-3); }
.thumb.is-unpublishable { outline: 2px solid var(--warning); }

/* 4.19 Paginacion */
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--text-dim); }
.pagination[hidden] { display: none; }

/* Lista simple de items (usada en inicio, sugerencias, tendencias) */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item:last-child { padding-bottom: 0; }
.list-body { flex: 1 1 auto; min-width: 0; }
.list-title { font-weight: var(--fw-medium); overflow-wrap: anywhere; }
.list-text { font-size: var(--fs-sm); color: var(--text-dim); margin: 2px 0 0; overflow-wrap: anywhere; }
.list-actions { flex: none; }
@media (max-width: 639px) { .list-item { flex-wrap: wrap; } .list-actions { width: 100%; } .list-actions .btn { width: 100%; } }

/* 4.20 Idioma de luz del panel (maqueta de referencia de Inicio, 24 sept 2026; docs/spec/30 §2.5.1)
   Compartido por las pantallas que ya lo hablan (Inicio, Sugerencias...). Todo color sale de tokens. */
/* Superficie "lit": radio 8, sin sombra proyectada, una linea de luz interior arriba (--edge). */
.stat .num, .num.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.lit { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: inset 0 1px 0 var(--edge); }
/* Rotulo de 11 px en MAYUSCULAS con espaciado. */
.rotulo { font-size: var(--fs-label); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
/* Enlace discreto de cabecera ("Ver todas"). */
.link-more { color: var(--text-muted); text-decoration: none; font-size: var(--fs-label); font-weight: var(--fw-medium); white-space: nowrap; flex: none; transition: color var(--dur-fast) var(--ease); }
/* Como <button> (p. ej. "Ver todo el periodo" en Calendario) se ve igual que como enlace: sin caja del navegador. */
button.link-more { background: none; border: 0; padding: 0; font: inherit; font-size: var(--fs-label); font-weight: var(--fw-medium); cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .link-more:hover { color: var(--accent-text); } }
.grow { min-width: 0; flex: 1 1 auto; }
/* Tarjeta .lit: sin padding propio; la cabecera lleva el titulo a 13 px con la rayita 3x12 de acento y un hilo de
   acento debajo que se apaga hacia la derecha; el cuerpo lo ponen las filas. */
.card.lit { padding: 0; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.card.lit > .card-head { position: relative; margin: 0; padding: 11px 13px; border-bottom: 1px solid var(--border-soft); flex-wrap: nowrap; }
.card.lit > .card-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(to right, var(--accent-line), transparent 45%); }
.card.lit .card-title { font-size: var(--fs-ui); font-weight: var(--fw-semibold); letter-spacing: -.012em; gap: 8px; }
.card.lit .card-title::before { content: ""; width: 3px; height: 12px; border-radius: 2px; flex: none; background: linear-gradient(to bottom, var(--accent), transparent); }
.card.lit > .card-body { padding: 0; }
.card.lit > .card-body > .empty, .card.lit > .card-body > .skeleton-wrap, .card.lit > .card-body > .alert, .card.lit > .card-body > .chart-empty { margin: 13px; }
.card.lit > .card-body > .alert.mb-4 { margin-bottom: 0; }
/* Insignias dentro de una superficie .lit: pastillas de 11 px, radio 5, sin punto (el color ya va en el texto). */
.lit .badge { height: auto; padding: 2px 7px; border-radius: 5px; font-size: var(--fs-label); font-weight: var(--fw-medium); }
.lit .badge::before { display: none; }
/* Filas: actividad, notificaciones, recomendaciones, publicaciones. Verde (.is-done) = lo que el sistema hizo solo y completo. */
.feed { list-style: none; margin: 0; padding: 0; }
.feed-item { display: flex; gap: 10px; align-items: center; padding: 10px 13px; border-bottom: 1px solid var(--border-soft); position: relative; }
.feed-item:last-child { border-bottom: 0; }
.feed-item.is-done::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 2px; border-radius: 2px; background: var(--rayita-success); }
.feed-t { font-weight: var(--fw-medium); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
@media (hover: hover) and (pointer: fine) { a.feed-t:hover { color: var(--accent-text); } }
.feed-when { color: var(--text-muted); font-size: var(--fs-label); white-space: nowrap; }
.feed-d { display: block; color: var(--text-dim); }
.feed-item .link-more { font-size: var(--fs-label); }
.daymark { font-size: var(--fs-label); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); padding: 9px 13px 3px; }
/* Estado vacio en fila: icono en caja de acento, texto, accion. La rayita va tenue: invita, no urge. */
.empty-row { display: flex; align-items: center; gap: 11px; padding: 13px; position: relative; }
.empty-row::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--rayita-accent); opacity: .55; }
.empty-ico { width: 30px; height: 30px; border-radius: 7px; color: var(--accent-text); background: var(--accent-soft); border: 1px solid var(--accent-line); display: grid; place-items: center; flex: none; box-shadow: inset 0 1px 0 var(--edge); }
.empty-ico .icon { width: 15px; height: 15px; }
.empty-row p { margin: 0; color: var(--text-dim); }
.empty-row strong { display: block; color: var(--text); font-weight: var(--fw-medium); }
@media (max-width: 639px) { .empty-row { flex-wrap: wrap; } }
/* Entrada: cada bloque se asienta 5 px en 220 ms. Solo transform, nunca opacidad: si la animacion falla, nada
   queda invisible. Cada pantalla decide que bloques y con que escalon (20/60/100/140 ms). */
@keyframes settle { from { transform: translateY(5px); } to { transform: translateY(0); } }
/* Metricas: la fila de instrumentos (maqueta de Inicio). Rotulo 11 px, valor 23 mono, grafica pequena (js/spark.js) y delta en pastilla. */
.stat {
  padding: 12px 13px 10px; gap: 3px; position: relative; overflow: hidden;
  background: linear-gradient(to bottom, var(--tint), transparent 58%), var(--surface);
}
/* Hilo de acento arriba de cada metrica; casi apagado cuando la metrica esta en cero o sin conectar. */
.stat::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; background: linear-gradient(to right, transparent, var(--accent-line), transparent); }
.stat.is-zero::after { opacity: .35; }
.stat-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; min-width: 0; }
.stat-v { font-size: var(--fs-num); font-weight: var(--fw-semibold); letter-spacing: -.03em; line-height: 1.1; min-width: 0; overflow-wrap: anywhere; }
.spark, .spark-slot { width: 62px; height: 22px; flex: none; overflow: visible; }
.spark-fill { fill: var(--accent-soft); stroke: none; }
.spark-line { fill: none; stroke: var(--chart-1); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.spark-live, .spark-halo { fill: var(--chart-1); }
/* El punto final late (2,6 s) y su halo se expande y se desvanece: una senal en vivo. Solo cuando hay dato. */
.spark-live { animation: latido 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.spark-halo { animation: halo 2.6s ease-in-out infinite; }
@keyframes latido { 0%, 100% { r: 2.4; opacity: 1; } 50% { r: 3.4; opacity: .55; } }
@keyframes halo { 0% { r: 2.4; opacity: .5; } 100% { r: 9; opacity: 0; } }
/* Metrica en cero o sin conectar: linea punteada gris y punto quieto. No late porque no hay nada vivo. */
.spark-flat { fill: none; stroke: var(--text-muted); stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 3 4; }
.spark-dot { fill: var(--text-muted); }
.stat-delta { display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap; color: var(--text-muted); font-size: var(--fs-label); }
.stat-delta b { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: var(--fw-medium); border-radius: 5px; padding: 1px 5px; color: var(--text-dim); background: var(--surface-2); }
.stat-delta.is-up b { color: var(--success); background: var(--success-soft); }
.stat-delta.is-down b { color: var(--danger); background: var(--danger-soft); }
.stat-delta a { color: var(--accent-text); }

@media (max-width: 639px) { .stat { padding: 10px 11px 9px; } }
@media (prefers-reduced-motion: reduce) { .spark-live, .spark-halo { animation: none; } }

/* Pantalla completa de error (shell) */
.fullscreen-state { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--gutter); }

/* ---------------------------------------------------------------- barra de acciones de formulario
   Fija al pie mientras se edita (public/js/barra-acciones.js). Sticky y ULTIMO hijo del formulario:
   ocupa su propio sitio en el flujo, asi que nunca tapa el ultimo campo — el "hueco" es la barra misma.
   La franja de sistema del telefono se respeta con --safe-bottom (tokens.css), que vale 0 donde no
   aplica. Fondo solido de token (--sticky-bar-bg), nunca transparente: ver tokens.css. */
.form-actions-bar {
  position: sticky; bottom: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  margin-top: var(--sp-6);
  /* Se sale del padding de la tarjeta para llegar a los bordes, y lo repone por dentro. */
  margin-left: calc(-1 * var(--sp-5)); margin-right: calc(-1 * var(--sp-5)); margin-bottom: calc(-1 * var(--sp-5));
  padding: var(--sp-3) var(--sp-5) calc(var(--sp-3) + var(--safe-bottom));
  background: var(--sticky-bar-bg);
  border-top: 1px solid var(--sticky-bar-border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  /* Sin sombra: el borde superior fuerte ya separa la barra del contenido que pasa por debajo (PR 0 de diseno). */
}
.form-actions-buttons { display: flex; gap: var(--sp-2); margin-left: auto; }
.form-actions-bar .btn-block { width: auto; }
/* Aviso discreto: color semantico de advertencia, ya medido sobre --surface en las 12 paletas. */
.form-actions-note { color: var(--warning); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.form-actions-note[hidden] { display: none; }
@media (max-width: 639px) {
  .form-actions-buttons { width: 100%; }
  .form-actions-buttons .btn { flex: 1 1 0; }
}
