:root {
  --bg: #0f1422;
  --panel: #171e31;
  --borde: #2a3450;
  --ink: #e8edf7;
  --muted: #8b97b5;
  --accent: #0b5fff;
  --ia: #8b5cf6;
  --peligro: #dc2626;
  --ok: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.barra {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--borde);
  position: sticky;
  top: 0;
  z-index: 10;
}

.marca { font-weight: 800; display: flex; align-items: center; gap: 0.5rem; }
.logo {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  background: var(--accent); color: white;
  border-radius: 6px; font-weight: 900;
}

.acciones-barra { display: flex; gap: 0.6rem; }

main { max-width: 1300px; margin: 0 auto; padding: 1.5rem; }

h1 { font-size: 1.4rem; }
h2 { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.btn {
  border: 1px solid var(--borde);
  background: var(--panel);
  color: var(--ink);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.2); }
.btn-pri { background: var(--accent); border-color: var(--accent); }
.btn-ia { background: var(--ia); border-color: var(--ia); }
.btn-peligro { background: transparent; border-color: var(--peligro); color: #f87171; }

/* Listado */
.lista { display: grid; gap: 0.7rem; }
.tarjeta {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  cursor: pointer;
}
.tarjeta:hover { border-color: var(--accent); }
.tarjeta h3 { margin: 0 0 0.25rem; font-size: 1.02rem; }
.tarjeta p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.meta { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }
.chip {
  font-size: 0.7rem; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 99px;
  background: rgba(11, 95, 255, 0.18); color: #7aa8ff;
}
.chip.borrador { background: rgba(234, 179, 8, 0.15); color: #facc15; }

/* Editor */
.editor-cabecera { display: flex; justify-content: space-between; margin-bottom: 1rem; }
.grupo-derecha { display: flex; gap: 0.6rem; align-items: center; }
.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }

.campos { display: grid; gap: 0.8rem; margin-bottom: 1.2rem; }
.fila { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 0.8rem; }
label { display: grid; gap: 0.3rem; font-size: 0.8rem; font-weight: 700; color: var(--muted); }

input, select, textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 8px;
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.panel-doble {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  align-items: start;
}
#campo-cuerpo {
  min-height: 60vh;
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  resize: vertical;
}

.preview {
  background: white; color: #1a2235;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  min-height: 60vh;
  line-height: 1.65;
  font-size: 0.93rem;
}
.preview h2 { color: #0f1f3d; text-transform: none; letter-spacing: 0; font-size: 1.25rem; margin-top: 1.6em; }
.preview a { color: var(--accent); }
.preview code { background: #eef1f7; padding: 0.1em 0.35em; border-radius: 4px; }

/* Modal */
dialog {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--borde); border-radius: 14px;
  padding: 1.6rem; width: min(560px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 1.15rem; margin-top: 0; }
dialog label { margin-bottom: 0.8rem; }
.ayuda { color: var(--muted); font-size: 0.85rem; }
.modal-acciones { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.estado { color: var(--ia); font-weight: 700; font-size: 0.85rem; }

/* Chat IA del editor */
.chat-ia {
  margin-top: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 1.1rem 1.3rem;
}
.chat-ia h2 { margin-top: 0; color: var(--ia); }
.chat-mensajes {
  max-height: 260px;
  overflow-y: auto;
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.chat-vacio { color: var(--muted); font-size: 0.82rem; margin: 0; }
.msg {
  max-width: 85%;
  padding: 0.55rem 0.9rem;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.msg.editor { background: var(--accent); color: white; justify-self: end; border-bottom-right-radius: 4px; }
.msg.ia { background: var(--bg); border: 1px solid var(--borde); justify-self: start; border-bottom-left-radius: 4px; }
.msg.ia.espera { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 0.6rem; }
.chat-input input { flex: 1; }
.chat-input select { max-width: 220px; }
.chat-nota { margin: 0.5rem 0 0; font-size: 0.72rem; color: var(--muted); }

/* Destello en campos modificados por la IA */
@keyframes destello {
  0% { outline: 2px solid var(--ia); background: rgba(139, 92, 246, 0.18); }
  100% { outline: 2px solid transparent; background: var(--panel); }
}
.destello { animation: destello 2.5s ease-out; }

/* Toast */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--borde);
  border-left: 4px solid var(--ok);
  padding: 0.8rem 1.3rem; border-radius: 10px;
  font-size: 0.88rem; font-weight: 600;
  z-index: 50; max-width: 90vw;
}
.toast.error { border-left-color: var(--peligro); }

@media (max-width: 900px) {
  .panel-doble, .fila { grid-template-columns: 1fr; }
}
