/* =============================================================
   components.css — Componentes de Atlas (contrato visual común).
   Botones, campos, tarjetas, chips, hojas, avisos, tablas, pestañas,
   estados, badges de estado y de riesgo, diff, plegables y piezas de edición.
   ============================================================= */

/* ===================== BOTONES ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 12px 20px;
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  line-height: 1.25;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  transition: transform var(--transition-fast), background var(--transition), box-shadow var(--transition), filter var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn i { font-size: 1.1em; }

.btn-primary { background: var(--primary-solid); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger { background: var(--danger-solid); color: #FFFFFF; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.94); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger-text); }
.btn-danger-soft:hover:not(:disabled) { filter: brightness(0.97); }

.btn-sm { min-height: 40px; padding: 8px 14px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-lg { min-height: 54px; padding: 15px 24px; font-size: var(--fs-md); border-radius: var(--radius-md); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 48px; min-height: 48px; flex: 0 0 auto; font-size: 1.1rem; }
.btn-icon.btn-sm { width: 40px; min-height: 40px; }

/* Botón redondo de solo icono (44 px) */
.round-button {
  width: 44px; height: 44px;
  border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: transform var(--transition-fast), background var(--transition);
}
.round-button:hover { background: var(--surface-hover); }
.round-button:active { transform: scale(0.92); }
.round-button:disabled { opacity: 0.4; }
.round-button.plain { border-color: transparent; background: transparent; }
.round-button.plain:hover { background: var(--surface-2); }

/* Enlace con aspecto de texto que mantiene zona táctil de 44 px */
.link-button {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 44px; padding: 0 var(--space-1);
  color: var(--primary); font-weight: var(--fw-semibold);
}
.link-button:hover { text-decoration: underline; text-underline-offset: 3px; }

.button-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* ===================== CAMPOS ===================== */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field + .field, .field + .form-row, .form-row + .field, .form-row + .form-row { margin-top: var(--space-4); }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-secondary); }
.field-label .optional { font-weight: var(--fw-medium); color: var(--text-muted); }
.field-hint { font-size: var(--fs-sm); color: var(--text-muted); }
.field-error { font-size: var(--fs-sm); color: var(--danger-text); font-weight: var(--fw-semibold); display: flex; gap: var(--space-1); align-items: flex-start; }
.form-row { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
.form-row > .field { margin-top: 0; }
@media (min-width: 640px) { .form-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.form-control, .form-select {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  color: var(--text);
  line-height: 1.4;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-control::placeholder { color: var(--text-muted); opacity: 1; }
.form-control:focus, .form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.form-control[aria-invalid="true"], .form-select[aria-invalid="true"] { border-color: var(--danger); }
.form-control:disabled, .form-select:disabled { background: var(--surface-2); color: var(--text-secondary); cursor: not-allowed; }
.form-control[readonly] { background: var(--surface-2); }
textarea.form-control { resize: vertical; min-height: 96px; }
.form-control.mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
.form-select {
  appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}
.form-control.compact, .form-select.compact { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }

/* Contraseña con botón mostrar/ocultar */
.input-with-action { position: relative; }
.input-with-action .form-control { padding-right: 52px; }
.input-with-action .input-action {
  position: absolute; top: 50%; right: 2px; transform: translateY(-50%);
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); border-radius: var(--radius-sm);
}
.input-with-action .input-action:hover { color: var(--primary); }

/* Casilla y opción en línea con zona táctil completa */
.check {
  position: relative; display: flex; align-items: flex-start; gap: var(--space-3);
  min-height: 44px; padding: 10px 0; cursor: pointer;
}
.check input[type="checkbox"], .check input[type="radio"] {
  width: 20px; height: 20px; margin-top: 1px; flex-shrink: 0; accent-color: var(--primary-solid); cursor: pointer;
}
/* La casilla no admite ::before en todos los navegadores: la zona de 40×40 la pone la etiqueta. */
.check::before { content: ''; position: absolute; top: 1px; left: -8px; width: 40px; height: 40px; }
.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-text small { color: var(--text-muted); font-size: var(--fs-sm); }

/* Interruptor (button role="switch") */
.switch {
  position: relative; flex-shrink: 0;
  width: 50px; height: 44px; border-radius: var(--radius-full);
  background: transparent;
}
.switch::before {
  content: ''; position: absolute; left: 0; right: 0; top: 7px; height: 30px;
  border-radius: var(--radius-full); background: var(--control-border);
  transition: background var(--transition-fast);
}
.switch::after {
  content: ''; position: absolute; top: 10px; left: 3px;
  width: 24px; height: 24px; border-radius: var(--radius-full);
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition-fast);
}
.switch[aria-checked="true"]::before { background: var(--primary-solid); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--surface); }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
.switch-row { display: flex; align-items: center; gap: var(--space-3); min-height: 54px; }
.switch-row .check-text { flex: 1; min-width: 0; }

