:root {
  --bg: #0e1621;
  --bg-panel: #17212b;
  --bg-input: #242f3d;
  --bg-own: #2b5278;
  --bg-other: #182533;
  --text: #e9eef3;
  --text-dim: #8d9bab;
  --accent: #5288c1;
  --danger: #e56767;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============ Login ============ */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0e1621 0%, #1c3a5a 100%);
}
.login-card {
  background: var(--bg-panel);
  padding: 40px 44px;
  border-radius: 18px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 18px 50px rgba(0,0,0,.4);
}
.login-logo { font-size: 60px; margin-bottom: 10px; }
.login-card h1 { font-size: 28px; margin-bottom: 6px; }
.login-card p { color: var(--text-dim); margin-bottom: 24px; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 26px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.1); }
.login-msg { margin-top: 14px; color: var(--danger); font-size: 14px; }

/* ============ Layout ============ */
.app { display: flex; height: 100%; }

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0c131c;
  display: none;
}
@media (min-width: 760px) { .sidebar { display: flex; } }
.sidebar-header { padding: 16px; font-weight: 700; font-size: 18px; border-bottom: 1px solid #0c131c; }
.conversation { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.conversation.active { background: var(--bg-input); }
.conversation-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.conversation-name { font-weight: 600; }
.conversation-last { color: var(--text-dim); font-size: 13px; }
.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid #0c131c;
}
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar-img { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-input); object-fit: cover; }
.btn-ghost {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; padding: 6px;
}
.btn-ghost:hover { color: var(--danger); }


/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  padding: 12px 18px;
  background: var(--bg-panel);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid #0c131c;
}
.chat-header-title { display: flex; align-items: center; gap: 12px; }
.chat-header-status { font-size: 13px; color: var(--text-dim); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #5ecd72; margin-right: 5px; }
.model-selector select {
  background: var(--bg-input); color: var(--text); border: none;
  padding: 8px 12px; border-radius: 8px; font-size: 13px;
}
.model-selector label { color: var(--text-dim); font-size: 12px; margin-right: 6px; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60"><rect width="60" height="60" fill="none"/></svg>');
}
.msg {
  max-width: 75%;
  padding: 9px 12px 7px;
  border-radius: var(--radius);
  position: relative;
  line-height: 1.4;
  font-size: 15px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.own { align-self: flex-end; background: var(--bg-own); border-top-right-radius: 4px; }
.msg.other { align-self: flex-start; background: var(--bg-other); border-top-left-radius: 4px; }
.msg.from { align-self: center; background: transparent; font-size: 12px; color: var(--text-dim); }
.msg img { max-width: 260px; border-radius: 8px; display: block; margin-bottom: 6px; }
.msg .meta { font-size: 11px; color: rgba(255,255,255,.55); text-align: right; margin-top: 3px; }
.msg.error { background: rgba(229,103,103,.18); color: var(--danger); }
.msg.pending { opacity: .75; }
.msg.pending .meta { color: rgba(255,255,255,.75); font-style: italic; }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); display: inline-flex; align-items: center; justify-content: center;
  margin-right: 8px; vertical-align: middle; font-size: 17px; flex-shrink: 0;
}

