:root, [data-theme="light"] {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #C7106F;
  --accent-hover: #a90d5e;
  --accent-soft: #fdf2f8;
  --rail-bg: #ffffff;
  --msg-in: #ffffff;
  --msg-bot: #eff6ff;
  --msg-bot-border: #bfdbfe;
  --msg-agent: #fdf2f8;
  --msg-agent-border: #fbcfe8;
}

[data-theme="dark"] {
  --bg: #0b0e17;
  --panel: #131826;
  --panel-2: #1b2236;
  --border: #26304a;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #C7106F;
  --accent-hover: #e01880;
  --accent-soft: rgba(199,16,111,0.16);
  --rail-bg: #0f1420;
  --msg-in: #1b2236;
  --msg-bot: #172554;
  --msg-bot-border: #3b82f6;
  --msg-agent: rgba(199,16,111,0.22);
  --msg-agent-border: #C7106F;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 16px; }
.full { width: 100%; }

input, select, textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font: inherit; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; margin: 10px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }

button {
  border: none; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600;
  cursor: pointer; transition: 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel-2); }
.btn-icon {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 10px; border-radius: 8px;
}
.btn-icon:hover { border-color: var(--accent); }
.small-btn { padding: 6px 10px; font-size: 12px; }

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: 0 12px 32px rgba(15,23,42,0.08);
}
.brand-badge {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
  margin-bottom: 14px;
}
.login-card h1 { margin: 0 0 6px; font-size: 19px; }
.pw-wrap { display: flex; gap: 6px; }
.error-box {
  margin-top: 12px; padding: 10px; border-radius: 8px;
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; font-size: 13px;
}
#login-btn { margin-top: 16px; }

