/* Habi · app unificada (chats + CRM). Mismos tokens que ficha/panel.css: si se cambia uno, cambiar el otro. */
:root {
  color-scheme: light dark;
  --bg: #f3f5f7; --bg-elev: #ffffff; --bg-sunken: #e9edf1; --line: #e0e5eb; --line-strong: #c9d1da; --line-ctrl: #7f8c9b;
  --text: #141a22; --text-2: #4f5b6b; --text-3: #5f6a78;
  --accent: #0e9f8b; --accent-ink: #0b7f6f; --accent-soft: #d6f2ec; --accent-text: #0a6b5e;
  --primary-bg: #0b7f6f; --primary-bg-hover: #09685b; --primary-fg: #ffffff;
  --warn: #945700; --warn-soft: #fdeed6; --danger: #b4242c; --danger-soft: #fbe3e5; --info: #1f55c2; --info-soft: #e2ebfc;
  --toast-ok: #0e9f8b; --toast-err: #d4363f;
  --radius: 10px; --radius-s: 8px;
  --shadow: 0 1px 2px rgba(20, 26, 34, .06), 0 10px 28px -18px rgba(20, 26, 34, .35);
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1); --t: 180ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318; --bg-elev: #161b22; --bg-sunken: #0b0e12; --line: #262d37; --line-strong: #353e4a; --line-ctrl: #66707e;
    --text: #e7ecf2; --text-2: #a3aebc; --text-3: #828e9d;
    --accent: #2bc4ad; --accent-ink: #1ea893; --accent-soft: rgba(43, 196, 173, .14); --accent-text: #5fe0cb;
    --primary-bg: #2bc4ad; --primary-bg-hover: #1ea893; --primary-fg: #0f1318;
    --warn: #e9a23b; --warn-soft: rgba(233, 162, 59, .14); --danger: #f0666c; --danger-soft: rgba(240, 102, 108, .14); --info: #6e9ef5; --info-soft: rgba(110, 158, 245, .14);
    --toast-ok: #0a6b5e; --toast-err: #b9262f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -18px rgba(0, 0, 0, .8);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318; --bg-elev: #161b22; --bg-sunken: #0b0e12; --line: #262d37; --line-strong: #353e4a; --line-ctrl: #66707e;
  --text: #e7ecf2; --text-2: #a3aebc; --text-3: #828e9d;
  --accent: #2bc4ad; --accent-ink: #1ea893; --accent-soft: rgba(43, 196, 173, .14); --accent-text: #5fe0cb;
  --primary-bg: #2bc4ad; --primary-bg-hover: #1ea893; --primary-fg: #0f1318;
  --warn: #e9a23b; --warn-soft: rgba(233, 162, 59, .14); --danger: #f0666c; --danger-soft: rgba(240, 102, 108, .14); --info: #6e9ef5; --info-soft: rgba(110, 158, 245, .14);
  --toast-ok: #0a6b5e; --toast-err: #b9262f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -18px rgba(0, 0, 0, .8);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 400 13.5px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[v-cloak] { display: none; }
.ph { line-height: 1; }

