/* CMD Agentes — dashboard styles (dark, monospace-ish, dense) */

:root {
  --bg-0: #0a0e1a;
  --bg-1: #12182a;
  --bg-2: #1a2238;
  --bg-3: #232d48;
  --fg-0: #e6eaf2;
  --fg-1: #a7b0c2;
  --fg-2: #6e7896;
  --accent: #e7c86b;
  --accent-2: #7fb7ff;
  --ok: #6bdc99;
  --warn: #e7b06b;
  --err: #ff6b7a;
  --border: #263049;
  --shadow: 0 6px 20px rgba(0,0,0,.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg-0); color: var(--fg-0); font-family: var(--ui); font-size: 14px; }
a, a:visited { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ───── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--border);
}
.logo {
  font-family: var(--mono);
  font-size: 28px; color: var(--accent);
  line-height: 1;
}
.brand-name { font-weight: 600; letter-spacing: .02em; flex: 1; }
.brand-status {
  color: var(--err);
  font-size: 18px;
  transition: color .3s;
}
.brand-status.connected { color: var(--ok); }
.brand-status.connecting { color: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.agents h3, .tasks h3 {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--fg-2); margin: 16px 0 8px;
}
.agent-btn {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent;
  padding: 10px 12px; border-radius: 8px;
  text-align: left; color: var(--fg-0);
  margin-bottom: 6px;
  transition: background .15s, border-color .15s;
}
.agent-btn:hover { background: var(--bg-2); }
.agent-btn.active {
  background: var(--bg-2); border-color: var(--border);
  box-shadow: var(--shadow);
}
.agent-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(231,200,107,.12);
}
.agent-dot-duo {
  background: linear-gradient(135deg, #e7c86b 0 50%, #7fb7ff 50% 100%);
}
.agent-name { flex: 1; font-weight: 500; }
.agent-sub {
  font-size: 10px; color: var(--fg-2);
}
.agent-btn.active .agent-sub { color: var(--fg-1); }

.tasks { flex: 1; min-height: 100px; }
.tasks .badge {
  display: inline-block; background: var(--bg-3); color: var(--fg-0);
  padding: 1px 6px; border-radius: 10px; font-size: 10px;
  vertical-align: middle; margin-left: 6px;
}
.tasks-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.task-item {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
  font-size: 12px;
}
.task-row { display: flex; align-items: center; gap: 8px; }
.task-icon { font-family: var(--mono); color: var(--accent); }
.task-title { flex: 1; }
.task-agent { color: var(--fg-2); font-size: 10px; }
.task-progress {
  height: 3px; background: var(--border);
  border-radius: 2px; margin-top: 6px; overflow: hidden;
}
.task-bar {
  height: 100%; background: var(--accent);
  width: 0; transition: width .3s;
}
.task-item.done .task-bar { background: var(--ok); }
.task-item.failed .task-bar { background: var(--err); }

.sidebar-foot {
  margin-top: 12px; border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex; gap: 6px;
}
.sidebar-foot button {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg-0); padding: 8px; border-radius: 6px; font-size: 12px;
}
.sidebar-foot button:hover { background: var(--bg-3); }

