/* Sistema Faro — herramienta interna de un solo operador. Paleta oscura generica: NO es
   brand de ningun cliente (Sistema Faro sirve a multiples clientes de Sistema Viralidad). */

:root {
  --c-primary: #6366F1;
  --c-primary-dim: #4F52D6;
  --c-accent: #A5B4FC;
  --c-bg: #0A0D13;
  --c-surface: #11151E;
  --c-surface-raised: #171C28;
  --c-surface-hover: #1B2130;
  --c-border: #252D3D;
  --c-border-soft: #1D2432;
  --c-text: #F3F5FA;
  --c-text-dim: #C5CBDA;
  --c-muted: #8892A8;
  --c-success: #34D399;
  --c-warn: #FBBF24;
  --c-danger: #F87171;
  --c-info: #60A5FA;

  --unit: 8px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.28);

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }

html, body { margin: 0; background: var(--c-bg); color: var(--c-text); font-family: var(--font-body); }
body {
  min-height: 100vh;
  padding: calc(var(--unit) * 3) var(--unit) calc(var(--unit) * 10);
  background:
    radial-gradient(900px 380px at 50% -120px, rgba(99, 102, 241, 0.13), transparent 70%),
    var(--c-bg);
  line-height: 1.5;
}

main { max-width: 860px; margin: 0 auto; padding: 0 calc(var(--unit) * 1.5); }
main.wide { max-width: 980px; }

a { color: var(--c-accent); }
p { margin: 0 0 8px; }
h1, h2, h3, h4 { margin: 0; }
h1 { overflow-wrap: anywhere; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.page-title { font-size: 1.9rem; }
h2 {
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--c-muted); margin: calc(var(--unit) * 4) 0 var(--unit);
}
h4 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-muted); margin: 18px 0 8px; }

a.back { display: inline-block; color: var(--c-muted); text-decoration: none; font-size: 0.85rem; margin-bottom: 14px; }
a.back:hover { color: var(--c-accent); }

.muted { color: var(--c-muted); }
.small { font-size: 0.78rem; }
.hero { margin-bottom: calc(var(--unit) * 3); }
p.subtitle { color: var(--c-muted); margin: 6px 0 0; font-size: 0.98rem; max-width: 62ch; }
p.subtitle strong { color: var(--c-text-dim); }
.empty { color: var(--c-muted); padding: 20px; text-align: center; border: 1px dashed var(--c-border); border-radius: var(--radius); }

/* --------------------------------------------------------------- formularios / botones */

label { display: block; font-size: 0.78rem; color: var(--c-muted); margin-bottom: 5px; font-weight: 500; }
.field-hint { font-size: 0.78rem; color: var(--c-muted); margin: 6px 0 0; line-height: 1.4; }

input, select, textarea {
  width: 100%; padding: 10px 12px; background: var(--c-bg); border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); color: var(--c-text); font-family: inherit; font-size: 0.92rem;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}
input[type="date"] { color-scheme: dark; }

.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--c-primary); color: #fff; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; font-family: inherit; font-weight: 600; font-size: 0.86rem; cursor: pointer;
  text-decoration: none; transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover:not(:disabled), button:hover:not(:disabled) { background: var(--c-primary-dim); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--ghost { background: transparent; border-color: var(--c-border); color: var(--c-text-dim); }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-hover); border-color: var(--c-muted); }
.btn--success { background: #059669; }
.btn--success:hover:not(:disabled) { background: #047857; }
.btn--danger { background: transparent; border-color: rgba(248, 113, 113, 0.5); color: var(--c-danger); }
.btn--danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.12); }

.actions { margin: 10px 0 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.sticky-actions { position: sticky; bottom: 10px; z-index: 3; padding: 10px 12px; margin: 14px 0; background: rgba(23, 28, 40, 0.94);
  backdrop-filter: blur(8px); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.35); }

.grid-2, .grid-3 { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------- tarjetas / index */

.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: calc(var(--unit) * 2); box-shadow: var(--shadow); }
details.new-client { padding: 0; }
details.new-client > summary { padding: 16px 20px; font-weight: 600; cursor: pointer; list-style: none; color: var(--c-accent); }
details.new-client > summary::-webkit-details-marker { display: none; }
details.new-client[open] > summary { border-bottom: 1px solid var(--c-border); }
details.new-client form { display: grid; gap: 16px; padding: 20px; }
details.more { border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); padding: 0 14px; }
details.more > summary { padding: 12px 0; cursor: pointer; color: var(--c-muted); font-size: 0.88rem; }
details.more[open] { padding-bottom: 14px; }
details.more[open] > summary { margin-bottom: 8px; }
details.more > div { margin-top: 12px; }

