﻿/* =========================================================
   ADMIN · EDIT MODE (scope .tmx) — estilos pulidos (tokens base.css)
   ========================================================= */

/* ===== Tokens locales (mapeados a base.css) ===== */
.tmx .tmx-edit {
  /* Tipografía / tinta */
  --edg-font: var(
    --tmx-font,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    "Noto Sans",
    "Liberation Sans",
    sans-serif
  );
  --edg-ink: var(--tmx-ink, #0f172a);
  --edg-muted: var(--tmx-ink-muted, #475569);

  /* Superficies */
  --edg-panel: var(--tmx-panel, #f8fafc);
  --edg-surface: var(--tmx-surface, #ffffff);
  --edg-shadow: var(
    --tmx-shadow,
    0 8px 20px rgba(0, 0, 0, 0.06),
    0 2px 6px rgba(0, 0, 0, 0.06)
  );
  /* Borde ligeramente más notorio que el de lista */
  --edg-border: color-mix(in hsl, var(--tmx-border, #e2e8f0) 70%, black 30%);

  /* Marca */
  --edg-brand: var(--tmx-brand, #e77918);
  --edg-brand-ink: var(--tmx-brand-ink, #ffffff);

  /* Estados */
  --edg-ok: var(--tmx-ok, #15803d);
  --edg-bad: var(--tmx-bad, #dc2626);

  /* Foco / anillo accesible */
  --edg-focus: color-mix(in hsl, var(--edg-brand) 78%, white 0%);
  --edg-ring: 0 0 0 5px color-mix(in hsl, var(--edg-brand) 18%, transparent);

  /* Inputs (derivados de panel/surface) */
  --edg-input-bg: color-mix(
    in hsl,
    var(--edg-panel) 78%,
    var(--edg-surface) 22%
  );
  --edg-input-bg-hover: color-mix(
    in hsl,
    var(--edg-panel) 64%,
    var(--edg-surface) 36%
  );
  --edg-input-border: color-mix(
    in hsl,
    var(--tmx-border, #e2e8f0) 60%,
    black 40%
  );
  --edg-input-ink: var(--edg-ink);
  --edg-placeholder: color-mix(in hsl, var(--edg-muted) 78%, white 22%);

  /* Chips */
  --edg-chip-bg: var(
    --tmx-chip-bg,
    color-mix(in hsl, var(--edg-brand) 12%, white 88%)
  );
  --edg-chip-radius: var(--tmx-chip-radius, 999px);

  /* Radios */
  --edg-radius: 14px;

  display: grid;
  gap: 16px;
  font-family: var(--edg-font);
  color: var(--edg-ink);
}

/* ====== Sheet más ancho y mejor padding ====== */
.tmx .tmx-admin-sheet__box {
  width: min(980px, 98vw);
}
.tmx .tmx-admin-sheet__body {
  padding: 16px;
  background: var(--edg-surface);
}

/* ====== Barra superior ====== */
.tmx .tmx-edit__bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--edg-surface);
  border: 1px solid var(--edg-border);
  border-radius: var(--edg-radius);
  padding: 12px 16px;
  box-shadow: var(--edg-shadow);
}
.tmx .tmx-edit__bar strong {
  font-weight: 800;
  color: var(--edg-ink);
}
.tmx .tmx-edit__bar-actions {
  display: inline-flex;
  gap: 10px;
}

/* ====== Botones ====== */
.tmx .tmx-btn {
  appearance: none;
  border: 1px solid var(--tmx-brand);
  background: var(--edg-surface);
  color: var(--edg-ink);
  font-weight: 800;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: var(--edg-shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease,
    border-color 0.2s ease, filter 0.2s ease;
}
.tmx .tmx-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.08);
  background: color-mix(in hsl, var(--edg-surface) 88%, black 12%);
}
.tmx .tmx-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.tmx .tmx-btn--primary {
  background: linear-gradient(
    135deg,
    color-mix(in hsl, var(--edg-brand) 92%, white 0%),
    color-mix(in hsl, var(--edg-brand) 65%, black 12%)
  );
  color: var(--edg-brand-ink);
  border-color: color-mix(in hsl, var(--edg-brand) 70%, white 30%);
}
.tmx .tmx-btn--primary:hover {
  filter: saturate(1.05) brightness(1.02);
}
.tmx .tmx-btn--ghost {
  background: var(--edg-surface);
  color: var(--edg-muted);
  border-color: var(--edg-border);
}

/* Spinner en Guardar */
.tmx .tmx-btn.is-busy {
  position: relative;
  pointer-events: none;
}
.tmx .tmx-btn.is-busy::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-top-color: #fff;
  animation: tmx-spin 0.8s linear infinite;
}
@keyframes tmx-spin {
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}

/* ====== Grid de campos ====== */
.tmx .tmx-edit__grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .tmx .tmx-edit__grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }
  .tmx .tmx-edit__grid > .tmx-field {
    grid-column: span 6;
  } /* 2 col */
  .tmx .tmx-field.tmx-field--full {
    grid-column: 1 / -1;
  }
}

/* ====== Tarjetas de campo ====== */
.tmx .tmx-field {
  display: grid;
  gap: 8px;
  background: color-mix(in hsl, var(--edg-surface) 85%, var(--edg-panel) 15%);
  border: 1px solid var(--edg-input-border);
  border-radius: var(--edg-radius);
  padding: 12px 14px;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.06);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.tmx .tmx-field:hover {
  border-color: color-mix(in hsl, var(--edg-border) 40%, var(--edg-brand) 16%);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
.tmx .tmx-field:focus-within {
  border-color: var(--edg-focus);
  box-shadow: var(--edg-ring);
}

/* ====== Etiquetas / Ayudas ====== */
.tmx .tmx-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--edg-muted);
  letter-spacing: 0.25px;
}
.tmx .tmx-help {
  font-size: 12px;
  color: var(--edg-muted);
}

/* ====== Inputs / Textareas ====== */
.tmx .tmx-input,
.tmx .tmx-textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--edg-input-border) !important;
  background: var(--edg-input-bg);
  color: var(--edg-input-ink);
  font: inherit;
  line-height: 1.4;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.tmx .tmx-input::placeholder,
.tmx .tmx-textarea::placeholder {
  color: var(--edg-placeholder);
}
.tmx .tmx-input:hover,
.tmx .tmx-textarea:hover {
  background: var(--edg-input-bg-hover);
}
.tmx .tmx-input:focus,
.tmx .tmx-textarea:focus {
  outline: none;
  border-color: var(--edg-brand) !important;
  background: var(--edg-surface);
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--edg-brand) 28%, transparent);
}
.tmx .tmx-textarea {
  min-height: 120px;
  resize: vertical;
}
.tmx .tmx-input:invalid,
.tmx .tmx-textarea:invalid {
  border-color: var(--edg-bad);
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--edg-bad) 18%, transparent);
}

