/* ==========================================================
   Commerza = sistema de diseño
   Un solo archivo, sin build, sin CDN. Todo con variables CSS.
   ========================================================== */

/* ==========================================================
   SISTEMA DE DISE=O
   Semáforo de estado, una sola regla:
     azul     =  acción (todo lo que se puede pulsar)
     rojo     =  error (algo salió mal)
     amarillo =  no permitido / requiere atención
     verde    =  confirmado (sólo para resultados positivos)

   Tipografía, dos tamaños y nada más:
     32px =  la cifra principal del resumen (una por pantalla)
     16px =  absolutamente todo lo demás, botones incluidos
   ========================================================== */

:root {
  /* Acción */
  --brand:        #1c64f2;
  --brand-strong: #1549c4;
  --brand-soft:   #1c64f214;
  --brand-line:   #1c64f240;

  /* Semáforo */
  --error:        #d92d20;   /* rojo   · algo falló */
  --error-soft:   #d92d2014;
  --warn:         #dc9a00;   /* ámbar  · no permitido / atención */
  --warn-soft:    #dc9a0018;
  --ok:           #067647;   /* verde  · confirmado */
  --ok-soft:      #06764714;

  /* Alias heredados: el resto del CSS sigue funcionando sin tocarlo. */
  --rose:   var(--error);
  --amber:  var(--warn);
  --mint:   var(--ok);
  --violet: #6941c6;

  /* Superficies = blanco */
  --bg:        #ffffff;
  --bg-2:      #f9fafb;
  --surface:   #ffffff;
  --surface-2: #f2f4f7;
  --line:      #e4e7ec;
  --line-2:    #d0d5dd;

  /* Texto */
  --text:   #101828;
  --text-2: #475467;
  --text-3: #667085;

  /* Formas */
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --shadow:    0 1px 3px #1018280f, 0 1px 2px #1018281a;
  --shadow-lg: 0 12px 32px #10182814, 0 4px 8px #1018280a;

  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  --mono: 'Cascadia Code', Consolas, 'SF Mono', Menlo, monospace;

  /* Escala tipográfica */
  --fs-hero: 32px;   /* la cifra principal */
  --fs-base: 16px;   /* todo lo demás */

  --sidebar-w: 248px;
}

/* Tema oscuro opcional: mismo semáforo, superficies invertidas. */
:root[data-theme='dark'] {
  --bg:        #0c111d;
  --bg-2:      #111827;
  --surface:   #161b26;
  --surface-2: #1f242f;
  --line:      #ffffff14;
  --line-2:    #ffffff26;
  --text:   #f5f6f8;
  --text-2: #cecfd2;
  --text-3: #94969c;

  --brand:      #528bff;
  --brand-soft: #528bff1f;
  --brand-line: #528bff4d;
  --error:      #f97066;
  --error-soft: #f9706618;
  --warn:       #fdb022;
  --warn-soft:  #fdb02218;
  --ok:         #47cd89;
  --ok-soft:    #47cd8918;

  --shadow:    0 4px 16px #00000040;
  --shadow-lg: 0 20px 50px #00000055;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Los títulos comparten el tamaño base y se distinguen por peso, no por
   tamaño. Así la única cifra grande de la pantalla es la del resumen. */
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.35; letter-spacing: -.01em; }
h1 { font-size: var(--fs-base); font-weight: 700; }
h2 { font-size: var(--fs-base); font-weight: 700; }
h3 { font-size: var(--fs-base); font-weight: 650; }
h4 { font-size: var(--fs-base); font-weight: 650; }
p  { margin: 0 0 1em; }

::selection { background: var(--brand); color: #fff; }

/* ==== Marca ======================================================================================================== */

.logo {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 19px; letter-spacing: -.03em; color: var(--text);
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--brand) 0%, var(--violet) 100%);
  display: grid; place-items: center;
  color: #fff; font-size: var(--fs-base); font-weight: 900;
  box-shadow: 0 4px 14px var(--brand-soft);
}

/* ==== Botones ==================================================================================================== */

/* Todos los botones son azules o neutros: el azul marca lo pulsable. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--r); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: var(--fs-base);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

/* Rojo sólo para acciones destructivas: borrar, cancelar, revocar. */
.btn-danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error-soft); border-color: var(--error); }

/* Amarillo para lo que está bloqueado o requiere atención antes de seguir. */
.btn-warn { background: transparent; border-color: var(--warn); color: var(--warn); }
.btn-warn:hover { background: var(--warn-soft); }

