/* ============ Dchati — embedded CRM demo ============
   Reuses the design tokens from styles.css (same document). */

#crm { position: relative; z-index: 1; }

.crm-window {
  max-width: 1080px;
  margin: 0 auto;
  background: oklch(0.165 0.025 250);
  border: 1px solid var(--line-quiet);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 40px 100px oklch(0.04 0.02 250 / 0.6),
              0 0 0 1px oklch(0.8 0.1 var(--accent-h) / 0.04);
}

/* ---------- Title bar ---------- */

.crm-titlebar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: oklch(0.19 0.028 250);
  border-bottom: 1px solid var(--line-quiet);
}

.crm-lights { display: flex; gap: 8px; }
.crm-lights span {
  width: 12px; height: 12px; border-radius: 50%;
  background: oklch(0.4 0.02 250);
}
.crm-lights span:nth-child(1) { background: oklch(0.65 0.16 25); }
.crm-lights span:nth-child(2) { background: oklch(0.78 0.14 85); }
.crm-lights span:nth-child(3) { background: oklch(0.72 0.15 150); }

.crm-url {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
  font-size: 13px;
  color: var(--ink-dim);
  background: oklch(0.15 0.02 250);
  border: 1px solid var(--line-quiet);
  border-radius: 999px;
  padding: 6px 18px;
}
.crm-url svg { color: oklch(0.72 0.15 150); }

.crm-tbicons { display: flex; gap: 14px; }
.crm-tbicons span { width: 15px; height: 2px; background: oklch(0.4 0.02 250); border-radius: 2px; box-shadow: 0 5px 0 oklch(0.4 0.02 250), 0 -5px 0 oklch(0.4 0.02 250); }

/* ---------- App shell ---------- */

.crm-app { display: flex; height: 620px; }

.crm-sidebar {
  width: 232px;
  flex: none;
  background: oklch(0.185 0.028 250);
  border-right: 1px solid var(--line-quiet);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
}

.crm-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  padding: 0 10px 18px;
}
.crm-brand span { color: var(--accent); }

.crm-nav { display: flex; flex-direction: column; gap: 3px; }

.crm-navitem {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background 0.18s, color 0.18s;
}
.crm-navitem svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.crm-navitem:hover { background: oklch(0.22 0.03 250); color: var(--ink); }
.crm-navitem.active { background: var(--accent-soft); color: var(--accent); }
.crm-navitem.active::before {
  content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.crm-navitem .badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent-strong);
  color: oklch(0.14 0.03 250);
  border-radius: 999px;
  padding: 1px 7px;
}

.crm-workspace {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--line-quiet);
}
.crm-ws-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-strong); color: oklch(0.14 0.03 250);
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
}
.crm-ws-meta { display: flex; flex-direction: column; line-height: 1.3; }
.crm-ws-meta b { font-size: 14px; }
.crm-ws-meta span { font-size: 12px; color: var(--ink-dim); }

/* ---------- Screen ---------- */

.crm-screen { flex: 1; min-width: 0; display: flex; flex-direction: column; background: oklch(0.165 0.022 250); }

.crm-topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  height: 60px;
  flex: none;
  border-bottom: 1px solid var(--line-quiet);
}
.crm-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }

.crm-search {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: min(260px, 38%);
  color: var(--ink-dim);
  font-size: 13.5px;
  background: oklch(0.15 0.02 250);
  border: 1px solid var(--line-quiet);
  border-radius: 9px;
  padding: 8px 13px;
}

.crm-user {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: oklch(0.30 0.06 var(--accent-h)); color: var(--ink);
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  cursor: pointer;
}

/* ---------- Panels & transitions ---------- */

.crm-panels { position: relative; flex: 1; min-height: 0; }

.crm-panel {
  position: absolute;
  inset: 0;
  padding: 24px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s;
  scrollbar-width: thin;
  scrollbar-color: oklch(0.35 0.03 250) transparent;
}
.crm-panel.active { opacity: 1; visibility: visible; transform: none; }
.crm-panel::-webkit-scrollbar { width: 8px; }
.crm-panel::-webkit-scrollbar-thumb { background: oklch(0.32 0.03 250); border-radius: 8px; }

