:root {
  --bg: #f4f6fa; --fg: #182230; --muted: #667085; --line: #e3e8ef; --brand: #1f5eff; --brand-dark: #1747c4; --nav: #0f1b33; --nav-fg: #cdd6e8;
  --green: #d9fdd3; --ok: #16713d; --warn: #8a5a00; --bad: #b42318; --card: #fff; --wa-bg: #efeae2;
  --safe-bottom: env(safe-area-inset-bottom, 0px); --safe-top: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 Inter, "Segoe UI", system-ui, sans-serif; overscroll-behavior-y: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
a { color: var(--brand); }
input, textarea, select, button { font: inherit; }
input, textarea, select { width: 100%; padding: 9px 12px; border: 1px solid #d0d7e2; border-radius: 8px; background: #fff; color: var(--fg); }
input[type=checkbox] { width: auto; }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 94, 255, .15); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; color: var(--fg); }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0 12px 6px 0; color: var(--fg); font-size: 14px; }
button { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
button:hover:not(:disabled) { filter: brightness(.93); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: #eef1f6; color: var(--fg); }
button.danger { background: #d92d20; }
button.sm { padding: 6px 12px; font-size: 13px; }
button.link { background: none; color: var(--brand); padding: 0; font-weight: 500; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(16, 24, 40, .06); }
.error { color: #a4282a; background: #fde8e8; border: 1px solid #f7c6c6; padding: 8px 12px; border-radius: 8px; margin: 8px 0; }
.ok-box { color: var(--ok); background: #e3f6ea; border: 1px solid #b7e4c7; padding: 8px 12px; border-radius: 8px; margin: 8px 0; word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Acceso */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #0f1b33, #1f3b78); }
.login .card { width: min(400px, 100%); }
.login button { width: 100%; margin-top: 4px; }
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.logo img { width: 44px; height: 44px; border-radius: 10px; }
.logo strong { font-size: 20px; }

/* Estructura */
.shell { height: 100dvh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.side { background: var(--nav); color: var(--nav-fg); display: flex; flex-direction: column; padding: 14px 10px; gap: 6px; overflow: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 8px 12px; }
.side .brand img { width: 30px; height: 30px; border-radius: 8px; }
.navlink { display: flex; align-items: center; gap: 10px; background: transparent; color: var(--nav-fg); padding: 9px 12px; border-radius: 8px; text-align: left; width: 100%; font-weight: 500; }
.navlink:hover:not(:disabled) { background: #1b2a4a; }
.navlink.active { background: #243a6b; color: #fff; }
.navlink .ico { width: 22px; text-align: center; }
.badge { background: #e53935; color: #fff; border-radius: 99px; padding: 0 7px; font-size: 12px; font-weight: 700; margin-left: auto; min-width: 20px; text-align: center; }
.side .spacer { flex: 1; }
.side .who { padding: 8px; font-size: 13px; border-top: 1px solid #243253; margin-top: 6px; }
.side .who strong { color: #fff; display: block; }
.pill { font-size: 12.5px; font-weight: 600; padding: 4px 12px; border-radius: 99px; background: #e8ebf0; color: #4a5566; white-space: nowrap; display: inline-block; }
.pill.ok { background: #d8f5e4; color: var(--ok); }
.pill.warn { background: #fff0cc; color: var(--warn); }
.pill.bad { background: #fde1e1; color: #a4282a; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.mobilebar { display: none; }
.view { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 20px; max-width: 1100px; margin: 0 auto; display: grid; gap: 16px; align-content: start; }
.page > h1 { font-size: 22px; margin: 0; }
.tabbar { display: none; }
.offline { background: #8a5a00; color: #fff; text-align: center; padding: 4px; font-size: 13px; }

/* Tarjetas e indicadores */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.alert .n { color: var(--bad); }
.kpi button { margin-top: 6px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 130px 1fr 44px; gap: 8px; align-items: center; font-size: 13px; }
.bar .track { background: #eef1f6; border-radius: 6px; height: 14px; overflow: hidden; }
.bar .fill { background: var(--brand); height: 100%; border-radius: 6px; }
.daily { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.daily .col { flex: 1; max-width: 36px; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr.click { cursor: pointer; }
tr.click:hover { background: #f4f7fb; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c5ccd8; margin-right: 6px; }
.dot.on { background: #25d366; }

/* Etiquetas de estado */
.chip { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eef1f6; color: #4a5566; white-space: nowrap; }
.st-NEW { background: #e0ebff; color: #1747c4; }
.st-IN_PROGRESS { background: #d8f5e4; color: var(--ok); }
.st-PENDING { background: #fff0cc; color: var(--warn); }
.st-TRANSFERRED { background: #efe0ff; color: #6b21a8; }
.st-CLOSED { background: #e8ebf0; color: #4a5566; }
.pr-URGENT { background: #fde1e1; color: #a4282a; }
.pr-HIGH { background: #ffe8d1; color: #9a4a00; }
.pr-LOW { background: #eef1f6; color: #667085; }
.lv-GOLD { background: #fff0cc; color: var(--warn); }
.lv-VIP { background: #efe0ff; color: #6b21a8; }
.lv-SILVER { background: #e8ebf0; color: #4a5566; }
.tag { color: #fff; }

/* Chats */
.chats { height: 100%; display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.chats.info-open { grid-template-columns: 340px minmax(0, 1fr) 320px; }
.list { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; gap: 8px; padding: 10px; }
.filters { display: flex; gap: 6px; padding: 0 10px 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.fchip { background: #eef1f6; color: var(--fg); padding: 4px 11px; font-size: 13px; border-radius: 99px; font-weight: 500; }
.fchip.active { background: var(--brand); color: #fff; }
.filters select { width: auto; padding: 4px 8px; font-size: 13px; }
.convs { overflow: auto; flex: 1; padding: 6px; }
.conv { width: 100%; text-align: left; background: #fff; color: inherit; border-radius: 10px; padding: 9px 10px; font-weight: 400; display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; border: 1px solid transparent; }
.conv:hover:not(:disabled) { background: #f4f7fb; }
.conv.active { background: #e8f0ff; border-color: #c5d7fb; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: #dbe5fb; color: var(--brand-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; position: relative; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv .top strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .last { color: #5b6677; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; align-items: center; }
.conv .unread { background: #25d366; color: #fff; border-radius: 99px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.pdot { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid #fff; background: #c5ccd8; }
.pdot.URGENT { background: #d92d20; }
.pdot.HIGH { background: #f79009; }
.pdot.NORMAL { background: #3b82f6; }
.pane { background: var(--wa-bg); min-width: 0; min-height: 0; display: flex; }
.empty { margin: auto; text-align: center; padding: 20px; }
.chat { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #f7f9fc; border-bottom: 1px solid var(--line); }
.chat-head .who { flex: 1; display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.chat-head .who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 6px; padding: 6px 12px; background: #f7f9fc; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.back { display: none; }
.msgs { flex: 1; min-height: 0; overflow: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.m { display: flex; }
.m.out { justify-content: flex-end; }
.bubble { max-width: min(560px, 80%); padding: 7px 10px 4px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); background: #fff; overflow-wrap: anywhere; }
.m.out .bubble { background: var(--green); }
.m.ai .bubble { background: #e6efff; }
.bubble .who { font-size: 12px; font-weight: 600; color: var(--brand-dark); }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { font-size: 11px; color: #667781; text-align: right; margin-top: 2px; }
.bubble .meta.fail { color: var(--bad); }
.bubble img.pic { max-width: 260px; max-height: 240px; border-radius: 8px; display: block; cursor: zoom-in; margin-bottom: 4px; }
.bubble audio, .bubble video { max-width: 260px; display: block; margin-bottom: 4px; }
.bubble a.doc { display: inline-block; background: rgba(0, 0, 0, .06); border-radius: 8px; padding: 6px 10px; margin-bottom: 4px; color: inherit; text-decoration: none; }
.read { color: #2196f3; }
.sep { align-self: center; background: #fff; color: var(--muted); font-size: 12px; padding: 2px 10px; border-radius: 8px; margin: 6px 0; }
.sep.case { background: #dbe5fb; color: var(--brand-dark); }
.note { align-self: center; max-width: 86%; background: #fff8d6; border: 1px solid #f1e08a; border-radius: 8px; padding: 6px 10px; font-size: 13.5px; }
.note small { color: #7a6a00; display: block; }
.composer { padding: 8px 12px calc(8px + var(--safe-bottom)); background: #f0f2f5; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; border-radius: 20px; padding: 9px 14px; width: auto; }
.iconbtn { font-size: 18px; padding: 6px 10px; background: #e4e8ef; color: var(--fg); }
.composer .row { flex-wrap: nowrap; }
.composer textarea { min-width: 0; }
.iconbtn.rec { background: #d92d20; color: #fff; }
.attached { display: flex; gap: 8px; align-items: center; background: #fff; border: 1px solid #d5dbe6; border-radius: 8px; padding: 4px 8px; margin-bottom: 6px; font-size: 13px; }
.recbar { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid #f7c6c6; border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; }
.recbar .blink { width: 10px; height: 10px; border-radius: 50%; background: #d92d20; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.linkbox { background: #fff8e1; border-bottom: 1px solid #f1d98a; padding: 10px 16px; font-size: 13.5px; }
.linkbox input { max-width: 260px; }
.lightbox { position: fixed; inset: 0; background: rgba(15, 27, 51, .75); display: flex; align-items: center; justify-content: center; z-index: 50; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: 8px; }
.infopanel { background: #fff; border-left: 1px solid var(--line); overflow: auto; padding: 14px; display: grid; gap: 14px; align-content: start; }
.infopanel h3 { margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 124px 1fr; gap: 4px 8px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.tagrow { display: flex; gap: 6px; flex-wrap: wrap; }
.tagbtn { padding: 3px 10px; font-size: 12.5px; border-radius: 99px; background: #eef1f6; color: var(--fg); border: 2px solid transparent; }
.tagbtn.on { color: #fff; }

/* Cuadros de diálogo y avisos */
.dlg { border: 0; border-radius: 14px; padding: 18px; width: min(460px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(15, 27, 51, .35); color: var(--fg); }
.dlg::backdrop { background: rgba(15, 27, 51, .5); }
.checks { margin-top: 6px; }
.toast { position: fixed; top: calc(12px + var(--safe-top)); right: 12px; background: var(--nav); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); max-width: min(360px, calc(100vw - 24px)); cursor: pointer; }
.notif { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); cursor: pointer; background: #fff; }
.notif.unread { background: #eef4ff; }
.notif:hover { background: #f4f7fb; }
.notif .ic { font-size: 22px; text-align: center; }
.code { font: 700 28px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 4px; background: #eef1f6; padding: 10px 16px; border-radius: 8px; display: inline-block; }
.qr { width: min(320px, 100%); border: 1px solid var(--line); border-radius: 10px; }
.big { font-size: 20px; font-weight: 700; margin: 4px 0; }
.result { background: #f4f7fb; border: 1px solid var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 14px; }
.menu-list { display: grid; gap: 8px; }
.menu-list button { text-align: left; background: #fff; color: var(--fg); border: 1px solid var(--line); padding: 14px; display: flex; gap: 12px; align-items: center; }

/* Celular y tableta: barra inferior tipo aplicación */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side { display: none; }
  .mobilebar { display: flex; align-items: center; gap: 10px; background: var(--nav); color: #fff; padding: calc(8px + var(--safe-top)) 14px 8px; }
  .mobilebar strong { flex: 1; font-size: 17px; }
  .mobilebar .pill { font-size: 11px; padding: 2px 9px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
  .tabbar button { background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; padding: 7px 2px; border-radius: 0; font-weight: 600; position: relative; }
  .tabbar button .ico { font-size: 20px; }
  .tabbar button.active { color: var(--brand); }
  .tabbar .badge { position: absolute; top: 2px; left: 55%; margin: 0; font-size: 10px; padding: 0 5px; min-width: 16px; }
  .page { padding: 14px; }
  .chats, .chats.info-open { grid-template-columns: 1fr; }
  .chats .pane, .chats .infopanel { display: none; }
  .chats.open .list { display: none; }
  .chats.open .pane { display: flex; }
  .chats.open.info-open .pane { display: none; }
  .chats.open.info-open .infopanel { display: grid; }
  .back { display: inline-block; }
  .bubble { max-width: 88%; }
  .msgs { padding: 10px; }
  input, textarea, select { font-size: 16px; }
  .bar { grid-template-columns: 96px 1fr 38px; }
  .composer .iconbtn { padding: 6px 8px; font-size: 17px; }
  .composer .row { gap: 5px; }
  .composer .sendbtn { padding: 9px 12px; }
  .toast { left: 12px; right: 12px; max-width: none; }
}

.grid-gap { display: grid; gap: 16px; }

.bubble video.thumb { width: 260px; max-width: 100%; max-height: 300px; border-radius: 8px; background: #000; }

.mini { display: flex; align-items: center; gap: 8px; }
.mini .track { width: 90px; background: #eef1f6; border-radius: 6px; height: 10px; overflow: hidden; }
.mini .fill { background: var(--brand); height: 100%; }

/* Inscripción pública */
.signup { width: min(460px, 100%); }
.signup button { width: 100%; }
.perks { margin: 8px 0 14px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.trap { position: absolute; left: -10000px; height: 0; overflow: hidden; }
.center { text-align: center; }
a.btn { display: block; text-align: center; background: var(--brand); color: #fff; padding: 11px 16px; border-radius: 8px; font-weight: 600; text-decoration: none; margin-top: 12px; }
.trialbar { background: #fff0cc; color: var(--warn); text-align: center; padding: 6px 12px; font-size: 13.5px; font-weight: 600; }
.trialbar.urgent { background: #fde1e1; color: #a4282a; }

/* Botón de soporte por WhatsApp */
.wa-float { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; align-items: center; gap: 6px; background: #25d366; color: #fff; text-decoration: none; font-weight: 700; padding: 11px 16px; border-radius: 99px; box-shadow: 0 6px 18px rgba(0, 0, 0, .28); }
.wa-float:hover { filter: brightness(.94); }
.wa-float .ico { font-size: 20px; line-height: 1; }
@media (max-width: 860px) {
  .shell:not(.hidden) ~ .wa-float { bottom: calc(76px + var(--safe-bottom)); right: 12px; padding: 12px; }
  .shell:not(.hidden) ~ .wa-float .txt { display: none; }
}
button.wa-float { border: 0; cursor: pointer; font: inherit; font-weight: 700; }
.wa-menu { position: fixed; right: 16px; bottom: 72px; z-index: 41; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); overflow: hidden; display: grid; min-width: 170px; }
.wa-menu a { padding: 12px 16px; color: var(--fg); text-decoration: none; font-weight: 600; }
.wa-menu a:hover { background: #eefaf2; }
.wa-menu a + a { border-top: 1px solid var(--line); }
@media (max-width: 860px) { .shell:not(.hidden) ~ .wa-menu { bottom: calc(132px + var(--safe-bottom)); right: 12px; } }

/* Datos de la empresa */
.logo-box { display: flex; align-items: center; justify-content: center; min-height: 160px; background: #f4f7fb; border: 1px dashed #c9d3e3; border-radius: 12px; margin-bottom: 10px; padding: 12px; }
.company-logo { max-width: 100%; max-height: 140px; object-fit: contain; border-radius: 8px; }
.company-logo.empty { display: flex; align-items: center; justify-content: center; width: 140px; height: 100px; }
.company-logo.small { width: 44px; height: 44px; max-height: 44px; border-radius: 10px; }
.side .brand img { object-fit: cover; }
.side .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo img { object-fit: cover; }

/* Panel de comandos */
.cmd-layout { align-items: start; }
.cmd-layout textarea { width: 100%; }
.wa-preview { background: #d9fdd3; border-radius: 10px; padding: 12px 14px; font-size: 14px; line-height: 1.45; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); overflow-wrap: anywhere; }
.wa-preview .gap { height: 8px; }
.cmd-layout td code { background: #eef1f6; padding: 2px 6px; border-radius: 5px; white-space: nowrap; }
.cmd-layout td { vertical-align: top; }