/* ---- controles ---- */
.btn { touch-action: manipulation; height: 34px; padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line-ctrl); background: var(--bg-elev); color: var(--text); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background var(--t) var(--ease), border-color var(--t), color var(--t), transform 120ms var(--ease), opacity var(--t); }
.btn .ph { font-size: 16px; }
.btn:hover { background: var(--bg-sunken); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); }
.btn--primary:hover { background: var(--primary-bg-hover); border-color: var(--primary-bg-hover); }
.btn--ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn--ghost:hover { background: var(--bg-sunken); color: var(--text); }
.btn--danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn--sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ''; position: absolute; width: 16px; height: 16px; border: 2px solid var(--text-2); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn--primary.busy::after { border-color: var(--primary-fg); border-right-color: transparent; }
.ibtn { touch-action: manipulation; width: 34px; height: 34px; border-radius: var(--radius-s); border: 1px solid var(--line-ctrl); background: var(--bg-elev); color: var(--text-2); display: inline-grid; place-items: center; cursor: pointer; text-decoration: none; transition: background var(--t), color var(--t); }
.ibtn .ph { font-size: 17px; }
.ibtn:hover { background: var(--bg-sunken); color: var(--text); }
.ibtn.on { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.ibtn[disabled] { opacity: .45; cursor: not-allowed; }
.in { height: 34px; width: 100%; border: 1px solid var(--line-ctrl); border-radius: var(--radius-s); background: var(--bg); padding: 0 10px; font-size: 13px; transition: border-color var(--t), box-shadow var(--t); }
.in::placeholder { color: var(--text-3); }
.in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.in { padding-right: 28px; }
.seg { display: flex; gap: 2px; background: var(--bg-sunken); padding: 3px; border-radius: 9px; }
.seg button { flex: 1; height: 28px; border: 0; background: none; border-radius: 7px; font-weight: 600; font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--bg-sunken); color: var(--text-2); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip--ok { background: var(--accent-soft); color: var(--accent-text); }
.chip--warn { background: var(--warn-soft); color: var(--warn); }
.chip--danger { background: var(--danger-soft); color: var(--danger); }
.chip--info { background: var(--info-soft); color: var(--info); }
.lbl { font-size: 10.5px; font-weight: 700; background: var(--bg-sunken); color: var(--text-2); padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700; font-size: 14px; color: #fff; background: var(--avatar, var(--accent)); }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.mono { font-family: var(--mono); }
.hint { color: var(--text-3); font-size: 12px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); height: 100dvh; }
.shell.compacta { grid-template-columns: 64px minmax(0, 1fr); }
.side { background: var(--bg-elev); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.brand { height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); min-width: 0; }
.brand .logo { width: 30px; height: 30px; flex: none; border-radius: 9px; background: var(--primary-bg); color: var(--primary-fg); display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.brand .txt { min-width: 0; line-height: 1.2; }
.brand b { font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--text-3); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.nav { padding: 10px 8px; display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; }
.nav a:hover { background: var(--bg-sunken); color: var(--text); }
.nav a.activa { background: var(--accent-soft); color: var(--accent-text); }
.nav a .ph { font-size: 18px; flex: none; }
.nav .badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.compacta .brand .txt, .compacta .nav a span, .compacta .yo .txt, .compacta .nav .badge { display: none; }
.compacta .nav a { justify-content: center; padding: 0; }
.yo { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; min-width: 0; }
.yo .txt { min-width: 0; line-height: 1.25; } .yo b { font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .yo small { color: var(--text-3); font-size: 11px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--bg-elev); }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 700; }
.topbar .der { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.contenido { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.contenido.sin-pad { padding: 0; overflow: hidden; }
.banner { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg-elev); display: flex; gap: 10px; align-items: flex-start; }
.banner--error { border-color: var(--danger-soft); } .banner--error .ph { color: var(--danger); font-size: 20px; }
.vacio { display: grid; place-items: center; height: 100%; min-height: 200px; color: var(--text-3); text-align: center; padding: 24px; }
.vacio .ph { font-size: 36px; margin-bottom: 8px; display: block; }

/* ---- login ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(100%, 380px); background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login h1 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.login label { display: grid; gap: 5px; font-size: 12px; color: var(--text-2); font-weight: 600; }
.login .err { color: var(--danger); font-size: 12.5px; }

/* ---- chats ---- */
.chats { display: grid; grid-template-columns: 350px minmax(0, 1fr) 470px; height: 100%; min-height: 0; }
.chats.sin-ficha { grid-template-columns: 350px minmax(0, 1fr); }
.lista { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg-elev); min-width: 0; }
.filtros { padding: 10px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.busca { position: relative; } .busca .ph { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 15px; } .busca .in { padding-left: 32px; }
.items { overflow: auto; flex: 1; }
.item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; align-items: start; }
.item:hover { background: var(--bg-sunken); } .item.on { background: var(--accent-soft); }
.item .n { font-weight: 700; font-size: 13px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.item .n span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .p { color: var(--text-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.item .der { display: grid; justify-items: end; gap: 4px; }
.item .t { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.item .nuevo { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.urg { color: var(--danger); font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.masbtn { margin: 8px; }
.conv { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.conv-head { min-height: 56px; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg-elev); flex-wrap: wrap; }
.conv-head h2 { font-size: 14px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-head .sub { font-size: 12px; color: var(--text-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.conv-head .acciones { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.msgs { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 74%; padding: 8px 11px; border-radius: 12px; font-size: 13.5px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--bg-elev); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.msg.out.bot { background: var(--info-soft); }
.msg.nota { align-self: flex-end; background: var(--warn-soft); border: 1px dashed var(--warn); }
.msg .quien { font-size: 11px; font-weight: 700; color: var(--text-2); margin-bottom: 2px; display: flex; gap: 6px; align-items: center; }
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; font-size: 10.5px; color: var(--text-3); margin-top: 3px; font-family: var(--mono); }
.msg .adj img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-top: 4px; }
.msg .adj a { display: inline-flex; gap: 6px; align-items: center; margin-top: 4px; }
.act { align-self: center; font-size: 11.5px; color: var(--text-3); background: var(--bg-sunken); padding: 3px 10px; border-radius: 999px; text-align: center; }
.dia { align-self: center; font-size: 11px; color: var(--text-3); font-weight: 700; margin: 8px 0 2px; letter-spacing: .04em; text-transform: uppercase; }
.redactor { border-top: 1px solid var(--line); background: var(--bg-elev); padding: 10px 12px; display: grid; gap: 8px; }
.redactor textarea { width: 100%; min-height: 66px; max-height: 220px; resize: vertical; border: 1px solid var(--line-ctrl); border-radius: var(--radius-s); background: var(--bg); padding: 9px 11px; font-size: 13.5px; line-height: 1.4; }
.redactor textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.redactor.nota textarea { background: var(--warn-soft); border-color: var(--warn); }
.redactor .fila { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.redactor .fila .enviar { margin-left: auto; }
.adjuntos-pend { display: flex; gap: 6px; flex-wrap: wrap; }
.adjuntos-pend span { font-size: 11.5px; background: var(--bg-sunken); padding: 3px 8px; border-radius: 999px; display: inline-flex; gap: 6px; align-items: center; }
.adjuntos-pend button { border: 0; background: none; cursor: pointer; color: var(--text-3); padding: 0; display: grid; }
.ficha-col { border-left: 1px solid var(--line); min-height: 0; background: var(--bg); position: relative; }
.ficha-col iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---- kanban ---- */
.kanban { display: flex; gap: 12px; height: 100%; overflow-x: auto; padding-bottom: 6px; }
.col { width: 272px; flex: none; display: flex; flex-direction: column; background: var(--bg-elev); border: 1px solid var(--line); border-top: 3px solid var(--col, var(--accent)); border-radius: var(--radius); min-height: 0; }
.col h3 { margin: 0; padding: 10px 12px; font-size: 12.5px; display: flex; justify-content: space-between; align-items: center; }
.col h3 small { color: var(--text-3); font-family: var(--mono); font-weight: 500; }
.col .cards { flex: 1; overflow: auto; padding: 0 8px 8px; display: grid; gap: 8px; align-content: start; min-height: 80px; }
.col.sobre { outline: 2px dashed var(--accent); outline-offset: -4px; }
.tarjeta { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 10px; cursor: grab; display: grid; gap: 3px; }
.tarjeta:hover { border-color: var(--line-ctrl); }
.tarjeta:active { cursor: grabbing; }
.tarjeta b { font-size: 13px; }
.tarjeta .p { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tarjeta .t { font-family: var(--mono); font-size: 11px; color: var(--text-3); display: flex; justify-content: space-between; }
.tarjeta.arrastrando { opacity: .4; }

/* ---- tablas, kpis ---- */
table.tabla { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tabla th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 9px 12px; border-bottom: 1px solid var(--line); }
.tabla td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tabla tbody tr { cursor: pointer; } .tabla tbody tr:hover td { background: var(--bg-sunken); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.kpi:hover { border-color: var(--line-ctrl); }
.kpi b { font-family: var(--mono); font-size: 26px; font-weight: 500; display: block; line-height: 1.1; }
.kpi span { color: var(--text-3); font-size: 12px; }
.kpi.alerta b { color: var(--danger); }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h2 { margin: 0 0 10px; font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.grid2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; margin-top: 12px; }
.lista-mini { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.lista-mini a { display: flex; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; text-decoration: none; color: inherit; }
.lista-mini a:hover { background: var(--bg-sunken); }
.lista-mini .p { flex: 1; min-width: 0; color: var(--text-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- avisos ---- */
.toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 440px); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 14px; border-radius: var(--radius); background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 13px; animation: rise 220ms var(--ease); }
.toast .ph { font-size: 18px; flex: none; } .toast--ok .ph { color: var(--toast-ok); } .toast--error .ph { color: var(--toast-err); }
.toast span { flex: 1; }
.toast button { border: 0; background: color-mix(in srgb, currentColor 14%, transparent); color: inherit; padding: 5px 9px; border-radius: 6px; font-weight: 600; cursor: pointer; }
.toast.out { animation: sink 200ms var(--ease) forwards; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes sink { to { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1500px) { .chats { grid-template-columns: 300px minmax(0, 1fr) 400px; } .chats.sin-ficha { grid-template-columns: 300px minmax(0, 1fr); } }
@media (max-width: 1360px) { .shell:not(.ancha) { grid-template-columns: 64px minmax(0, 1fr); } .shell:not(.ancha) .brand .txt, .shell:not(.ancha) .nav a span, .shell:not(.ancha) .yo .txt, .shell:not(.ancha) .nav .badge { display: none; } .shell:not(.ancha) .nav a { justify-content: center; padding: 0; } .conv-head .acciones select { max-width: 150px; } }
@media (max-width: 1180px) { .chats { grid-template-columns: 320px minmax(0, 1fr); } .ficha-col { display: none; } .chats.ficha-abierta { grid-template-columns: minmax(0, 1fr) 420px; } .chats.ficha-abierta .lista { display: none; } .chats.ficha-abierta .ficha-col { display: block; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 64px minmax(0, 1fr); }
  .brand .txt, .nav a span, .yo .txt, .nav .badge { display: none; } .nav a { justify-content: center; padding: 0; }
  .chats { grid-template-columns: 1fr; } .chats .lista { display: none; } .chats.lista-abierta .lista { display: flex; } .chats.lista-abierta .conv { display: none; }
  .msg { max-width: 90%; } .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .btn.busy::after { animation: spin 1.2s linear infinite !important; }
}