/* small shared bits */
.crm-card {
  background: oklch(0.20 0.028 250);
  border: 1px solid var(--line-quiet);
  border-radius: 13px;
  padding: 18px;
}
.crm-h {
  font-family: var(--font-display);
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 14px;
}
.pill {
  font-size: 11.5px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  display: inline-block;
}
.pill.lead { background: oklch(0.78 0.14 85 / 0.16); color: oklch(0.85 0.12 85); }
.pill.cliente { background: oklch(0.72 0.15 150 / 0.16); color: oklch(0.82 0.13 150); }
.pill.activo { background: var(--accent-soft); color: var(--accent); }
.pill.activa { background: oklch(0.72 0.15 150 / 0.16); color: oklch(0.82 0.13 150); }
.pill.programada { background: oklch(0.78 0.14 85 / 0.16); color: oklch(0.85 0.12 85); }
.pill.finalizada { background: oklch(0.5 0.02 250 / 0.3); color: var(--ink-dim); }

/* ---------- Dashboard ---------- */

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: oklch(0.20 0.028 250); border: 1px solid var(--line-quiet); border-radius: 13px; padding: 16px 17px; }
.kpi .l { font-size: 13px; color: var(--ink-dim); margin-bottom: 8px; }
.kpi .v { font-family: var(--font-display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .d { font-size: 12.5px; margin-top: 6px; }
.kpi .d.up { color: oklch(0.82 0.13 150); }
.kpi .d.down { color: oklch(0.75 0.15 25); }

.dash-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; background: linear-gradient(to top, var(--accent-strong), oklch(0.72 0.12 var(--accent-h) / 0.35)); border-radius: 6px 6px 0 0; min-height: 4px; transition: height 0.6s cubic-bezier(0.2,0.7,0.2,1); position: relative; }
.bars .bar span { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--ink-dim); }
.bars-x { display: flex; gap: 8px; margin-top: 8px; }
.bars-x span { flex: 1; text-align: center; font-size: 11px; color: var(--ink-dim); }

.feed { display: flex; flex-direction: column; gap: 2px; }
.feed-item { display: flex; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--line-quiet); }
.feed-item:last-child { border-bottom: none; }
.feed-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex: none; }
.feed-item .ft { font-size: 13.5px; }
.feed-item .fm { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.feed-item .fwhen { margin-left: auto; font-size: 11.5px; color: var(--ink-dim); white-space: nowrap; }

/* ---------- Contacts ---------- */

.contacts-layout { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; height: 100%; }
.ctable { display: flex; flex-direction: column; }
.crow {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  transition: background 0.16s, border-color 0.16s;
}
.crow:hover { background: oklch(0.20 0.028 250); }
.crow.sel { background: var(--accent-soft); border-color: oklch(0.8 0.1 var(--accent-h) / 0.25); }
.cavatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: 14px; color: oklch(0.14 0.03 250); flex: none; }
.crow .cn { font-size: 14.5px; font-weight: 500; }
.crow .cmeta { font-size: 12.5px; color: var(--ink-dim); margin-top: 2px; }
.crow .cwhen { font-size: 11.5px; color: var(--ink-dim); text-align: right; }

.cdetail { animation: fadeSlide 0.35s ease; }
.cdetail .cd-head { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; }
.cdetail .cd-avatar { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 19px; color: oklch(0.14 0.03 250); }
.cdetail h4 { font-family: var(--font-display); font-size: 18px; }
.cd-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-quiet); font-size: 13.5px; }
.cd-row span:first-child { color: var(--ink-dim); }
.cd-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.cd-note { margin-top: 14px; font-size: 13px; color: var(--ink-dim); background: oklch(0.165 0.022 250); border: 1px solid var(--line-quiet); border-radius: 10px; padding: 12px; }

