/* ==========================================================================
   TOOLBOX · UI COMPONENTS CANÓNICOS · Fase 8B.1
   --------------------------------------------------------------------------
   Contrato de componentes comunes para 8B.2 / 8B.3. Requiere
   toolbox-design-tokens.css. NO cargar globalmente todavía; no sustituye
   los componentes actuales. Prefijo reservado: .tb-
   ========================================================================== */

/* ── BASE ──────────────────────────────────────────────────────────────── */
.tb-root { font-family: var(--tb-font-family); color: var(--tb-color-text); }

/* Foco visible universal (corrige A-01: outline suprimido) */
.tb-root :focus-visible,
[class^="tb-"]:focus-visible {
  outline: none;
  box-shadow: var(--tb-focus-ring);
  border-radius: var(--tb-radius-sm);
}

/* ── BUTTON · jerarquía primary/secondary/tertiary/danger/icon ─────────── */
.tb-button {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--tb-space-2);
  font-family: var(--tb-font-family);
  font-size: var(--tb-font-size-md); font-weight: var(--tb-font-weight-semibold);
  border-radius: var(--tb-radius-pill);
  padding: 10px 20px; min-height: 40px;
  border: 1px solid transparent; cursor: pointer; user-select: none;
  transition: background var(--tb-motion-fast) var(--tb-ease),
              color var(--tb-motion-fast) var(--tb-ease),
              border-color var(--tb-motion-fast) var(--tb-ease);
}
.tb-button--primary   { background: var(--tb-gradient-brand); color: #fff; box-shadow: var(--tb-shadow-brand); }
.tb-button--primary:hover { filter: brightness(1.06); }
.tb-button--secondary { background: var(--tb-color-surface); color: var(--tb-color-primary); border: var(--tb-border-interactive); }
.tb-button--secondary:hover { background: var(--tb-color-surface-tint); }
.tb-button--tertiary  { background: transparent; color: var(--tb-color-primary); }
.tb-button--tertiary:hover { background: var(--tb-color-surface-tint); }
.tb-button--danger    { background: var(--tb-color-danger); color: #fff; }
.tb-button--danger:hover { background: var(--tb-color-danger-text); }
.tb-button--sm { min-height: 32px; padding: 6px 14px; font-size: var(--tb-font-size-sm); }
.tb-button:disabled, .tb-button[aria-disabled="true"] {
  opacity: .45; cursor: not-allowed; box-shadow: none; filter: none;
}
.tb-button--loading { position: relative; color: transparent !important; pointer-events: none; }
.tb-button--loading::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: tb-spin .8s linear infinite;
}
.tb-button--secondary.tb-button--loading::after,
.tb-button--tertiary.tb-button--loading::after { border-color: var(--tb-color-border); border-top-color: var(--tb-color-primary); }
/* Icon button: requiere aria-label. Táctil ≥44px en tienda/mobile. */
.tb-icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--tb-radius-md);
  background: var(--tb-color-surface-tint); color: var(--tb-color-primary);
  border: none; cursor: pointer;
  transition: background var(--tb-motion-fast) var(--tb-ease);
}
.tb-icon-button:hover { background: var(--tb-color-bg-alt); }
.tb-icon-button--touch { width: 44px; height: 44px; }

/* ── LINK ──────────────────────────────────────────────────────────────── */
.tb-link { color: var(--tb-color-primary); text-decoration: none; font-weight: var(--tb-font-weight-medium); }
.tb-link:hover { color: var(--tb-color-secondary); text-decoration: underline; }