.client-list { display: grid; gap: 10px; }
.client-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 18px; align-items: center; padding: 16px 20px;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
  text-decoration: none; color: inherit; transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.client-row:hover { border-color: var(--c-primary); background: var(--c-surface-hover); transform: translateY(-1px); }
.client-row__name { font-weight: 650; font-size: 1.02rem; }
.client-row__meta { color: var(--c-muted); font-size: 0.82rem; margin-top: 2px; }
@media (max-width: 640px) { .client-row { grid-template-columns: 1fr; gap: 10px; } }

.mini-stepper { display: flex; gap: 5px; }
.pip { width: 26px; height: 6px; border-radius: 3px; background: var(--c-border); }
.pip--aprobado { background: var(--c-success); }
.pip--revision { background: var(--c-warn); }
.pip--listo { background: var(--c-primary); opacity: 0.7; }
.pip--generando { background: var(--c-info); animation: pulse 1.2s ease-in-out infinite; }
.pip--error { background: var(--c-danger); }

/* --------------------------------------------------------------- badges / chips */

.badge {
  display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 650; line-height: 1.5; white-space: nowrap; border: 1px solid transparent;
}
.badge--muted { background: rgba(136, 146, 168, 0.12); color: var(--c-muted); }
.badge--ready { background: rgba(99, 102, 241, 0.16); color: var(--c-accent); border-color: rgba(99, 102, 241, 0.35); }
.badge--working { background: rgba(96, 165, 250, 0.14); color: var(--c-info); animation: pulse 1.4s ease-in-out infinite; }
.badge--review { background: rgba(251, 191, 36, 0.14); color: var(--c-warn); border-color: rgba(251, 191, 36, 0.35); }
.badge--done { background: rgba(52, 211, 153, 0.14); color: var(--c-success); }
.badge--error { background: rgba(248, 113, 113, 0.14); color: var(--c-danger); border-color: rgba(248, 113, 113, 0.4); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--c-surface-raised); border: 1px solid var(--c-border); color: var(--c-text-dim);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.chip--soft { color: var(--c-muted); font-weight: 500; }
.chip--warn { background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.4); color: var(--c-warn); }
.chip--bad { background: rgba(248, 113, 113, 0.12); border-color: rgba(248, 113, 113, 0.4); color: var(--c-danger); }

/* --------------------------------------------------------------- cabecera cliente + stepper */

.client-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--c-info); font-size: 0.82rem; font-weight: 600;
  background: rgba(96, 165, 250, 0.1); border: 1px solid rgba(96, 165, 250, 0.3); padding: 6px 12px; border-radius: 999px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c-info); animation: pulse 1s ease-in-out infinite; }

.stepper { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin-bottom: 28px; position: relative; }
.step { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; text-decoration: none; color: var(--c-muted); position: relative; padding: 0 4px; }
.step::before { content: ""; position: absolute; top: 17px; left: -50%; width: 100%; height: 2px; background: var(--c-border); z-index: 0; }
.step:first-child::before { display: none; }
.step--aprobado::before { background: var(--c-success); }
.step__dot {
  position: relative; z-index: 1; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c-surface); border: 2px solid var(--c-border); font-weight: 700; font-size: 0.85rem; color: var(--c-muted);
}
.step--aprobado .step__dot { background: var(--c-success); border-color: var(--c-success); color: #052e21; }
.step--revision .step__dot { border-color: var(--c-warn); color: var(--c-warn); background: rgba(251, 191, 36, 0.1); }
.step--listo .step__dot { border-color: var(--c-primary); color: var(--c-accent); }
.step--generando .step__dot { border-color: var(--c-info); }
.step--error .step__dot { border-color: var(--c-danger); color: var(--c-danger); }
.step__label { font-size: 0.85rem; font-weight: 650; color: var(--c-text-dim); }
.step__state { font-size: 0.72rem; line-height: 1.3; max-width: 130px; }
.step--revision .step__state { color: var(--c-warn); }
.step--aprobado .step__state { color: var(--c-success); }
.step--error .step__state { color: var(--c-danger); }
.step:hover .step__label { color: var(--c-accent); }
@media (max-width: 560px) { .step__state { display: none; } .step__label { font-size: 0.74rem; } .step__dot { width: 30px; height: 30px; } .step::before { top: 14px; } }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(96, 165, 250, 0.25); border-top-color: var(--c-info); animation: spin 0.8s linear infinite; display: inline-block; }
.spinner--sm { width: 15px; height: 15px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(350%); } }

/* --------------------------------------------------------------- etapas */

