*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0b0410;
  --bg-1: #160a26;
  --rose: #ff0054;
  --scribe: #ff9d5c;
  --scribe-soft: #ffd0a0;
  --cream: #f5ecdc;
  --text: #efe6f5;
  --text-soft: rgba(239,230,245,0.62);
  --glass: rgba(24,12,38,0.55);
  --glass-brd: rgba(255,255,255,0.09);
  --field: rgba(255,255,255,0.045);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(120% 70% at 50% -5%, #38154f 0%, transparent 55%),
    radial-gradient(90% 60% at 85% 8%, #40122e 0%, transparent 45%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 40%, #08030d 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Grano de película (como el hub) */
.grain {
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  opacity: 0.05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ════════ Cabecera ════════ */
header { position: relative; z-index: 2; text-align: center; padding: 52px 24px 10px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.26em; text-transform: uppercase;
  color: var(--text-soft); margin-bottom: 20px; padding: 8px 16px; border-radius: 9999px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-brd); backdrop-filter: blur(8px);
}
.eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--scribe); box-shadow: 0 0 14px var(--scribe); animation: pulse 2.2s ease infinite; }
header h1 {
  font-size: clamp(1.9rem, 4.5vw, 3.1rem); font-weight: 900; letter-spacing: -0.035em; line-height: 1;
  margin-bottom: 12px; text-shadow: 0 2px 24px rgba(11,4,16,0.85);
}
header h1 .scribe { color: var(--scribe); text-shadow: 0 0 34px rgba(255,157,92,0.4); }
header .sub { font-size: clamp(0.9rem, 1.6vw, 1.05rem); color: var(--text-soft); font-weight: 500; max-width: 560px; margin: 0 auto; }
#btnConfig { position: absolute; top: 20px; right: 20px; }

/* ════════ Barra de pasos ════════ */
.steps {
  position: relative; z-index: 2;
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  max-width: 700px; margin: 24px auto 4px; padding: 0 18px;
}
.step {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 0.74rem; font-weight: 700; color: var(--text-soft);
  padding: 8px 16px; border-radius: 9999px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--glass-brd);
  transition: color 0.3s var(--ease-out), border-color 0.3s var(--ease-out), background 0.3s var(--ease-out);
}
.step i {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  font-size: 0.7rem; font-weight: 800; font-style: normal;
  background: rgba(255,255,255,0.08); color: var(--text-soft);
}
.step.is-active { color: var(--text); border-color: rgba(255,157,92,0.5); background: rgba(255,157,92,0.08); }
.step.is-active i { background: linear-gradient(135deg, var(--scribe), var(--rose)); color: #fff; }
.step.is-done i { background: rgba(255,157,92,0.85); color: #23120a; }
.step.is-done i::after { content: "✓"; }
.step.is-done i { font-size: 0; }
.step.is-done i::after { font-size: 0.72rem; }

main { position: relative; z-index: 2; max-width: 1100px; margin: 20px auto 28px; padding: 0 18px; display: flex; flex-direction: column; gap: 22px; }

/* ════════ Tarjetas glass ════════ */
.card {
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  border-radius: 26px;
  padding: 26px 30px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px -24px rgba(0,0,0,0.7);
  transition: border-color 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out);
}
.card:hover { border-color: rgba(255,157,92,0.22); }
.card h2 {
  font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.22em;
  color: var(--scribe); margin-bottom: 18px;
}

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.row.actions { margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1; min-width: 220px; }

label { font-size: 0.68rem; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.1em; }

input, select, textarea {
  color-scheme: dark;
  border: 1px solid var(--glass-brd);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  background: var(--field);
  color: var(--text);
  transition: border-color 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}
select option { background: var(--bg-1); color: var(--text); }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: rgba(239,230,245,0.35); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--scribe);
  box-shadow: 0 0 0 3px rgba(255,157,92,0.18);
}
input[type="checkbox"] { width: auto; accent-color: var(--scribe); }

/* ════════ Botones ════════ */
.btn {
  border: none;
  border-radius: 9999px;
  padding: 10px 22px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out), background 0.25s var(--ease-out), filter 0.25s var(--ease-out);
}
.btn.primary {
  background: linear-gradient(135deg, var(--scribe), var(--rose));
  color: #fff;
  box-shadow: 0 10px 26px -10px rgba(255,0,84,0.55);
}
.btn.primary:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 14px 32px -10px rgba(255,0,84,0.65); }
.btn.primary:disabled { filter: grayscale(0.6) brightness(0.7); cursor: wait; transform: none; }
.btn.secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--glass-brd);
}
.btn.secondary:hover { background: rgba(255,255,255,0.11); border-color: rgba(255,157,92,0.35); }
.btn.ghost { background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--glass-brd); }
.btn.ghost:hover { background: rgba(255,255,255,0.12); }