/* ====== Fila de toggles (meta + control) ====== */
.tmx .tmx-toggle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.tmx .tmx-toggle-meta {
  display: grid;
  gap: 4px;
}
.tmx .tmx-toggle-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.tmx .tmx-toggle-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 12px;
  border-radius: var(--edg-chip-radius);
  background: var(--edg-chip-bg);
  border: 1px solid var(--edg-border);
  color: var(--edg-ink);
}

/* =========================================================
   TOGGLE SWITCH (Uiverse — renombrado para evitar colisión)
   ========================================================= */
.tmx .tmx-toggle {
  font-size: 17px;
  position: relative;
  display: inline-block;
  width: 3.5em;
  height: 2em;
  line-height: 0;
}
.tmx .tmx-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.tmx .tmx-toggle-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background-color: var(--edg-surface);
  border: 1px solid var(--edg-border);
  transition: 0.25s ease;
  border-radius: 30px;
  box-shadow: inset 0 1px 2px rgba(2, 6, 23, 0.06);
}
.tmx .tmx-toggle-slider::before {
  content: "";
  position: absolute;
  height: 1.4em;
  width: 1.4em;
  border-radius: 20px;
  left: 0.27em;
  bottom: 0.25em;
  background-color: color-mix(in hsl, var(--edg-border) 35%, white 65%);
  transition: 0.25s ease;
  box-shadow: 0 2px 6px rgba(2, 6, 23, 0.15);
}
.tmx .tmx-toggle input:checked + .tmx-toggle-slider {
  background-color: var(--edg-brand);
  border: 1px solid var(--edg-brand);
}
.tmx .tmx-toggle input:focus + .tmx-toggle-slider {
  box-shadow: 0 0 0 4px color-mix(in hsl, var(--edg-brand) 18%, transparent);
  outline: none;
}
.tmx .tmx-toggle input:checked + .tmx-toggle-slider::before {
  transform: translateX(1.4em);
  background-color: var(--edg-brand-ink);
}
.tmx .tmx-toggle input:disabled + .tmx-toggle-slider {
  background: color-mix(in hsl, var(--edg-surface) 65%, var(--edg-panel) 35%);
  border-color: var(--tmx-border, #e2e8f0);
  cursor: not-allowed;
}
.tmx .tmx-toggle input:disabled + .tmx-toggle-slider::before {
  background: color-mix(in hsl, var(--edg-border) 70%, white 30%);
  box-shadow: none;
}

/* ====== Botón EDITAR (en cabecera de sheet) ====== */
.tmx .tmx-btn-edit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  background: color-mix(in hsl, var(--tmx-brand) 10%, transparent 90%);
  color: var(--tmx-brand);
  border: 1px solid var(--tmx-brand);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--edg-shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.tmx .tmx-btn-edit:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.12);
  filter: saturate(1.06);
}
.tmx .tmx-btn-edit svg {
  width: 16px;
  height: 16px;
}

/* ====== Toasts ====== */
.tmx .tmx-toast {
  background: var(--edg-ink);
  color: var(--tmx-brand-ink, #fff);
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.1);
  margin-top: 8px;
  font-weight: 700;
}
.tmx .tmx-toast.tmx-toast--err {
  background: color-mix(in hsl, var(--edg-bad) 12%, white 88%);
  color: color-mix(in hsl, var(--edg-bad) 80%, black 20%);
}

