/* ============================================================ tokens */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --hover: #f1f5f9;
  --border: #e4e8ee;
  --border-strong: #cfd6df;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #1f5aa6;
  --accent-hover: #184a8a;
  --accent-ink: #ffffff;
  --accent-soft: #eaf1fa;
  --accent-ring: rgba(31, 90, 166, .22);
  --danger: #dc2626;
  --warn-bg: #fff7e6;
  --warn-border: #fcd9a0;
  --warn-ink: #8a4b0b;
  --bubble-in: #ffffff;
  --bubble-out: #e2f3dc;
  --chat-bg: #eceff2;
  --side: #1c2533;
  --side-2: #263142;
  --side-ink: #b7c0cd;
  --side-muted: #7d8899;
  --tip-bg: #0f172a;
  --tip-ink: #f8fafc;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, .16);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17; --panel: #121826; --panel-2: #0f1520; --hover: #1a2233; --border: #222b3b; --border-strong: #2e3a4f;
    --text: #e6eaf0; --text-2: #c3cad6; --muted: #8b96a8; --accent: #5b9be6; --accent-hover: #7cb0ec; --accent-ink: #0b1220;
    --accent-soft: #16263d; --accent-ring: rgba(91, 155, 230, .3); --warn-bg: #2a1e0b; --warn-border: #5c4113; --warn-ink: #f5c77a;
    --bubble-in: #1a2233; --bubble-out: #1d3324; --chat-bg: #0d121b; --side: #0d121b; --side-2: #1a2230;
    --tip-bg: #e6eaf0; --tip-ink: #0b0f17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25); color-scheme: dark;
  }
}

/* ============================================================ base */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 11px; width: 100%; min-height: 38px; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 5px; font-weight: 400; color: var(--text); font-size: 14px; }
h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h3 { margin: 0 0 12px; font-size: 14.5px; font-weight: 600; }
code { background: var(--panel-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ============================================================ botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  border-radius: var(--radius-sm); padding: 0 14px; height: 38px; cursor: pointer; white-space: nowrap;
  font-weight: 500; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--hover); }
.btn:focus-visible, .icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(220, 38, 38, .08); border-color: rgba(220, 38, 38, .4); }
.btn.small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.small svg { width: 15px; height: 15px; }
.btn.block { width: 100%; height: 42px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 0; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: rgba(148, 163, 184, .15); }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; font-size: 13px; }