/* Composer */
.composer { background: var(--bg-panel); border-top: 1px solid #0c131c; padding: 10px 14px 18px; }
.attachment-preview { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.attachment-preview img {
  max-width: 110px; max-height: 90px; border-radius: 8px; border: 1px solid #0c131c;
}
.remove-attach {
  background: rgba(0,0,0,.5); color: #fff; border: none; cursor: pointer;
  width: 24px; height: 24px; border-radius: 50%; font-size: 13px;
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.attach-btn { font-size: 24px; cursor: pointer; padding: 6px; }
textarea#message-input {
  flex: 1;
  background: var(--bg-input);
  color: var(--text);
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  resize: none;
  max-height: 120px;
  outline: none;
}
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Typing indicator */
.typing-indicator { color: var(--text-dim); font-size: 13px; margin-top: 6px; padding-left: 4px; }
.typing-indicator span {
  display: inline-block; width: 5px; height: 5px; background: var(--text-dim);
  border-radius: 50%; margin-left: 3px; animation: blink 1.2s infinite;
}
.typing-indicator span:nth-child(2){ animation-delay: .2s; }
.typing-indicator span:nth-child(3){ animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.2;} 40%{opacity:1;} }

/* ==========================================================================
 *  WIZARD DE MARKETING (Instagram) — estilos del chat
 * ========================================================================== */

/* Botón "Nueva campaña" de la barra lateral */
.new-campaign-btn {
  margin: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #5f38f9, #8b3fd6);
  border: none;
  color: #fff;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: filter .15s, transform .05s;
}
.new-campaign-btn:hover { filter: brightness(1.1); }
.new-campaign-btn:active { transform: scale(.98); }
.nc-icon { font-size: 18px; }

/* Opciones clicables dentro de la burbuja del asistente */
.msg-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  width: 100%;
}
.option-btn {
  background: rgba(95,56,249,.16);
  color: #cdc2ff;
  border: 1px solid rgba(95,56,249,.4);
  padding: 7px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, color .15s, transform .05s;
}
.option-btn:hover { background: rgba(95,56,249,.3); color: #fff; }
.option-btn:active { transform: scale(.97); }

/* Input inline (escena / nombre) dentro del chat */
.msg-inline-form {
  flex-shrink: 0;
  width: 60%;
  max-width: 420px;
  margin-top: 4px;
  align-self: flex-start;
  background: var(--bg-other);
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.inline-row { display: flex; gap: 8px; align-items: center; }
.mt6 { margin-top: 6px; }
.inline-input {
  flex: 1;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
}
.inline-input:focus { border-color: var(--accent); }
.inline-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.inline-btn.primary { background: #5f38f9; }
.inline-btn.danger { background: #c5283a; }
.inline-btn:hover { filter: brightness(1.1); }
.format-btn {
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,.12);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.format-btn.active { background: rgba(95,56,249,.25); color: #fff; border-color: #5f38f9; }

/* Tarjeta de la pieza generada (revisión y aprobación) */
.creative-card {
  flex-shrink: 0;
  max-width: 420px;
  align-self: flex-start;
  width: 92%;
  background: var(--bg-other);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  margin-top: 4px;
}
.creative-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.creative-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #cdc2ff;
  background: rgba(95,56,249,.16);
  padding: 4px 9px;
  border-radius: 6px;
}
.creative-code { font-family: ui-monospace, monospace; font-size: 13px; color: var(--text-dim); }
.creative-img { width: 100%; display: block; background: #0a0f16; }
.creative-null { width: 100%; height: 260px; display: flex; align-items: center; justify-content: center; color: var(--text-dim); background: var(--bg-input); }
/* Editor: imagen actual + corrección */
.edit-box { display: flex; flex-direction: column; gap: 8px; }
.edit-preview {
  width: 100%;
  max-height: 260px;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: #0a0f16;
}
.edit-preview img { width: 100%; display: block; object-fit: cover; }

/* Estado "Regenerando": reemplaza input + botones mientras se genera */
.edit-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.4;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  background: var(--bg-input);
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(95,56,249,.25);
  border-top-color: #5f38f9;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.creative-body { padding: 12px 14px; }
.creative-caption { font-size: 13.5px; line-height: 1.5; color: var(--text); white-space: normal; }
.creative-cta { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: 12.5px; color: var(--text-dim); }
.creative-cta a { color: var(--accent); }
.creative-reject { margin-top: 8px; font-size: 12.5px; color: var(--danger); background: rgba(229,103,103,.12); padding: 7px 10px; border-radius: 8px; }
.creative-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.act-btn {
  border: none;
  padding: 9px 13px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
.act-btn.submit { background: var(--accent); }
.act-btn.ok { background: #1f7a4d; }
.act-btn.danger { background: #c5283a; }
.act-btn.share { background: linear-gradient(135deg, #d62976, #962fbf, #4f5bd5); }
.act-btn.ghost { background: var(--bg-input); color: var(--text); }
.act-btn:hover { filter: brightness(1.1); }
.permalink { color: var(--accent); font-weight: 600; font-size: 13.5px; text-decoration: none; }
.permalink:hover { text-decoration: underline; }

/* Fijar el texto de la burbuja para que las opciones queden debajo del texto */
.msg-text { display: block; white-space: normal; }

/* Formulario de la pieza (paso 1 del wizard) — campos apilados */
.promo-form {
  width: 82%;
  max-width: 440px;
}
.promo-form .inline-row {
  margin-bottom: 6px;
}
.promo-form .inline-input {
  font-size: 13.5px;
  padding: 8px 11px;
}
.promo-form .inline-btn {
  width: 100%;
  justify-content: center;
}

/* Campo IMAGEN del formulario de la pieza (adjuntar / pegar) */
.promo-form .inline-btn.ghost {
  background: var(--bg-input);
  color: var(--text);
  border: 1px dashed rgba(255,255,255,.3);
}
.promo-form .inline-btn.ghost:hover { border-color: var(--accent); color: #fff; }
.pf-img-hint { font-size: 11px; color: var(--text-dim); line-height: 1.2; }
.promo-form .inline-btn.ghost { flex: 1; justify-content: center; }

.pf-img-preview {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
}
.pf-img-preview img {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: cover;
}
.pf-img-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
}
.hidden { display: none !important; }