/* Segmentado (pocas opciones excluyentes) */
.segmented { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; min-height: 40px; padding: 8px 12px; border-radius: 9px;
  font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.segmented button[aria-checked="true"], .segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* Opciones de una lista de selección */
.choice-list { display: flex; flex-direction: column; gap: var(--space-2); }
.choice {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 56px; padding: var(--space-2) var(--space-4); width: 100%;
  border-radius: var(--radius-control); border: 1px solid var(--border); background: var(--surface);
  font-weight: var(--fw-semibold); text-align: left;
}
.choice > i:first-child { font-size: 1.2rem; color: var(--text-secondary); }
.choice > span { flex: 1; min-width: 0; }
.choice small { display: block; font-weight: var(--fw-medium); color: var(--text-muted); font-size: var(--fs-sm); }
.choice .choice-check { color: var(--primary); font-size: 1.2rem; visibility: hidden; }
.choice[aria-checked="true"] { border: 2px solid var(--primary); padding: calc(var(--space-2) - 1px) calc(var(--space-4) - 1px); background: var(--primary-soft); }
.choice[aria-checked="true"] .choice-check { visibility: visible; }

/* Mensaje de error o éxito de un formulario completo */
.form-alert {
  display: flex; gap: var(--space-2); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  background: var(--danger-soft); color: var(--danger-text);
}
.form-alert.success { background: var(--success-soft); color: var(--success-text); }
.form-alert.info { background: var(--info-soft); color: var(--info-text); }
.form-alert i { line-height: 1.5; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-5); }
.form-actions .btn { flex: 0 0 auto; }

/* Subtítulo de bloque y fila de acciones bajo un bloque (Contratar y ficha del empleado) */
.hire-subtitle { font-size: var(--fs-xs); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: var(--space-4) 0 var(--space-2); }
.hire-subtitle:first-child { margin-top: 0; }
.hire-row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }

