:root {
  --bg: #eef3f1;
  --surface: #ffffff;
  --surface-sidebar: #f7faf8;
  --ink: #122824;
  --ink-muted: #5c766f;
  --border: #d6e1dc;
  --accent: #075e54;
  --accent-strong: #054c44;
  --wa-bg: #e5ddd5;
  --wa-out: #dcf8c6;
  --wa-in: #ffffff;
  --wa-check: #4fc3f7;
  --danger: #b3492f;
  --success: #1f8f5f;
  --warn: #c97a1f;
  --shadow: 0 20px 45px -25px rgba(10, 30, 25, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

header.top .brand { display: flex; align-items: center; gap: 10px; }
header.top .mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex: none;
}
header.top h1 { font-size: 19px; margin: 0; font-weight: 650; }
header.top p { margin: 1px 0 0; font-size: 13px; color: var(--ink-muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 22px;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---- Telefono WhatsApp ---- */
.phone {
  background: var(--wa-bg);
  border-radius: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: min(700px, 78vh);
}

.wa-header {
  background: var(--accent);
  color: #fff;
  padding: 12px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.wa-back { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 0 2px; }
.wa-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.18);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex: none;
}
.wa-who { flex: 1; min-width: 0; }
.wa-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.wa-status { font-size: 12px; opacity: 0.85; }
.wa-header-icons { display: flex; gap: 16px; font-size: 16px; opacity: 0.9; }

.wa-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(0,0,0,0.02) 2px, transparent 2px),
    radial-gradient(circle at 65% 65%, rgba(0,0,0,0.02) 2px, transparent 2px),
    radial-gradient(circle at 85% 15%, rgba(0,0,0,0.02) 2px, transparent 2px);
  background-size: 90px 90px, 130px 130px, 110px 110px;
}

.row { display: flex; flex-direction: column; max-width: 82%; margin-bottom: 8px; }
.row.in { align-self: flex-start; align-items: flex-start; }
.row.out { align-self: flex-end; align-items: flex-end; }
.row.system { align-self: center; max-width: 90%; align-items: center; margin: 6px 0; }

.bubble {
  padding: 7px 10px 8px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-line;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  position: relative;
}
.row.in .bubble { background: var(--wa-in); border-top-left-radius: 0; }
.row.out .bubble { background: var(--wa-out); border-top-right-radius: 0; }
.row.system .bubble {
  background: rgba(225, 245, 254, 0.9);
  color: #5b6a72;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 8px;
  box-shadow: none;
}

.meta {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: #8a8f8a;
  margin: 2px 3px 0;
}
.meta .check { color: var(--wa-check); font-weight: 700; }
.provider-tag {
  font-size: 10px;
  color: var(--ink-muted);
  margin: 1px 3px 4px;
}
/* Mensajes de una persona del equipo de soporte (Slack), no del agente. */
.row.soporte .bubble { border-left: 3px solid var(--success); }
.row.soporte .provider-tag { color: var(--success); font-weight: 600; }

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 9px 12px;
  background: var(--wa-in);
  border-radius: 8px;
  border-top-left-radius: 0;
  margin-bottom: 8px;
  width: fit-content;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9aa39a; opacity: 0.6;
  animation: bounce 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: 0.8; }
}

.wa-quickbar {
  display: flex;
  justify-content: center;
  padding: 6px 10px 0;
  background: #f0f0f0;
  flex: none;
}
.quick-chip {
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
}
.quick-chip:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 10%, #fff); }
.quick-chip:active:not(:disabled) { background: var(--accent); color: #fff; }
.quick-chip:disabled { opacity: 0.5; cursor: default; }

.wa-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 10px;
  background: #f0f0f0;
  flex: none;
}
.wa-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 22px;
  padding: 8px 12px;
}
.wa-input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
}
.wa-icon { font-size: 18px; opacity: 0.55; flex: none; }
.wa-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex: none;
}
.wa-send:hover { background: var(--accent-strong); }
.wa-send:disabled { opacity: 0.5; cursor: default; }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface-sidebar);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar h2 {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted); margin: 0 0 4px; font-weight: 650;
}
.sidebar > div > p.lead { margin: 0; font-size: 13px; color: var(--ink-muted); line-height: 1.5; }

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.status-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.status-row.small { font-size: 11.5px; color: var(--ink-muted); }
.pill {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 3px 10px; font-size: 11.5px; font-weight: 650;
  background: #eef3f1; color: var(--ink-muted);
}
.pill.anthropic { background: color-mix(in srgb, #075e54 18%, transparent); color: #075e54; }
.pill.mantle { background: color-mix(in srgb, #c97a1f 18%, transparent); color: #c97a1f; }
.pill.ollama { background: color-mix(in srgb, #b3492f 18%, transparent); color: #b3492f; }
.pill.ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.panel-sections { display: flex; flex-direction: column; gap: 16px; }
.panel-section { border-top: 1px solid var(--border); padding-top: 10px; }
.panel-section + .panel-section { margin-top: -6px; }
.panel-section > summary {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; list-style: none; user-select: none;
}
.panel-section > summary::-webkit-details-marker { display: none; }
.panel-section > summary::before {
  content: "▸"; color: var(--ink-muted); font-size: 12px;
  transition: transform 0.15s ease; flex: none;
}
.panel-section[open] > summary::before { transform: rotate(90deg); }
.panel-section > summary h2 { margin: 0; flex: 1; }
.panel-section > summary .count {
  font-size: 11px; color: var(--ink-muted); background: #eef3f1;
  border-radius: 999px; padding: 1px 8px; flex: none;
}
.panel-section > summary:hover h2 { color: var(--accent); }
.panel-section > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.panel-section[open] > summary { margin-bottom: 8px; }
.panel-sections p.lead { margin: 0 0 6px; font-size: 13px; color: var(--ink-muted); line-height: 1.5; }
.panel-sections .card-group + p.lead { margin-top: 10px; }
.panel-sections .endpoint {
  margin: 0 0 6px; font-size: 11.5px; color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.card-group { display: flex; flex-direction: column; gap: 8px; max-height: 480px; overflow-y: auto; }
.datacard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.datacard .title { font-size: 13px; font-weight: 650; }
.datacard .subtitle { font-size: 11.5px; color: var(--ink-muted); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.field-row .val { color: var(--ink-muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.use-btn {
  border: 1px solid var(--border); background: var(--surface-sidebar);
  color: var(--accent); border-radius: 7px; padding: 3px 9px;
  font-size: 11.5px; cursor: pointer; flex: none;
}
.use-btn:hover { background: color-mix(in srgb, var(--accent) 12%, var(--surface-sidebar)); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.full-reset {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; cursor: pointer; text-align: left;
}
.full-reset:hover { border-color: var(--accent); }
.fine { font-size: 11.5px; color: var(--ink-muted); line-height: 1.5; }

.wa-thread::-webkit-scrollbar, .card-group::-webkit-scrollbar { width: 8px; }
.wa-thread::-webkit-scrollbar-thumb, .card-group::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 8px; }
