/* Componentes — POS-SAAS-0A.2
   Cada combinación texto/fondo de este archivo está listada y verificada en
   js/core/contrast-pairs.js (AA ≥ 4.5 con texto normal). */

/* ─────────────────────────── Botones ─────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: 0 var(--s-5);
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: var(--fs-md);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .5; }

.btn--primary { background: var(--c-primary-strong); color: var(--c-on-primary); }
.btn--primary:hover:not(:disabled) { background: var(--c-primary-hover); }

.btn--secondary { background: var(--c-surface); color: var(--c-ink); border-color: var(--c-line-strong); }
.btn--secondary:hover:not(:disabled) { border-color: var(--c-ink); }

.btn--ghost { background: transparent; color: var(--c-ink); }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-2); }

.btn--danger { background: var(--c-surface); color: var(--c-danger); border-color: currentColor; }
.btn--danger:hover:not(:disabled) { background: var(--c-danger-soft); }

.btn--lg { min-height: var(--touch-lg); font-size: var(--fs-lg); }
.btn--touch { min-height: var(--touch-xl); padding: 0 var(--s-6); font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn--icon { width: var(--touch); padding: 0; }
.btn--icon.btn--touch { width: var(--touch-xl); }
.btn .icon { width: 20px; height: 20px; }

/* ─────────────────────── Badges, chips, estados ─────────────────────── */

.badge, .status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.badge .icon, .status .icon { width: 16px; height: 16px; }

.badge--neutral { background: var(--c-surface-2); color: var(--c-ink); }
.badge--primary { background: var(--c-primary-soft); color: var(--c-ink); }
.badge--primary .icon { color: var(--c-primary-ink); }
.badge--success, .status--success { background: var(--c-secondary-soft); color: var(--c-secondary-ink); }
.badge--active, .status--active { background: var(--c-surface-2); color: var(--c-petrol); } /* estado activo o en curso (activo, caja abierta, en preparación): petróleo, no verde ni ámbar */
.badge--warning, .status--warning { background: var(--c-accent-soft); color: var(--c-accent-ink); box-shadow: inset 0 0 0 1px var(--c-accent); }
.badge--danger, .status--danger { background: var(--c-danger-soft); color: var(--c-danger); }
.status--info { background: var(--c-surface-2); color: var(--c-ink); }
.status--neutral { background: var(--c-surface); color: var(--c-ink-2); box-shadow: inset 0 0 0 1px var(--c-line-strong); }
.badge--demo {
  background: var(--c-surface-2);
  color: var(--c-petrol);
  box-shadow: inset 0 0 0 1px var(--c-petrol);
  font-size: var(--fs-xs);
  letter-spacing: .08em;
  min-height: 24px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border: 1.5px solid var(--c-line-strong);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-ink);
  font-weight: 600;
}
.chip:hover { border-color: var(--c-ink); }
.chip.is-selected { background: var(--c-petrol); border-color: var(--c-petrol); color: var(--c-on-petrol); }
.chip.is-selected .icon { color: var(--c-on-petrol); }
.chip .icon { width: 18px; height: 18px; }

/* ─────────────────────────── Superficies ─────────────────────────── */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-1);
}
.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-6) 0;
}
.card__title { font-size: var(--fs-lg); font-weight: 700; }
.card__subtitle { margin-top: var(--s-1); color: var(--c-ink-2); }
.card__actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.card__body { padding: var(--s-5) var(--s-6) var(--s-6); display: grid; gap: var(--s-4); }

