:root {
  --paper: #f4f2ed;
  --surface: #fbfaf7;
  --sunken: #ebe8e1;
  --line: #dedad1;
  --line-strong: #c4bfb3;
  --ink: #1c1b18;
  --ink-2: #57534a;
  --ink-3: #8b867b;
  --on-ink: #f7f5f0;
  --accent: #1f6b4a;
  --accent-ink: #185a3d;
  --accent-soft: rgba(31, 107, 74, 0.11);
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.08);
  --shadow-sm: 0 1px 0 rgba(60, 50, 30, 0.04), 0 1px 2px rgba(60, 50, 30, 0.06);
  --shadow-md: 0 1px 0 rgba(60, 50, 30, 0.04), 0 8px 24px -12px rgba(60, 50, 30, 0.22);
  --shadow-lg: 0 24px 60px -20px rgba(40, 30, 20, 0.35), 0 2px 6px rgba(40, 30, 20, 0.08);

  /* El único momento "IA": el botón de llamar y lo que se relaciona con la llamada */
  --ai: linear-gradient(100deg, #4f7cff 0%, #9b5cff 22%, #ff5ca8 44%, #ff9a3d 62%, #9b5cff 82%, #4f7cff 100%);
  --ai-glow: rgba(155, 92, 255, 0.55);

  --font: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --gutter: clamp(16px, 4vw, 24px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151412;
    --surface: #1d1c19;
    --sunken: #11100e;
    --line: #2f2d28;
    --line-strong: #46433c;
    --ink: #ece9e2;
    --ink-2: #aaa59a;
    --ink-3: #7a766c;
    --on-ink: #151412;
    --accent: #5fb88c;
    --accent-ink: #7fcaa3;
    --accent-soft: rgba(95, 184, 140, 0.14);
    --danger: #f08a80;
    --danger-soft: rgba(240, 138, 128, 0.1);
    --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, 0.75);
    --ai-glow: rgba(155, 92, 255, 0.7);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.sheet-open { overflow: hidden; }

/* Grano sutil para quitar lo plano */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.25 0 0 0 0 0.15 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 50;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
  font-weight: 500;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Barra superior ---------- */
.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px var(--gutter);
  padding-top: max(18px, env(safe-area-inset-top, 0px));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex-shrink: 0; width: 26px; height: 26px; }
.brand-mark rect { fill: var(--ink); }
.brand-mark path { stroke: url(#ai-grad); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.brand-tag {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}
.topbar-note {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-3);
  font-size: 13px;
}
.topbar-note::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.log-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease), border-color 0.15s;
}
.log-toggle:active { transform: scale(0.96); }
.log-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.log-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: var(--on-ink);
  font-family: var(--mono);
  font-size: 11px;
}
.log-badge.bump { animation: bump 0.5s var(--spring); }
@keyframes bump { 40% { transform: scale(1.35); } }

/* ---------- Layout ---------- */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 56px;
  align-items: start;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px var(--gutter) 72px;
}

.composer { max-width: 620px; min-width: 0; }

.intro { margin-bottom: 32px; }
.intro h1 {
  margin: 0 0 10px;
  font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.intro p {
  margin: 0;
  max-width: 46ch;
  color: var(--ink-2);
  font-size: clamp(15px, 0.9rem + 0.2vw, 16px);
  text-wrap: pretty;
}

/* ---------- Formulario ---------- */
.form { display: flex; flex-direction: column; gap: 28px; }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.step-n {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--sunken);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}

/* Campañas: radios reales, se navegan con flechas */
.campaign-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.campaign { position: relative; cursor: pointer; }
.campaign input { position: absolute; opacity: 0; pointer-events: none; }
.campaign-body {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
  padding: 14px 14px 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), transform 0.2s var(--spring);
}
@media (hover: hover) {
  .campaign:hover .campaign-body { border-color: var(--line-strong); transform: translateY(-1px); }
}
.campaign:active .campaign-body { transform: scale(0.98); }
.campaign input:checked + .campaign-body {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink), var(--shadow-md);
}
.campaign input:focus-visible + .campaign-body { box-shadow: 0 0 0 1px var(--ink), 0 0 0 5px var(--accent-soft); }

.campaign-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.2s, transform 0.3s var(--spring);
}
.campaign input:checked + .campaign-body .campaign-icon { stroke: var(--ink); transform: scale(1.08); }

.campaign-text { display: flex; flex-direction: column; min-width: 0; }
.campaign-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.campaign-desc { color: var(--ink-3); font-size: 13px; line-height: 1.35; }

