:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e6e8ec;
  --brand: #0f766e; --brand-hover: #115e59; --brand-soft: #e6f4f1;
  --side: #0f172a; --side-2: #1e293b; --side-ink: #cbd5e1; --side-muted: #64748b;
  --ok: #059669; --ok-soft: #ecfdf5; --warn: #b45309; --warn-soft: #fef3c7; --danger: #dc2626;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-lg: 0 4px 12px rgba(15, 23, 42, .08);
  --focus: 0 0 0 3px rgba(15, 118, 110, .25);
}
* { box-sizing: border-box; }
body { margin: 0; display: grid; grid-template-columns: 236px 1fr; min-height: 100vh;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius-sm); padding: 7px 14px; font-weight: 500; transition: background .15s, border-color .15s, box-shadow .15s; }
button:hover:not(:disabled) { border-color: #cbd2da; background: #fafbfc; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow); }
button.primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: none; box-shadow: var(--focus); }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.005em; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.grow { flex: 1; min-width: 0; }
* { scrollbar-width: thin; scrollbar-color: #cbd2da transparent; }

/* sidebar */
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--side); color: var(--side-ink);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 14px; }
.logo { width: 30px; height: 30px; }
.wordmark { font-weight: 700; font-size: 18px; color: #fff; letter-spacing: -.03em; }
.workspace { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; margin-bottom: 14px;
  background: var(--side-2); border: 1px solid #263449; color: var(--side-ink); padding: 8px; }
.workspace:hover:not(:disabled) { background: #243247; border-color: #334155; }
.ws-avatar { width: 32px; height: 32px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #22c55e, #15803d); }
.ws-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ws-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-plan { font-size: 11px; color: var(--side-muted); }
.workspace .icon { width: 14px; height: 14px; color: var(--side-muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); text-decoration: none;
  padding: 8px 10px; border-radius: var(--radius-sm); font-weight: 500; position: relative; transition: background .15s, color .15s; }
.sidebar nav a .icon { color: var(--side-muted); transition: color .15s; }
.sidebar nav a:hover { background: var(--side-2); color: #fff; }
.sidebar nav a.active { background: rgba(20, 184, 166, .14); color: #fff; }
.sidebar nav a.active .icon, .sidebar nav a:hover .icon { color: #5eead4; }
.sidebar nav a.active::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #14b8a6; }
.nav-count { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #14b8a6; color: #042f2e; }
.nav-count:empty { display: none; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--side-muted); padding: 0 6px; }

/* projects: --c = project color, --dot overrides the dot (Todos) */
body { --project: var(--brand); --project-soft: color-mix(in srgb, var(--project) 10%, #fff); }
.nav-label { margin: 18px 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); }
.projects { display: flex; flex-direction: column; gap: 2px; }
.project { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none;
  color: var(--side-ink); padding: 7px 10px; font-weight: 500; font-size: 13px; }
.project:hover:not(:disabled) { background: var(--side-2); border: 0; color: #fff; }
.project.active, .project.active:hover:not(:disabled) { background: color-mix(in srgb, var(--c) 30%, var(--side)); color: #fff; box-shadow: inset 3px 0 0 var(--c); }
.pdot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--dot, var(--c)); }
.project .nav-count { background: var(--side-2); color: var(--side-ink); }
.project.active .nav-count { background: var(--c); color: #fff; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.project-pill, .ptag { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; font-weight: 600; white-space: nowrap;
  color: color-mix(in srgb, var(--c) 70%, #000); background: color-mix(in srgb, var(--c) 12%, #fff); }
.project-pill { font-size: 12px; padding: 3px 10px; border: 1px solid color-mix(in srgb, var(--c) 35%, #fff); }
.ptag { font-size: 10px; padding: 1px 7px; flex: none; }
.project-pill::before, .ptag::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--c)); }

/* topbar */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar { border-top: 4px solid var(--project); height: 68px; display: flex; align-items: center; gap: 14px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.search { display: flex; align-items: center; gap: 8px; width: 260px; padding: 0 10px; height: 36px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--muted); }
.search:focus-within { box-shadow: var(--focus); border-color: var(--brand); background: var(--panel); }
.search .icon { width: 16px; height: 16px; }
.search input { border: 0; background: none; font: inherit; color: var(--ink); width: 100%; outline: none; }
.icon-btn { position: relative; padding: 8px; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn .dot { position: absolute; top: 6px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--panel); }
.user { display: flex; align-items: center; gap: 10px; padding-left: 14px; border-left: 1px solid var(--line); }
.user .avatar { background: linear-gradient(135deg, #14b8a6, #0f766e); color: #fff; }
.user-text { display: flex; flex-direction: column; line-height: 1.2; font-size: 13px; }
.user-text span { color: var(--muted); font-size: 11px; }

main { padding: 24px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.muted { color: var(--muted); font-size: 12px; }
.chip { display: inline-block; font-size: 10px; font-weight: 700; color: #fff; padding: 2px 6px; border-radius: 6px; letter-spacing: .02em; vertical-align: 1px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.badge.humano { background: var(--warn-soft); color: var(--warn); }
.status-open, .status-closed { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.status-open { color: var(--ok); }
.status-closed { color: var(--danger); }
.status-open::before, .status-closed::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.avatar { position: relative; width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; background: #e2e8f0; color: var(--ink-2); }
.avatar-ch { position: absolute; right: -2px; bottom: -2px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--panel); }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 270px; gap: 16px; height: calc(100vh - 68px - 48px); }
.conv-list { overflow: auto; padding: 6px; }
.conv { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; border-radius: var(--radius-sm); padding: 10px; background: none; font-weight: 400; }
.conv + .conv { margin-top: 2px; }
.conv:hover:not(:disabled) { background: #f1f5f9; border: 0; }
.conv.active, .conv.active:hover { background: var(--project-soft); }
.conv.active .avatar-ch { border-color: var(--project-soft); }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; gap: 6px; align-items: center; }
.conv-name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 4px; }
.conv-mid { display: flex; align-items: center; gap: 6px; margin: 2px 0 4px; }
.conv-mid .conv-preview { flex: 1; min-width: 0; margin: 0; }
.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-head { display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 14px; flex-wrap: wrap; }
.messages { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 16px 4px; }
.msg { max-width: 75%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; }
.msg.cliente { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.bot { background: var(--brand-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.asesor { background: var(--warn-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-meta { font-size: 10px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.msg.bot .msg-meta::before { content: ''; width: 12px; height: 12px; background: var(--brand);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 8V4H8'/%3E%3Crect width='16' height='12' x='4' y='8' rx='2'/%3E%3Cpath d='M2 14h2M20 14h2M15 13v2M9 13v2'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 8V4H8'/%3E%3Crect width='16' height='12' x='4' y='8' rx='2'/%3E%3Cpath d='M2 14h2M20 14h2M15 13v2M9 13v2'/%3E%3C/svg%3E") center / contain no-repeat; }
.composer { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding-top: 14px; }
.composer input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; }
.composer input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.notice { font-size: 12px; color: var(--warn); padding: 10px 12px; background: #fffbeb; border-radius: var(--radius-sm); }
.composer .notice { padding: 8px 12px; }
div.notice { margin-top: 14px; }
dl.fields { margin: 0; }
dl.fields dt { font-size: 12px; color: var(--muted); }
dl.fields dd { margin: 2px 0 14px; font-weight: 600; }
dl.fields dd:last-child { margin-bottom: 0; }

/* leads */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 4px; }
.column { background: #eef1f4; border-radius: var(--radius); padding: 10px; min-height: 300px; transition: background .15s; }
.column.over { outline: 2px dashed var(--brand); background: var(--brand-soft); }
.column-head { display: flex; justify-content: space-between; font-weight: 600; margin: 2px 4px 2px; }
.column-head .muted { background: var(--panel); padding: 0 8px; border-radius: 999px; font-weight: 600; }
.column-total { font-size: 12px; color: var(--muted); margin: 0 4px 10px; font-variant-numeric: tabular-nums; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: grab;
  box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.card-name { font-weight: 600; }
.card > .ptag { margin-bottom: 6px; }
.card-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.score { font-weight: 700; font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.score.high { background: var(--ok-soft); color: var(--ok); }
.score.mid { background: var(--warn-soft); color: var(--warn); }
.score.low { background: #f1f5f9; color: var(--muted); }

/* analytics */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.delta { font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.meter { height: 6px; border-radius: 3px; background: #eef1f4; overflow: hidden; margin: 6px 0; }
.meter div { height: 100%; border-radius: 3px; background: var(--project); }
/* chart bars: one solid color per view (--project = brand teal in Todos) */
.fill { background: var(--project); border-radius: 4px; }
.bar-row > .fill { height: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.bar-row { display: grid; grid-template-columns: 200px 1fr 50px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.bar-row .muted { text-align: right; font-variant-numeric: tabular-nums; }
.vbars { display: flex; align-items: flex-end; gap: 10px; height: 170px; }
.vbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 11px; color: var(--muted); gap: 4px; }
.vbar .fill { width: 100%; border-radius: 4px 4px 2px 2px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
tr:last-child th, tr:last-child td { border-bottom: 0; color: var(--ink); font-size: 13px; text-transform: none; letter-spacing: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ajustes */
.channels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.channel-card { display: flex; flex-direction: column; gap: 8px; }
.channel-card > div:last-child { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.connected { color: var(--ok); font-weight: 600; font-size: 12px; }
pre.snippet { background: var(--side); color: #99f6e4; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 11px; white-space: pre-wrap; word-break: break-all; margin: 0; }
.stack { display: grid; gap: 16px; }
ul.plain { margin: 0; padding-left: 18px; }
label.toggle { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
label.toggle input { accent-color: var(--brand); width: 16px; height: 16px; }

@media (max-width: 1100px) {
  body { grid-template-columns: 1fr; align-content: start; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .brand { padding: 0 6px; }
  .workspace { width: auto; margin: 0; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a.active::before { display: none; }
  .nav-label { display: none; }
  .projects { flex-direction: row; flex-wrap: wrap; }
  .project { width: auto; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  .search { order: 5; width: 100%; }
  main { padding: 16px; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 360px; }
  .thread { min-height: 480px; }
  .kpis, .channels { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .user-text { display: none; }
  .bar-row { grid-template-columns: 1fr auto; row-gap: 4px; }
  .bar-row > .fill { grid-column: 1 / -1; grid-row: 2; }
  .kpis, .channels { grid-template-columns: 1fr; }
}
