/* ====================================================================
   Firma limpia · limpieza y verificación local de firmas
   Reutiliza las variables de tema de style.css.
   ==================================================================== */

.firma-body {
  overflow: auto;
  min-height: 100%;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 45% at 100% -10%, rgba(255, 107, 44, .16), transparent 55%),
    radial-gradient(ellipse 55% 40% at 0% 105%, rgba(20, 184, 166, .14), transparent 55%);
  background-attachment: fixed;
}

/* ---------- Cabecera ---------- */
.firma-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
}

.firma-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s ease, color .15s ease;
}
.firma-back:hover { background: var(--hover); color: var(--text); }
.firma-back svg { width: 18px; height: 18px; }

.firma-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  min-width: 0;
}
.firma-brand img {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--panel-2);
  padding: 4px;
}
.firma-brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -.01em;
}
.firma-brand p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Contenido ---------- */
.firma-main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 26px 20px 64px;
}

.firma-hero { max-width: 720px; }
.firma-hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .01em;
}
.firma-hero .eyebrow svg { width: 14px; height: 14px; }
.firma-hero h2 {
  margin: 14px 0 8px;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.08;
  letter-spacing: -.03em;
}
.firma-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 15.5px;
  line-height: 1.55;
}

/* ---------- Zona de carga ---------- */
.dropzone {
  margin-top: 24px;
  padding: 38px 24px;
  border: 2px dashed var(--line);
  border-radius: 20px;
  background: var(--panel);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--accent);
  background: var(--panel-2);
}
.dropzone:focus-visible { box-shadow: 0 0 0 4px rgba(255, 107, 44, .18); }
.dropzone.over { transform: scale(1.006); }

.drop-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--panel-3);
  color: var(--accent-strong);
}
.drop-icon svg { width: 28px; height: 28px; }
.dropzone h3 { margin: 0 0 4px; font-size: 18px; }
.dropzone p { margin: 0; color: var(--muted); font-size: 14px; }
.dropzone small { display: block; margin-top: 10px; color: var(--muted); font-size: 12.5px; }

/* ---------- Rejilla de trabajo ---------- */
.firma-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: stretch;
}

.card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: 52px;
}
.card-head h3 { margin: 0; font-size: 13.5px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }

.link-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 8px;
}
.link-btn:hover { background: var(--hover); }

.preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 300px;
  height: 100%;
  padding: 16px;
  overflow: hidden;
}
.preview-original { background: var(--panel-2); }

.preview canvas {
  display: block;
  max-width: 100%;
  max-height: 360px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.preview-result.checker,
.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e6e9ef 25%, transparent 25%),
    linear-gradient(-45deg, #e6e9ef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6e9ef 75%),
    linear-gradient(-45deg, transparent 75%, #e6e9ef 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.preview-result.white { background: #fff; }
.preview-result.dark { background: #111827; }

.bg-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 9px;
  background: var(--panel-3);
  gap: 2px;
}
.bg-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 7px;
}
.bg-switch button.on {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

/* ---------- Panel de calidad ---------- */
.quality { display: flex; flex-direction: column; }
.verdict {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.score {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.03em;
  background: var(--panel-3);
  color: var(--muted);
  border: 2px solid var(--line);
}
.score.ok { background: rgba(20, 184, 166, .12); border-color: var(--accent-2); color: #0f766e; }
.score.warn { background: rgba(245, 158, 11, .14); border-color: #f59e0b; color: #b45309; }
.score.bad { background: rgba(234, 84, 85, .12); border-color: var(--danger); color: #b91c1c; }
[data-theme="dark"] .score.ok { color: #5eead4; }
[data-theme="dark"] .score.warn { color: #fcd34d; }
[data-theme="dark"] .score.bad { color: #fca5a5; }

.verdict-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.verdict-text strong { font-size: 15px; line-height: 1.25; }
.verdict-text span { font-size: 12.5px; color: var(--muted); line-height: 1.35; }

.checks {
  list-style: none;
  margin: 0;
  padding: 10px 14px;
  display: grid;
  gap: 7px;
}
.checks li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.35;
}
.checks li svg { flex: none; width: 15px; height: 15px; margin-top: 1px; }
.checks li.ok svg { color: var(--accent-2); }
.checks li.warn svg { color: #d97706; }
.checks li.bad svg { color: var(--danger); }
.checks li strong { font-weight: 700; }
.checks li span { color: var(--muted); }

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 14px;
  margin-top: auto;
}
.metrics span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
}

/* ---------- Barra de controles ---------- */
.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}
.control { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.control > span { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 150px; }
.control output { color: var(--text); font-variant-numeric: tabular-nums; }
.control input[type="range"] { width: 180px; accent-color: var(--accent); }
.control select {
  appearance: none;
  padding: 8px 30px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 7px;
}
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 700;
  transition: transform .1s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; }
.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(255, 107, 44, .3);
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}
.btn.ghost:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.privacy {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
}
.privacy svg { width: 14px; height: 14px; }

/* ---------- Explicación ---------- */
.explain {
  margin-top: 22px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 13.5px;
  color: var(--muted);
}
.explain summary { cursor: pointer; font-weight: 700; color: var(--text); }
.explain p { margin: 10px 0 0; line-height: 1.6; }
.explain code { background: var(--panel-3); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

/* ---------- Cargando ---------- */
/* Aviso pequeño: no tapa la firma mientras se recalcula */
.loading {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.loading[hidden] { display: none; }
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--panel);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  max-width: min(92vw, 520px);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .firma-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .quality { grid-column: 1 / -1; }
  .quality .checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .firma-main { padding: 18px 14px 60px; }
  .firma-grid { grid-template-columns: 1fr; }
  .quality .checks { grid-template-columns: 1fr; }
  .preview { min-height: 200px; }
  .preview canvas { max-height: 260px; }
  .toolbar { align-items: stretch; }
  .controls { gap: 14px; }
  .control, .control > span, .control input[type="range"] { width: 100%; min-width: 0; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .firma-back span { display: none; }
  .firma-brand p { display: none; }
  .card-head { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