/* Shell moderno estilo GoHighLevel (barra izquierda oscura + área clara limpia) */
.cw-shell { display: flex; height: 100vh; overflow: hidden; }
.cw-rail {
  width: 214px; background: #111827; color: #e2e8f0; border-right: 1px solid #1f2937;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 14px 10px; flex-shrink: 0;
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; gap: 4px; }
.ghl-brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px;
  border-bottom: 1px solid #1f2937; margin-bottom: 8px;
}
.ghl-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.ghl-brand-text strong { font-size: 13px; color: #fff; }
.ghl-brand-text span { font-size: 11px; color: #94a3b8; }
.rail-logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px;
  flex-shrink: 0;
}
.rail-btn {
  position: relative; width: 100%; height: 38px; border-radius: 8px; padding: 0 10px;
  background: transparent; color: #cbd5e1; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; text-align: left;
}
.rail-ico { font-size: 16px; width: 20px; text-align: center; }
.rail-btn:hover { background: #1f2937; color: #fff; }
.rail-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.rail-badge {
  margin-left: auto; background: #fff; color: var(--accent);
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px;
}
@media (max-width: 900px) {
  .cw-rail { width: 58px; padding: 12px 6px; }
  .ghl-brand-text, .rail-lbl { display: none; }
  .rail-btn { justify-content: center; padding: 0; }
}

.cw-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.cw-topbar {
  height: 52px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-bcv { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
[data-theme="dark"] .pill-bcv { background: rgba(16,185,129,0.15); color: #6ee7b7; border-color: rgba(16,185,129,0.35); }
.pill-muted { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.pill-warn { background: #fef9c3; color: #a16207; }

.tab-panel { flex: 1; min-height: 0; overflow: hidden; }

/* Inbox 3 columnas limpias */
.inbox-grid { display: grid; grid-template-columns: 300px 1fr 320px; height: 100%; }
.col-list {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.list-controls { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.contacts-list { flex: 1; overflow-y: auto; }
.contact-item {
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
}
.contact-item:hover { background: var(--panel-2); }
.contact-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.avatar {
  width: 36px; height: 36px; border-radius: 999px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.contact-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.contact-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.stage-chip { padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 11px; }
.unread-dot {
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 6px;
}

/* Centro chat */
.col-chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.empty-state { margin: auto; text-align: center; max-width: 340px; padding: 24px; }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.chat-active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-header {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.chat-peer { display: flex; align-items: center; gap: 10px; }
.chat-title-row { display: flex; align-items: center; gap: 6px; }
.chat-header-actions { display: flex; align-items: center; gap: 6px; }
.chat-header-actions select { width: auto; min-width: 155px; font-size: 12px; padding: 6px 8px; }
.btn-bot { padding: 6px 10px; font-size: 12px; border-radius: 999px; }
.btn-bot.on { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.btn-bot.off { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.messages-box {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 75%; padding: 10px 13px; border-radius: 12px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.msg-in { align-self: flex-start; background: var(--msg-in); border: 1px solid var(--border); }
.msg-out-bot { align-self: flex-end; background: var(--msg-bot); border: 1px solid var(--msg-bot-border); }
.msg-out-agent { align-self: flex-end; background: var(--msg-agent); border: 1px solid var(--msg-agent-border); }
.msg-meta {
  font-size: 11px; color: var(--muted); margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.teach-btn {
  padding: 1px 6px; font-size: 10px; border-radius: 6px;
  background: transparent; color: var(--muted); border: 1px solid var(--border);
}
.teach-btn:hover { color: var(--accent); border-color: var(--accent); }

.sim-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: #fefce8; border-top: 1px solid #fde047;
}
[data-theme="dark"] .sim-bar { background: rgba(234,179,8,0.1); border-color: rgba(234,179,8,0.3); }
.sim-label { font-size: 12px; font-weight: 600; color: #a16207; white-space: nowrap; }
.reply-bar {
  display: flex; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--border);
}

/* Panel derecho por pestañas */
.col-side {
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.side-active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.side-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--border);
}
.side-tab {
  background: transparent; color: var(--muted); border-radius: 0; padding: 10px 6px; font-size: 12px;
  border-bottom: 2px solid transparent;
}
.side-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-soft); }
.side-panel { flex: 1; overflow-y: auto; padding: 12px 14px; }

.tags-wrap { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.tag-btn {
  padding: 4px 8px; border-radius: 999px; font-size: 11px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.tag-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.catalog-search-row { display: flex; gap: 6px; margin-bottom: 10px; }
.catalog-results { display: flex; flex-direction: column; gap: 8px; }
.prod-card {
  display: flex; gap: 8px; padding: 8px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border); align-items: center;
}
.prod-card img { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; }
.prod-info { flex: 1; min-width: 0; }
.prod-name { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prod-price { font-size: 11px; color: #047857; font-weight: 600; }
[data-theme="dark"] .prod-price { color: #6ee7b7; }
.prod-btns { display: flex; flex-direction: column; gap: 4px; }

.draft-box {
  padding: 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border);
}
.draft-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.draft-items { display: flex; flex-direction: column; gap: 6px; }
.draft-row {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font-size: 12px; padding-bottom: 4px; border-bottom: 1px dashed var(--border);
}
.draft-actions { display: flex; gap: 6px; margin-top: 8px; }

.orders-list { display: flex; flex-direction: column; gap: 6px; }
.order-card {
  padding: 8px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); font-size: 12px;
}

/* Kanban */
#tab-kanban { display: flex; flex-direction: column; padding: 14px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.kanban-board { flex: 1; display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kanban-col {
  min-width: 255px; max-width: 255px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; display: flex; flex-direction: column; max-height: 100%;
}
.kanban-col-head {
  padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 13px;
}
.kanban-cards { padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.kanban-card {
  padding: 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.kanban-card-actions { display: flex; gap: 6px; align-items: center; }

/* Config, Training & Team */
.config-wrap { padding: 18px; height: 100%; overflow-y: auto; max-width: 1200px; margin: 0 auto; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.check-row input { width: auto; }
.toast {
  margin-bottom: 12px; padding: 10px 14px; border-radius: 8px;
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; font-size: 13px;
}
.training-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-height: 420px; overflow-y: auto; }
.train-item {
  padding: 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); font-size: 12px;
}
.train-item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.team-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.team-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border);
}

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px;
}
.modal-card h3 { margin: 0 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 1024px) {
  .inbox-grid { grid-template-columns: 260px 1fr; }
  .col-side { display: none; }
  .config-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .inbox-grid { grid-template-columns: 1fr; }
  .col-list { max-height: 38vh; }
}