.kpis { display: grid; gap: var(--s-4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  display: grid;
  gap: var(--s-1);
  padding: var(--s-5);
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.kpi__top { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.kpi__label { color: var(--c-ink-2); font-weight: 600; font-size: var(--fs-sm); }
.kpi__icon {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  color: var(--c-petrol);
}
.kpi__value { font-size: var(--fs-3xl); font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.kpi__sub { color: var(--c-ink-2); font-size: var(--fs-sm); }
.kpi--warning { border-color: var(--c-accent); }
.kpi--warning .kpi__icon { background: var(--c-accent-soft); color: var(--c-accent-ink); }

/* ─────────────────────────── Tabla ─────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--c-line); border-radius: var(--r-lg); }
.table { width: 100%; border-collapse: collapse; background: var(--c-surface); }
.table th, .table td { padding: var(--s-3) var(--s-4); text-align: left; vertical-align: middle; }
.table th {
  background: var(--c-surface-2);
  color: var(--c-ink);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
}
.table td { border-top: 1px solid var(--c-line); }
.table .is-end { text-align: right; }
.table .is-center { text-align: center; }

/* ─────────────────────────── Formularios ─────────────────────────── */

.field { display: grid; gap: 6px; }
.field__label { font-weight: 600; }
.field__hint { font-size: var(--fs-sm); color: var(--c-ink-2); }
.input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border: 1.5px solid var(--c-line-strong);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-ink);
}
.input::placeholder { color: var(--c-ink-2); }
.input:hover:not(:disabled) { border-color: var(--c-ink-2); }
.input:focus-visible { border-color: var(--c-ink); }
.input:disabled { background: var(--c-surface-2); cursor: not-allowed; }
.select {
  appearance: none;
  padding-right: var(--s-10);
  background-image: linear-gradient(45deg, transparent 50%, var(--c-ink) 50%), linear-gradient(135deg, var(--c-ink) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

/* Interruptor: el estado se lee por posición, icono y texto, no solo por color. */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  background: var(--c-surface);
}
.switch-row.is-on { border-color: var(--c-petrol); }
.switch-row__text { display: grid; gap: 2px; min-width: 0; }
.switch-row__label { font-weight: 700; font-size: var(--fs-md); }
.switch-row__desc { color: var(--c-ink-2); font-size: var(--fs-sm); }
.switch-row__control { display: flex; align-items: center; gap: var(--s-3); flex: none; }
.switch__state { min-width: 6.5em; text-align: right; font-weight: 600; font-size: var(--fs-sm); color: var(--c-ink-2); }
.switch-row.is-on .switch__state { color: var(--c-petrol); }
.switch-row__lock { color: var(--c-ink-2); width: 18px; height: 18px; }

.switch {
  display: inline-grid;
  place-items: center;
  width: 64px;
  min-height: var(--touch);
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: var(--r-pill);
}
.switch__track {
  position: relative;
  width: 56px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  box-shadow: inset 0 0 0 1.5px var(--c-line-strong);
  transition: background var(--t-fast) var(--ease);
}
.switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c-surface);
  color: var(--c-ink-2);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--c-line-strong);
  transition: transform var(--t-fast) var(--ease);
}
.switch__thumb .icon { width: 16px; height: 16px; stroke-width: 2.5; }
.switch .switch__on { display: none; }
.switch[aria-checked="true"] .switch__track { background: var(--c-petrol); box-shadow: none; }
.switch[aria-checked="true"] .switch__thumb { transform: translateX(24px); color: var(--c-petrol); box-shadow: var(--shadow-1); }
.switch[aria-checked="true"] .switch__on { display: block; }
.switch[aria-checked="true"] .switch__off { display: none; }
.switch:hover:not(:disabled) .switch__track { box-shadow: inset 0 0 0 1.5px var(--c-ink-2); }
.switch[aria-checked="true"]:hover:not(:disabled) .switch__track { box-shadow: inset 0 0 0 2px var(--c-ink); }
.switch:disabled { cursor: not-allowed; opacity: .55; }
.switch-row.is-locked { background: var(--c-bg); }

/* ─────────────────────────── Pestañas ─────────────────────────── */

.tabs {
  display: flex;
  gap: var(--s-1);
  border-bottom: 1px solid var(--c-line);
  margin-bottom: var(--s-6);
  overflow-x: auto;
}
.tabs__tab {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--touch-lg);
  padding: 0 var(--s-4);
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--c-ink-2);
  font-weight: 600;
  white-space: nowrap;
}
.tabs__tab:hover { color: var(--c-ink); background: var(--c-surface-2); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.tabs__tab.is-selected { color: var(--c-ink); font-weight: 700; border-bottom-color: var(--c-interact); }
.tabs__tab.is-selected .icon { color: var(--c-interact-ink); }
.tabpanel:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--r-lg); }

/* ─────────────────────────── Modal ─────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background: var(--c-overlay);
  animation: fade-in var(--t-fast) var(--ease);
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  animation: rise var(--t-fast) var(--ease);
}
.modal--sm { width: min(420px, 100%); }
.modal--lg { width: min(760px, 100%); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--c-line); }
.modal__title { font-size: var(--fs-xl); }
.modal__body { padding: var(--s-6); overflow: auto; display: grid; gap: var(--s-4); }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--c-line); }

/* ─────────────────────────── Toasts ─────────────────────────── */

.toasts {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  z-index: 60;
  display: grid;
  gap: var(--s-3);
  width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-4);
  background: var(--c-surface);
  color: var(--c-ink);
  border: 1px solid var(--c-line);
  border-left: 5px solid var(--c-ink-2);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  animation: rise var(--t-fast) var(--ease);
}
.toast > .icon { margin-top: 2px; }
.toast__msg { flex: 1; font-weight: 600; }
.toast__close {
  display: grid; place-items: center;
  width: 32px; height: 32px; margin: -4px -4px -4px 0;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--c-ink-2);
}
.toast__close:hover { background: var(--c-surface-2); color: var(--c-ink); }
.toast--success { border-left-color: var(--c-secondary); }
.toast--success > .icon { color: var(--c-secondary-ink); }
.toast--warning { border-left-color: var(--c-accent); }
.toast--warning > .icon { color: var(--c-accent-ink); }
.toast--error { border-left-color: var(--c-danger); }
.toast--error > .icon { color: var(--c-danger); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all 200ms var(--ease); }

/* 0A.7 · Dentro de un diálogo: en el flujo, entre el encabezado y el contenido.
   Nunca se encima con «Cerrar», el pie ni los campos. */
.modal__toasts:empty, .modal__toasts:has(> .toasts:empty) { display: none; }
.modal__toasts { flex: none; padding: var(--s-3) var(--s-6) 0; }
.toasts--inline { position: static; width: auto; gap: var(--s-2); }
.toasts--inline .toast { padding: var(--s-2) var(--s-3); box-shadow: none; animation: none; }
@media (max-width: 640px) {
  .toasts { left: var(--s-4); right: var(--s-4); bottom: var(--s-4); width: auto; }
  .toast { padding: var(--s-3); }
  .modal__toasts { padding: var(--s-2) var(--s-4) 0; }
}

.note { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2); color: var(--c-ink-2); font-size: var(--fs-sm); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
