/* ─── Variables ─────────────────────────────────────────────────── */
:root {
  --bg-app:      #111b21;
  --bg-panel:    #202c33;
  --bg-header:   #1f2c34;
  --bg-input:    #2a3942;
  --border:      #2a3942;
  --text-1:      #e9edef;
  --text-2:      #8696a0;
  --bubble-bot:  #005c4b;
  --bubble-lead: #202c33;
  --accent:      #00a884;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg-app); color: var(--text-1); height: 100dvh; overflow: hidden; }
button { cursor: pointer; border: none; font-family: inherit; font-size: inherit; }
input  { font-family: inherit; font-size: inherit; }
p, span, div { line-height: 1.4; }

/* ─── Scrollbar oscura ───────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374045; border-radius: 3px; }

/* ─── Layout principal ───────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#app-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
}

#metrics-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex-wrap: wrap;
}
#metrics-bar strong { color: var(--text-1); }
.m-sep { color: var(--border); }

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Panel izquierdo ────────────────────────────────────────────── */
#left-panel {
  width: 30%;
  min-width: 260px;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
}

#left-header {
  padding: 10px 12px 6px;
  flex-shrink: 0;
}

#search-input {
  width: 100%;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-1);
  outline: none;
  margin-bottom: 8px;
}
#search-input::placeholder { color: var(--text-2); }

#filter-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-btn {
  background: transparent;
  color: var(--text-2);
  border-radius: 16px;
  padding: 3px 10px;
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
}
.filter-btn:hover  { background: var(--bg-input); color: var(--text-1); }
.filter-btn.active { background: var(--accent); color: #fff; }

#leads-list {
  flex: 1;
  overflow-y: auto;
}

/* ─── Lead item ──────────────────────────────────────────────────── */
.lead-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.lead-item:hover     { background: #263238; }
.lead-item.item-active { background: #1d282f; border-left: 3px solid var(--accent); }

.item-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.item-phone { font-size: 13px; font-weight: 600; color: var(--text-1); }
.item-time  { font-size: 11px; color: var(--text-2); }

.item-row-bot {
  display: flex;
  align-items: center;
  gap: 6px;
}

.item-vehicle {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.res-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #111b21;
}

.icon-handoff { font-size: 12px; color: #66bb6a; font-weight: 700; }
.icon-manual  { font-size: 12px; color: #ffa726; }

/* ─── Panel derecho ──────────────────────────────────────────────── */
#right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  overflow: hidden;
}

/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 14px;
}

/* Chat view */
#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Chat header ────────────────────────────────────────────────── */
#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 54px;
  flex-wrap: wrap;
  gap: 8px;
}

.lh-info   { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lh-phone  { font-size: 15px; font-weight: 600; }
.lh-vehicle { font-size: 12px; color: var(--text-2); }
.lh-b2b    { font-size: 11px; background: #7e57c2; color: #fff; padding: 2px 7px; border-radius: 10px; }

.lh-badges { display: flex; align-items: center; gap: 6px; }

.module-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}
.badge-manual  { font-size: 11px; background: #ffa726; color: #111b21; padding: 3px 8px; border-radius: 10px; font-weight: 700; }
.badge-handoff { font-size: 11px; background: #66bb6a; color: #111b21; padding: 3px 8px; border-radius: 10px; font-weight: 700; }

/* ─── Tab bar ────────────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 9px 0;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover  { color: var(--text-1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Chat area (burbujas) ───────────────────────────────────────── */
#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bubble {
  max-width: 72%;
  padding: 8px 12px;
  border-radius: 8px;
  word-break: break-word;
}
.bubble-lead {
  align-self: flex-start;
  background: var(--bubble-lead);
  border-radius: 0 8px 8px 8px;
}
.bubble-bot {
  align-self: flex-end;
  background: var(--bubble-bot);
  border-radius: 8px 0 8px 8px;
}
.bubble-body { color: var(--text-1); font-size: 14px; }
.bubble-time { display: block; font-size: 11px; color: var(--text-2); margin-top: 3px; text-align: right; }

/* ─── Panel de estado ────────────────────────────────────────────── */
#state-panel {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.state-section {
  background: var(--bg-panel);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.prog-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.prog-step {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 8px;
  background: #2a3942;
  color: var(--text-2);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}
.prog-active {
  background: var(--mc, #9e9e9e);
  color: #fff;
}
.prog-past {
  background: var(--mc, #9e9e9e);
  opacity: 0.4;
  color: #fff;
}
.prog-arrow { font-size: 12px; color: var(--text-2); }

.state-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  gap: 8px;
}
.state-label { font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.state-value { font-size: 12px; color: var(--text-1); text-align: right; word-break: break-word; }

.res-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: #111b21;
}

.bool-val       { font-size: 14px; font-weight: 700; }
.bool-yes       { color: #66bb6a; }
.bool-no        { color: #ef5350; }

.guard-reason   { font-size: 11px; word-break: break-word; }

/* Flags de OutputGuard */
.flags-wrap     { display: flex; flex-wrap: wrap; gap: 6px; }
.flag           { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.flag-red       { background: #ef5350; color: #fff; }
.flag-orange    { background: #ffa726; color: #111b21; }
.flag-yellow    { background: #ffee58; color: #111b21; }

/* ─── Barra de intervención ──────────────────────────────────────── */
#intervention-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  color: var(--text-1);
  outline: none;
}
#msg-input::placeholder { color: var(--text-2); }

#btn-send {
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s;
}
#btn-send:hover    { background: #00c896; }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

#btn-pause {
  background: #ffa726;
  color: #111b21;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}
#btn-pause:hover { background: #ffb74d; }

#btn-resume {
  background: #66bb6a;
  color: #111b21;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}
#btn-resume:hover { background: #81c784; }

/* ─── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #323739;
  color: var(--text-1);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
.toast-show  { opacity: 1 !important; transform: translateX(-50%) translateY(0) !important; }
.toast-error { background: #c62828; }

/* ─── Utilidades ─────────────────────────────────────────────────── */
.hidden    { display: none !important; }
.empty-msg { color: var(--text-2); font-size: 13px; padding: 20px; text-align: center; }