.campaign-check {
  flex-shrink: 0;
  margin-left: auto;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  transition: border 0.25s var(--spring), background 0.2s;
}
.campaign input:checked + .campaign-body .campaign-check { border: 5px solid var(--ink); background: var(--surface); }

/* Campos */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label:not(.step) { font-size: 13px; font-weight: 500; color: var(--ink-2); }

input, select {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input::placeholder { color: var(--ink-3); opacity: 0.7; }
input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="date"] { font-variant-numeric: tabular-nums; -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%238b867b' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  cursor: pointer;
}

/* Teléfono: el campo protagonista */
.phone-box {
  position: relative;
  display: flex;
  align-items: center;
  height: 66px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.2s var(--ease);
}
.phone-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.phone.complete .phone-box { border-color: transparent; box-shadow: 0 0 0 1.5px #9b5cff, 0 10px 30px -14px var(--ai-glow); }
.phone-prefix {
  flex-shrink: 0;
  align-self: stretch;
  display: grid;
  place-items: center;
  padding: 0 14px 0 18px;
  border-right: 1px solid var(--line);
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 18px;
}
.phone-box input {
  flex: 1;
  height: 100%;
  padding: 0 12px 0 16px;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-family: var(--mono);
  font-size: clamp(22px, 5.6vw, 28px);
  font-weight: 500;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.phone-box input:focus { box-shadow: none; }
.phone-box input::placeholder { color: var(--ink-3); opacity: 0.4; }

.phone-progress {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 16px;
}
.phone-progress svg { width: 24px; height: 24px; transform: rotate(-90deg); overflow: visible; }
.ring-track { fill: none; stroke: var(--line); stroke-width: 2.4; }
.ring-fill {
  fill: none;
  stroke: url(#ai-grad);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.35s var(--ease);
}
.ring-check {
  fill: none;
  stroke: #9b5cff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transform: rotate(90deg);
  transform-origin: 12px 12px;
  transition: stroke-dashoffset 0.35s var(--ease) 0.15s;
}
.phone.complete .ring-check { stroke-dashoffset: 0; }
.phone-count {
  min-width: 34px;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.phone.complete .phone-count { color: #9b5cff; font-weight: 600; }

.hint { margin: 2px 0 0; color: var(--ink-3); font-size: 13px; transition: color 0.2s; }
.hint.note { color: var(--accent-ink); font-weight: 500; }
.phone.invalid .phone-box { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); animation: shake 0.35s var(--ease); }
.phone.invalid .hint { color: var(--danger); font-weight: 500; }
@keyframes shake {
  20% { transform: translateX(-5px); }
  45% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
}

/* Datos opcionales */
.extra { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.extra summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 0;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.extra summary::-webkit-details-marker { display: none; }
.extra summary .step { margin: 0; }
.extra-meta { color: var(--ink-3); font-size: 13px; }
.extra-meta.filled { color: var(--accent-ink); font-weight: 500; }
.chevron {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.25s var(--spring), border-color 0.15s;
}
.extra summary:hover .chevron { border-color: var(--ink); }
.extra[open] .chevron { transform: translateY(2px) rotate(-135deg); }
.extra[open] .extra-grid:not([hidden]) { animation: rise 0.3s var(--ease); }

.extra-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  padding: 4px 0 22px;
}
.span-2 { grid-column: span 2; }

/* ---------- Barra de acción (fija abajo) ---------- */
.actions {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: -12px 0 -16px;
  padding: 14px 0 calc(16px + var(--safe-b));
  background: linear-gradient(to bottom, transparent, var(--paper) 16px);
}

.call-wrap { position: relative; isolation: isolate; }

/* Halo difuminado detrás del botón */
.call-wrap::before {
  content: "";
  position: absolute;
  inset: 6px 10px -4px;
  z-index: -1;
  border-radius: 16px;
  background: var(--ai);
  background-size: 300% 100%;
  filter: blur(18px);
  opacity: 0.35;
  animation: flow 6s linear infinite alternate;
  transition: opacity 0.4s var(--ease), inset 0.4s var(--ease);
}
.call-wrap.ready::before { opacity: 0.75; inset: 2px 4px -8px; }
.call-wrap.busy::before { opacity: 0.9; animation-duration: 1.4s; }

.call-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 10px 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--ai);
  background-size: 300% 100%;
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
  text-shadow: 0 1px 1px rgba(30, 10, 60, 0.25);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  animation: flow 6s linear infinite alternate;
  transition: transform 0.25s var(--spring), filter 0.2s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.call-btn:not(.ready-btn) { filter: saturate(0.75) brightness(0.97); }
.call-btn.ready-btn { filter: none; }
@media (hover: hover) {
  .call-btn:hover { transform: translateY(-1px); }
  .call-btn:hover .call-shine { opacity: 1; }
}
.call-btn:active { transform: scale(0.97); }
.call-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px #9b5cff; }

/* Brillo que sigue al cursor */
.call-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(120px circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, 0.35), transparent 60%);
  transition: opacity 0.25s;
}
/* Barrido de luz cuando el número queda completo */
.call-btn.ready-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.55) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: sweep 0.9s var(--ease) 0.05s;
}