section.stage {
  background: var(--c-surface); border: 1px solid var(--c-border); border-left: 4px solid var(--c-border);
  border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow); scroll-margin-top: 16px;
}
section.stage--aprobado { border-left-color: var(--c-success); }
section.stage--revision { border-left-color: var(--c-warn); }
section.stage--listo { border-left-color: var(--c-primary); }
section.stage--generando { border-left-color: var(--c-info); }
section.stage--error { border-left-color: var(--c-danger); }
section.stage--bloqueado { opacity: 0.62; }

.stage__head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; }
.stage__num { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--c-surface-raised); color: var(--c-muted); flex: none; }
.stage__num--aprobado { background: rgba(52, 211, 153, 0.15); color: var(--c-success); }
.stage__num--revision { background: rgba(251, 191, 36, 0.15); color: var(--c-warn); }
.stage__num--listo { background: rgba(99, 102, 241, 0.16); color: var(--c-accent); }
.stage__num--error { background: rgba(248, 113, 113, 0.15); color: var(--c-danger); }
.stage__title { flex: 1; min-width: 0; }
.stage__title h2 { margin: 0; font-size: 1.05rem; text-transform: none; letter-spacing: -0.01em; color: var(--c-text); }
.stage__title p { margin: 2px 0 0; font-size: 0.8rem; }
.stage__body { padding: 0 22px 22px; }
@media (max-width: 560px) { .stage__head { padding: 14px 14px; gap: 10px; flex-wrap: wrap; } .stage__body { padding: 0 14px 16px; } }

.error-banner {
  background: rgba(248, 113, 113, 0.09); border: 1px solid rgba(248, 113, 113, 0.4); color: #fecaca;
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 0.86rem; line-height: 1.5; margin: 8px 0 12px; white-space: pre-wrap; word-break: break-word;
}
#toast-error { position: sticky; top: 8px; z-index: 20; }

.approved-note { color: var(--c-success); font-weight: 600; font-size: 0.86rem; margin: 0 0 12px; }

.progress { padding: 8px 0 4px; }
.progress__bar { height: 4px; border-radius: 2px; background: var(--c-border); overflow: hidden; margin-bottom: 10px; }
.progress__bar span { display: block; width: 30%; height: 100%; background: linear-gradient(90deg, transparent, var(--c-info), transparent); animation: slide 1.6s ease-in-out infinite; }

.callout { background: var(--c-surface-raised); border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0; font-size: 0.88rem; }
.callout > strong { display: block; margin-bottom: 4px; }
.callout--warn { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.06); }
.callout--warn > strong { color: var(--c-warn); }
.warn-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
details.cites { margin-top: 8px; }
details.cites > summary { cursor: pointer; color: var(--c-muted); font-size: 0.82rem; }
.warn-list .ctx { color: var(--c-text-dim); font-size: 0.82rem; margin-top: 3px; font-style: italic; }

/* --------------------------------------------------------------- contenido generado */

.doc { display: grid; gap: 10px; margin-top: 12px; }
details.fold { background: var(--c-surface-raised); border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); }
details.fold > summary {
  cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 0.92rem; list-style: none; display: flex; align-items: center; gap: 10px;
}
details.fold > summary::before { content: "▸"; color: var(--c-muted); font-size: 0.8rem; transition: transform 0.15s; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { border-bottom: 1px solid var(--c-border-soft); }
.fold__body { padding: 14px 16px 16px; }

.prose { color: var(--c-text-dim); line-height: 1.62; font-size: 0.92rem; margin: 0 0 8px; }
ul.bullets { margin: 4px 0 8px; padding-left: 20px; color: var(--c-text-dim); font-size: 0.9rem; line-height: 1.55; }
ul.bullets li { margin-bottom: 5px; }
.stack { display: grid; gap: 10px; }
.subcard { background: var(--c-bg); border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); padding: 12px 14px; }
.subcard p:last-child { margin-bottom: 0; }

