:root {
  --bg1: #e9eef8; --bg2: #f5eef4;
  --card: rgba(255,255,255,.78); --card-solid: #fff;
  --line: #e6e9f0; --ink: #12141a; --muted: #6b7280;
  --blue: #2563eb; --teal: #2a9db0; --yellow: #f6d54a; --black: #111318; --pink: #fbe4e6;
  --radius: 22px; --shadow: 0 8px 30px rgba(30,40,80,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif; color: var(--ink); font-size: 14px;
  background: linear-gradient(135deg, var(--bg1), var(--bg2)); background-attachment: fixed;
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 15px; font-weight: 600; }
small { color: var(--muted); font-size: 12px; }
.error { color: #c0392b; font-size: 13px; min-height: 1em; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.card { background: var(--card); backdrop-filter: blur(14px); border: 1px solid rgba(255,255,255,.9);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 18px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--black); color: #fff; border-color: var(--black); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: #fff;
  display: inline-grid; place-items: center; cursor: pointer; text-decoration: none; flex: none; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 9px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; color: var(--ink); font-size: 14px; }

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 16px; }
.logo { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--teal)); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card-solid); border-radius: 28px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 26px; margin: 26px 0 18px; }
.login-card .btn { width: 100%; margin-top: 6px; padding: 12px; }

/* Layout */
.app { max-width: 1480px; margin: 0 auto; padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 16px; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tabs { display: flex; gap: 4px; background: rgba(255,255,255,.6); padding: 4px; border-radius: 999px; }
.tabs button { border: 0; background: transparent; padding: 8px 18px; border-radius: 999px; cursor: pointer; font-weight: 500; }
.tabs button.active { background: var(--black); color: #fff; }
.me { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { background: var(--card); border-radius: 18px; padding: 14px 16px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); }
.kpi b { font-size: 22px; display: block; }
.kpi-ico { width: 40px; height: 40px; border-radius: 12px; background: #fff; display: grid; place-items: center; border: 1px solid var(--line); }

main { flex: 1; min-height: 0; }
.view { height: calc(100vh - 190px); min-height: 520px; }

/* Bandeja */
.inbox { display: grid; grid-template-columns: 320px 1fr 300px; gap: 16px; }
.list-card { display: flex; flex-direction: column; min-height: 0; padding-bottom: 8px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.search { margin-bottom: 10px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--black); color: #fff; border-color: var(--black); }
.conv-list { list-style: none; margin: 0 -8px; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 10px; margin: 0 4px 4px; border-radius: 16px; cursor: pointer; align-items: center; }
.conv:hover { background: rgba(255,255,255,.8); }
.conv.active { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.conv .meta { flex: 1; min-width: 0; }
.conv .row { display: flex; justify-content: space-between; gap: 6px; }
.conv b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv p { margin: 2px 0 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--blue); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none;
  background: linear-gradient(135deg, #8aa4ff, #e39bc0); }
.avatar.big { width: 88px; height: 88px; font-size: 28px; margin: 0 auto 10px; border: 4px solid #fff; }

.chat-card { padding: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-head small { display: block; }
.chat-head .back { display: none; }
.stage-pill { margin-left: auto; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; background: rgba(255,255,255,.9); border-radius: 10px; padding: 3px 10px; font-size: 12px; color: var(--muted); margin: 8px 0; }
.bubble { max-width: 70%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.bubble.in { background: #fff; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--black); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .t { display: block; font-size: 11px; opacity: .6; margin-top: 3px; text-align: right; }
.bubble.failed { background: #fde2e1; color: #8a1c13; }
.window-warn { margin: 0 18px; background: #fff7d6; border: 1px solid #f3dc7a; padding: 10px 12px; border-radius: 14px; font-size: 13px; }
.composer { display: flex; gap: 10px; padding: 14px 18px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 140px; border-radius: 18px; }
#sendError { padding: 0 18px 10px; margin: 0; }

.side { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow-y: auto; }
.profile { text-align: center; background: linear-gradient(160deg, #fff 0%, var(--pink) 100%); }
.profile h2 { font-size: 18px; }
.profile p { color: var(--muted); margin: 4px 0 12px; }
.p-actions { display: flex; gap: 8px; justify-content: center; }
.details h3 { margin-bottom: 12px; }
.details .mt { margin-top: 8px; }
.field { margin-bottom: 12px; }
.field small { display: block; }
.notes { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.notes li { background: #fff; border-radius: 12px; padding: 8px 10px; font-size: 13px; }
.notes li small { display: block; margin-top: 2px; }
.note-form { display: flex; gap: 6px; }

/* Embudo */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 14px; height: 100%; overflow-x: auto; }
.col { background: rgba(255,255,255,.5); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; min-height: 0; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-weight: 600; }
.col-body { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 60px; border-radius: 16px; }
.col-body.over { outline: 2px dashed var(--blue); }
.deal { border-radius: 18px; padding: 14px; cursor: grab; color: #fff; }
.deal small { color: inherit; opacity: .75; display: block; }
.deal b { display: block; margin: 6px 0 2px; }
.deal p { margin: 6px 0 0; font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Colores por etapa */
.st-nuevo { background: var(--blue); color: #fff; }
.st-interesado { background: var(--teal); color: #fff; }
.st-pago { background: var(--yellow); color: var(--ink); }
.st-entregado { background: var(--black); color: #fff; }
.st-perdido { background: #fff; color: var(--ink); border: 1px solid var(--line); }

/* Equipo */
.team { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; height: auto; }
.agent-list { list-style: none; padding: 0; margin: 12px 0 0; }
.agent-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.agent-list li .meta { flex: 1; }
.agent-list li small { display: block; }
.agent-form { margin-top: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--black); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 10; }

/* Responsive */
@media (max-width: 1180px) {
  .inbox { grid-template-columns: 300px 1fr; }
  .side { display: none !important; }
}
@media (max-width: 760px) {
  .app { padding: 12px 16px; }
  .topbar { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; justify-content: space-between; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .view { height: calc(100vh - 260px); }
  .inbox { grid-template-columns: 1fr; }
  .inbox.chat-open .list-card { display: none; }
  .inbox:not(.chat-open) .chat-card { display: none; }
  .chat-head .back { display: inline-grid; }
  .bubble { max-width: 85%; }
  .team { grid-template-columns: 1fr; }
}