.call-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}
.icon-phone { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; transition: transform 0.3s var(--spring); }
.call-btn.ready-btn .icon-phone { animation: ring 1.2s var(--ease) 0.2s; }
@media (hover: hover) { .call-btn:hover .icon-phone { transform: rotate(-12deg) scale(1.08); } }

.icon-wave { position: absolute; display: none; gap: 2px; align-items: center; height: 14px; }
.icon-wave i { width: 2.5px; height: 100%; border-radius: 2px; background: #fff; animation: wave 0.9s ease-in-out infinite; }
.icon-wave i:nth-child(2) { animation-delay: -0.75s; }
.icon-wave i:nth-child(3) { animation-delay: -0.5s; }
.icon-wave i:nth-child(4) { animation-delay: -0.25s; }
.icon-wave i:nth-child(5) { animation-delay: -0.6s; }

.call-label { white-space: nowrap; font-variant-numeric: tabular-nums; }
.call-label .num { font-family: var(--mono); font-weight: 500; letter-spacing: 0; }
.call-chip {
  margin-left: 4px;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 12px;
  font-weight: 500;
  text-shadow: none;
}

.call-btn[aria-busy="true"] { cursor: progress; animation-duration: 1.4s; }
.call-btn[aria-busy="true"] .icon-phone { display: none; }
.call-btn[aria-busy="true"] .icon-wave { display: flex; }

.call-btn.sent { animation: none; background: var(--accent); filter: none; }
.call-wrap.sent::before { background: var(--accent); animation: none; opacity: 0.5; }
.call-btn.sent .call-chip { display: none; }

.call-ripple {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  animation: ripple 0.6s var(--ease) forwards;
}

@keyframes flow { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }
@keyframes sweep { to { transform: translateX(120%); } }
@keyframes ripple { to { transform: scale(18); opacity: 0; } }
@keyframes wave { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@keyframes ring {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-16deg); }
  30% { transform: rotate(12deg); }
  45% { transform: rotate(-8deg); }
  60% { transform: rotate(4deg); }
}

.kbd-hint { color: var(--ink-3); font-size: 13px; }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
}

/* ---------- Resultado: tarjeta flotante sobre el botón ---------- */
.result {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% - 4px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 2px 12px;
  padding: 14px 12px 14px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop 0.4s var(--spring);
}
.result-mark {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: #fff;
}
.result.ok .result-mark { background: var(--ai); background-size: 300% 100%; animation: flow 3s linear infinite alternate; }
.result.error .result-mark { background: var(--danger); }
.result-mark svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.result-wave { display: flex; gap: 2px; align-items: center; height: 16px; }
.result-wave i { width: 3px; height: 100%; border-radius: 2px; background: #fff; animation: wave 1s ease-in-out infinite; }
.result-wave i:nth-child(2) { animation-delay: -0.8s; }
.result-wave i:nth-child(3) { animation-delay: -0.4s; }
.result-wave i:nth-child(4) { animation-delay: -0.65s; }
.result.error { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.result-title { margin: 0; font-weight: 600; line-height: 1.35; }
.result-text { grid-column: 2; margin: 0; color: var(--ink-2); font-size: 14px; }
.result-text .num { font-family: var(--mono); color: var(--ink); }
.result-text code { font-family: var(--mono); font-size: 0.9em; }
.result details { grid-column: 2 / -1; margin-top: 6px; }
.result summary { width: fit-content; color: var(--ink-3); font-size: 13px; cursor: pointer; }
.result summary:hover { color: var(--ink); }
.result pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  max-height: 140px;
  overflow: auto;
  border-radius: 8px;
  background: var(--sunken);
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-close { grid-row: 1; grid-column: 3; margin: -4px -2px 0 0; }
.result-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: var(--ai);
  background-size: 300% 100%;
  transform-origin: left;
  animation: timer var(--dur, 6s) linear forwards, flow 3s linear infinite alternate;
}
.result.leaving { animation: drop 0.22s var(--ease) forwards; }

@keyframes timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes drop { to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

/* ---------- Historial ---------- */
.log {
  position: sticky;
  top: 24px;
  padding: 18px 0 0;
  border-top: 2px solid var(--ink);
}
.sheet-handle { display: none; }
.log-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; min-height: 32px; }
.log-tools { display: flex; align-items: center; gap: 8px; }
.log-close { display: none; }
.log h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.log-count { color: var(--ink-3); font-family: var(--mono); font-size: 12px; font-weight: 400; margin-left: 4px; }

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }
.link-btn.danger { color: var(--danger); }