dl.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 10px 18px; margin: 0; }
dl.kv dt { color: var(--c-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 3px; }
dl.kv dd { margin: 0; min-width: 0; }
dl.kv dd > p:last-child, dl.kv dd > ul:last-child { margin-bottom: 0; }
dl.kv--flat dd { color: var(--c-text-dim); font-size: 0.9rem; }
@media (max-width: 640px) { dl.kv { grid-template-columns: 1fr; gap: 2px; } dl.kv dt { margin-top: 10px; } }

.table-wrap { overflow-x: auto; border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); margin: 4px 0 10px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data th { text-align: left; color: var(--c-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 9px 12px; background: var(--c-bg); }
table.data td { padding: 10px 12px; border-top: 1px solid var(--c-border-soft); color: var(--c-text-dim); vertical-align: top; line-height: 1.5; }
@media (max-width: 560px) {
  table.data, table.data thead, table.data tbody, table.data tr, table.data td { display: block; }
  table.data thead { display: none; }
  table.data tr { border-top: 1px solid var(--c-border-soft); padding: 8px 10px; }
  table.data td { border: 0; padding: 3px 0; }
  table.data td::before { content: attr(data-label) ": "; color: var(--c-muted); font-size: 0.72rem; text-transform: uppercase; }
}

.offer { display: grid; grid-template-columns: 1fr auto 1fr auto auto; gap: 10px; align-items: stretch; margin-bottom: 14px; }
.offer__step { background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 0.92rem; line-height: 1.45; }
.offer__step small { display: block; color: var(--c-accent); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.68rem; font-weight: 700; margin-bottom: 4px; }
.offer__step--time { align-self: stretch; min-width: 110px; }
.offer__arrow { align-self: center; color: var(--c-muted); font-size: 1.2rem; }
@media (max-width: 720px) { .offer { grid-template-columns: 1fr; } .offer__arrow { transform: rotate(90deg); justify-self: center; } }

/* --------------------------------------------------------------- guiones */

.gen-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 14px; background: var(--c-surface-raised); border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); margin-bottom: 8px; }
.gen-form > div { min-width: 90px; }
.gen-form .grow { flex: 1 1 200px; }
.gen-form__btn { margin-left: auto; }

details.guion { background: var(--c-bg); border: 1px solid var(--c-border); border-left: 3px solid var(--c-border); border-radius: var(--radius); }
details.guion--borrador { border-left-color: var(--c-warn); }
details.guion--aprobado { border-left-color: var(--c-success); }
details.guion--rechazado { opacity: 0.7; }
details.guion--error { border-left-color: var(--c-danger); }
details.guion > summary { display: flex; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; list-style: none; }
details.guion > summary::-webkit-details-marker { display: none; }
.guion__num { font-family: var(--font-mono); color: var(--c-accent); font-weight: 700; }
.guion__title { flex: 1; font-weight: 600; min-width: 0; }
.guion__meta { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 4px; }
.guion__body { padding: 8px 18px 18px; }

.script { margin: 12px 0; display: grid; gap: 6px; }
.script__label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--c-muted); margin-top: 10px; }
.script p { margin: 0 0 8px; }
.script__hook { font-size: 1.12rem; line-height: 1.45; font-weight: 600; background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.3); border-radius: var(--radius-sm); padding: 14px 16px; }
.script__body { font-size: 0.98rem; line-height: 1.65; color: var(--c-text-dim); padding: 4px 4px 0 16px; border-left: 2px solid var(--c-border); }
.script__cta { font-weight: 600; padding: 10px 14px; border-left: 3px solid var(--c-success); background: rgba(52, 211, 153, 0.06); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.dir { color: var(--c-muted); font-style: italic; font-size: 0.92em; }
.notes { font-size: 0.86rem; color: var(--c-text-dim); margin: 12px 0; }
.notes p { margin: 0 0 4px; }

.qa-panel { margin: 14px 0; }
.qa { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.qa__pill { padding: 3px 11px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; cursor: help; }
.qa__pill--ok { background: rgba(52, 211, 153, 0.12); color: var(--c-success); }
.qa__pill--bad { background: rgba(248, 113, 113, 0.14); color: var(--c-danger); }

.reject-box { margin: 10px 0; }

/* --------------------------------------------------------------- entregable */

.checklist-visual { margin: 12px 0; }
.checklist-visual ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.checklist-visual li { display: flex; gap: 10px; padding: 9px 12px; background: var(--c-surface-raised); border: 1px solid var(--c-border-soft); border-radius: var(--radius-sm); font-size: 0.86rem; }
.checklist-visual li .mark { font-weight: 700; flex: none; width: 18px; }
.checklist-visual li.ok .mark { color: var(--c-success); }
.checklist-visual li.bad { border-color: rgba(248, 113, 113, 0.4); }
.checklist-visual li.bad .mark { color: var(--c-danger); }
iframe.preview { width: 100%; height: 680px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: #fff; }

/* --------------------------------------------------------------- dialogo */

dialog.dialog { background: var(--c-surface); color: var(--c-text); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 22px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6); }
dialog.dialog::backdrop { background: rgba(4, 6, 10, 0.7); backdrop-filter: blur(2px); }
dialog.dialog h3 { font-size: 1.02rem; margin-bottom: 10px; }
dialog.dialog ul { margin: 0 0 6px; padding-left: 18px; color: var(--c-text-dim); font-size: 0.86rem; display: grid; gap: 6px; max-height: 40vh; overflow: auto; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