@keyframes fadeSlide { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

/* ---------- Conversations ---------- */

.conv-layout { display: grid; grid-template-columns: 270px 1fr; gap: 0; height: 100%; border: 1px solid var(--line-quiet); border-radius: 13px; overflow: hidden; }
.conv-list { border-right: 1px solid var(--line-quiet); overflow-y: auto; background: oklch(0.185 0.026 250); }
.conv-item { display: grid; grid-template-columns: auto 1fr auto; gap: 11px; padding: 13px 14px; cursor: pointer; border-bottom: 1px solid var(--line-quiet); align-items: center; }
.conv-item:hover { background: oklch(0.21 0.028 250); }
.conv-item.sel { background: var(--accent-soft); }
.conv-item .cn { font-size: 14px; font-weight: 500; }
.conv-item .cp { font-size: 12.5px; color: var(--ink-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.conv-item .cw { font-size: 11px; color: var(--ink-dim); }
.conv-unread { background: var(--accent-strong); color: oklch(0.14 0.03 250); font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; margin-top: 4px; display: inline-block; }

.conv-thread { display: flex; flex-direction: column; background: oklch(0.165 0.022 250); }
.conv-thead { padding: 13px 18px; border-bottom: 1px solid var(--line-quiet); display: flex; align-items: center; gap: 11px; }
.conv-thead .cn { font-size: 15px; font-weight: 600; font-family: var(--font-display); }
.conv-thead .st { font-size: 12px; color: oklch(0.82 0.13 150); }
.conv-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 9px; }
.cmsg { max-width: 76%; padding: 9px 13px; border-radius: 13px; font-size: 13.5px; line-height: 1.45; }
.cmsg.them { align-self: flex-start; background: oklch(0.25 0.03 250); border-bottom-left-radius: 4px; }
.cmsg.me { align-self: flex-end; background: oklch(0.34 0.085 var(--accent-h)); border-bottom-right-radius: 4px; }
.cmsg .tag { display: block; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 3px; }
.conv-suggest { padding: 11px 18px; border-top: 1px solid var(--line-quiet); display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-dim); }
.conv-suggest b { color: var(--accent); font-weight: 600; }

/* ---------- Campaigns ---------- */

.camp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.camp-card .camp-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.camp-card h4 { font-family: var(--font-display); font-size: 16px; margin-bottom: 4px; }
.camp-card .aud { font-size: 12.5px; color: var(--ink-dim); }
.camp-stats { display: flex; flex-direction: column; gap: 11px; }
.camp-stat .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.camp-stat .row span:last-child { color: var(--ink); font-weight: 600; }
.track { height: 7px; background: oklch(0.26 0.03 250); border-radius: 999px; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--accent-strong); border-radius: 999px; width: 0; transition: width 0.7s cubic-bezier(0.2,0.7,0.2,1); }

/* ---------- AI assistant ---------- */

.ai-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.ai-cap { display: flex; align-items: center; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--line-quiet); }
.ai-cap:last-child { border-bottom: none; }
.ai-cap .txt b { font-size: 14px; font-weight: 600; display: block; }
.ai-cap .txt span { font-size: 12.5px; color: var(--ink-dim); }
.switch { margin-left: auto; flex: none; width: 44px; height: 25px; border-radius: 999px; background: oklch(0.30 0.03 250); border: none; cursor: pointer; position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.switch.on { background: var(--accent-strong); }
.switch.on::after { transform: translateX(19px); background: oklch(0.14 0.03 250); }

.ai-preview { display: flex; flex-direction: column; gap: 11px; }
.ai-bubble { background: oklch(0.165 0.022 250); border: 1px solid var(--line-quiet); border-radius: 12px; padding: 14px; }
.ai-bubble .q { font-size: 13px; color: var(--ink-dim); margin-bottom: 8px; }
.ai-bubble .a { font-size: 14px; line-height: 1.5; }
.ai-bubble .a b { color: var(--accent); }

/* ---------- Analytics ---------- */

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric { background: oklch(0.20 0.028 250); border: 1px solid var(--line-quiet); border-radius: 13px; padding: 15px 16px; }
.metric .l { font-size: 12.5px; color: var(--ink-dim); margin-bottom: 7px; }
.metric .v { font-family: var(--font-display); font-size: 25px; font-weight: 700; }
.ana-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.breakdown-row { margin-bottom: 13px; }
.breakdown-row .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.breakdown-row .row span:last-child { color: var(--ink-dim); }

/* ---------- CTA row ---------- */

.crm-cta-row { text-align: center; margin-top: 30px; color: var(--ink-dim); font-size: 16px; }
.crm-cta-row a { color: var(--accent); text-decoration: none; font-weight: 600; }
.crm-cta-row a:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .crm-app { height: auto; flex-direction: column; }
  .crm-sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px;
    gap: 6px;
    border-right: none;
    border-bottom: 1px solid var(--line-quiet);
  }
  .crm-brand { display: none; }
  .crm-nav { flex-direction: row; flex-wrap: nowrap; }
  .crm-navitem { white-space: nowrap; padding: 9px 12px; }
  .crm-navitem.active::before { display: none; }
  .crm-navitem .label-hide { display: none; }
  .crm-workspace { display: none; }
  .crm-panels { height: 560px; }
  .crm-panel { position: absolute; }
  .kpi-grid, .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols, .contacts-layout, .conv-layout, .camp-grid, .ai-layout, .ana-cols { grid-template-columns: 1fr; }
  .crm-search { display: none; }
  .conv-layout { height: auto; }
}