/* ============================================================ ingreso */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.login-card h1 { margin: 0 0 18px; font-size: 18px; font-weight: 600; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-size: 15px; color: var(--text-2); }
.login-brand b { color: var(--text); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 15px; color: #fff; letter-spacing: -.01em; }
.brand small { display: block; font-size: 11.5px; color: var(--side-ink); }
.brand.big b { font-size: 22px; }
.brand.big small { font-size: 13.5px; color: #94a3b8; }
.logo { width: 32px; height: 32px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; }
.logo svg { width: 58%; height: 58%; stroke-width: 2; }

/* ============================================================ layout */
.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 16px 12px; gap: 2px; overflow-y: auto; }
.sidebar .brand { padding: 4px 8px 18px; }
.nav-group { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 14px 10px 6px; }
.sidebar a {
  position: relative; display: flex; align-items: center; gap: 11px; color: var(--side-ink); text-decoration: none;
  padding: 8px 10px; border-radius: 6px; font-weight: 500; transition: background .15s, color .15s;
}
.sidebar a:hover { background: var(--side-2); color: #fff; }
.sidebar a.active { background: var(--side-2); color: #fff; }
.sidebar a.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; background: #8fb6e8; }
.sidebar a.active svg { color: #fff; }
.sidebar .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding-top: 16px; display: grid; gap: 10px; }
.wa-status { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 6px 10px; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--side-2); }
.me-avatar { width: 32px; height: 32px; border-radius: 50%; background: #334155; color: #e2e8f0; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.me-info { min-width: 0; flex: 1; }
.me-info b { display: block; color: #e2e8f0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-info small { color: var(--side-muted); font-size: 11.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.view { overflow: auto; min-width: 0; }
.page { padding: 28px 32px; max-width: 1240px; }
.page-title h2 + p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.badge { background: #d64545; color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; line-height: 18px; }
.badge.warn { background: #d97706; color: #fff; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input, .toolbar select { width: auto; min-width: 170px; }
.toolbar .spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }

/* ============================================================ tooltip */
.tip {
  position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; max-width: 280px;
  background: var(--tip-bg); color: var(--tip-ink); padding: 7px 10px; border-radius: 4px; font-size: 12.5px; line-height: 1.4;
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .12s; transform: translate(-9999px, 0);
}
.tip.show { opacity: 1; }
.tip b { display: block; font-size: 13px; margin-bottom: 2px; }
.tip span { opacity: .8; }

/* ============================================================ etiquetas y chips */
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; white-space: nowrap; }
.tag button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 13px; line-height: 1; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 4px; white-space: nowrap; border: 1px solid transparent; }
.chip.red { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.chip.orange { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }
.chip.yellow { background: #fefce8; color: #a16207; border-color: #fde68a; }
.chip.green { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.chip.grey { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
@media (prefers-color-scheme: dark) {
  .chip.red { background: #3b0f0f; color: #fca5a5; border-color: #5b1a1a; }
  .chip.orange { background: #3a1d0a; color: #fdba74; border-color: #5a2d10; }
  .chip.yellow { background: #33290a; color: #fde047; border-color: #4d3d0f; }
  .chip.green { background: #0b2e1e; color: #86efac; border-color: #14532d; }
  .chip.grey { background: #1e2533; color: #cbd5e1; border-color: #2e3a4f; }
}
.plate {
  display: inline-block; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 700; font-size: 12.5px; letter-spacing: .08em;
  background: #f6d34a; color: #111; border: 1px solid #333; border-radius: 3px; padding: 0 6px;
}

/* ============================================================ bandeja */
.inbox { display: grid; grid-template-columns: 330px 1fr 320px; height: 100vh; }
.convlist { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.convlist-head { padding: 16px 14px 12px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.tabs { display: inline-flex; gap: 2px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--border); padding: 3px; border-radius: 6px; }
.tabs button { border: 0; background: transparent; border-radius: 4px; padding: 5px 11px; font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); font-weight: 600; }
.convs { overflow: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 42px 1fr auto; gap: 11px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.conv:hover { background: var(--hover); }
.conv.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #dfe4ea; color: #3b4656; font-weight: 600; font-size: 13.5px; flex: none; }
@media (prefers-color-scheme: dark) { .avatar { background: #2a3445; color: #cbd3de; } }
.conv-main { min-width: 0; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { text-align: right; font-size: 11.5px; color: var(--muted); display: grid; gap: 4px; justify-items: end; align-content: start; }
.conv-agent { font-size: 11px; color: var(--muted); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: 64px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 140px; }
.chat-head .who b { display: block; font-size: 15px; }
.chat-head .who span { font-size: 12.5px; }
.chat-head select { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }
.messages { flex: 1; overflow: auto; padding: 20px 7%; display: flex; flex-direction: column; gap: 4px; }
.bubble { max-width: 68%; padding: 7px 11px 5px; border-radius: 8px; box-shadow: 0 1px 1px rgba(15, 23, 42, .08); white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: var(--bubble-in); align-self: flex-start; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; }
.bubble .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.bubble .tick.read { color: #0ea5e9; }
.bubble .tick.failed { color: var(--danger); }
.bubble.failed { outline: 1px solid var(--danger); }
.day-sep { align-self: center; color: var(--muted); font-size: 11.5px; margin: 10px 0; text-transform: capitalize; }
.composer { display: flex; gap: 8px; padding: 12px 14px; background: var(--panel); border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { resize: none; max-height: 140px; }
.composer .btn { height: 40px; }
.window-warn { background: var(--warn-bg); color: var(--warn-ink); border-top: 1px solid var(--warn-border); padding: 9px 16px; font-size: 13px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 40px 24px; }
.empty-ico { width: 40px; height: 40px; margin: 0 auto 10px; display: grid; place-items: center; color: var(--muted); }
.empty-ico svg { width: 26px; height: 26px; }

.details { border-left: 1px solid var(--border); background: var(--panel); overflow: auto; padding: 18px; }
.details section { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.details section:last-child { border-bottom: 0; }
.details h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.details .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 8px; white-space: pre-wrap; font-size: 13px; }
.note small { display: block; color: var(--muted); margin-top: 4px; }

/* ============================================================ tablas */
.table-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { position: sticky; top: 0; z-index: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================ embudo */
.board { display: flex; gap: 14px; overflow-x: auto; padding: 0 32px 24px; align-items: flex-start; min-height: calc(100vh - 110px); }
.col { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); width: 270px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 130px); }
.col-head { padding: 12px 14px; border-top: 3px solid; border-radius: var(--radius) var(--radius) 0 0; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; background: var(--panel); border-bottom: 1px solid var(--border); }
.col-head small { color: var(--muted); font-weight: 500; }
.col-body { padding: 10px; display: grid; gap: 8px; overflow: auto; min-height: 70px; align-content: start; }
.col.drop .col-body { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 0 0 var(--radius) var(--radius); }
.deal { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; cursor: grab; display: grid; gap: 4px; }
.deal:hover { border-color: var(--border-strong); }
.deal:active { cursor: grabbing; }
.deal .value { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============================================================ métricas */
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 6px 0 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .value a { color: inherit; text-decoration: none; }
.kpi .value a:hover { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 120px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.bar-track { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.daily { display: flex; align-items: flex-end; gap: 3px; height: 170px; border-bottom: 1px solid var(--border); }
.daily .day { flex: 1; display: flex; flex-direction: column-reverse; gap: 1px; height: 100%; justify-content: flex-start; min-width: 2px; }
.daily .seg-in { background: #0ea5e9; border-radius: 3px 3px 0 0; }
.daily .seg-out { background: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }

/* ============================================================ SOAT y recordatorios */
.mini { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-top: 8px; display: grid; gap: 5px; font-size: 13px; }
.mini-title { display: inline-flex; align-items: center; gap: 6px; }
.mini-title svg { width: 15px; height: 15px; color: var(--muted); }
.mini .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.rem { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px; }
.rem.overdue { box-shadow: inset 3px 0 0 var(--danger); }
.rem .ico { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.rem.overdue .ico { background: rgba(220, 38, 38, .1); color: var(--danger); }
.rem .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.rem .actions select { width: auto; min-height: 30px; padding: 3px 8px; font-size: 12.5px; }
.rem-ico { width: 38px; height: 38px; border-radius: 6px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); flex: none; }
.rem-ico svg { width: 22px; height: 22px; }
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }

/* ============================================================ modal y avisos */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 22px; width: 100%; max-width: 460px; box-shadow: var(--shadow-lg); max-height: 92vh; overflow: auto; animation: pop .18s; }
.modal h3 { font-size: 17px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--border); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 60; max-width: calc(100vw - 36px); }
.toast { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow-lg); max-width: 380px; cursor: pointer; animation: slide .2s; font-size: 13.5px; }
.toast.error { border-left-color: var(--danger); }
.toast.action { border-left-color: #d97706; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; } }
@keyframes slide { from { opacity: 0; transform: translateX(20px); } }

.settings-row { display: grid; grid-template-columns: 1fr 60px 140px auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.settings-row input[type=color], input[type=color] { padding: 3px; height: 38px; cursor: pointer; }
pre.code { background: var(--panel-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius-sm); overflow: auto; font-size: 12.5px; }

/* ============================================================ responsive */
/* Pantallas medianas: menú solo con íconos (el nombre aparece al pasar el mouse) */
@media (max-width: 1180px) {
  .app { grid-template-columns: 72px 1fr; }
  .sidebar { padding: 14px 10px; align-items: center; }
  .sidebar .brand { padding: 2px 0 14px; }
  .brand-text, .nav-label, .nav-group, .me-info, .wa-status-text { display: none; }
  .sidebar a { justify-content: center; width: 48px; height: 44px; padding: 0; }
  .sidebar a.active::before { left: -10px; }
  .sidebar a svg { width: 20px; height: 20px; }
  .sidebar .badge { position: absolute; top: 3px; right: 1px; margin: 0; font-size: 10px; min-width: 18px; padding: 0 5px; line-height: 16px; }
  .sidebar-foot { justify-items: center; }
  .wa-status { padding: 8px; }
  .me { flex-direction: column; border: 0; padding: 0; gap: 6px; }
  .inbox { grid-template-columns: 300px 1fr; }
  .details { display: none; }
  .inbox.show-details .details { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100vw); z-index: 20; box-shadow: var(--shadow-lg); }
  .page { padding: 24px; }
  .board { padding: 0 24px 24px; }
}
/* Teléfonos y ventanas angostas: menú abajo con íconos y nombre corto */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { order: 2; flex-direction: row; padding: 4px 6px; overflow-x: auto; gap: 0; align-items: stretch; border-top: 1px solid var(--side-2); }
  .sidebar .brand, .sidebar-foot, .nav-group { display: none; }
  .sidebar a { flex: 1 0 70px; max-width: 96px; width: auto; height: 58px; padding: 4px 3px; flex-direction: column; justify-content: center; gap: 3px; border-radius: 8px; }
  .sidebar a .nav-label { display: block; font-size: 10px; font-weight: 500; white-space: normal; text-align: center; line-height: 1.15; }
  .sidebar a.active::before { left: 18px; right: 18px; top: -4px; bottom: auto; width: auto; height: 2px; }
  .sidebar .badge { right: 8px; }
  .view { height: calc(100vh - 67px); }
  .inbox { grid-template-columns: 1fr; height: 100%; }
  .inbox .chat { display: none; }
  .inbox.chat-open .convlist { display: none; }
  .inbox.chat-open .chat { display: flex; }
  .page { padding: 16px; }
  .board { padding: 0 16px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
  .settings-row { grid-template-columns: 1fr 50px; }
  .rem { grid-template-columns: auto 1fr; }
  .rem .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 32px 24px; gap: 20px; }
  .login-points { display: none; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1 1 140px; }
}

/* acciones de fila y rango de fechas */
.row-actions { display: flex; gap: 4px; flex-wrap: nowrap; justify-content: flex-end; }
.date-range { display: inline-flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.date-range input { width: 150px; min-width: 0; }

/* consultar placa */
.consulta { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 18px; align-items: start; }
.q-preview { position: sticky; top: 16px; padding: 14px; }
.q-preview canvas { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 4px; background: #eef1f5; }
.q-actions { display: flex; gap: 8px; margin-top: 12px; }
.q-actions .btn.primary { flex: 1; }
.form-sec { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.tabs + .form-sec { border-top: 0; padding-top: 0; margin-top: 4px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text-2); font-size: 13px; }
label.check input { width: auto; min-height: 0; margin: 0; }
.bubble-img { display: block; max-width: 260px; width: 100%; border-radius: 6px; margin-bottom: 4px; cursor: zoom-in; border: 1px solid var(--border); }
@media (max-width: 1180px) { .consulta { grid-template-columns: minmax(0, 1fr) 340px; } }
@media (max-width: 900px) { .consulta { grid-template-columns: 1fr; } .q-preview { position: static; max-width: 460px; } .grid-3 { grid-template-columns: 1fr 1fr; } }

/* panel "Para gestionar" */
.manage { margin-bottom: 14px; padding: 16px 20px; }
.manage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.manage-head h3 { display: inline; margin: 0 10px 0 0; }
.manage-head .muted { font-size: 13px; }
.manage-total { font-size: 30px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.buckets { display: flex; flex-wrap: wrap; gap: 8px; }
.bucket {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 8px 14px; cursor: pointer; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--c, var(--border-strong)); border-radius: 6px;
}
.bucket:hover { background: var(--hover); }
.bucket b { font-size: 20px; font-variant-numeric: tabular-nums; }
.bucket span { font-size: 13px; color: var(--text-2); }
.bucket.zero b, .bucket.zero span { color: var(--muted); opacity: .7; }
.bucket.agent { border-left-width: 1px; }
.bucket.agent span { text-transform: uppercase; font-size: 12.5px; letter-spacing: .02em; }
.bucket.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.bucket.active[style] { border-left-color: var(--c); }
.kpis-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi .label .dot { width: 7px; height: 7px; vertical-align: 1px; }
.inline-select { width: auto; min-height: 30px; padding: 3px 8px; font-size: 12.5px; font-weight: 600; }
.inline-select.sold { color: #1e7b45; border-color: #bfe0cb; }
.inline-select.not_sold { color: #b42318; border-color: #f0c4be; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: wait; }
.months { display: flex; align-items: flex-end; gap: 14px; height: 190px; border-bottom: 1px solid var(--border); padding: 0 6px; }
.month { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; position: relative; }
.month .num { font-size: 12px; color: var(--text-2); }
.month .mbar { width: 60%; max-width: 46px; min-height: 2px; background: var(--accent); border-radius: 3px 3px 0 0; }
.month small { position: absolute; bottom: -22px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.months + * { margin-top: 30px; }
@media (max-width: 1180px) { .kpis-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .kpis-5 { grid-template-columns: 1fr 1fr; } .manage-head { flex-direction: column; } }
a.btn { text-decoration: none; }
.months { margin-bottom: 30px; }

/* historial de etapas y movimientos automáticos */
.moves { display: grid; gap: 10px; }
.move { display: grid; grid-template-columns: 10px 1fr; gap: 10px; align-items: start; font-size: 13px; }
.move-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; }
.conv-row { grid-template-columns: 130px 1fr 150px; }
.conv-row small { font-size: 11.5px; }
.auto-row { display: grid; grid-template-columns: 1fr 260px; gap: 12px; align-items: center; font-size: 13.5px; color: var(--text); font-weight: 400; }
.auto-row select { margin: 0; }
@media (max-width: 760px) { .auto-row { grid-template-columns: 1fr; } .conv-row { grid-template-columns: 100px 1fr 110px; } }

/* mostrar / ocultar contraseña */
.pw-wrap { position: relative; display: block; margin-top: 5px; }
.pw-wrap input { margin-top: 0 !important; padding-right: 44px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 32px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 4px; }
.pw-eye:hover { color: var(--text); background: var(--hover); }
.pw-eye:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

/* vinculación por QR */
.qr-wrap { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 10px; }
.qr-img { width: 220px; height: 220px; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 6px; }
.qr-steps { margin: 0 0 8px; padding-left: 20px; font-size: 13.5px; display: grid; gap: 6px; }
.qr-risk { font-size: 12.5px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-border); border-radius: 6px; padding: 8px 10px; }
.file-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; }
.bubble audio { max-width: 260px; display: block; }

/* archivos y grupos */
.attach-btn { width: 40px; height: 40px; padding: 0; flex: none; }
.chat.dropping .messages { outline: 2px dashed var(--accent); outline-offset: -10px; background: var(--accent-soft); }
.files { display: grid; gap: 6px; }
.file-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.file-main { min-width: 0; }
.file-main a { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.file-ico { display: grid; place-items: center; color: var(--muted); }
.file-ico.big svg { width: 34px; height: 34px; }
.file-preview { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.file-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; }
.group-tag { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #6d28d9; background: #f3e8ff; border-radius: 3px; padding: 0 5px; vertical-align: 1px; }
.group-tag svg { width: 12px; height: 12px; }
.group-tag.big { font-size: 11.5px; padding: 3px 8px; }
@media (prefers-color-scheme: dark) { .group-tag { color: #d8b4fe; background: #3b1f5c; } }
.bubble .sender { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }

/* llamadas */
.call-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.call-qr { width: 150px; height: 150px; background: #fff; border-radius: 4px; padding: 4px; border: 1px solid var(--border); }
.call-number { font-size: 22px; font-weight: 700; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.call-box .btn { margin-top: 4px; }
.call-item { align-self: center; max-width: 80%; display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: center; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; margin: 6px 0; color: var(--text-2); }
.call-item svg { width: 15px; height: 15px; color: var(--muted); }
.call-item.answered svg { color: #1e7b45; }
.call-item.wrong_number svg { color: var(--danger); }
.call-note { grid-column: 2; color: var(--muted); white-space: pre-wrap; }

/* respuestas rápidas y notas de voz */
.composer { position: relative; }
.qr-pop { position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px); max-height: 320px; overflow: auto; z-index: 15;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 4px; }
.qr-item { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.qr-item span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.qr-item.active, .qr-item[data-i]:hover { background: var(--accent-soft); }
.qr-manage { display: block; padding: 8px 10px; font-size: 12.5px; border-top: 1px solid var(--border); text-decoration: none; }
.composer.recording > :not(.rec-bar):not(.qr-pop) { display: none; }
.rec-bar { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; }
.rec-bar .spacer { flex: 1; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #d64545; animation: rec 1s infinite; }
@keyframes rec { 50% { opacity: .25; } }

/* encabezado del chat, historial y programados */
.head-actions { display: inline-flex; gap: 2px; }
.head-btn { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-2); }
.head-btn.on { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }
.stage-chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--panel-2); font: inherit; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-chip:hover { background: var(--hover); }
.stage-menu { position: fixed; z-index: 70; width: 280px; max-height: 420px; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 8px; }
.stage-tabs { display: flex; margin-bottom: 6px; }
.stage-tabs button { flex: 1; }
.stage-list { overflow: auto; display: grid; gap: 1px; }
.stage-opt { display: flex; align-items: center; gap: 9px; text-align: left; border: 0; background: transparent; font: inherit; font-size: 13.5px; color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.stage-opt:hover { background: var(--hover); }
.stage-opt.current { font-weight: 700; }
.stage-opt small { color: var(--muted); font-weight: 400; }
.avatar.tiny { width: 22px; height: 22px; font-size: 10px; }
.modal.wide { max-width: 640px; }
.history { display: grid; gap: 4px; max-height: 60vh; overflow: auto; }
.h-item { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.h-item:last-child { border-bottom: 0; }
.h-ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.h-ico svg { width: 14px; height: 14px; }
.h-detail { color: var(--text-2); white-space: pre-wrap; margin: 2px 0; }
#scheduled:empty { display: none; }
#scheduled { display: grid; gap: 4px; padding: 6px 14px; background: var(--panel); border-top: 1px solid var(--border); }
.sched { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.sched svg { width: 14px; height: 14px; color: var(--accent); flex: none; }
.sched.failed svg { color: var(--danger); }
.sched-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* aviso automático de vencimiento */
.auto-notice { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--accent); margin-top: 3px; }
.auto-notice svg { width: 12px; height: 12px; }

/* SMS */
.sms-tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .05em; color: #0f5f8c; background: #e0f2fe; border-radius: 3px; padding: 0 5px; margin-bottom: 3px; }
@media (prefers-color-scheme: dark) { .sms-tag { color: #7dd3fc; background: #0c3a52; } }

/* Mi app */
.install-how { border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; background: var(--panel-2); font-size: 13.5px; }
.install-how ol { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 4px; }
/* en el celular instalado, respetar la zona de la barra de estado */
@supports (padding-top: env(safe-area-inset-top)) {
  @media (display-mode: standalone) { body { padding-top: env(safe-area-inset-top); } .sidebar { padding-bottom: max(4px, env(safe-area-inset-bottom)); } }
}

/* ---- CRM Eventos: ventas, eventos y localidades */
.inline-select.pending { color: #a16207; border-color: #fde68a; }
.inline-select.paid { color: #c2410c; border-color: #fed7aa; }
.kpi-btn { text-align: left; font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--border); }
.kpi-btn:hover { border-color: var(--accent); }
.kpi-btn.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.event-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.event-card { display: flex; flex-direction: column; gap: 8px; }
.event-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.event-head h3 { margin: 0 0 2px; }
.event-head .muted { font-size: 13px; }
table.zones { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 6px; }
table.zones th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.zones td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
table.zones .num { text-align: right; font-variant-numeric: tabular-nums; }
.event-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; margin-top: auto; padding-top: 6px; }
.zone-head, .zone-row { display: grid; grid-template-columns: 1.4fr 1fr 0.8fr auto; gap: 8px; align-items: center; }
.zone-head { font-size: 12px; margin-bottom: 4px; }
.zone-row { margin-bottom: 8px; }
.zone-row input { min-width: 0; }
@media (max-width: 760px) {
  .event-grid { grid-template-columns: 1fr; }
  .zone-head { display: none; }
  .zone-row { grid-template-columns: 1fr 1fr; }
  .zone-row input[data-k="name"] { grid-column: 1 / -1; }
}