/* Subida de archivo: el input real cubre la zona con opacidad 0 */
.file-drop {
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); border: 1.5px dashed var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.file-drop:hover { border-color: var(--primary); }
.file-drop:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.file-drop input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-drop-icon {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: var(--radius-sm);
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.file-drop-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-drop-text strong { font-weight: var(--fw-semibold); }
.file-drop-text span { font-size: var(--fs-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-drop.has-file { border-style: solid; border-color: var(--primary); }

/* ===================== TARJETAS Y FILAS ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
}
.card.compact { padding: var(--space-4); }
.card-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-4); }
.card-header > div:first-child { flex: 1 1 220px; min-width: 0; }
.card-title { font-size: var(--fs-md); font-weight: var(--fw-extra); }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
a.card, button.card { display: block; color: inherit; text-align: left; width: 100%; transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition-fast); }
a.card:hover, button.card:hover { text-decoration: none; border-color: var(--border-strong); }
@media (hover: hover) { a.card:hover, button.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); } }

.card-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-card); }

/* Fila genérica de lista: icono · texto · meta · cola */
.list-row {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 60px; padding: 10px var(--space-4); width: 100%;
  color: inherit; text-align: left; text-decoration: none;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.list-row + .list-row { border-top: 1px solid var(--border); }
a.list-row:hover, button.list-row:hover { text-decoration: none; background: var(--surface-hover); }
a.list-row:active, button.list-row:active { transform: scale(0.99); }
.list-icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  background: var(--surface-2); color: var(--text-secondary);
}
.list-icon.primary { background: var(--primary-soft); color: var(--primary-ink); }
.list-icon.success { background: var(--success-soft); color: var(--success-text); }
.list-icon.warning { background: var(--warning-soft); color: var(--warning-text); }
.list-icon.danger { background: var(--danger-soft); color: var(--danger-text); }
.list-icon.info { background: var(--info-soft); color: var(--info-text); }
.list-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-text strong { font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-text small, .list-meta { font-size: var(--fs-sm); color: var(--text-muted); }
.list-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-trailing { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; color: var(--text-muted); font-size: var(--fs-sm); }
@media (max-width: 599px) {
  .list-row.stack-mobile { flex-wrap: wrap; }
  .list-row.stack-mobile .list-text { flex-basis: calc(100% - 52px); }
  .list-row.stack-mobile .list-trailing { width: 100%; justify-content: flex-end; }
}

/* Lista de ajustes (Pay v5) */
.settings-group + .settings-group { margin-top: var(--space-6); }
.settings-title {
  font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0 var(--space-1); margin-bottom: var(--space-2);
}
.settings-list { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow-card); }
.settings-row {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 54px; padding: 8px var(--space-4);
  background: none; color: var(--text); text-align: left; text-decoration: none;
}
.settings-row + .settings-row { border-top: 1px solid var(--border); }
button.settings-row:hover, a.settings-row:hover { background: var(--surface-hover); text-decoration: none; }
.settings-icon {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  background: var(--surface-2); color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.settings-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.settings-text strong { font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.settings-text small { font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.settings-value { color: var(--text-muted); font-size: var(--fs-sm); font-weight: var(--fw-semibold); white-space: nowrap; }
.settings-chevron { color: var(--text-muted); }
.settings-row.is-danger, .settings-row.is-danger .settings-icon { color: var(--danger-text); }

/* Lista etiqueta / valor */
.kv-list { display: flex; flex-direction: column; }
.kv-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; font-size: var(--fs-sm); }
.kv-row + .kv-row { border-top: 1px solid var(--border); }
.kv-label { color: var(--text-secondary); flex-shrink: 0; }
.kv-value { text-align: right; min-width: 0; overflow-wrap: anywhere; font-weight: var(--fw-semibold); }

/* Aviso destacado */
.callout {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  font-size: var(--fs-sm); background: var(--surface-2); color: var(--text);
}
.callout > i { flex-shrink: 0; font-size: 1.1rem; line-height: 1.3; }
.callout-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.callout-body strong { font-weight: var(--fw-bold); }
.callout-info { background: var(--info-soft); color: var(--info-text); }
.callout-success { background: var(--success-soft); color: var(--success-text); }
.callout-warning { background: var(--warning-soft); color: var(--warning-text); }
.callout-danger { background: var(--danger-soft); color: var(--danger-text); }
.callout .btn, .callout .link-button { margin-left: auto; flex-shrink: 0; }

/* Bloque de código o secreto que se muestra una sola vez */
.code-block {
  display: block; padding: var(--space-3) var(--space-4);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text);
  white-space: pre-wrap; word-break: break-all; user-select: all;
}
.copy-field { display: flex; gap: var(--space-2); align-items: stretch; }
.copy-field .code-block { flex: 1; min-width: 0; }

/* Barra de progreso (presupuesto) */
.progress { height: 8px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary-solid); transform-origin: left center; animation: grow-x 0.9s var(--ease-out) backwards; }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }
@keyframes grow-x { from { transform: scaleX(0); } }

/* Avatar con iniciales y tinte estable por id */
.avatar {
  width: 40px; height: 40px; border-radius: var(--radius-full); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--fw-extra); font-size: var(--fs-sm); letter-spacing: 0.02em;
  background: var(--tint-1-bg); color: var(--tint-1);
}
.avatar.sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar.lg { width: 56px; height: 56px; font-size: var(--fs-md); }
.avatar.square { border-radius: var(--radius-sm); }
.tint-1 { background: var(--tint-1-bg); color: var(--tint-1); }
.tint-2 { background: var(--tint-2-bg); color: var(--tint-2); }
.tint-3 { background: var(--tint-3-bg); color: var(--tint-3); }
.tint-4 { background: var(--tint-4-bg); color: var(--tint-4); }
.tint-5 { background: var(--tint-5-bg); color: var(--tint-5); }
.tint-6 { background: var(--tint-6-bg); color: var(--tint-6); }
.tint-7 { background: var(--tint-7-bg); color: var(--tint-7); }
.tint-8 { background: var(--tint-8-bg); color: var(--tint-8); }

/* ===================== CHIPS ===================== */
.chip-row {
  display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--space-5)); padding: var(--space-1) var(--space-5);
}
.chip-row::-webkit-scrollbar { display: none; }
@media (min-width: 600px) { .chip-row { flex-wrap: wrap; overflow: visible; margin: 0; padding: var(--space-1) 0; } }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
  min-height: 40px; padding: 0 var(--space-4);
  border-radius: var(--radius-full); background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: 1.25; white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