.btn-sm { padding: 6px 12px; border-radius: var(--r-sm); }
.btn-lg { padding: 12px 24px; }
.btn-block { display: flex; width: 100%; }

/* ==== Formularios ============================================================================================ */

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: var(--fs-base); font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field .hint { font-size: var(--fs-base); color: var(--text-3); margin-top: 5px; line-height: 1.45; }

/* Interruptor: la casilla y su texto en una línea, cliqueables juntos. */
.field .switch-row {
  display: flex; align-items: center; gap: 9px;
  margin-bottom: 0; cursor: pointer; font-weight: 600; color: var(--text);
}
.field .switch-row input[type="checkbox"] {
  width: 18px; height: 18px; flex: 0 0 18px; margin: 0; padding: 0;
  accent-color: var(--brand); cursor: pointer;
}
input[type="color"] { height: 38px; padding: 3px; cursor: pointer; }

input, select, textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font: inherit; font-size: var(--fs-base);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
/* Campo con error: rojo. Campo bloqueado: amarillo. */
input.is-error, select.is-error, textarea.is-error { border-color: var(--error); }
input.is-error:focus { box-shadow: 0 0 0 3px var(--error-soft); }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2); color: var(--text-3); cursor: not-allowed;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { resize: vertical; min-height: 76px; }
select { cursor: pointer; }

.row  { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.row3 { display: grid; gap: 14px; grid-template-columns: repeat(3, 1fr); }

/* ==== Tarjetas y superficies ====================================================================== */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-sub { color: var(--text-2); font-size: var(--fs-base); margin: -10px 0 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ==== KPIs ========================================================================================================== */

.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; position: relative; overflow: hidden;
}
.kpi::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--brand); opacity: .8;
}
.kpi.ok::after   { background: var(--mint); }
.kpi.warn::after { background: var(--amber); }
.kpi.bad::after  { background: var(--rose); }

.kpi-label {
  font-size: var(--fs-base); font-weight: 600;
  color: var(--text-3); margin-bottom: 6px;
}
.kpi-value { font-size: var(--fs-base); font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.kpi-meta { font-size: var(--fs-base); color: var(--text-2); margin-top: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/**
 * La cifra principal del resumen. Sólo UNA por pantalla: si dos números
 * compiten por ser el más grande, ninguno destaca.
 */
.kpi.hero .kpi-value { font-size: var(--fs-hero); font-weight: 750; line-height: 1.15; }

.delta { font-weight: 650; font-size: var(--fs-base); }
.delta.up   { color: var(--mint); }
.delta.down { color: var(--rose); }
.delta.flat { color: var(--text-3); }

/* ==== Tablas ====================================================================================================== */

.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
thead th {
  text-align: left; padding: 10px 14px;
  background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-base); font-weight: 650;
  white-space: nowrap; border-bottom: 1px solid var(--line);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.strong { font-weight: 650; }

/* ==== Etiquetas de estado ============================================================================ */

/* Etiquetas de estado, con el mismo semáforo que el resto del sistema. */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 99px;
  font-size: var(--fs-base); font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--line);
}
.tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* Azul · en curso, requiere acción tuya */
.tag.nueva, .tag.confirmada, .tag.ia {
  background: var(--brand-soft); color: var(--brand); border-color: var(--brand-line);
}
/* Amarillo · en tránsito o no permitido todavía */
.tag.en_ruta, .tag.pausado {
  background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent);
}
/* Verde · cerrado con éxito */
.tag.entregada, .tag.activo, .tag.publicada {
  background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}
/* Rojo · falló */
.tag.devuelta, .tag.rechazada {
  background: var(--error-soft); color: var(--error); border-color: color-mix(in srgb, var(--error) 35%, transparent);
}
/* Gris · inactivo */
.tag.cancelada, .tag.archivado, .tag.borrador, .tag.plantilla {
  background: var(--surface-2); color: var(--text-3);
}

/* ==== Layout de la app ================================================================================== */

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .logo { padding: 4px 8px 20px; }

.nav-group {
  font-size: var(--fs-base); font-weight: 800; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-3); padding: 16px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--r-sm);
  color: var(--text-2); font-size: var(--fs-base); font-weight: 550;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.nav-link .ico { font-size: var(--fs-base); width: 20px; text-align: center; flex: none; }
.nav-link .badge {
  margin-left: auto; background: var(--rose); color: #fff;
  font-size: var(--fs-base); font-weight: 700; padding: 1px 7px; border-radius: 99px;
}