.log-list { list-style: none; margin: 0; padding: 0; max-height: min(62dvh, 560px); overflow-y: auto; overscroll-behavior: contain; }
.log-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 2px 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.log-item.fresh { animation: slideIn 0.45s var(--spring); }
.log-item.fresh .log-dot { animation: ping 1.2s var(--ease) 2; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 var(--accent-soft); } 70% { box-shadow: 0 0 0 8px transparent; } }

.log-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.log-item.error .log-dot { background: var(--danger); }
.log-number { font-family: var(--mono); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.log-meta { grid-column: 2; color: var(--ink-3); font-size: 12px; }
.log-item.error .log-meta { color: var(--danger); }
.log-reuse {
  grid-row: 1 / span 2;
  grid-column: 3;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
}
.log-reuse:hover { border-color: var(--ink); color: var(--ink); }
.log-item:hover .log-reuse, .log-reuse:focus-visible { opacity: 1; }

.log-empty {
  padding: 18px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--ink-3);
  font-size: 13px;
}
.log-empty p { margin: 0; }
.log-empty p + p { margin-top: 4px; }
.log-empty strong { color: var(--ink-2); font-weight: 500; }
.log-note { margin: 14px 0 0; color: var(--ink-3); font-size: 12px; }

.sheet-backdrop { display: none; }

/* ---------- Tablet y celular: historial como hoja inferior ---------- */
@media (max-width: 900px) {
  .shell { display: block; padding-top: 8px; padding-bottom: 24px; }
  .composer { max-width: 640px; margin: 0 auto; }
  .topbar { max-width: 688px; }
  .topbar-note { display: none; }
  .log-toggle { display: inline-flex; }

  .sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(20, 18, 14, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s var(--ease);
  }
  .sheet-backdrop.show { opacity: 1; }

  .log {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 31;
    width: 100%;
    max-width: 640px;
    max-height: 78dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: 8px var(--gutter) calc(16px + var(--safe-b));
    border-top: 0;
    border-radius: 20px 20px 0 0;
    background: var(--surface);
    box-shadow: 0 -20px 60px -20px rgba(0, 0, 0, 0.35);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.4s var(--ease), visibility 0s linear 0.4s;
  }
  .log.open { transform: none; visibility: visible; transition: transform 0.45s var(--spring), visibility 0s; }
  .sheet-handle { display: block; width: 40px; height: 4px; margin: 2px auto 10px; border-radius: 4px; background: var(--line-strong); }
  .log-close { display: grid; }
  .log-list { max-height: none; flex: 1; }
  .log-reuse { opacity: 1; }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .topbar { padding-bottom: 10px; }
  .brand-tag { display: none; }
  .intro { margin-bottom: 22px; }
  .intro p { font-size: 14.5px; }
  .form { gap: 22px; }

  /* Campañas lado a lado, apiladas por dentro */
  .campaign-body { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; position: relative; }
  .campaign-check { position: absolute; top: 12px; right: 12px; }
  .campaign-desc { font-size: 12px; }

  /* iOS hace zoom en campos con letra < 16px */
  input, select { height: 46px; font-size: 16px; }
  .phone-box { height: 62px; }
  .phone-prefix { font-size: 16px; padding: 0 10px 0 14px; }
  .phone-box input { padding: 0 8px 0 12px; }
  .phone-progress { padding-right: 12px; gap: 6px; }
  .phone-count { display: none; }

  .extra-grid { gap: 12px; }

  .actions { margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
  .call-wrap { flex: 1; }
  .call-btn { width: 100%; height: 56px; justify-content: flex-start; font-size: 16px; }
  .call-label { flex: 1; overflow: hidden; text-overflow: ellipsis; text-align: left; }
  .kbd-hint { display: none; }
  .result { left: var(--gutter); right: var(--gutter); }
}

@media (max-width: 370px) {
  .campaign-desc { display: none; }
  .extra-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .call-chip { display: none; }
}

/* Celular horizontal: menos aire arriba */
@media (max-height: 500px) and (orientation: landscape) {
  .intro p { display: none; }
  .intro { margin-bottom: 16px; }
  .intro h1 { font-size: 1.5rem; }
}

@media (hover: none) {
  .kbd-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