button.chip:hover { border-color: var(--border-strong); }
.chip:active { transform: scale(0.97); }
.chip[aria-pressed="true"], .chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .chip-count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-secondary); font-size: var(--fs-xs); font-weight: var(--fw-bold);
}
.chip[aria-pressed="true"] .chip-count, .chip.active .chip-count { background: color-mix(in srgb, var(--bg) 22%, transparent); color: var(--bg); }

/* ===================== BADGES DE ESTADO Y DE RIESGO ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
  min-height: 22px; padding: 1px 9px; border-radius: var(--radius-full);
  font-size: 0.75rem; font-weight: var(--fw-bold); line-height: 1.3; white-space: nowrap;
  background: var(--surface-2); color: var(--text-secondary);
}
.badge i { font-size: 0.85em; }
.badge-neutral { background: var(--surface-2); color: var(--text-secondary); }
.badge-primary { background: var(--primary-soft); color: var(--primary-ink); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-secondary); }
.badge-dot::before { content: ''; width: 7px; height: 7px; border-radius: var(--radius-full); background: currentColor; }

/* Riesgo: siempre con icono, nunca solo color */
.risk-badge { border: 1px solid transparent; }
.risk-badge.risk-high { background: var(--danger-soft); color: var(--danger-text); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.risk-badge.risk-medium { background: var(--warning-soft); color: var(--warning-text); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.risk-badge.risk-low { background: var(--info-soft); color: var(--info-text); }
.badge-list { display: flex; flex-wrap: wrap; gap: var(--space-1); }

/* Contador (bandeja) */
.count-badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger-solid); color: #FFFFFF; font-size: 0.75rem; font-weight: var(--fw-extra); line-height: 1;
}

