/* Estilos mínimos del panel (sin librerías externas) */
:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --border: #e5e7eb;
    --ok: #16a34a;
    --warn: #d97706;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --success-bg: #dcfce7;
    --success-text: #166534;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code { background: #eef; padding: 0 .3em; border-radius: 4px; }

/* Barra superior */
.topbar {
    display: flex; align-items: center; gap: 1.5rem;
    padding: .75rem 1.5rem; background: var(--card);
    border-bottom: 1px solid var(--border);
}
.brand { color: var(--primary); }
.topbar-nav { flex: 1; }
.topbar-nav a { color: var(--text); text-decoration: none; margin-right: 1rem; }
.topbar-nav a:hover { color: var(--primary); }
.topbar-user { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.topbar-user form { margin: 0; }

/* Contenedores */
.container { max-width: 1000px; margin: 2rem auto; padding: 0 1rem; }
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem; }
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; padding: 1.5rem; margin-top: 1.5rem;
}
.card-narrow { width: 100%; max-width: 400px; margin-top: 0; }

/* Formularios */
label { display: block; font-weight: 600; margin: 1rem 0 .3rem; font-size: .9rem; }
input[type=text], input[type=email], input[type=password] {
    width: 100%; padding: .65rem .75rem; font-size: 1rem;
    border: 1px solid var(--border); border-radius: 8px;
}
input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* Botones */
.btn { cursor: pointer; border: 0; border-radius: 8px; padding: .7rem 1.2rem; font-size: 1rem; }
.btn-primary { background: var(--primary); color: #fff; margin-top: 1.5rem; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-link { background: none; color: var(--primary); padding: 0; font-size: .95rem; }
.btn-link:hover { text-decoration: underline; }

/* Alertas */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; width: 100%; max-width: 1000px; }
.center .alert { max-width: 400px; }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }

/* Tarjetas de estadísticas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; }
.stat-number { display: block; font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--muted); font-size: .9rem; }

/* Lista de estado */
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: .35rem 0; }
.checklist li::before { display: inline-block; width: 1.5rem; font-weight: 700; }
.checklist .ok::before { content: "✓"; color: var(--ok); }
.checklist .pending::before { content: "…"; color: var(--warn); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; gap: .5rem; }
}

/* Tabla de últimos eventos */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .02em; }
.nowrap { white-space: nowrap; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; color: #fff; }
.badge-instagram { background: #c13584; }
.badge-whatsapp  { background: #128c4b; }
.badge-messenger { background: #0866ff; }

/* ===== Etapa 3: reglas, conversaciones y estados ===== */

/* Menú: página actual */
.topbar-nav a.active { color: var(--primary); font-weight: 600; }

/* Encabezado de página con acciones a la derecha */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

/* Formularios: selects, áreas de texto, filas */
select, textarea, input[type=number] {
    width: 100%; padding: .6rem .7rem; font-size: 1rem; font-family: inherit;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
textarea { resize: vertical; line-height: 1.45; }
select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.hint { color: var(--muted); font-size: .82rem; margin: .3rem 0 0; }
label.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin: 1rem 0 0; }
label.checkbox input { width: auto; }
.error-list { margin: .4rem 0 0; padding-left: 1.2rem; }

/* Filtros de listados */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1rem; margin-top: 1rem; }
.filters > div { min-width: 150px; }
.filters .grow { flex: 1; min-width: 220px; }
.filters label { margin-top: 0; }
.filters label.checkbox { margin: 0 0 .6rem; }

/* Botones extra */
.btn-secondary { background: #eef0f6; color: var(--text); text-decoration: none; display: inline-block; }
.btn-secondary:hover { background: #e2e5ef; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-inline { margin-top: 0; text-decoration: none; display: inline-block; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-danger { color: #dc2626; }

/* Acciones en tablas y encabezados */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; }
.actions form { margin: 0; }
.row-muted td { color: var(--muted); }
.row-unread td { font-weight: 600; }
.count { display: inline-block; min-width: 1.4rem; padding: 0 .35rem; margin-left: .3rem; border-radius: 999px;
         background: var(--primary); color: #fff; font-size: .75rem; text-align: center; }

/* Estados (mensajes, reglas, conversaciones) */
.status { display: inline-block; padding: .1rem .5rem; border-radius: 6px; font-size: .78rem; font-weight: 600; }
.status-ok      { background: var(--success-bg); color: var(--success-text); }
.status-warn    { background: #fef3c7; color: #92400e; }
.status-error   { background: var(--error-bg); color: var(--error-text); }
.status-neutral { background: #eef0f6; color: var(--muted); }
.status-sim     { background: #ede9fe; color: #5b21b6; border: 1px dashed #7c3aed; }

.alert-warn { background: #fef3c7; color: #92400e; }

/* Paginación */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1.25rem; margin-top: 1rem; }

/* Hilo de una conversación */
.thread { display: flex; flex-direction: column; gap: .9rem; }
.msg { max-width: 75%; }
.msg-in  { align-self: flex-start; }
.msg-out { align-self: flex-end; text-align: right; }
.msg-meta { color: var(--muted); font-size: .78rem; margin-bottom: .2rem; }
.bubble { display: inline-block; text-align: left; padding: .6rem .85rem; border-radius: 12px;
          background: #f1f3f9; white-space: normal; word-wrap: break-word; }
.bubble-out { background: #e0e7ff; }
.msg-simulated .bubble { background: #f5f3ff; border: 1px dashed #7c3aed; }
.msg-status { margin-top: .25rem; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .4rem; align-items: center; }
.msg-error { width: 100%; color: var(--error-text); }

/* Probador y confirmaciones */
.tester-result { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.card-center { margin: 2rem auto 0; max-width: 520px; }

/* Tarjetas del dashboard */
.stat-sim .stat-number { color: #7c3aed; }
.stat-error .stat-number { color: #dc2626; }

@media (max-width: 600px) {
    .msg { max-width: 100%; }
}

/* ===== Etapa 4: flujos y datos capturados ===== */
input[type=date] {
    width: 100%; padding: .55rem .7rem; font-size: 1rem; font-family: inherit;
    border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.form-actions { margin-top: 1.25rem; }
.form-actions .btn-primary { margin-top: 0; }

/* Respuestas capturadas: clave / valor */
.answers { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .9rem; margin: .3rem 0 0; font-size: .9rem; }
.answers dt { color: var(--muted); font-weight: 600; }
.answers dd { margin: 0; word-break: break-word; }

/* Historial de sesiones de un contacto */
.session { border-top: 1px solid var(--border); padding: .8rem 0; }
.session:first-of-type { border-top: 0; }
.session p { margin: 0 0 .3rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
