/* Paleta tomada de reference/bsl/public/irischat.html, sin BSL branding. */
:root {
  --bg: #F5F6F8;
  --sidebar: #ECEEF2;
  --sidebar-hover: #E2E5EB;
  --panel: #FFFFFF;
  --line: #E4E7EC;
  --line-soft: #EFF1F4;
  --ink: #0F1115;
  --ink-2: #2A2F39;
  --ink-3: #5B6271;
  --ink-4: #8B93A3;
  --ink-5: #B7BDC9;
  --accent: #0c0140;
  --accent-2: #1e0a80;
  --accent-soft: #ece8f7;
  --accent-tint: #e0d9f5;
  --green: #16A34A;
  --green-soft: #DCFCE7;
  --amber: #D97706;
  --amber-soft: #FEF3C7;
  --rose: #DC2626;
  --rose-soft: #FEE2E2;
  --shadow-1: 0 1px 0 rgba(15,17,21,.04);
  --shadow-2: 0 1px 2px rgba(15,17,21,.04), 0 8px 24px rgba(15,17,21,.05);
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter Tight', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent); }

.app { display: grid; grid-template-rows: 56px 1fr; height: 100vh; overflow: hidden; }

/* TOP BAR */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 0 18px;
}
.topbar-brand { display: flex; align-items: baseline; gap: 10px; }
.topbar-brand .name { font-weight: 700; font-size: 18px; color: var(--ink); letter-spacing: -0.01em; }
.topbar-brand .name .accent { color: var(--accent); }
.topbar-brand .version { font-size: 10px; color: var(--ink-4); background: var(--bg); border: 1px solid var(--line); padding: 2px 6px; border-radius: 999px; }
.topbar-nav { display: flex; align-items: center; gap: 6px; }
.topbar-nav a {
  text-decoration: none; color: var(--ink-3); font-size: 13px; font-weight: 500;
  padding: 6px 12px; border-radius: 8px;
}
.topbar-nav a:hover { background: var(--bg); color: var(--ink); }
.topbar-nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user .who { font-size: 12px; color: var(--ink-3); text-align: right; }
.topbar-user .who b { color: var(--ink-2); font-weight: 600; display: block; font-size: 13px; }
.topbar-user button {
  background: transparent; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; color: var(--ink-3); font-size: 12px;
}
.topbar-user button:hover { background: var(--bg); color: var(--ink); }

/* Layout 3 cols */
.main3 { display: grid; grid-template-columns: 320px 1fr 320px; overflow: hidden; }
.main2 { display: grid; grid-template-columns: 320px 1fr; overflow: hidden; }

.col { background: var(--panel); overflow: auto; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.col:last-child { border-right: none; }
.col-left { background: var(--sidebar); }

/* Sidebar conversaciones */
.left-head { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.left-head input, .left-head select {
  width: 100%; height: 34px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px;
  padding: 0 10px; font-size: 13px; color: var(--ink); outline: none;
}
.left-head input:focus, .left-head select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(12,1,64,.10); }
.conv-list { flex: 1; overflow-y: auto; padding: 6px 8px; }

.conv {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; position: relative; transition: background 120ms;
  margin-bottom: 4px;
}
.conv:hover { background: rgba(255,255,255,.6); }
.conv.active { background: #fff; box-shadow: var(--shadow-2); }
.conv .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); flex-shrink: 0;
}
.conv .body { min-width: 0; flex: 1; }
.conv .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv .nombre { font-size: 13.5px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .hora { font-size: 11px; color: var(--ink-4); flex-shrink: 0; }
.conv .preview { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .row3 { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.conv .badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px;
}
.conv .bot-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
}
.conv .bot-tag.on { background: var(--green-soft); color: var(--green); }
.conv .bot-tag.off { background: var(--rose-soft); color: var(--rose); }

/* Chat central */
.chat-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #fff;
}
.chat-head .who h2 { margin: 0; font-size: 15px; color: var(--ink); }
.chat-head .who .cel { font-size: 12px; color: var(--ink-4); }
.chat-head .acts { display: flex; gap: 8px; align-items: center; }
.chat-head select, .chat-head button {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink-2); font-size: 12.5px;
}
.chat-head button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.chat-head button.muted { background: var(--bg); color: var(--ink-3); }

.chat-body {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  background: #fafbfc;
}
.bubble {
  max-width: 70%; padding: 8px 12px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.4; word-wrap: break-word;
  position: relative;
}
.bubble.in {
  background: #fff; border: 1px solid var(--line); align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.out {
  background: var(--accent); color: #fff; align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.bubble.out.bot {
  background: #fff; color: var(--ink); border: 1px solid var(--accent-tint);
}
.bubble .meta { font-size: 10.5px; opacity: .7; margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.bubble.out .meta { justify-content: flex-end; }
.bubble img { max-width: 100%; border-radius: 8px; display: block; }
.bubble .corregir {
  border: none; background: transparent; color: var(--accent); font-size: 11px;
  cursor: pointer; padding: 0; text-decoration: underline;
}

.chat-foot {
  padding: 12px; border-top: 1px solid var(--line); background: #fff;
  display: flex; gap: 8px; align-items: center;
}
.chat-foot textarea {
  flex: 1; min-height: 38px; max-height: 120px; resize: vertical;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  font-size: 13.5px; outline: none;
}
.chat-foot textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(12,1,64,.08); }
.chat-foot button {
  height: 38px; padding: 0 16px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px;
}
.chat-foot button.muted { background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }
.chat-foot input[type=file] { display: none; }