/* Chip de entrega de una propuesta aprobada */
.delivery-chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  min-height: 28px; padding: 2px 10px 2px 8px; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: var(--fw-bold); white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
}
.delivery-chip i { font-size: 0.95rem; }
.delivery-chip.tone-success { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.delivery-chip.tone-warning { background: var(--warning-soft); color: var(--warning-text); border-color: transparent; }
.delivery-chip.tone-danger { background: var(--danger-soft); color: var(--danger-text); border-color: transparent; }
.delivery-chip.tone-info { background: var(--info-soft); color: var(--info-text); border-color: transparent; }
.delivery-chip.tone-shadow { background: var(--surface-2); color: var(--text-secondary); border-style: dashed; border-color: var(--border-strong); }

/* ===================== HOJAS (MODALES) ===================== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: var(--z-sheet);
  background: var(--scrim); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity var(--transition);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  background: var(--bg);
  width: 100%; max-width: var(--content-narrow); margin: 0 auto;
  height: 100%; min-height: 100dvh;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform var(--transition-bounce);
  overflow: hidden; outline: none;
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); padding-top: calc(var(--safe-top) + var(--space-3));
  border-bottom: 1px solid var(--border); background: var(--bg); flex-shrink: 0;
}
.sheet-title { font-size: var(--fs-md); font-weight: var(--fw-extra); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sheet-close {
  width: 44px; height: 44px; border-radius: var(--radius-full); flex-shrink: 0;
  background: var(--surface-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.sheet-body { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-4); -webkit-overflow-scrolling: touch; }
.sheet-footer {
  display: flex; gap: var(--space-3); flex-shrink: 0;
  padding: var(--space-4); padding-bottom: calc(var(--safe-bottom) + var(--space-4));
  border-top: 1px solid var(--border); background: var(--bg);
}
.sheet-footer .btn { flex: 1; min-width: 0; }
.sheet.no-footer .sheet-body { padding-bottom: calc(var(--safe-bottom) + var(--space-6)); }

/* Compacta: confirmaciones con alto según contenido y tirador */
.sheet-overlay.compact .sheet {
  height: auto; min-height: 0; max-height: 85dvh;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--shadow-lg);
}
.sheet-overlay.compact .sheet::before {
  content: ''; display: block; flex-shrink: 0;
  width: 40px; height: 5px; margin: 8px auto 0; border-radius: var(--radius-full); background: var(--border-strong);
}
.sheet-overlay.compact .sheet-header { border-bottom: none; padding-top: var(--space-3); padding-bottom: 0; }
.sheet-overlay.compact .sheet-body { flex: 0 1 auto; padding-top: var(--space-3); color: var(--text-secondary); }
.sheet-overlay.compact .sheet-footer { border-top: none; }

/* Escritorio: diálogo centrado en vez de pantalla completa */
@media (min-width: 900px) {
  .sheet-overlay { justify-content: center; padding: var(--space-8); }
  .sheet, .sheet-overlay.compact .sheet {
    height: auto; min-height: 0; max-height: min(88dvh, 900px);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
    transform: translateY(24px) scale(0.98); opacity: 0;
    transition: transform var(--transition), opacity var(--transition);
  }
  .sheet-overlay.open .sheet { transform: none; opacity: 1; }
  .sheet-overlay.compact .sheet { max-width: 480px; }
  .sheet-overlay.compact .sheet::before { display: none; }
  .sheet-overlay.compact .sheet-header { padding-top: var(--space-4); }
  .sheet-header { padding-top: var(--space-3); }
  .sheet-footer { padding-bottom: var(--space-4); justify-content: flex-end; }
  .sheet-footer .btn { flex: 0 0 auto; min-width: 140px; }
  .sheet-overlay.wide .sheet { max-width: 960px; }
}

/* ===================== AVISOS (TOASTS) ===================== */
.toast-container {
  position: fixed; top: calc(var(--safe-top) + var(--space-3)); left: 50%; transform: translateX(-50%);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2);
  width: calc(100% - var(--space-8)); max-width: 440px; pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--border); border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text);
  animation: toast-in 0.32s var(--ease-out) both; pointer-events: auto;
}
.toast > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast i { font-size: 1.15rem; line-height: 1.2; color: var(--primary); }
.toast.success { border-left-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.danger i { color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.warning i { color: var(--warning-text); }
.toast.info { border-left-color: var(--info); }
.toast.info i { color: var(--info); }
.toast.hide { animation: fadeIn 0.25s ease reverse both; }
.toast-close { width: 40px; height: 40px; margin: -10px -12px -10px 0; border-radius: var(--radius-full); color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.98); } }

/* ===================== TABLAS ===================== */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-card); }
.data-table { width: 100%; font-size: var(--fs-sm); }
.data-table caption { text-align: left; padding: var(--space-3) var(--space-4); font-weight: var(--fw-bold); }
.data-table th {
  text-align: left; padding: 10px var(--space-4); white-space: nowrap;
  font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px var(--space-4); vertical-align: middle; border-top: 1px solid var(--border); }
