/* CRM Ros · estilos. Tema claro y sobrio: fondo marfil, paneles blancos, texto casi negro cálido y el dorado de la clínica como acento.
   Tipografía del sistema (San Francisco en Mac/iPhone, Segoe UI en Windows): sin fuentes externas.
   Marca configurable: --brand se sobrescribe con organizations.brand.primary_color. */
:root {
  color-scheme: light;
  --brand: #C19A5B;
  --brand-ink: #1A140C;
  --brand-text: color-mix(in srgb, var(--brand) 60%, #1F1B16);
  --brand-soft: color-mix(in srgb, var(--brand) 12%, var(--panel));
  --brand-line: color-mix(in srgb, var(--brand) 50%, transparent);
  --bg: #F6F4F0;
  --panel: #FFFFFF;
  --raised: #FFFFFF;
  --hover: #F2EFEA;
  --sunken: #F4F1EC;
  --ink: #1F1B16;
  --ink-2: #4A433A;
  --muted: #776E62;
  --line: #E4DFD6;
  --line-2: #EDE9E2;
  --nav: #FBFAF7;
  --nav-ink: #6B6358;
  --ok: #2F7D4F;
  --warn: #A9661A;
  --bad: #B8433A;
  --info: #3667A6;
  --ok-soft: #E6F2EA;
  --warn-soft: #FBF0E1;
  --bad-soft: #FBE9E7;
  --info-soft: #E7EEF8;
  --wa-in: #FFFFFF;
  --wa-out: #E9F3E6;
  --note: #FBF3DC;
  --thread-bg: #F1EEE8;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(60, 45, 25, .06), 0 1px 3px rgba(60, 45, 25, .05);
  --shadow-lg: 0 24px 48px rgba(60, 45, 25, .14), 0 8px 16px rgba(60, 45, 25, .08), 0 0 0 1px rgba(60, 45, 25, .06);
  --ease: cubic-bezier(.25, 1, .5, 1);
  --sidebar: 84px;
  --topbar: 60px;
  --display: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
::selection { background: color-mix(in srgb, var(--brand) 35%, transparent); }
* { scrollbar-color: #D3CCC1 transparent; scrollbar-width: thin; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout --------------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar { background: var(--nav); color: var(--nav-ink); border-right: 1px solid var(--line-2); display: flex; flex-direction: column; align-items: stretch; padding: 10px 6px; gap: 2px; overflow-y: auto; }
.sidebar .logo { display: grid; place-items: center; height: 46px; margin-bottom: 8px; }
.sidebar .logo span { width: 38px; height: 38px; border-radius: 11px; background: transparent; border: 1px solid var(--brand-line); color: var(--brand-text); display: grid; place-items: center; font-family: var(--display); font-weight: 600; font-size: 19px; overflow: hidden; }
.sidebar .logo img { width: 36px; height: 36px; object-fit: cover; border-radius: 10px; }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 2px; border-radius: 10px; text-decoration: none; font-size: 11px; letter-spacing: .01em; color: var(--nav-ink); position: relative; transition: background .2s var(--ease), color .2s var(--ease); }
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-text); }
.nav-item.active::before { content: ""; position: absolute; left: -6px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--brand); }
.nav-item svg { width: 20px; height: 20px; stroke-width: 1.75; }
.nav-item .badge { position: absolute; top: 4px; right: 10px; }
.sidebar .spacer { flex: 1; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--bg); border-bottom: 1px solid var(--line-2); flex-shrink: 0; }
.topbar h1 { font-family: var(--display); font-size: 19px; margin: 0; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .grow { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.mode-pill { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--raised); color: var(--ink-2); border: 1px solid var(--line); letter-spacing: .02em; }
.mode-pill.live { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.mode-pill.sandbox { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.content { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* Controles -------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--raised); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; transition: background .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease), filter .2s var(--ease); }
.btn:hover { background: var(--hover); border-color: #D3CCC1; }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary { font-weight: 600; box-shadow: 0 1px 0 rgba(255, 245, 225, .35) inset, 0 1px 2px rgba(60, 45, 25, .18); }
.btn.primary:hover { background: var(--brand); border-color: var(--brand); filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.danger.solid { background: var(--bad); color: #FFFFFF; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg, label.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
svg { max-width: 100%; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--ink-2); text-decoration: none; transition: background .2s var(--ease), color .2s var(--ease); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.on { color: var(--brand-text); }
.input, select.input, textarea.input { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 10px; background: var(--sunken); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.input::placeholder, textarea::placeholder { color: #9A9184; }
.input:focus { outline: none; border-color: var(--brand-line); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.input-prefix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--sunken); }
.input-prefix span { padding: 0 2px 0 10px; color: var(--brand-text); font-weight: 600; }
.input-prefix .input { border: 0; background: transparent; padding-left: 2px; }
.input-prefix:focus-within { border-color: var(--brand-line); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.input-prefix .input:focus { box-shadow: none; }
textarea.input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
.input.sm { height: 30px; font-size: 13px; }
label.field { display: grid; gap: 6px; font-size: 12px; color: var(--ink-2); font-weight: 500; letter-spacing: .01em; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--brand); color: var(--brand-ink); font-size: 11px; font-weight: 700; }
.badge.soft { background: var(--hover); color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 9px; border-radius: 99px; font-size: 12px; background: var(--hover); color: var(--ink-2); white-space: nowrap; max-width: 100%; }
.chip .x { border: 0; background: none; cursor: pointer; padding: 0; color: inherit; opacity: .6; }
.chip.tag { background: color-mix(in srgb, var(--c, #8F8576) 18%, var(--panel)); color: color-mix(in srgb, var(--c, #8F8576) 55%, var(--ink)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--c, #8F8576) 22%, transparent) inset; }
.chip.status-open { background: var(--info-soft); color: var(--info); }
.chip.status-won { background: var(--ok-soft); color: var(--ok); }
.chip.status-lost { background: var(--hover); color: var(--muted); }
.chip.status-abandoned { background: var(--warn-soft); color: var(--warn); }
.chip.bc-draft { background: var(--hover); color: var(--muted); }
.chip.bc-sending { background: var(--info-soft); color: var(--info); }
.chip.bc-paused { background: var(--warn-soft); color: var(--warn); }
.chip.bc-done { background: var(--ok-soft); color: var(--ok); }
.chip.bc-cancelled { background: var(--bad-soft); color: var(--bad); }
.progress { height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; min-width: 80px; margin: 6px 0 2px; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }
.bc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.bc-summary { position: sticky; top: 0; }
.bc-big { font-size: 15px; } .bc-big b { font-family: var(--display); font-size: 34px; font-weight: 600; letter-spacing: -.02em; margin-right: 4px; color: var(--ink); }
.bc-reasons { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.bc-reasons li { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-2); }
.bc-preview { background: var(--thread-bg); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; }
.bc-preview .bubble { max-width: 100%; }
.bc-param { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.capi-steps { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand-text); box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 22%, transparent) inset; font-weight: 600; flex-shrink: 0; position: relative; font-size: 13px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar .wa { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; background: #3FB872; border: 2px solid var(--panel); }
.card { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-h, .cp-right .card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.card .card-h h2, .card .card-h h3, .cp-right .card-h h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.card .card-b { padding: 16px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; font-family: var(--display); font-weight: 600; font-size: 18px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 12px; border: 0; background: none; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; transition: color .2s var(--ease), border-color .2s var(--ease); }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--brand); }
.tab .badge { margin-left: 4px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { border: 0; background: var(--raised); padding: 0 12px; height: 34px; cursor: pointer; color: var(--ink-2); }
.segmented button { display: inline-flex; align-items: center; gap: 6px; }
.segmented button svg { width: 16px; height: 16px; }
.segmented button.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.search { position: relative; min-width: 200px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 32px; }
.filters-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

/* Tablas ------------------------------------------------------------------------- */
.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; background: var(--raised); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:hover td { background: var(--raised); }
.table tr.selected td { background: var(--brand-soft); }
.table .name-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.table a.link { text-decoration: none; font-weight: 500; }
.table a.link:hover { text-decoration: underline; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 2px; color: var(--ink-2); flex-wrap: wrap; }

/* Toasts, modales y cajones --------------------------------------------------------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--raised); color: var(--ink); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; border-left: 3px solid var(--muted); animation: toast-in .3s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
#overlay:empty { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(40, 30, 18, .32); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; animation: modal-in .25s var(--ease); width: min(720px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal.sm { width: min(440px, 100%); }
.modal.lg { width: min(980px, 100%); }
.modal-h { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-h h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 17px; letter-spacing: -.01em; flex: 1; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.99); } }
.modal-b { padding: 20px; overflow: auto; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-split { display: grid; grid-template-columns: 180px 1fr; min-height: 0; flex: 1; }
.modal-split nav { border-right: 1px solid var(--line); padding: 10px; display: grid; align-content: start; gap: 2px; }
.modal-split nav button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--ink-2); }
.modal-split nav button.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.menu { position: fixed; background: var(--raised); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; min-width: 200px; max-height: 60vh; overflow: auto; }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu button svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted); }
.menu button:hover { background: var(--hover); }
.menu { max-width: min(420px, calc(100vw - 16px)); }
.qr-item { display: grid; gap: 2px; min-width: 0; }
.qr-item b { color: var(--brand-text); font-weight: 600; }
.qr-item small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu .menu-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 6px 10px 2px; }

/* Login ---------------------------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login .card { width: min(400px, 100%); box-shadow: var(--shadow-lg); border-color: var(--line); }
.login h1 { font-family: var(--display); font-weight: 600; font-size: 22px; letter-spacing: -.015em; margin: 0 0 4px; }
.login .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login .brand span { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--brand-line); color: var(--brand-text); display: grid; place-items: center; font-family: var(--display); font-size: 21px; font-weight: 600; }

/* Inicio ----------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; transition: border-color .2s var(--ease), transform .2s var(--ease); }
a.kpi:hover { border-color: var(--brand-line); transform: translateY(-1px); }
.kpi .label { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.kpi .value { font-family: var(--display); font-size: 30px; font-weight: 600; margin-top: 6px; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: lining-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi a, a.card { text-decoration: none; color: inherit; }
.home-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; border-radius: 3px 3px 0 0; overflow: hidden; cursor: default; }
.bars .seg { width: 100%; }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.funnel-row { display: grid; grid-template-columns: 170px 1fr 92px; gap: 10px; align-items: center; padding: 6px 0; }
.funnel-row .track { background: var(--sunken); height: 22px; border-radius: 6px; overflow: hidden; }
.funnel-row .fill { height: 100%; background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 70%, var(--panel)), var(--brand)); border-radius: 6px; min-width: 2px; }
.funnel-row .pct { font-size: 12px; color: var(--ink-2); text-align: right; }

/* Bandeja ---------------------------------------------------------------------------- */
.inbox { display: grid; grid-template-columns: 210px 340px minmax(0, 1fr) 320px; height: 100%; min-height: 0; background: var(--panel); }
.inbox > * { min-height: 0; }
.inbox-folders { border-right: 1px solid var(--line-2); padding: 12px 8px; overflow: auto; background: var(--bg); }
.inbox-folders .folder { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--ink-2); text-align: left; }
.inbox-folders .folder:hover { background: var(--hover); }
.inbox-folders .folder.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.inbox-folders h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 10px 6px; }
.inbox-list { border-right: 1px solid var(--line-2); display: flex; flex-direction: column; min-height: 0; }
.inbox-list .list-h { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.inbox-list .items { overflow: auto; flex: 1; }
.inbox-list .tab { padding: 8px 7px; font-size: 13px; }
.conv { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; text-decoration: none; position: relative; transition: background .15s var(--ease); }
.conv:hover { background: var(--raised); }
.conv.active { background: var(--brand-soft); }
.conv.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--brand); }
.conv .who { font-weight: 600; }
.conv.unread .who::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-left: 6px; vertical-align: middle; }
.conv .preview { color: var(--muted); font-size: 13px; }
.conv .meta { display: grid; justify-items: end; gap: 4px; font-size: 11px; color: var(--muted); }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--thread-bg); }
.thread-h { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line-2); }
.thread-h .t { flex: 1; min-width: 0; }
.thread-h .t strong { display: block; }
.messages { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 11px; background: var(--raised); color: var(--muted); padding: 3px 12px; border-radius: 99px; margin: 10px 0; border: 1px solid var(--line-2); letter-spacing: .02em; }
.new-sep { display: flex; align-items: center; gap: 8px; color: var(--brand-text); font-size: 11px; font-weight: 600; margin: 6px 0; }
.new-sep::before, .new-sep::after { content: ""; flex: 1; height: 1px; background: var(--brand); opacity: .4; }
.bubble { max-width: min(560px, 78%); padding: 8px 11px 6px; border-radius: 12px 12px 12px 4px; background: var(--wa-in); box-shadow: 0 1px 1px rgba(60, 45, 25, .08), 0 0 0 1px rgba(60, 45, 25, .05); line-height: 1.45; overflow-wrap: anywhere; position: relative; }
.bubble .txt { white-space: pre-wrap; }
.bubble.out { align-self: flex-end; background: var(--wa-out); border-radius: 12px 12px 4px 12px; }
.bubble.note { align-self: center; border-radius: 10px; background: var(--note); border: 1px dashed color-mix(in srgb, var(--warn) 45%, transparent); max-width: min(620px, 92%); }
.bubble.system { align-self: center; border-radius: 10px; background: var(--raised); color: var(--ink-2); font-size: 12px; }
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .tpl { font-size: 11px; color: var(--brand-text); font-weight: 600; margin-bottom: 3px; letter-spacing: .02em; }
.bubble.failed { border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent); }
.bubble .err { color: var(--bad); font-size: 12px; margin-top: 4px; }
.bubble .att svg { width: 18px; height: 18px; flex-shrink: 0; }
.bubble .att { display: flex; align-items: center; gap: 8px; padding: 8px; background: rgba(60, 45, 25, .06); border-radius: 8px; margin-bottom: 4px; text-decoration: none; }
.bubble .att img { max-width: 240px; border-radius: 6px; display: block; }
.ticks { font-size: 12px; letter-spacing: -3px; }
.ticks.read { color: #2E8BC9; }
.composer { background: var(--panel); border-top: 1px solid var(--line-2); }
.composer .tabs { padding: 0 10px; }
.composer .box { padding: 10px 12px; display: grid; gap: 8px; }
.composer textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: none; min-height: 64px; max-height: 200px; background: var(--sunken); transition: border-color .2s var(--ease); }
.composer textarea:focus { outline: none; border-color: var(--brand-line); }
.composer textarea:disabled { opacity: .6; }
.composer.note-mode textarea { background: var(--note); }
.window-banner { display: flex; gap: 8px; align-items: center; padding: 8px 14px; font-size: 12px; background: var(--warn-soft); color: var(--warn); border-top: 1px solid color-mix(in srgb, var(--warn) 25%, transparent); }
.window-banner.open { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.contact-pane { border-left: 1px solid var(--line-2); overflow: auto; background: var(--panel); }
.inbox .back-btn { display: none; }

/* Ficha de contacto ---------------------------------------------------------------- */
.contact-page { display: grid; grid-template-columns: 340px minmax(0, 1fr) 340px 52px; height: 100%; min-height: 0; background: var(--panel); }
.contact-page > * { min-height: 0; overflow: auto; }
.cp-left { border-right: 1px solid var(--line); }
.cp-center { display: flex; flex-direction: column; overflow: hidden; }
.cp-right { border-left: 1px solid var(--line-2); background: var(--bg); }
.cp-rail { border-left: 1px solid var(--line-2); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: var(--bg); }
.cp-rail .icon-btn.active { background: var(--brand-soft); color: var(--brand-text); }
.cp-head { padding: 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.cp-head .name { display: flex; align-items: center; gap: 10px; }
.cp-head .name h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 19px; letter-spacing: -.01em; flex: 1; min-width: 0; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; align-items: center; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
details.folder-box { border-bottom: 1px solid var(--line-2); }
details.folder-box > summary { list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
details.folder-box > summary::-webkit-details-marker { display: none; }
details.folder-box > summary::after { content: "▾"; color: var(--muted); }
details.folder-box:not([open]) > summary::after { content: "▸"; }
details.folder-box .fields { padding: 0 16px 14px; display: grid; gap: 10px; }
.timeline { padding: 14px 16px; display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.tl-item::before { content: ""; position: absolute; left: 10px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--hover); display: grid; place-items: center; font-size: 11px; }
.tl-dot.lead { background: var(--info-soft); }
.tl-dot.stage { background: var(--brand-soft); }
.tl-dot.msg { background: var(--ok-soft); }
.tl-dot.bad { background: var(--bad-soft); }
.tl-item .t { font-weight: 500; }
.tl-item .d { font-size: 12px; color: var(--muted); }
.attribution { margin: 0 16px 14px; padding: 10px 12px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--line); font-size: 12px; display: grid; gap: 4px; }

/* Pipeline --------------------------------------------------------------------------- */
.board { display: flex; gap: 12px; padding: 4px 4px 16px; align-items: flex-start; min-height: 100%; }
.col { width: 280px; flex-shrink: 0; background: var(--sunken); border: 1px solid var(--line-2); border-radius: 14px; display: flex; flex-direction: column; max-height: calc(100dvh - var(--topbar) - 150px); }
.col.collapsed { width: 46px; }
.col.collapsed .col-b, .col.collapsed .col-h .sum, .col.collapsed .col-h .count-row { display: none; }
.col.collapsed .col-h .title { writing-mode: vertical-rl; transform: rotate(180deg); }
.col-h { padding: 12px 12px 10px; display: grid; gap: 2px; border-top: 2px solid var(--c, #8F8576); border-radius: 13px 13px 0 0; background: var(--panel); }
.col-h .title-row { display: flex; align-items: center; gap: 6px; }
.col-h .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-h .sum { font-size: 12px; color: var(--ink-2); }
.col-b { padding: 8px; overflow: auto; display: grid; gap: 8px; align-content: start; min-height: 60px; }
.opp-card { background: var(--raised); border-radius: 10px; padding: 11px 12px; box-shadow: var(--shadow); display: grid; gap: 6px; cursor: grab; border: 1px solid var(--line-2); transition: border-color .2s var(--ease), transform .2s var(--ease); }
.opp-card:hover { border-color: #D3CCC1; transform: translateY(-1px); }
.opp-card .top { display: flex; align-items: center; gap: 6px; }
.opp-card .top strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-card .meta { display: grid; gap: 2px; font-size: 12px; color: var(--ink-2); }
.opp-card .quick { display: flex; gap: 2px; border-top: 1px solid var(--line-2); padding-top: 6px; }
.opp-card .quick .icon-btn { width: 28px; height: 28px; }
.opp-card.sortable-ghost { opacity: .4; }
.opp-card.sortable-chosen { box-shadow: var(--shadow-lg); }
.load-more { border: 1px dashed var(--line); background: transparent; border-radius: 8px; padding: 6px; cursor: pointer; color: var(--ink-2); }

/* Tareas ------------------------------------------------------------------------------ */
.task-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.task-row .check { width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid #B9B0A3; background: none; cursor: pointer; display: grid; place-items: center; color: var(--bg); transition: background .2s var(--ease), border-color .2s var(--ease); }
.task-row .check:hover { border-color: var(--brand); }
.task-row.done .check { background: var(--ok); border-color: var(--ok); }
.task-row.done .title { text-decoration: line-through; color: var(--muted); }
.task-row .due.overdue { color: var(--bad); font-weight: 600; }

/* Ajustes ------------------------------------------------------------------------------ */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; }
.settings nav { display: grid; gap: 2px; align-content: start; }
.settings nav a { padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-2); transition: background .2s var(--ease); }
.settings nav a:hover { background: var(--hover); }
.settings nav a.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #D8D1C6; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: .2s var(--ease); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { background: var(--brand-ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.rule { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); align-items: start; }
.rule .key { font-weight: 700; color: var(--brand-text); width: 30px; }
.stage-row { display: grid; grid-template-columns: 24px 28px 1fr 130px 90px 160px auto; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line-2); }
.drag-handle { cursor: grab; color: var(--muted); }
.color-dot { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); padding: 0; cursor: pointer; }

/* Responsive ------------------------------------------------------------------------------ */
@media (max-width: 1280px) {
  .inbox { grid-template-columns: 190px 300px minmax(0, 1fr); }
  .inbox .contact-pane { display: none; }
  .inbox.show-contact .contact-pane { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100vw); z-index: 40; box-shadow: var(--shadow-lg); }
  .contact-page { grid-template-columns: 320px minmax(0, 1fr) 52px; }
  .contact-page .cp-right { display: none; }
  .contact-page.show-right .cp-right { display: block; position: fixed; right: 52px; top: var(--topbar); bottom: 0; width: min(340px, calc(100vw - 52px)); z-index: 30; box-shadow: var(--shadow-lg); }
  .contact-page:not(.show-right) .cp-rail .icon-btn.active { background: none; }
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox .inbox-folders { display: none; }
  .inbox .thread { display: none; }
  .inbox.has-active .inbox-list { display: none; }
  .inbox.has-active .thread { display: flex; }
  .inbox .back-btn { display: inline-grid; }
  .inbox-list .folder-select:not([hidden]) { display: block !important; }
  .contact-page { grid-template-columns: minmax(0, 1fr); grid-auto-rows: max-content; overflow: auto; }
  .contact-page > * { overflow: visible; min-width: 0; }
  .contact-page .cp-center { min-height: 70dvh; border-top: 1px solid var(--line); }
  .contact-page .cp-rail { flex-direction: row; justify-content: center; border-left: 0; border-top: 1px solid var(--line); position: sticky; bottom: 0; }
  /* En móvil el panel lateral sustituye a las columnas (no flota) para que el raíl siga a la vista */
  .contact-page.show-right > .cp-left, .contact-page.show-right > .cp-center { display: none; }
  .contact-page.show-right { display: flex; flex-direction: column; }
  .contact-page.show-right .cp-right { position: static; width: auto; box-shadow: none; border-left: 0; flex: 1 0 auto; }
  .settings { grid-template-columns: minmax(0, 1fr); }
  .bc-grid { grid-template-columns: minmax(0, 1fr); }
  .bc-summary { position: static; }
  .settings nav { grid-auto-flow: column; justify-content: start; overflow-x: auto; }
  .settings nav a { white-space: nowrap; }
  .modal-split { grid-template-columns: minmax(0, 1fr); }
  .modal-split nav { grid-auto-flow: column; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
}
@media (max-width: 720px) {
  :root { --topbar: 52px; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .sidebar { order: 2; flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around; overflow: visible; }
  .sidebar .logo, .sidebar .spacer, .sidebar .nav-extra { display: none; }
  .nav-item { flex: 1; padding: 6px 2px; font-size: 10px; }
  .nav-item.active::before { left: 20%; right: 20%; top: -4px; bottom: auto; width: auto; height: 3px; }
  .topbar { padding: 0 12px; }
  .topbar .who .name { display: none; }
  .page { padding: 12px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .funnel-row { grid-template-columns: 110px 1fr 70px; }
  .table .hide-sm { display: none; }
  .col { width: 82vw; max-height: none; }
  .board { scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .kpi .value { font-size: 22px; }
  .stage-row { grid-template-columns: 20px 24px 1fr auto; }
  .stage-row .hide-sm { display: none; }
  .bubble { max-width: 88%; }
}