/* Panel derecho contacto */
.contact-panel { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.contact-panel h3 { margin: 0 0 8px 0; font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.contact-panel label { display: block; font-size: 11px; color: var(--ink-4); margin: 6px 0 4px 0; font-weight: 500; }
.contact-panel input, .contact-panel textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; outline: none; background: #fff;
}
.contact-panel textarea { min-height: 70px; resize: vertical; }
.contact-panel .chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 36px; }
.contact-panel .chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: 11.5px; }
.contact-panel .chip button { border: none; background: transparent; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; line-height: 1; }
.contact-panel .chips input { flex: 1; min-width: 80px; border: none; outline: none; padding: 4px; font-size: 12.5px; }
.contact-panel button.guardar {
  height: 36px; background: var(--accent); color: #fff; border: none; border-radius: 8px;
  font-weight: 600; font-size: 13px;
}
.kv-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.kv-row input { font-size: 12px; }
.kv-row button { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; color: var(--ink-3); padding: 0 8px; }
.contact-panel .enriched { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 10px; }
.contact-panel .enriched pre { margin: 0; font-size: 11px; color: var(--ink-3); white-space: pre-wrap; word-wrap: break-word; }

/* Forms genéricos */
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow-1);
}
.card h2 { margin: 0 0 10px 0; font-size: 16px; color: var(--ink); }
.card .desc { color: var(--ink-3); font-size: 13px; margin-bottom: 10px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.form-row input, .form-row textarea, .form-row select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; background: #fff;
}
.form-row textarea { min-height: 110px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); font-size: 13px; font-weight: 500; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { background: var(--rose); color: #fff; border-color: var(--rose); }
.btn.muted { background: var(--bg); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.flash { position: fixed; right: 18px; bottom: 18px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; opacity: 0; transition: opacity 200ms; z-index: 50; }
.flash.show { opacity: 1; }
.flash.error { background: var(--rose); }
.flash.ok { background: var(--green); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-card {
  background: #fff; padding: 32px; border-radius: 14px; border: 1px solid var(--line);
  width: 380px; box-shadow: var(--shadow-2);
}
.login-card h1 { font-size: 22px; margin: 0 0 6px 0; }
.login-card h1 .accent { color: var(--accent); }
.login-card p.sub { color: var(--ink-3); font-size: 13px; margin: 0 0 18px 0; }
.login-card .form-row label { color: var(--ink-2); }
.login-card .toggle-tenant { font-size: 12px; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0; margin-bottom: 8px; }
.login-card .err { background: var(--rose-soft); color: var(--rose); padding: 8px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }
.login-card .btn { width: 100%; }
.login-card .alt { text-align: center; font-size: 12.5px; color: var(--ink-3); margin-top: 14px; }

/* Tabla (entrenamiento) */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: top; }
.tbl th { font-size: 11px; color: var(--ink-4); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.tbl tr:hover td { background: var(--bg); }
.tbl .fuente { display: inline-block; padding: 2px 8px; font-size: 11px; border-radius: 999px; }
.tbl .fuente.admin { background: var(--accent-soft); color: var(--accent); }
.tbl .fuente.bot { background: var(--green-soft); color: var(--green); }
.tbl .fuente.correccion { background: var(--amber-soft); color: var(--amber); }

/* Flujos */
.flujos-wrap { display: grid; grid-template-columns: 320px 1fr; height: 100%; overflow: hidden; }
.tree { padding: 14px; overflow: auto; border-right: 1px solid var(--line); background: var(--sidebar); }
.tree-node {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
  font-size: 13px; color: var(--ink-2); display: flex; gap: 6px; align-items: center;
}
.tree-node:hover { background: rgba(255,255,255,.7); }
.tree-node.active { background: #fff; box-shadow: var(--shadow-1); color: var(--ink); font-weight: 600; }
.tree-node .tipo { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.tree-children { padding-left: 16px; border-left: 1px dashed var(--line); margin-left: 8px; }
.flujos-form { padding: 18px; overflow: auto; }
.flujos-form .opciones { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.flujos-form .opciones .opt { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }

/* Container generico para entrenamiento / configuracion */
.page-content { padding: 24px; max-width: 960px; margin: 0 auto; width: 100%; overflow: auto; }
.page-content h1 { font-size: 22px; margin: 0 0 4px 0; }
.page-content .lede { color: var(--ink-3); margin: 0 0 20px 0; font-size: 13.5px; }