/* ── CARD · standard/kpi/alert/restricted ──────────────────────────────── */
.tb-card {
  background: var(--tb-color-surface);
  border: var(--tb-border);
  border-radius: var(--tb-radius-card);
  padding: var(--tb-space-4);
}
.tb-card--raised { box-shadow: var(--tb-shadow-soft); }
.tb-card__header { display: flex; align-items: center; gap: var(--tb-space-2); margin-bottom: var(--tb-space-3); }
.tb-card__title {
  font-family: var(--tb-font-family-display);
  font-weight: var(--tb-font-weight-display);
  font-size: var(--tb-font-size-xl); line-height: var(--tb-line-height-tight);
  color: var(--tb-color-text);
}
.tb-card__footer { margin-top: var(--tb-space-3); padding-top: var(--tb-space-3); border-top: var(--tb-border); }
.tb-card--kpi .tb-kpi-label {
  font-size: var(--tb-font-size-xs); font-weight: var(--tb-font-weight-semibold);
  letter-spacing: var(--tb-letter-spacing-caps); text-transform: uppercase;
  color: var(--tb-color-text-muted);
}
.tb-card--kpi .tb-kpi-value {
  font-family: var(--tb-font-family-display); font-weight: var(--tb-font-weight-display);
  font-size: var(--tb-font-size-2xl); line-height: var(--tb-line-height-tight);
}
.tb-card--alert { border-left: none; background: var(--tb-color-surface); }
.tb-card--alert[data-severity="warning"]  { border-color: #F0DDB4; background: var(--tb-color-warning-bg); }
.tb-card--alert[data-severity="critical"] { border-color: #F3C9CB; background: var(--tb-color-danger-bg); }
.tb-card--alert[data-severity="info"]     { border-color: #B9D6EA; background: var(--tb-color-info-bg); }
.tb-card--restricted { background: var(--tb-color-bg-alt); border-style: dashed; color: var(--tb-color-text-muted); }

/* ── BADGE / STATUS PILL (estado nunca solo por color: punto + texto) ──── */
.tb-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--tb-font-size-xs); font-weight: var(--tb-font-weight-semibold);
  border-radius: var(--tb-radius-pill); padding: 3px 10px;
  background: var(--tb-color-bg-alt); color: var(--tb-color-text-muted);
}
.tb-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.tb-status, .tb-badge--status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--tb-font-size-xs); font-weight: var(--tb-font-weight-semibold); border-radius: var(--tb-radius-pill); padding: 3px 10px; }
.tb-status--success  { color: var(--tb-color-success-text); background: var(--tb-color-success-bg); }
.tb-status--warning  { color: var(--tb-color-warning-text); background: var(--tb-color-warning-bg); }
.tb-status--danger   { color: var(--tb-color-danger-text);  background: var(--tb-color-danger-bg); }
.tb-status--info     { color: var(--tb-color-info);         background: var(--tb-color-info-bg); }
.tb-status--blocked  { color: var(--tb-color-blocked);      background: var(--tb-color-bg-alt); }

/* ── FORMULARIOS ───────────────────────────────────────────────────────── */
.tb-field { display: flex; flex-direction: column; gap: 6px; }
.tb-label {
  font-size: var(--tb-font-size-sm); font-weight: var(--tb-font-weight-semibold);
  color: var(--tb-color-text);
}
.tb-label--required::after { content: " *"; color: var(--tb-color-danger-text); }
.tb-help  { font-size: var(--tb-font-size-xs); color: var(--tb-color-text-muted); }
.tb-error { font-size: var(--tb-font-size-xs); color: var(--tb-color-danger-text); font-weight: var(--tb-font-weight-medium); display: flex; align-items: center; gap: 5px; }
.tb-input, .tb-select, .tb-textarea {
  font-family: var(--tb-font-family); font-size: var(--tb-font-size-md);
  color: var(--tb-color-text); background: var(--tb-color-surface);
  border: var(--tb-border); border-radius: var(--tb-radius-md);
  padding: 9px 12px; min-height: 40px; width: 100%;
  transition: border-color var(--tb-motion-fast) var(--tb-ease), box-shadow var(--tb-motion-fast) var(--tb-ease);
}
.tb-input:hover, .tb-select:hover, .tb-textarea:hover { border-color: var(--tb-color-border-strong); }
.tb-input:focus-visible, .tb-select:focus-visible, .tb-textarea:focus-visible {
  outline: none; border-color: var(--tb-color-focus); box-shadow: var(--tb-focus-ring);
}
.tb-input[aria-invalid="true"], .tb-textarea[aria-invalid="true"] {
  border-color: var(--tb-color-danger); background: var(--tb-color-danger-bg);
}
.tb-input:disabled, .tb-select:disabled, .tb-textarea:disabled {
  background: var(--tb-color-bg-alt); color: var(--tb-color-text-faint); cursor: not-allowed;
}
.tb-input--touch, .tb-select--touch { min-height: 44px; }
.tb-checkbox, .tb-radio { width: 18px; height: 18px; accent-color: var(--tb-color-primary); }
.tb-switch { /* contrato: input[type=checkbox][role=switch] 40×22, track border → primary */ }

/* ── PROGRESS ──────────────────────────────────────────────────────────── */
.tb-progress {
  height: 7px; border-radius: var(--tb-radius-pill);
  background: var(--tb-color-bg-alt); overflow: hidden;
}
.tb-progress__bar {
  height: 100%; border-radius: inherit;
  background: var(--tb-gradient-brand);
  transition: width var(--tb-motion-base) var(--tb-ease);
}
.tb-progress__bar--success { background: var(--tb-color-success); }
.tb-progress__bar--warning { background: var(--tb-color-warning); }