/* Grupos desplegables del menú */
.nav-parent {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  font: inherit; font-size: var(--fs-base); font-weight: 550; text-align: left;
  cursor: pointer; transition: background .12s, color .12s;
}
.nav-parent:hover { background: var(--surface-2); color: var(--text); }
.nav-parent.has-active { color: var(--text); font-weight: 650; }
.nav-parent .ico { font-size: var(--fs-base); width: 20px; text-align: center; flex: none; }
.nav-parent .label { flex: 1; min-width: 0; }
.nav-parent .caret {
  font-size: var(--fs-base); color: var(--text-3); flex: none;
  transition: transform .18s ease;
}
.nav-parent[aria-expanded='true'] .caret { transform: rotate(180deg); }

.nav-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height .22s ease;
  margin-left: 19px;
  border-left: 1px solid var(--line-2);
  padding-left: 4px;
}
.nav-children.open { max-height: 340px; }
.nav-children .nav-link { font-size: var(--fs-base); padding: 8px 11px; }
.nav-children .nav-link .ico { font-size: var(--fs-base); width: 18px; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--violet));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: var(--fs-base);
}
.who-name { font-size: var(--fs-base); font-weight: 650; line-height: 1.2; }
.who-role { font-size: var(--fs-base); color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 26px; border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .spacer { flex: 1; }

.content { padding: 24px 26px 60px; flex: 1; }

.menu-btn { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 18px 16px 60px; }
  .topbar { padding: 14px 16px; }
  .row, .row3 { grid-template-columns: 1fr; }
}

.scrim {
  display: none; position: fixed; inset: 0; background: #0009; z-index: 50;
  backdrop-filter: blur(2px);
}
.scrim.show { display: block; }

/* ==== Gráficas (SVG propio) ======================================================================== */

.chart { width: 100%; height: 240px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: var(--fs-base); }
.chart .bar { fill: var(--brand); }
.chart .bar-2 { fill: var(--amber); }
.chart .area { fill: url(#gradBrand); }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-2 { fill: none; stroke: var(--amber); stroke-width: 2; stroke-dasharray: 4 4; }
.chart .dot { fill: var(--brand); }

.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: var(--fs-base); color: var(--text-2); margin-top: 10px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }

/* ==== Barras de progreso ============================================================================== */

.bar-track { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 99px; background: var(--brand); transition: width .3s ease; }
.bar-fill.ok   { background: var(--mint); }
.bar-fill.warn { background: var(--amber); }
.bar-fill.bad  { background: var(--rose); }

/* ==== Modal ======================================================================================================== */

.modal-backdrop {
  position: fixed; inset: 0; background: #000a; z-index: 100;
  display: grid; place-items: center; padding: 20px; overflow-y: auto;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
}
.modal.wide { max-width: 860px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 20px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 22px 24px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--line);
  position: sticky; bottom: 0; background: var(--surface);
}
.icon-btn {
  background: none; border: 0; color: var(--text-3); cursor: pointer;
  font-size: 22px; line-height: 1; padding: 4px 8px; border-radius: var(--r-sm);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ==== Avisos ====================================================================================================== */

.alert {
  padding: 12px 16px; border-radius: var(--r); font-size: var(--fs-base);
  border: 1px solid transparent; margin-bottom: 16px; line-height: 1.5;
}
.alert-info  { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }
.alert-ok    { background: var(--ok-soft);    border-color: color-mix(in srgb, var(--ok) 35%, transparent);    color: var(--ok); }
.alert-warn  { background: var(--warn-soft);  border-color: color-mix(in srgb, var(--warn) 40%, transparent);  color: var(--warn); }
.alert-error { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 35%, transparent); color: var(--error); }

/* ==== Toasts ====================================================================================================== */

.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: grid; gap: 10px; max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--line-2);
  border-left: 4px solid var(--brand);
  border-radius: var(--r); padding: 13px 16px; box-shadow: var(--shadow-lg);
  font-size: var(--fs-base); animation: slideIn .22s ease; color: var(--text);
}
.toast.ok    { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--error); }
.toast.warn  { border-left-color: var(--warn); }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } }

/* ==== Estados vacíos / carga ====================================================================== */