/* ====== Util ====== */
.tmx .tmx-more-compact {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}

/* -------- Reduced motion -------- */
@media (prefers-reduced-motion: reduce) {
  .tmx .tmx-btn,
  .tmx .tmx-btn-edit {
    transition: none !important;
  }
}

/* ================================
   Toggle switch personalizado (tokens base.css)
   ================================ */
.tmx .tmx-toggle {
  font-size: 17px;
  position: relative;
  display: inline-block;
  width: 3.5em;
  height: 2em;
}

.tmx .tmx-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* Pista del switch */
.tmx .tmx-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--tmx-surface, #fff);
  border: 1px solid var(--tmx-border, #e2e8f0);
  transition: 0.4s;
  border-radius: 30px;
  box-shadow: inset 0 1px 2px rgba(2, 6, 23, 0.06);
}

/* Thumb */
.tmx .tmx-toggle-slider::before {
  position: absolute;
  content: "";
  height: 1.4em;
  width: 1.4em;
  border-radius: 20px;
  left: 0.27em;
  bottom: 0.25em;
  background-color: color-mix(
    in hsl,
    var(--tmx-border, #e2e8f0) 65%,
    white 35%
  );
  transition: 0.4s;
  box-shadow: 0 2px 6px rgba(2, 6, 23, 0.15);
}

/* Checked (activo) */
.tmx .tmx-toggle input:checked + .tmx-toggle-slider {
  background-color: var(--tmx-brand, #e77918);
  border: 1px solid var(--tmx-brand, #e77918);
}
.tmx .tmx-toggle input:checked + .tmx-toggle-slider::before {
  transform: translateX(1.4em);
  background-color: var(--tmx-brand-ink, #fff);
}

/* Focus accesible */
.tmx .tmx-toggle input:focus + .tmx-toggle-slider {
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--tmx-brand) 24%, transparent);
  outline: none;
}

/* ===== Parche de contraste para inputs (borde más visible) ===== */
.tmx .tmx-edit {
  /* Borde base más oscuro y una variante “strong” para el estado normal */
  --edg-input-border: color-mix(
    in hsl,
    var(--tmx-border, #e2e8f0) 35%,
    black 65%
  );
  --edg-input-border-strong: color-mix(
    in hsl,
    var(--tmx-border, #e2e8f0) 20%,
    black 80%
  );
}

/* Borde más grueso y notorio por defecto */
.tmx .tmx-input,
.tmx .tmx-textarea {
  border-width: 1.5px !important;
  border-color: var(--edg-input-border-strong) !important;
  background: color-mix(in hsl, var(--edg-surface, #fff) 92%, black 8%);
}

/* Hover: un pelín más claro para distinguir */
.tmx .tmx-input:hover,
.tmx .tmx-textarea:hover {
  background: color-mix(in hsl, var(--edg-surface, #fff) 96%, black 4%);
}

/* Focus: color de marca + anillo accesible (ya lo tenías, lo reforzamos) */
.tmx .tmx-input:focus,
.tmx .tmx-textarea:focus {
  border-color: var(--edg-brand) !important;
  background: var(--edg-surface);
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--edg-brand) 30%, transparent);
}

/* Invalid: mantiene contraste alto */
.tmx .tmx-input:invalid,
.tmx .tmx-textarea:invalid {
  border-color: var(--edg-bad) !important;
  box-shadow: 0 0 0 3px color-mix(in hsl, var(--edg-bad) 22%, transparent);
}

/* Disabled: que se note, pero sin perder legibilidad */
.tmx .tmx-input:disabled,
.tmx .tmx-textarea:disabled {
  opacity: 0.85;
  background: color-mix(
    in hsl,
    var(--edg-surface, #fff) 75%,
    var(--edg-panel, #f8fafc) 25%
  );
  border-color: color-mix(in hsl, var(--tmx-border, #e2e8f0) 70%, black 30%);
  cursor: not-allowed;
}

/* ===== Mascara y spinner durante guardado ===== */
.tmx .tmx-edit {
  position: relative;
}

.tmx .tmx-edit__mask[hidden] {
  display: none !important;
}

.tmx .tmx-edit__mask {
  position: absolute;
  inset: 0;
  background: color-mix(
    in hsl,
    var(--tmx-surface, #fff) 80%,
    rgba(0, 0, 0, 0) 20%
  );
  backdrop-filter: blur(1px);
  display: grid;
  place-items: center;
  border-radius: var(--edg-radius, 14px);
  z-index: 2;
}

.tmx .tmx-edit__spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--tmx-brand, #e77918);
  animation: tmx-spin 0.8s linear infinite; /* ya existe en tu CSS */
}

/* (opcional) atenuar el formulario de fondo cuando está ocupado */
.tmx .tmx-edit.is-busy .tmx-edit__grid {
  filter: grayscale(0.2) opacity(0.85);
}