.hint { font-size: 0.8rem; color: var(--text-soft); margin-bottom: 10px; line-height: 1.55; }
.hint a, .hint b { color: var(--scribe); }
.hint b { font-weight: 700; }
.status { font-size: 0.84rem; color: var(--scribe-soft); font-weight: 600; }
.status.error { color: #ff5c6a; }
.counter { font-size: 0.7rem; color: var(--text-soft); align-self: flex-end; margin-top: 2px; }

.hidden { display: none !important; }

/* ════════ Spinner del botón ════════ */
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════ Chips de correos ════════ */
.recipients-hint { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 12px; min-height: 22px; }
.recipients-hint .none { font-size: 0.78rem; color: var(--text-soft); font-style: italic; }

.continuity { font-size: 0.8rem; color: var(--text-soft); line-height: 1.5; margin: 0 0 12px; display: none; }
.continuity.show { display: block; }
.continuity b { color: var(--scribe-soft); font-weight: 700; }
.continuity .cont-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--scribe); margin-right: 7px; vertical-align: middle; box-shadow: 0 0 8px var(--scribe); }
.continuity.warn { color: #ffcf9a; }
.continuity.warn .cont-dot { background: #e0a400; box-shadow: 0 0 8px #e0a400; }
.recipients-hint .lead { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-soft); margin-right: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.78rem; font-weight: 600; color: var(--scribe-soft);
  background: rgba(255,157,92,0.12); border: 1px solid rgba(255,157,92,0.32);
  padding: 4px 10px; border-radius: 9999px; white-space: nowrap;
}
.chip.invalid { color: #ff8f9a; background: rgba(255,60,90,0.12); border-color: rgba(255,60,90,0.4); }
.chip .x { cursor: pointer; opacity: 0.6; font-weight: 800; line-height: 1; }
.chip .x:hover { opacity: 1; }

.chips-static .chip { background: rgba(255,157,92,0.14); }

.chips-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  border: 1px solid var(--glass-brd); border-radius: 12px; padding: 8px 10px;
  background: var(--field); cursor: text; min-height: 46px;
  transition: border-color 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}
.chips-input:focus-within { border-color: var(--scribe); box-shadow: 0 0 0 3px rgba(255,157,92,0.18); }
.chips-list { display: contents; }
.chips-input input { border: none; background: transparent; flex: 1; min-width: 140px; padding: 4px; box-shadow: none !important; }
.chips-input input:focus { outline: none; }

/* ════════ Modal ════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px;
  background: rgba(6,2,10,0.72); backdrop-filter: blur(6px);
  animation: fadeIn 0.2s var(--ease-out);
}
.modal {
  width: 100%; max-width: 480px;
  background: linear-gradient(180deg, #1c1030, #150a24);
  border: 1px solid var(--glass-brd); border-radius: 22px; padding: 28px;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,0.8);
  animation: popIn 0.24s var(--ease-out);
}
.modal h3 { font-size: 1.1rem; font-weight: 800; margin-bottom: 18px; color: var(--text); }
.modal .field { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }

/* ════════ Encabezado del correo (paso 3) ════════ */
.mail-head {
  border: 1px solid var(--glass-brd); border-radius: 14px; padding: 14px 16px;
  background: rgba(255,255,255,0.03); margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px;
}
.mail-field { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.mail-label { font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-soft); min-width: 52px; }
.chips-static { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.mail-subject { font-size: 0.9rem; font-weight: 600; color: var(--text); flex: 1; }

/* ════════ Opciones de envío ════════ */
.send-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.send-card {
  border: 1px solid var(--glass-brd); border-radius: 16px; padding: 18px 18px 20px;
  background: rgba(255,255,255,0.025); display: flex; flex-direction: column; gap: 8px;
}
.send-title { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; color: var(--scribe); }
.send-desc { font-size: 0.82rem; color: var(--text-soft); line-height: 1.5; flex: 1; }
.send-desc b { color: var(--text); font-weight: 700; }
.send-card .btn { align-self: flex-start; margin-top: 4px; }

.table-wrap { overflow-x: auto; }

/* ════════ Respaldo / historial ════════ */
.cfg-sep { border: none; border-top: 1px solid var(--glass-brd); margin: 18px 0 14px; }
.cfg-lbl { display: block; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; color: var(--scribe); margin-bottom: 8px; }

.hist-results { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 4px; max-height: 340px; overflow-y: auto; }
.hist-empty { font-size: 0.82rem; color: var(--text-soft); font-style: italic; padding: 6px 2px; }
.hist-item {
  border: 1px solid var(--glass-brd); border-radius: 12px; padding: 11px 14px;
  background: rgba(255,255,255,0.025);
}
.hist-item .hi-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 5px; }
.hist-item .hi-badge { font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 9999px; background: rgba(255,157,92,0.14); color: var(--scribe-soft); border: 1px solid rgba(255,157,92,0.28); }
.hist-item .hi-estado { font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 9999px; border: 1px solid var(--glass-brd); color: var(--text-soft); }
.hist-item .hi-estado.completado { color: #7fe0a0; border-color: rgba(80,200,120,0.4); }
.hist-item .hi-estado.critico { color: #ff8f9a; border-color: rgba(255,90,120,0.45); }
.hist-item .hi-fecha { font-size: 0.72rem; color: var(--text-soft); margin-left: auto; }
.hist-item .hi-accion { font-size: 0.86rem; color: var(--text); line-height: 1.45; }
.hist-item .hi-accion mark { background: rgba(255,157,92,0.32); color: #fff; padding: 0 2px; border-radius: 3px; }
.hist-item .hi-meta { font-size: 0.72rem; color: var(--text-soft); margin-top: 4px; }

.minutas-list { display: flex; flex-direction: column; gap: 7px; margin: 8px 0; }
.minuta-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--glass-brd); border-radius: 10px; padding: 9px 14px;
  background: rgba(255,255,255,0.02);
}
.minuta-row .mr-fecha { font-weight: 700; font-size: 0.85rem; }
.minuta-row .mr-info { font-size: 0.76rem; color: var(--text-soft); }
.minuta-row .mr-actions { margin-left: auto; display: flex; gap: 8px; }
.minuta-row .link { background: none; border: none; color: var(--scribe); font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer; }
.minuta-row .link:hover { text-decoration: underline; }
.minuta-row .link.danger { color: #ff8f9a; }

#histPreview { width: 100%; height: 440px; border: 1px solid var(--glass-brd); border-radius: 14px; background: #fff; margin-top: 12px; }

.btn.scope-on { background: linear-gradient(135deg, var(--scribe), var(--rose)); color: #fff; border-color: transparent; }
.hist-group { margin-bottom: 14px; }
.hist-group .hg-head { font-size: 0.8rem; font-weight: 800; color: var(--scribe); margin: 4px 0 7px; display: flex; align-items: center; gap: 10px; }
.hist-group .hg-count { font-size: 0.66rem; font-weight: 700; color: var(--text-soft); border: 1px solid var(--glass-brd); border-radius: 9999px; padding: 2px 9px; }

/* columna Ítem editable */
td .f-item { text-align: center; font-weight: 700; color: var(--scribe-soft); }
td.num { width: 64px; }

/* ════════ Toasts ════════ */
.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 92vw;
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; font-weight: 600; color: var(--text);
  background: linear-gradient(180deg, #241534, #1a0d2c);
  border: 1px solid var(--glass-brd); border-left: 3px solid var(--scribe);
  border-radius: 12px; padding: 12px 18px;
  box-shadow: 0 18px 44px -18px rgba(0,0,0,0.8);
  animation: toastIn 0.3s var(--ease-out);
}
.toast.error { border-left-color: #ff5c6a; }
.toast.out { animation: toastOut 0.3s var(--ease-out) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(16px); } }

/* ════════ Tabla de acuerdos ════════ */
table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.85rem; }
th {
  background: rgba(255,157,92,0.1); color: var(--scribe);
  padding: 10px 8px; text-align: left;
  font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em;
  border: 1px solid rgba(255,255,255,0.07);
}
td { border: 1px solid rgba(255,255,255,0.07); padding: 4px; vertical-align: top; }
td input, td select, td textarea { border: none; background: transparent; padding: 7px; border-radius: 8px; }
td input:focus, td select:focus, td textarea:focus { box-shadow: 0 0 0 2px rgba(255,157,92,0.25); }
td textarea { min-height: 42px; }
tr:hover td { background: rgba(255,255,255,0.025); }
tr.critico td, tr.critico input, tr.critico select, tr.critico textarea { color: #ff5c6a; font-weight: 600; }
td.num { text-align: center; width: 36px; padding-top: 11px; color: var(--text-soft); }
td.center { text-align: center; width: 60px; padding-top: 11px; }
.btn-del { background: none; border: none; color: #ff5c6a; cursor: pointer; font-size: 1rem; opacity: 0.7; }
.btn-del:hover { opacity: 1; }

#previewFrame { width: 100%; height: 520px; border: 1px solid var(--glass-brd); border-radius: 16px; background: #fff; }

footer { position: relative; z-index: 2; text-align: center; padding: 14px 18px 44px; font-size: 0.76rem; color: var(--text-soft); }
footer .sep { margin: 0 8px; opacity: 0.4; }

@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.55;transform:scale(1.5)} }

@media (max-width: 600px) {
  header { padding-top: 72px; }
  .card { padding: 20px 18px; border-radius: 20px; }
  .send-options { grid-template-columns: 1fr; }
  .step { font-size: 0.68rem; padding: 7px 12px; }
}