.empty { text-align: center; padding: 52px 24px; color: var(--text-2); }
.empty .emoji { font-size: 44px; display: block; margin-bottom: 14px; opacity: .8; }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 42ch; margin: 0 auto 18px; font-size: var(--fs-base); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line-2) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
  border-radius: var(--r-sm); height: 15px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 17px; height: 17px; border-radius: 50%; display: inline-block;
  border: 2px solid #ffffff44; border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==== Filtros y utilidades ========================================================================== */

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 6px 13px; border-radius: 99px; border: 1px solid var(--line-2);
  background: transparent; color: var(--text-2);
  font-size: var(--fs-base); font-weight: 600; cursor: pointer; transition: all .12s;
}
.chip:hover { border-color: var(--brand); color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.mono { font-family: var(--mono); font-size: var(--fs-base); }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: var(--fs-base); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.pos { color: var(--mint); }
.neg { color: var(--rose); }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap-flex { flex-wrap: wrap; }
.mt-0 { margin-top: 0; }  .mt-1 { margin-top: 8px; }  .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }

.thumb {
  width: 38px; height: 38px; border-radius: var(--r-sm); object-fit: cover;
  background: var(--surface-2); flex: none;
}
.thumb-ph { display: grid; place-items: center; font-size: var(--fs-base); color: var(--text-3); }

.copy-box {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; font-size: var(--fs-base);
  white-space: pre-wrap; word-break: break-word; line-height: 1.6;
}

details.acc { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px; background: var(--surface); }
details.acc summary { cursor: pointer; font-weight: 650; }
details.acc[open] summary { margin-bottom: 10px; }

/* ==== Generador PRO ======================================================================================== */

.step-num {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 7px; background: var(--brand-soft); color: var(--brand);
  font-size: var(--fs-base); font-weight: 800; margin-right: 9px; flex: none;
}
.step-head { display: flex; align-items: center; margin-bottom: 12px; }
.step-head h3 { margin: 0; font-size: var(--fs-base); }

/* Selector de tarjetas (protagonista, estilo, tema⬦) */
.pickers { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.picker {
  position: relative; display: block; cursor: pointer; text-align: center;
  padding: 16px 12px; border-radius: var(--r);
  border: 2px solid var(--line-2); background: var(--bg-2);
  transition: border-color .14s, transform .14s, background .14s;
}
.picker:hover { border-color: var(--brand); transform: translateY(-1px); }
.picker input { position: absolute; opacity: 0; pointer-events: none; }
.picker:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.picker .emoji { font-size: 26px; display: block; margin-bottom: 7px; }
.picker .name { font-size: var(--fs-base); font-weight: 650; display: block; }
.picker .hint { font-size: var(--fs-base); color: var(--text-3); display: block; margin-top: 3px; line-height: 1.35; }

/* Interruptor de dos opciones */
.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 5px; border-radius: var(--r); }
.segmented label { flex: 1; position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 9px 12px; border-radius: var(--r-sm);
  font-size: var(--fs-base); font-weight: 650; color: var(--text-2); transition: background .14s, color .14s;
}
.segmented label:has(input:checked) span { background: var(--brand); color: #fff; }

/* Toggles de secciones */
.section-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); }
.section-toggle {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--bg-2);
  font-size: var(--fs-base); transition: border-color .14s, background .14s;
}
.section-toggle:hover { border-color: var(--brand); }
.section-toggle:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.section-toggle input { width: auto; margin: 0; flex: none; accent-color: var(--brand); }
.section-toggle .n { color: var(--text-3); font-size: var(--fs-base); font-variant-numeric: tabular-nums; }
.section-toggle .pro {
  margin-left: auto; font-size: 9.5px; font-weight: 800; letter-spacing: .06em;
  background: var(--violet); color: #fff; padding: 2px 6px; border-radius: 4px;
}

/* Selector de plantillas creativas */
.templates {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.template {
  position: relative; cursor: pointer; display: grid; gap: 0;
  border: 2px solid var(--line-2); border-radius: var(--r);
  background: var(--surface); overflow: hidden;
  transition: border-color .14s, transform .14s, box-shadow .14s;
}
.template:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.template input { position: absolute; opacity: 0; pointer-events: none; }
.template:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.template-bar { height: 4px; display: block; }
.template-head { display: block; padding: 10px 12px 8px; }
.template-head b { display: block; }
.template-head small { color: var(--text-3); display: block; line-height: 1.35; margin-top: 2px; }
.template-preview {
  width: 100%; display: block; background: var(--surface-2);
  border-block: 1px solid var(--line);
}
.template-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 12px; flex-wrap: wrap;
}
.template-secs { color: var(--text-3); }