/* ── TIMELINE ──────────────────────────────────────────────────────────── */
.tb-timeline { display: flex; flex-direction: column; gap: 0; }
.tb-timeline__item { display: grid; grid-template-columns: 22px 1fr; gap: var(--tb-space-3); position: relative; padding-bottom: var(--tb-space-4); }
.tb-timeline__dot {
  width: 12px; height: 12px; border-radius: 50%; margin: 3px auto 0;
  background: var(--tb-color-surface); border: 2.5px solid var(--tb-color-border-strong);
}
.tb-timeline__item--done .tb-timeline__dot    { border-color: var(--tb-color-success); background: var(--tb-color-success); }
.tb-timeline__item--current .tb-timeline__dot { border-color: var(--tb-color-primary); }
.tb-timeline__item:not(:last-child)::before {
  content: ""; position: absolute; left: 10.5px; top: 18px; bottom: 0;
  width: 1.5px; background: var(--tb-color-border);
}

/* ── TABS ──────────────────────────────────────────────────────────────── */
.tb-tabs { display: flex; gap: var(--tb-space-1); border-bottom: var(--tb-border); }
.tb-tab {
  font-size: var(--tb-font-size-md); font-weight: var(--tb-font-weight-semibold);
  color: var(--tb-color-text-muted); background: none; border: none; cursor: pointer;
  padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tb-tab:hover { color: var(--tb-color-text); }
.tb-tab[aria-selected="true"] { color: var(--tb-color-primary); border-bottom-color: var(--tb-color-primary); }

/* ── TABLE ─────────────────────────────────────────────────────────────── */
.tb-table { width: 100%; border-collapse: collapse; font-size: var(--tb-font-size-md); }
.tb-table th {
  text-align: left; font-size: var(--tb-font-size-xs);
  font-weight: var(--tb-font-weight-semibold); letter-spacing: var(--tb-letter-spacing-caps);
  text-transform: uppercase; color: var(--tb-color-text-muted);
  padding: 8px 12px; border-bottom: var(--tb-border);
}
.tb-table td { padding: 12px; border-bottom: var(--tb-border); }
.tb-table td[data-num], .tb-table th[data-num] { text-align: right; font-variant-numeric: tabular-nums; }
.tb-table tr:hover > td { background: var(--tb-color-bg); }
.tb-table tr[aria-selected="true"] > td { background: var(--tb-color-surface-tint); }

/* ── MODAL / DRAWER ────────────────────────────────────────────────────── */
.tb-modal-backdrop {
  position: fixed; inset: 0; z-index: var(--tb-z-modal);
  background: rgba(31,42,58,.5);
  display: flex; align-items: center; justify-content: center; padding: var(--tb-space-5);
}
.tb-modal {
  background: var(--tb-color-surface); border-radius: var(--tb-radius-lg);
  box-shadow: var(--tb-shadow-modal);
  max-width: 560px; width: 100%; max-height: calc(100vh - 64px); overflow-y: auto;
  padding: var(--tb-space-5);
  animation: tb-in var(--tb-motion-base) var(--tb-ease) both;
}
.tb-drawer {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: var(--tb-z-drawer);
  width: min(420px, 92vw); background: var(--tb-color-surface);
  box-shadow: var(--tb-shadow-modal); overflow-y: auto; padding: var(--tb-space-5);
}

/* ── EMPTY / RESTRICTED STATE ──────────────────────────────────────────── */
.tb-empty-state, .tb-restricted-state {
  text-align: center; padding: var(--tb-space-6) var(--tb-space-5);
  border-radius: var(--tb-radius-card);
}
.tb-empty-state { background: var(--tb-color-surface); border: var(--tb-border); color: var(--tb-color-text-muted); }
.tb-restricted-state { background: var(--tb-color-bg-alt); border: 1px dashed var(--tb-color-border-strong); color: var(--tb-color-text-muted); }
.tb-empty-state__title, .tb-restricted-state__title {
  font-family: var(--tb-font-family-display); font-weight: var(--tb-font-weight-display);
  font-size: var(--tb-font-size-2xl); color: var(--tb-color-text); line-height: var(--tb-line-height-tight);
}

/* ── ANIMACIONES + REDUCED MOTION ──────────────────────────────────────── */
@keyframes tb-in   { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes tb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  [class^="tb-"], [class^="tb-"]::before, [class^="tb-"]::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