.data-table tbody tr:first-child td { border-top: none; }
.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr.is-clickable { cursor: pointer; }
.data-table tbody tr.is-clickable:hover { background: var(--surface-hover); }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table .cell-primary { font-weight: var(--fw-semibold); color: var(--text); }
.data-table .cell-primary a, .data-table .cell-primary button { color: inherit; font-weight: inherit; text-align: left; min-height: 32px; }
.data-table .cell-sub { display: block; font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.data-table .cell-actions { text-align: right; white-space: nowrap; width: 1%; }
.link-cell { padding: 0; color: inherit; font-weight: inherit; text-align: left; min-height: 44px; }
.data-table .cell-primary a { color: var(--text); }
.data-table .cell-primary a:hover, .link-cell:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.table-footer { display: flex; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-3); border-top: 1px solid var(--border); }
.table-status:empty { display: none; }

/* Móvil: cada fila es una tarjeta con etiqueta por celda */
@media (max-width: 699px) {
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tbody tr { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }
  .data-table tbody tr:first-child { border-top: none; }
  .data-table td { border: none; padding: 3px 0; display: flex; gap: var(--space-3); justify-content: space-between; text-align: right; }
  .data-table td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-bold); text-align: left; flex-shrink: 0; }
  .data-table td.cell-primary { display: block; text-align: left; font-size: var(--fs-base); padding-bottom: var(--space-1); }
  .data-table td.cell-primary::before, .data-table td.cell-actions::before { content: none; }
  .data-table td.cell-actions { justify-content: flex-start; width: 100%; padding-top: var(--space-2); }
  .data-table .num { text-align: right; }
}

/* ===================== PESTAÑAS ===================== */
.tabs {
  position: relative; display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border); margin-bottom: var(--space-5);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2); flex: 0 0 auto;
  min-height: 48px; padding: 0 var(--space-4);
  color: var(--text-muted); font-weight: var(--fw-bold); font-size: var(--fs-sm); white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab[aria-selected="true"] { color: var(--primary); }
.tab[aria-selected="true"]::after {
  content: ''; position: absolute; left: var(--space-3); right: var(--space-3); bottom: -1px;
  height: 3px; border-radius: 3px 3px 0 0; background: var(--primary-solid);
}
.tab .count-badge { background: var(--surface-3); color: var(--text-secondary); }
.tab-panel:focus-visible { outline-offset: 6px; }

/* ===================== ESTADOS: CARGA, VACÍO Y ERROR ===================== */
.empty-state, .error-state {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-10) var(--space-5); text-align: center;
}
.empty-state > i, .error-state > i { font-size: 2.25rem; margin-bottom: var(--space-1); }
.empty-state > i { color: var(--text-muted); opacity: 0.65; }
.error-state > i { color: var(--danger); }
.empty-state strong, .error-state strong { font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--text); }
.empty-state p, .error-state p { font-size: var(--fs-sm); color: var(--text-muted); max-width: 46ch; }
.empty-state .btn, .error-state .btn { margin-top: var(--space-3); }
.empty-state.compact, .error-state.compact { padding: var(--space-6) var(--space-4); }
.loading-state { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-8); color: var(--text-muted); }
.skeleton-list { display: flex; flex-direction: column; }
.skeleton-row { display: flex; align-items: center; gap: var(--space-3); min-height: 60px; padding: 10px var(--space-4); }
.skeleton-row + .skeleton-row { border-top: 1px solid var(--border); }
.skeleton-row .skeleton.avatar-sk { width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0; }
.skeleton-row .skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line { height: 12px; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-card { height: 112px; border-radius: var(--radius-lg); }

/* ===================== TARJETA DE MÉTRICA ===================== */
.metric-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1500px) { .metric-grid.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.metric-card {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4); min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.metric-head { display: flex; align-items: center; gap: var(--space-2); }
.metric-icon {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
  background: var(--surface-2); color: var(--text-secondary);
}
.metric-icon.primary { background: var(--primary-soft); color: var(--primary-ink); }
.metric-icon.success { background: var(--success-soft); color: var(--success-text); }
.metric-icon.warning { background: var(--warning-soft); color: var(--warning-text); }
.metric-icon.danger { background: var(--danger-soft); color: var(--danger-text); }
.metric-icon.info { background: var(--info-soft); color: var(--info-text); }
.metric-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-muted); flex: 1; min-width: 0; }
.metric-value { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: 1.375rem; font-weight: var(--fw-extra); letter-spacing: -0.02em; line-height: 1.15; margin-top: var(--space-2); }
@media (min-width: 600px) { .metric-value { font-size: var(--fs-xl); } }
.metric-value .badge { letter-spacing: 0; }
.metric-value small { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--text-muted); letter-spacing: 0; margin-left: 4px; }
.metric-hint { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }

/* Barras por día (sin librerías) */
.day-bars { display: flex; align-items: flex-end; gap: 3px; height: 96px; padding-top: var(--space-2); }
.day-bar { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.day-bar > span { display: block; width: 100%; border-radius: 4px 4px 2px 2px; background: var(--chart-neutral); transform-origin: center bottom; animation: grow-y 0.8s var(--ease-out) backwards; }
.day-bar > span.accepted { background: var(--chart-accepted); }
.day-bar > span.edited { background: var(--chart-edited); border-radius: 0; }
.day-bar > span.rejected { background: var(--chart-rejected); border-radius: 0; }
.day-bars-axis { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--space-2); }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--fs-xs); color: var(--text-secondary); font-weight: var(--fw-semibold); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend span::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--legend-color, var(--surface-3)); }
@keyframes grow-y { from { transform: scaleY(0); } }

/* ===================== VISOR DE DIFERENCIAS ===================== */
.diff {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border);
  font-size: var(--fs-sm); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere;
}
.diff ins, .diff del { text-decoration: none; border-radius: 4px; padding: 1px 2px; }
.diff ins { background: var(--diff-add-bg); color: var(--diff-add-text); }
.diff del { background: var(--diff-del-bg); color: var(--diff-del-text); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff-lines { padding: 0; font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.6; overflow: hidden; }
.diff-line { display: flex; gap: var(--space-2); padding: 1px var(--space-3); white-space: pre-wrap; overflow-wrap: anywhere; }
.diff-line .diff-sign { flex-shrink: 0; width: 1ch; color: var(--text-muted); user-select: none; }
.diff-line.add { background: var(--diff-add-bg); color: var(--diff-add-text); }
.diff-line.del { background: var(--diff-del-bg); color: var(--diff-del-text); }
.diff-line.hunk { color: var(--text-muted); background: var(--surface-2); }
.diff-legend { display: flex; gap: var(--space-3); font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--space-2); }
.diff-legend ins, .diff-legend del { text-decoration: none; padding: 0 6px; border-radius: 4px; }
.diff-legend ins { background: var(--diff-add-bg); color: var(--diff-add-text); }
.diff-legend del { background: var(--diff-del-bg); color: var(--diff-del-text); }
.diff-fields { display: flex; flex-direction: column; gap: var(--space-3); }
.diff-field-label { font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-1); }
.diff-empty { color: var(--text-muted); font-style: italic; }

/* ===================== EDITOR POR FILAS ===================== */
.row-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.row-editor-list { display: flex; flex-direction: column; gap: var(--space-2); }
.row-editor-row {
  display: flex; gap: var(--space-2); align-items: flex-start;
  padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
}
.row-editor.is-scalar .row-editor-row { padding: 0; border: 0; background: none; align-items: center; }
.row-editor-index {
  width: 28px; height: 28px; flex-shrink: 0; margin-top: 10px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); background: var(--surface-2); color: var(--text-secondary);
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
}
.row-editor.is-scalar .row-editor-index { margin-top: 0; }
.row-editor-fields { flex: 1; min-width: 0; display: grid; gap: var(--space-2); grid-template-columns: 1fr; }
@media (min-width: 700px) { .row-editor-fields.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .row-editor-fields .span-all { grid-column: 1 / -1; } }
.row-editor-fields .field + .field { margin-top: 0; }
.row-editor-actions { display: flex; gap: 2px; flex-shrink: 0; }
.row-editor-actions .round-button { width: 40px; height: 40px; font-size: 1rem; }
.row-editor-empty { font-size: var(--fs-sm); color: var(--text-muted); padding: var(--space-2) 0; }
.row-editor-add { align-self: flex-start; }