/* ───── Main ─────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; overflow: hidden; }

.tabs {
  display: flex; background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}
.tab {
  background: transparent; border: 0;
  color: var(--fg-1); padding: 12px 16px;
  border-bottom: 2px solid transparent;
  font-size: 13px; letter-spacing: .02em;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--fg-0); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.panel.active { display: flex; }

/* CHAT panel */
.chat-header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.chat-header h2 { margin: 0; font-size: 15px; flex-shrink: 0; }
.chat-meta { display: flex; gap: 14px; flex: 1; justify-content: flex-end; align-items: center; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--fg-1); cursor: pointer; }
.toggle input { cursor: pointer; }
.voice-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 6px;
  background: var(--bg-1); border: 1px solid var(--border);
  color: var(--fg-1); font-size: 11px; cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
}
.voice-toggle:hover { background: var(--bg-2); color: var(--fg); }
.voice-toggle.voice-on { background: #3a2f0e; color: #e7c86b; border-color: #6a5520; }
.voice-toggle.voice-on .voice-icon::after { content: "·"; color: #e7c86b; margin-left: 2px; }
.voice-toggle.voice-speaking { animation: voice-pulse 1.2s ease-in-out infinite; }
.voice-toggle.voice-listening::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: #6ad488; margin-right: 4px; animation: voice-pulse 1s ease-in-out infinite;
}
.voice-toggle.voice-unsupported { opacity: 0.4; cursor: not-allowed; }
.voice-wake-toggle.voice-wake-on { background: #1f4f2a; color: #bff0c4; border-color: #2d7240; }

/* MODO COMERCIAL — Growth */
#panel-growth { overflow-y: auto; }
.growth-header { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg-1); }
.growth-header h2 { margin: 0 0 6px 0; font-size: 18px; }
.growth-hint { margin: 0; font-size: 12px; color: var(--fg-1); line-height: 1.4; }
.growth-form { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.growth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg-1); }
.growth-form input, .growth-form select, .growth-form textarea {
  background: var(--bg-0); border: 1px solid var(--border); color: var(--fg);
  padding: 8px 10px; border-radius: 5px; font-family: inherit; font-size: 13px;
}
.growth-form textarea { resize: vertical; min-height: 60px; }
.growth-form .req { color: #e77; }
.growth-form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.growth-form .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.creds-fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; background: var(--bg-1); }
.creds-fieldset legend { padding: 0 8px; font-size: 12px; color: var(--fg-1); }
.creds-fieldset .toggle-inline { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
.creds-note { font-size: 11px; color: var(--fg-2); margin: 8px 0 0 0; font-style: italic; }
.growth-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.btn-launch {
  background: linear-gradient(135deg, #3a2f0e, #6a5520);
  color: #e7c86b; border: 1px solid #6a5520;
  padding: 10px 18px; border-radius: 6px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.btn-launch:hover { background: linear-gradient(135deg, #6a5520, #8a7030); color: #fff6d6; }
.btn-launch:disabled { opacity: 0.5; cursor: wait; }
#growth-status { font-size: 12px; color: var(--fg-1); }
.growth-result { padding: 16px 20px; border-top: 1px solid var(--border); }

/* Sub-pestañas del Modo Comercial */
.growth-subtabs { display: flex; gap: 4px; padding: 8px 20px; background: var(--bg-1); border-bottom: 1px solid var(--border); }
.growth-subtab { background: transparent; border: 1px solid transparent; color: var(--fg-1); padding: 8px 14px; border-radius: 5px; cursor: pointer; font-size: 12px; font-weight: 600; }
.growth-subtab:hover { background: var(--bg-2); color: var(--fg); }
.growth-subtab.active { background: var(--bg-0); border-color: var(--border); color: var(--accent); }
.growth-subpanel { padding: 16px 20px; }
.growth-subpanel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.growth-subpanel-header h3 { margin: 0; font-size: 15px; }
.growth-subpanel-header .leads-filters,
.growth-subpanel-header .analytics-filters { display: flex; gap: 8px; align-items: center; }
.growth-subpanel-header select { background: var(--bg-0); border: 1px solid var(--border); color: var(--fg); padding: 6px 8px; border-radius: 4px; font-size: 12px; }
.btn-mini { background: var(--bg-0); border: 1px solid var(--border); color: var(--fg); padding: 5px 10px; border-radius: 4px; font-size: 12px; cursor: pointer; }
.btn-mini:hover { background: var(--bg-2); }

/* Campañas list */
.growth-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.campaign-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.campaign-card header { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.campaign-card h4 { margin: 0; font-size: 15px; color: var(--fg); }
.campaign-tag { background: #3a2f0e; color: var(--accent); padding: 3px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.campaign-url { margin: 0; font-size: 11px; font-family: var(--mono); }
.campaign-url a { color: var(--accent); text-decoration: none; }
.campaign-url a:hover { text-decoration: underline; }
.campaign-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.campaign-stats div { display: flex; flex-direction: column; }
.campaign-stats strong { color: var(--accent); font-size: 18px; }
.campaign-stats span { color: var(--fg-2); font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.campaign-card footer { display: flex; justify-content: space-between; align-items: center; }
.campaign-card footer small { color: var(--fg-2); font-size: 11px; }

/* Leads table */
.leads-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.leads-table th, .leads-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.leads-table th { background: var(--bg-1); color: var(--fg-1); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.leads-table tbody tr:hover { background: var(--bg-1); }
.status-pill { display: inline-block; padding: 3px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.status-new { background: #1e2436; color: var(--fg-1); }
.status-contacted { background: #1f2f4f; color: #a0c0ff; }
.status-mql { background: #243f52; color: #86d1f0; }
.status-sql { background: #2d3f5f; color: #a0c0e0; }
.status-hot { background: #4a2f1e; color: #f0b468; }
.status-demo_agendada { background: #3a2f0e; color: var(--accent); }
.status-cliente { background: #1f4f2a; color: #bff0c4; }
.status-perdido { background: #4a1d1d; color: #f0b4b4; }

/* Analytics KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 20px; }
.kpi-card { background: var(--bg-1); border: 1px solid var(--border); border-radius: 8px; padding: 14px; text-align: center; }
.kpi-card.kpi-green { border-color: #2d7240; background: linear-gradient(135deg, #1f4f2a, #2d7240); }
.kpi-card.kpi-green .kpi-value { color: #bff0c4; }
.kpi-card.kpi-yellow { border-color: #6a5520; background: #3a2f0e; }
.kpi-card.kpi-yellow .kpi-value { color: var(--accent); }
.kpi-card.kpi-red { border-color: #7a2c2c; background: #4a1d1d; }
.kpi-card.kpi-red .kpi-value { color: #f0b4b4; }
.kpi-card.kpi-muted { opacity: 0.6; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--accent); }
.kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-2); margin-top: 4px; }
.analytics-breakdown { list-style: none; padding: 0; margin: 10px 0 20px; display: flex; flex-wrap: wrap; gap: 10px; }
.analytics-breakdown li { background: var(--bg-1); padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); font-size: 12px; }
.analytics-breakdown li strong { color: var(--accent); }
.growth-analytics h4 { margin: 20px 0 6px; font-size: 13px; color: var(--fg-1); }
.analytics-note { color: var(--fg-2); font-size: 11px; margin-top: 20px; font-style: italic; }
.voice-wake-toggle.voice-wake-on .voice-icon { animation: voice-pulse 2s ease-in-out infinite; }
.voice-state { color: var(--fg-2); font-size: 10px; }
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 200, 107, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(231, 200, 107, 0); }
}

.chat-scroll {
  flex: 1; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.msg { max-width: 82%; }
.msg-system { align-self: center; max-width: 100%; }
.msg-user { align-self: flex-end; }
.msg-agent { align-self: flex-start; }
.msg-meta {
  font-size: 10px; color: var(--fg-2); margin-bottom: 4px;
  letter-spacing: .02em;
}
.msg-body {
  background: var(--bg-1); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 10px;
  white-space: pre-wrap; word-wrap: break-word;
  line-height: 1.45;
}
.msg-user .msg-body {
  background: var(--bg-3); border-color: transparent;
}
.msg-system .msg-body {
  background: transparent; border: 1px dashed var(--border);
  color: var(--fg-1); text-align: center; font-size: 12px;
}
/* Filtrado por agente activo — cada chat (Cambita / OpenClaw) es independiente.
   data-active-agent="duo" muestra todo. Mensajes sin data-agent (system) siempre visibles. */
.chat-scroll[data-active-agent="cambita"] .msg[data-agent]:not([data-agent=""]):not([data-agent="cambita"]) { display: none; }
.chat-scroll[data-active-agent="openclaw"] .msg[data-agent]:not([data-agent=""]):not([data-agent="openclaw"]) { display: none; }
.chat-scroll[data-active-agent="duo"] .msg { display: block; }

.msg-agent.streaming .msg-body::after {
  content: "▌";
  color: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input {
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  padding: 10px 12px;
  display: flex; gap: 8px; align-items: flex-end;
}
#chat-text {
  flex: 1;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg-0); padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--ui); font-size: 14px;
  resize: none;
  min-height: 42px; max-height: 200px;
  outline: none; transition: border-color .15s;
}
#chat-text:focus { border-color: var(--accent); }
.chat-actions { display: flex; gap: 4px; }
.chat-actions button {
  width: 42px; height: 42px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg-0); border-radius: 8px; font-size: 18px;
}
.chat-actions button:hover:not(:disabled) { background: var(--bg-3); }
.chat-actions button:disabled { opacity: .4; cursor: not-allowed; }
#send-btn { background: var(--accent); color: var(--bg-0); border-color: var(--accent); }
#send-btn:hover { filter: brightness(1.1); }

/* TAREAS panel */
.tasks-header, .preview-header, .logs-header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.tasks-header h2, .preview-header h2, .logs-header h2 { margin: 0; font-size: 15px; flex: 1; }
.tasks-header select, .preview-header input, .logs-header button, .tasks-header button, .preview-header button {
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg-0); padding: 6px 10px; border-radius: 6px; font-size: 12px;
}
.tasks-detail {
  flex: 1; overflow-y: auto; padding: 16px;
}
.placeholder { color: var(--fg-2); text-align: center; padding: 30px; }

/* PREVIEW */
.preview-iframe {
  flex: 1; width: 100%;
  border: 0; background: #ffffff;
}
.preview-hint {
  background: var(--bg-1); border-top: 1px solid var(--border);
  margin: 0; padding: 10px 16px;
  font-size: 12px; color: var(--fg-1);
}
.preview-header input { flex: 1; font-family: var(--mono); font-size: 11px; }
.preview-actions {
  display: flex; gap: 8px;
  padding: 10px 16px;
  background: var(--bg-1); border-top: 1px solid var(--border);
}
.preview-actions button {
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border);
  transition: transform 0.08s ease, box-shadow 0.1s ease;
}
.preview-actions button:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.preview-actions .btn-approve { background: #1f4f2a; color: #bff0c4; border-color: #2d7240; }
.preview-actions .btn-approve:hover { background: #2d7240; color: #ffffff; }
.preview-actions .btn-iterate { background: #3a2f0e; color: #e7c86b; border-color: #6a5520; }
.preview-actions .btn-iterate:hover { background: #6a5520; color: #fff6d6; }
.preview-actions .btn-reject { background: #4a1d1d; color: #f0b4b4; border-color: #7a2c2c; }
.preview-actions .btn-reject:hover { background: #7a2c2c; color: #ffffff; }

/* CUENTAS */
.accounts-wrap { flex: 1; overflow-y: auto; padding: 16px; }
.account-form {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.grid-2 label, .account-form label.full { display: block; font-size: 11px; color: var(--fg-1); margin-bottom: 8px; }
.grid-2 label.full, .account-form label.full { grid-column: 1/-1; }
.account-form input, .account-form select, .account-form textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--fg-0); padding: 8px 10px; border-radius: 6px;
  font-family: inherit; font-size: 13px; margin-top: 4px;
  outline: none;
}
.account-form input:focus, .account-form select:focus, .account-form textarea:focus { border-color: var(--accent); }
.account-form textarea { resize: vertical; font-family: var(--mono); font-size: 12px; }
.account-actions { display: flex; gap: 8px; margin-top: 12px; }
.account-actions button { background: var(--accent); color: var(--bg-0); border: 0; padding: 8px 16px; border-radius: 6px; font-weight: 500; }
.account-actions #account-cancel { background: var(--bg-2); color: var(--fg-0); border: 1px solid var(--border); }
.account-security-note {
  background: rgba(231,176,107,.08); border: 1px solid rgba(231,176,107,.3);
  padding: 10px 12px; border-radius: 6px; font-size: 11px; color: var(--fg-1);
  margin-bottom: 14px;
}
.accounts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.account-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px;
}
.account-card-head { display: flex; gap: 10px; align-items: center; }
.account-platform { background: var(--bg-3); padding: 2px 8px; border-radius: 12px; font-size: 11px; }
.account-handle { font-family: var(--mono); color: var(--accent); }
.account-owner { color: var(--fg-2); font-size: 11px; }
.account-card pre { background: var(--bg-0); padding: 8px; border-radius: 4px; font-size: 11px; margin: 6px 0; white-space: pre-wrap; }
.account-card .account-btns { display: flex; gap: 6px; margin-top: 8px; }
.account-card .account-btns button {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--fg-0);
  padding: 4px 10px; border-radius: 4px; font-size: 11px;
}
#account-add-btn { background: var(--accent); color: var(--bg-0); border: 0; padding: 6px 12px; border-radius: 6px; font-weight: 500; font-size: 12px; }

/* LOGS */
.logs-stream {
  flex: 1; margin: 0; padding: 12px 16px;
  background: var(--bg-0); color: var(--fg-1);
  font-family: var(--mono); font-size: 11px;
  overflow-y: auto; white-space: pre-wrap;
}

/* ───── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0; z-index: 10; }
}

/* Loading state */
#app.loading .panel { opacity: .4; pointer-events: none; }

/* ─── Filtrado por agente activo (cada selector = su chat) ─────────────── */
/* Cambita activa → oculta msgs dirigidos/provenientes de openclaw */
#chat-scroll[data-active-agent="cambita"] .msg[data-agent="openclaw"] { display: none; }
/* OpenClaw activa → oculta cambita */
#chat-scroll[data-active-agent="openclaw"] .msg[data-agent="cambita"] { display: none; }
/* Duo activo → muestra todo (incluyendo msgs de ambos agentes para comparar) */
#chat-scroll[data-active-agent="duo"] .msg { display: flex; }
/* Sistema siempre visible en cualquier agente (data-agent="" por addSystemMsg) */
#chat-scroll .msg-system { display: flex !important; }

/* Badge de no-leídos sobre el botón de agente */
.agent-badge {
  position: absolute; top: 6px; right: 8px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 10px; background: #ff5577; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px rgba(10,14,26,0.9);
}
.agent-btn { position: relative; }

/* ─── Proyectos + Sesiones (sidebar izquierdo) ───────────────────────── */
.projects { padding: 0 12px; margin-top: 8px; }
.projects h3 { display: flex; align-items: center; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8a93aa; margin: 12px 0 6px; }
.icon-btn { background: transparent; border: 1px solid #2a3446; color: #e7c86b; width: 20px; height: 20px; border-radius: 4px; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }
.icon-btn:hover { background: #1a2235; border-color: #e7c86b; }
.projects-tree { list-style: none; padding: 0; margin: 0; }
.project-root { margin-bottom: 4px; }
.project-row { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 13px; color: #cfd6e6; transition: background .12s; }
.project-row:hover { background: #141b2d; }
.project-row.active { background: rgba(231,200,107,0.12); color: #e7c86b; }
.project-caret { font-size: 10px; width: 10px; opacity: .6; }
.project-root.collapsed .project-caret { transform: rotate(-90deg); display: inline-block; }
.project-root.collapsed .sessions-list { display: none; }
.project-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.project-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-count { font-size: 10px; color: #6c7490; background: #0f1524; padding: 1px 5px; border-radius: 8px; }
.project-delete { background: transparent; border: 0; color: #6c7490; font-size: 16px; cursor: pointer; padding: 0 2px; }
.project-delete:hover { color: #ff5577; }
.sessions-list { list-style: none; padding: 0 0 0 18px; margin: 2px 0 0; }
.session-item { display: flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 4px; cursor: pointer; font-size: 12px; color: #a8b1c7; }
.session-item:hover { background: #0e1525; color: #e0e6f2; }
.session-item.active { background: rgba(127,183,255,0.14); color: #e0e6f2; }
.session-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { font-size: 9px; color: #6c7490; }
.session-rename { background: transparent; border: 0; color: #6c7490; cursor: pointer; font-size: 11px; padding: 0 2px; opacity: 0; transition: opacity .15s; }
.session-item:hover .session-rename { opacity: 1; }
.session-rename:hover { color: #e7c86b; }
.placeholder-sm { font-size: 11px; color: #6c7490; padding: 4px 10px; font-style: italic; }

/* ─── Modal nuevo proyecto ──────────────────────────────────────────── */
.dialog { background: #0f1524; color: #e0e6f2; border: 1px solid #2a3446; border-radius: 8px; padding: 20px; min-width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog h3 { margin: 0 0 14px; color: #e7c86b; }
.dialog label { display: block; margin-bottom: 10px; font-size: 12px; color: #a8b1c7; }
.dialog input, .dialog textarea { width: 100%; margin-top: 4px; background: #0a0e1a; color: #e0e6f2; border: 1px solid #2a3446; border-radius: 4px; padding: 6px 8px; font-size: 13px; }
.dialog input[type="color"] { height: 32px; padding: 2px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.dialog-actions button { background: #1a2235; color: #e0e6f2; border: 1px solid #2a3446; padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.dialog-actions button[type="submit"] { background: #e7c86b; color: #0a0e1a; border-color: #e7c86b; font-weight: 600; }

/* ─── Attachments preview en composer ───────────────────────────────── */
.attachments-preview { background: #0e1525; border: 1px dashed #2a3446; border-radius: 6px; padding: 8px 10px; margin: 0 12px 4px; font-size: 11px; }
.attachments-label { color: #e7c86b; }
.attachments-pending { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chip { background: #1a2235; border: 1px solid #2a3446; border-radius: 12px; padding: 3px 10px; display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: #cfd6e6; }
.attach-chip button { background: transparent; border: 0; color: #ff8899; cursor: pointer; font-size: 14px; padding: 0; }

/* ─── Panel Memoria ─────────────────────────────────────────────────── */
.memory-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid #1e2740; }
.memory-filters { display: flex; gap: 8px; align-items: center; }
.memory-filters select, .memory-filters button { background: #0f1524; color: #e0e6f2; border: 1px solid #2a3446; padding: 5px 10px; border-radius: 4px; font-size: 12px; cursor: pointer; }
.memory-filters button:hover { border-color: #e7c86b; }
.memory-form { margin: 16px 20px; padding: 16px; background: #0e1525; border: 1px solid #2a3446; border-radius: 8px; }
.memory-form label { display: block; margin-bottom: 10px; font-size: 12px; color: #a8b1c7; }
.memory-form label.full { grid-column: 1 / -1; }
.memory-form input, .memory-form select, .memory-form textarea { width: 100%; background: #0a0e1a; color: #e0e6f2; border: 1px solid #2a3446; border-radius: 4px; padding: 6px 8px; font-size: 13px; margin-top: 4px; }
.memory-actions { display: flex; gap: 8px; margin-top: 10px; }
.memory-actions button[type="submit"] { background: #e7c86b; color: #0a0e1a; border: 0; padding: 6px 14px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.memory-actions button[type="button"] { background: transparent; color: #a8b1c7; border: 1px solid #2a3446; padding: 6px 14px; border-radius: 4px; cursor: pointer; }
.memory-list { list-style: none; padding: 0; margin: 16px 20px; }
.memory-card { background: #0e1525; border: 1px solid #2a3446; border-radius: 6px; padding: 10px 14px; margin-bottom: 10px; }
.memory-card header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.memory-type { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 2px 7px; border-radius: 3px; font-weight: 600; }
.memory-type.type-feedback { background: #3d2c00; color: #e7c86b; }
.memory-type.type-user { background: #1a3a5c; color: #7fb7ff; }
.memory-type.type-project { background: #1e3d1e; color: #8fd98f; }
.memory-type.type-reference { background: #3a1a3a; color: #d98fd9; }
.memory-type.type-rule { background: #5c1a1a; color: #ff8fa8; }
.memory-scope { font-size: 10px; color: #6c7490; }
.memory-name { color: #e7c86b; flex: 1; font-size: 13px; }
.memory-card time { font-size: 10px; color: #6c7490; }
.memory-content { background: #0a0e1a; padding: 8px 10px; border-radius: 4px; font-size: 12px; color: #cfd6e6; white-space: pre-wrap; word-break: break-word; margin: 4px 0; max-height: 220px; overflow: auto; }
.memory-btns { display: flex; gap: 6px; margin-top: 6px; }
.memory-btns button { background: #1a2235; color: #a8b1c7; border: 1px solid #2a3446; padding: 3px 10px; border-radius: 3px; cursor: pointer; font-size: 11px; }
.memory-btns button:hover { border-color: #e7c86b; color: #e7c86b; }
.memory-hint { padding: 10px 20px; font-size: 11px; color: #6c7490; border-top: 1px solid #1e2740; }
.memory-hint code { background: #0a0e1a; padding: 1px 6px; border-radius: 3px; color: #e7c86b; }

/* ─── Login screen ──────────────────────────────────────────────────── */
.login-screen { position: fixed; inset: 0; background: radial-gradient(ellipse at top, #1a2442 0%, #0a0e1a 70%); display: flex; align-items: center; justify-content: center; z-index: 100; }
.login-card { background: #0f1524; border: 1px solid #2a3446; border-radius: 10px; padding: 36px 40px; width: 360px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { font-size: 52px; color: #e7c86b; font-family: monospace; display: block; line-height: 1; }
.login-brand h1 { margin: 10px 0 4px; color: #e0e6f2; font-size: 22px; font-weight: 600; }
.login-brand p { margin: 0; color: #8a93aa; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.login-card label { display: block; margin-bottom: 14px; color: #a8b1c7; font-size: 12px; }
.login-card input { width: 100%; background: #0a0e1a; color: #e0e6f2; border: 1px solid #2a3446; border-radius: 5px; padding: 10px 12px; font-size: 14px; margin-top: 5px; box-sizing: border-box; }
.login-card input:focus { outline: none; border-color: #e7c86b; }
.login-card button[type="submit"] { width: 100%; background: #e7c86b; color: #0a0e1a; border: 0; padding: 11px; border-radius: 5px; cursor: pointer; font-weight: 600; font-size: 14px; letter-spacing: .04em; margin-top: 6px; }
.login-card button[type="submit"]:hover { background: #f0d47b; }
.login-card button[type="submit"]:disabled { opacity: 0.6; cursor: wait; }
.login-error { color: #ff8fa8; background: rgba(255,87,119,0.08); border: 1px solid rgba(255,87,119,0.25); padding: 8px 10px; border-radius: 4px; font-size: 12px; margin-top: 12px; }
.login-note { color: #6c7490; font-size: 11px; text-align: center; margin-top: 22px; padding-top: 18px; border-top: 1px solid #1e2740; }

/* ─── User strip en sidebar-foot ────────────────────────────────────── */
.user-strip { padding: 8px 12px; background: #0e1525; border-top: 1px solid #1e2740; border-bottom: 1px solid #1e2740; display: flex; flex-direction: column; gap: 2px; }
.user-name { color: #e0e6f2; font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: #e7c86b; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-actions { display: flex; gap: 5px; padding: 10px 12px; }
.sidebar-actions button { background: #1a2235; color: #cfd6e6; border: 1px solid #2a3446; padding: 6px 8px; border-radius: 4px; cursor: pointer; font-size: 11px; flex: 1; }
.sidebar-actions button:hover { border-color: #e7c86b; color: #e7c86b; }
.sidebar-actions #logout-btn { flex: 0 0 auto; color: #ff8fa8; }
.sidebar-actions #logout-btn:hover { border-color: #ff8fa8; color: #ff5577; }

/* ─── Profile dialog ────────────────────────────────────────────────── */
.profile-info { background: #0a0e1a; padding: 10px 12px; border-radius: 4px; margin-bottom: 10px; }
.profile-info strong { color: #e7c86b; }
.profile-info small { color: #8a93aa; display: block; margin-top: 3px; }
.profile-error { color: #ff8fa8; background: rgba(255,87,119,0.08); padding: 6px 10px; border-radius: 4px; font-size: 11px; margin: 8px 0 0; }

/* ─── Markdown rendering dentro de mensajes del agente ──────────────── */
.msg-agent .msg-body { line-height: 1.55; }
.msg-agent .msg-body p { margin: 0 0 10px; }
.msg-agent .msg-body p:last-child { margin-bottom: 0; }
.msg-agent .msg-body h1, .msg-agent .msg-body h2, .msg-agent .msg-body h3 { margin: 14px 0 6px; color: #e7c86b; font-weight: 600; }
.msg-agent .msg-body h1 { font-size: 16px; }
.msg-agent .msg-body h2 { font-size: 14px; }
.msg-agent .msg-body h3 { font-size: 13px; }
.msg-agent .msg-body ul, .msg-agent .msg-body ol { margin: 6px 0 10px; padding-left: 22px; }
.msg-agent .msg-body li { margin: 3px 0; }
.msg-agent .msg-body code { background: #0a0e1a; padding: 2px 6px; border-radius: 3px; font-family: ui-monospace, monospace; font-size: .92em; color: #e7c86b; }
.msg-agent .msg-body pre { background: #0a0e1a; padding: 12px 14px; border-radius: 6px; overflow-x: auto; border: 1px solid #2a3446; margin: 10px 0; }
.msg-agent .msg-body pre code { background: transparent; padding: 0; color: #cfd6e6; font-size: 12px; display: block; }
.msg-agent .msg-body strong { color: #e0e6f2; font-weight: 600; }
.msg-agent .msg-body em { color: #cfd6e6; }
.msg-agent .msg-body a { color: #7fb7ff; text-decoration: none; border-bottom: 1px dashed #4a6a9a; }
.msg-agent .msg-body a:hover { color: #a8d0ff; border-bottom-color: #7fb7ff; }
.msg-agent .msg-body blockquote { border-left: 3px solid #e7c86b; padding: 2px 12px; margin: 10px 0; color: #a8b1c7; font-style: italic; }
.msg-agent .msg-body table { border-collapse: collapse; margin: 10px 0; font-size: 12px; }
.msg-agent .msg-body th, .msg-agent .msg-body td { border: 1px solid #2a3446; padding: 6px 10px; text-align: left; }
.msg-agent .msg-body th { background: #1a2235; color: #e7c86b; }
.msg-agent .msg-body hr { border: 0; border-top: 1px solid #2a3446; margin: 14px 0; }