/* Vista previa de formatos */
.looks { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.look {
  position: relative; cursor: pointer; border-radius: var(--r);
  border: 2px solid var(--line-2); overflow: hidden; background: var(--bg-2);
  transition: border-color .14s, transform .14s;
}
.look:hover { transform: translateY(-2px); }
.look input { position: absolute; opacity: 0; pointer-events: none; }
.look:has(input:checked) { border-color: var(--brand); }
.look-head { padding: 11px 13px 9px; border-left: 3px solid var(--brand); }
.look-head b { display: block; font-size: var(--fs-base); }
.look-head small { color: var(--text-3); font-size: var(--fs-base); line-height: 1.35; display: block; margin-top: 2px; }
.look-preview { height: 118px; display: grid; place-items: center; gap: 4px; padding: 10px; }
.look-preview .bar { border-radius: 3px; }

/* Panel de precios por pack */
.pack-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.pack-calc {
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: var(--fs-base); color: var(--text-2); margin-top: 10px;
}
.pack-calc b { color: var(--mint); }
.pack-calc .warn { color: var(--amber); }

/* Resumen lateral del generador */
.sticky-side { position: sticky; top: 88px; }

.timeline-row { display: grid; grid-template-columns: 74px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline-row:last-child { border-bottom: 0; }
.timeline-time { font-family: var(--mono); font-size: var(--fs-base); color: var(--brand); font-weight: 650; }

/* ----- Biblioteca de imagenes ----- */

.dropzone {
  border: 2px dashed var(--line-2); border-radius: var(--r-lg);
  padding: 32px 20px; text-align: center; cursor: pointer;
  display: grid; gap: 6px; justify-items: center;
  background: var(--bg-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--brand); background: var(--brand-soft); outline: none;
}
.dropzone.busy { opacity: .6; pointer-events: none; }
.dropzone .dz-icon { font-size: 32px; }

.media-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  max-height: 46vh; overflow-y: auto; padding: 2px;
}
.media-card {
  border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; background: var(--surface); transition: border-color .14s, transform .14s;
}
.media-card.selectable { cursor: pointer; }
.media-card.selectable:hover { border-color: var(--brand); transform: translateY(-2px); }
.media-thumb { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-info { padding: 8px 10px 4px; display: grid; gap: 2px; min-width: 0; }
.media-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-meta { color: var(--text-3); }
.media-actions { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 8px; }

.image-field { display: flex; gap: 14px; align-items: flex-start; }
.image-preview {
  width: 108px; height: 108px; flex: none; border-radius: var(--r);
  border: 1px solid var(--line-2); overflow: hidden; background: var(--surface-2);
  display: grid; place-items: center;
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview.empty { border-style: dashed; color: var(--text-3); }
.image-field-actions { display: grid; gap: 8px; align-content: start; }

.prompt-card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; background: var(--surface); margin-bottom: 12px; }
.prompt-card .prompt-text {
  background: var(--bg-2); border-radius: var(--r-sm); padding: 12px;
  font-family: var(--mono); font-size: var(--fs-base); line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; margin: 10px 0;
}

/* Style Selector UI */
.style-selector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 14px;
}
.style-card {
  border: 2px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.style-card:hover {
  border-color: var(--line-2);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.style-card.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand), var(--shadow-lg);
}
.style-card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
}
.style-bullet {
  width: 6px;
  height: 24px;
  border-radius: 3px;
  display: block;
}
.style-bullet.red { background-color: var(--rose); }
.style-bullet.blue { background-color: var(--brand); }
.style-bullet.green { background-color: var(--mint); }

.style-card-title {
  font-weight: 700;
  font-size: var(--fs-base);
  line-height: 1.2;
}
.style-card-subtitle {
  font-size: 13px;
  color: var(--text-3);
  grid-column: 2;
  line-height: 1.2;
}
.style-card-body {
  flex: 1;
  aspect-ratio: 4/5;
  background: var(--bg-2);
  overflow: hidden;
  position: relative;
}
.style-card-body img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.style-card:hover .style-card-body img {
  transform: scale(1.03);
}



/* Conexiones de imagen (Estudio) ------------------------------- */
.chip-conexion {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.chip-conexion.ok { border-color: var(--ok); }
.chip-conexion.pendiente { border-style: dashed; }

/* Marcas de los proveedores en Integraciones ------------------- */
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.brand-mark svg { width: 100%; height: 100%; display: block; }
.card.integracion .card-head .flex { gap: 12px; }
.probe-result:not(:empty) { margin-top: 12px; }