/* ===================== PLEGABLE (details con aspecto de tarjeta) ===================== */
.disclosure, .param-editor details.advanced { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.disclosure > summary, .param-editor details.advanced > summary {
  list-style: none; cursor: pointer; min-height: 48px; padding: 0 var(--space-4); border-radius: var(--radius-md);
  display: flex; align-items: center; gap: var(--space-2); font-weight: var(--fw-bold); font-size: var(--fs-sm); color: var(--text-secondary);
  transition: color var(--transition-fast);
}
.disclosure > summary:hover, .param-editor details.advanced > summary:hover { color: var(--text); }
.disclosure > summary::-webkit-details-marker, .param-editor details.advanced > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before, .param-editor details.advanced > summary::before { content: '\203A'; font-size: 1.2rem; transition: transform var(--transition-fast); }
.disclosure[open] > summary::before, .param-editor details.advanced[open] > summary::before { transform: rotate(90deg); }
.disclosure > .disclosure-body { padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.disclosure-body .field + .field, .disclosure-body .field + .form-row, .disclosure-body .form-row + .field, .disclosure-body .form-row + .form-row { margin-top: 0; }

/* ===================== PARÁMETROS DE HERRAMIENTAS ===================== */
.param-editor { display: flex; flex-direction: column; gap: var(--space-3); }
.param-editor details.advanced > .advanced-body { padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.args-form { display: flex; flex-direction: column; gap: var(--space-3); }
.args-form .field + .field { margin-top: 0; }
.args-form .field-label .param-type { font-weight: var(--fw-medium); color: var(--text-muted); }

/* ===================== MENÚ DE OPCIONES (hojas) ===================== */
.option-list { display: flex; flex-direction: column; gap: var(--space-2); }
.option-card {
  display: flex; align-items: center; gap: var(--space-3); width: 100%;
  min-height: 60px; padding: var(--space-3) var(--space-4); text-align: left; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}
.option-card:hover { border-color: var(--border-strong); text-decoration: none; }
.option-card:active { transform: scale(0.99); }
.option-card[aria-current="true"] { border: 2px solid var(--primary); padding: calc(var(--space-3) - 1px) calc(var(--space-4) - 1px); background: var(--primary-soft); }
.option-icon {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
}
.option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.option-text strong { font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.option-text span { font-size: var(--fs-sm); color: var(--text-muted); }

/* ===================== TOGGLE DE TEMA ===================== */
.theme-toggle { width: 44px; height: 44px; border-radius: var(--radius-full); color: var(--text-secondary); display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* ===================== TRAZA DE UNA EJECUCIÓN ===================== */
.trace-steps { display: flex; flex-direction: column; }
.trace-step { position: relative; display: flex; gap: var(--space-3); padding-bottom: var(--space-3); }
.trace-step:not(:last-child)::before { content: ''; position: absolute; left: 11px; top: 26px; bottom: 2px; width: 2px; background: var(--border); }
.trace-dot { width: 24px; height: 24px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.trace-step.tone-success .trace-dot { color: var(--success); }
.trace-step.tone-danger .trace-dot { color: var(--danger); }
.trace-step.tone-info .trace-dot { color: var(--info); }
.trace-body { flex: 1; min-width: 0; }
.trace-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); font-size: var(--fs-sm); }
.trace-detail { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px var(--space-3); margin-top: 4px; font-size: var(--fs-xs); color: var(--text-secondary); }
.trace-detail dt { color: var(--text-muted); }
.trace-detail dd { overflow-wrap: anywhere; }
