:root {
  color-scheme: light;
  /* Paleta de QA Multicanal (app/web/templates/base.html) */
  --bg: #f4f5f7; --card: #fff; --text: #1a1a1a; --muted: #6b7280; --line: #e5e7eb; --line-2: #d1d5db;
  --brand: #6b4e8c; --brand-d: #563d73; --brand-l: #f3eefa;
  --warn: #92400e; --warn-l: #fef3c7; --bad: #991b1b; --bad-l: #fee2e2; --crit: #dc2626;
  --ok: #065f46; --ok-l: #ecfdf5; --ok-line: #a7f3d0; --info: #1e40af; --info-l: #dbeafe;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 980px; margin: 0 auto; padding: 12px 16px 120px; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--brand-d); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.topbar h1 { font-size: 1.05rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: .8rem; opacity: .85; font-weight: 400; display: block; }
.topbar button { background: rgba(255,255,255,.18); border: 0; color: #fff; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.topbar button:hover { background: rgba(255,255,255,.3); }
.topbar .sede-sw { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.18); border-radius: 10px; padding: 0 4px 0 8px; flex: none; }
.topbar .sede-sw select { background: transparent; color: #fff; border: 0; padding: 8px 4px; min-height: 0; font-weight: 600; max-width: 170px; width: auto; text-overflow: ellipsis; cursor: pointer; }
.topbar .sede-sw select option { color: #1b1530; }
@media (max-width: 520px) { .topbar .sede-sw select { max-width: 112px; font-size: .85rem; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 12px; }
.card h2 { font-size: 1rem; margin-bottom: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--brand-l); color: var(--brand-d); }
.chip.warn { background: var(--warn-l); color: var(--warn); }
.chip.bad { background: var(--bad-l); color: var(--bad); }
.chip.ok { background: var(--ok-l); color: var(--ok); border: 1px solid var(--ok-line); }
.chip.info { background: var(--info-l); color: var(--info); }
.chip.orange { background: #ffedd5; color: #c2410c; border: 1px solid #fdba74; }

/* Botones */
.btn { border: 0; border-radius: 8px; padding: 14px 18px; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; min-height: 48px; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--brand-d); border: 1.5px solid var(--brand); }
.btn.danger { background: var(--crit); }
.btn.sm { padding: 6px 12px; min-height: 0; font-size: .85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.call { background: var(--ok); font-size: 1.15rem; padding: 16px; }

/* Formularios */
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--card); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
textarea { min-height: 84px; resize: vertical; }
.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login .card { padding: 24px; }
.login h1 { text-align: center; margin-bottom: 4px; }

/* Campañas */
.camp-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-top: 12px; }
.camp { text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; box-shadow: var(--shadow); }
.camp:hover { border-color: var(--brand); }
.camp h3 { font-size: 1.05rem; margin-bottom: 6px; }
.camp .big { font-size: 2rem; font-weight: 700; color: var(--brand-d); line-height: 1; }
.stats { display: flex; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.stats div { font-size: .8rem; color: var(--muted); }
.stats b { display: block; font-size: 1.05rem; color: var(--text); }

/* Pantalla de trabajo */
.client-name { font-size: 1.5rem; font-weight: 700; }
.phone { font-size: 1.25rem; font-weight: 600; color: var(--brand-d); text-decoration: none; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .95rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; padding: 4px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; font-size: .92rem; background: var(--bg); border: 1px solid var(--line); }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--brand-l); border-bottom-right-radius: 4px; }
.bubble small { display: block; color: var(--muted); font-size: .72rem; margin-top: 2px; }
.disp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .disp-grid { grid-template-columns: repeat(3, 1fr); } }
.disp { border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 8px; cursor: pointer; text-align: center; font-weight: 600; min-height: 64px; }
.disp .e { display: block; font-size: 1.4rem; }
.disp.sel { border-color: var(--brand); background: var(--brand-l); color: var(--brand-d); box-shadow: inset 0 0 0 1px var(--brand); }
.lock-bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.lock-bar i { display: block; height: 100%; background: var(--brand); transition: width 1s linear; }
.lock-bar.low i { background: var(--bad); }
.banner { padding: 12px 14px; border-radius: 8px; margin-top: 12px; background: var(--warn-l); color: var(--warn); font-weight: 600; }
.banner.bad { background: var(--bad-l); color: var(--bad); }

/* Barra de acciones fija (móvil) */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.actionbar > * { flex: 1; max-width: 480px; }
.actionbar { justify-content: center; }

/* Panel */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-top: 12px; }
.tab { border: 0; background: transparent; padding: 10px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tab.on { background: var(--brand-l); color: var(--brand-d); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--bg); border-radius: 12px; padding: 12px; }
.kpi b { font-size: 1.6rem; display: block; }
.bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--brand); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--brand-d); color: #fff;
  padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--crit); }
.empty { text-align: center; padding: 40px 16px; }
.empty .e { font-size: 2.6rem; }
@media (min-width: 900px) {
  .work-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; align-items: start; }
}

/* Avisos de reglas de remarcación */
.rule { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: .88rem; background: var(--brand-l); color: var(--brand-d); }
.rule.warn { background: var(--warn-l); color: var(--warn); font-weight: 600; }
.rule.bad { background: var(--bad-l); color: var(--bad); font-weight: 600; }
th { background: #f9fafb; }
.kpi { background: #f9fafb; }
tr.alert-row-critica { box-shadow: inset 3px 0 0 var(--crit); }

/* Cargos y permisos */
fieldset.perm-group { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 6px 12px 10px; }
fieldset.perm-group legend { font-weight: 600; font-size: .85rem; color: var(--brand-d); padding: 0 6px; }
label.perm { display: flex; gap: 8px; align-items: center; margin: 4px 0; font-size: .9rem; color: var(--text); font-weight: 400; }
label.perm input { width: auto; }

/* Procedimientos de la ficha */
ul.treat { list-style: none; margin: 6px 0 0; padding: 0; }
ul.treat li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
ul.treat li:last-child { border-bottom: 0; }

/* Alerta de Medklee: rojo, bien visible */
.alert-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 220px; overflow: auto; }
.alert-list li { padding: 8px 10px; border-left: 4px solid #dc2626; background: #fff5f5; border-radius: 6px; margin-bottom: 6px; font-size: .9rem; }
.alert-list li.media { border-left-color: #f59e0b; background: #fffbeb; }
.alert-list li.baja { border-left-color: #94a3b8; background: #f8fafc; }
.alert-list li div { margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.alert-red { margin-top: 8px; padding: 9px 12px; border-radius: 8px; background: #dc2626; color: #fff; font-size: .92rem; }
a.btn.sm { text-decoration: none; display: inline-flex; align-items: center; }

/* Oportunidades de Clientify */
ul.deals { list-style: none; margin: 0; padding: 0; }
ul.deals li { padding: 8px 10px; border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; margin-top: 6px; }
ul.deals li.expired { border-left-color: var(--crit); background: #fef7f7; }

/* ===== Panel: navegación lateral y más aire ===== */
.wrap.wide { max-width: 1480px; padding-top: 20px; }
.panel-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; align-items: start; }
.panel-layout.single { grid-template-columns: minmax(0, 1fr); }
.sidenav { position: sticky; top: 78px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 14px; box-shadow: var(--shadow); }
.nav-title { font-size: .7rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 14px 10px 6px; }
.nav-group:first-child .nav-title { margin-top: 8px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin: 2px 0; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font-weight: 600; font-size: .95rem; cursor: pointer; transition: background .15s; }
.nav-item:hover { background: #f5f3f9; }
.nav-item.on { background: var(--brand-l); color: var(--brand-d); box-shadow: inset 3px 0 0 var(--brand); }
.nav-ico { width: 1.4em; text-align: center; font-size: 1.05rem; }

.panel-body > :first-child { margin-top: 0 !important; }
.panel-body .card { padding: 24px 28px; margin-top: 20px; border-radius: 14px; }
.panel-body .card h2 { margin-bottom: 14px; }
.panel-body table { font-size: .92rem; }
.panel-body th, .panel-body td { padding: 13px 14px; }
.panel-body th { background: #faf9fc; }
.panel-body tbody tr:hover { background: #fbfafd; }
.panel-body .kpis { gap: 16px; }
.panel-body .kpi { padding: 18px 20px; border-radius: 14px; }
.panel-body .row { gap: 16px; }
.panel-body label { margin: 14px 0 6px; }
.panel-body .stats { gap: 22px; }
.panel-body .banner { margin-top: 0; margin-bottom: 4px; }
.panel-body details.card summary { padding: 2px 0; cursor: pointer; }

@media (max-width: 899px) {
  .panel-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .sidenav { position: static; display: flex; gap: 8px; overflow-x: auto; padding: 8px; border-radius: 14px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .sidenav::-webkit-scrollbar { display: none; }
  .nav-group { display: flex; gap: 6px; flex: none; }
  .nav-title { display: none; }
  .nav-item { width: auto; white-space: nowrap; padding: 11px 16px; margin: 0; border-radius: 999px; background: var(--bg); }
  .nav-item.on { box-shadow: none; background: var(--brand); color: #fff; }
  .panel-body .card { padding: 18px; margin-top: 14px; }
  .panel-body th, .panel-body td { padding: 11px 10px; }
}

/* ===== Tipificación en dos niveles ===== */
.grp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grp { display: flex; align-items: center; gap: 10px; padding: 14px 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--card);
  font-weight: 700; font-size: .95rem; text-align: left; cursor: pointer; color: var(--text); min-height: 56px; }
.grp .e { font-size: 1.3rem; }
.grp.sel { border-color: var(--brand); background: var(--brand-l); color: var(--brand-d); }
.step-title { margin: 16px 0 8px; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stage-tag { display: block; margin-top: 4px; font-size: .72rem; font-weight: 600; color: var(--muted); }
.disp.sel .stage-tag { color: var(--brand-d); }
.stage-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 16px; margin-top: 6px; }
@media (max-width: 520px) { .grp-grid { grid-template-columns: 1fr; } }

/* ===== Gestión por sede ===== */
.journey { display: grid; grid-template-columns: 210px 1fr 130px; align-items: center; gap: 12px; margin: 8px 0; }
.journey .jl { font-size: .9rem; font-weight: 600; }
.journey .jn { text-align: right; font-size: .95rem; }
.bar.brand i { background: var(--brand); }
.bar.ok i { background: #16a34a; }
td .bar { margin-top: 4px; min-width: 70px; }
.delta { font-weight: 700; font-size: .85rem; color: var(--muted); }
.delta.pos { color: #15803d; } .delta.neg { color: #b91c1c; }
details.sede-detail { border-top: 1px solid var(--line); padding: 10px 0; }
details.sede-detail summary { cursor: pointer; padding: 4px 0; }
details.sede-detail table { font-size: .85rem; }
@media (max-width: 700px) { .journey { grid-template-columns: 1fr; gap: 2px; } .journey .jn { text-align: left; } }

/* ===== Menú plegable y panel más ancho ===== */
.nav-toggle { display: block; width: 100%; margin: 0 0 6px; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  font-size: .8rem; font-weight: 600; text-align: right; cursor: pointer; }
.nav-toggle:hover { background: #f5f3f9; color: var(--brand-d); }
.wrap.wide.xl { max-width: 1760px; }
.panel-layout.collapsed { grid-template-columns: 64px minmax(0, 1fr); gap: 20px; }
.panel-layout.collapsed .sidenav { padding: 8px 6px 12px; }
.panel-layout.collapsed .nav-label, .panel-layout.collapsed .nav-title { display: none; }
.panel-layout.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.panel-layout.collapsed .nav-toggle { text-align: center; font-size: 1.1rem; padding: 6px 0; }
.panel-layout.collapsed .nav-group + .nav-group { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
@media (max-width: 899px) { .nav-toggle { display: none; } }

/* Detalle por sede: dos bloques que se acomodan al ancho y tablas compactas que no se salen */
.sd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 600px), 1fr)); gap: 20px; margin-top: 10px; align-items: start; }
.sd-grid .table-wrap { overflow-x: auto; }
details.sede-detail table { width: 100%; }
details.sede-detail th, details.sede-detail td { padding: 8px 10px; font-size: .84rem; }
details.sede-detail td:not(:first-child), details.sede-detail th:not(:first-child) { white-space: nowrap; }

table.cmp th, table.cmp td { padding: 9px 6px; font-size: .82rem; }
table.cmp .bar { min-width: 48px; }
table.cmp td:not(:first-child), table.cmp th:not(:first-child) { white-space: nowrap; }

/* ===== Guion de la llamada ===== */
.script-card summary { cursor: pointer; padding: 2px 0; }
.script-body { margin-top: 10px; font-size: .97rem; line-height: 1.5; max-height: 46vh; overflow: auto; }
.script-body.script-mini { font-size: .84rem; line-height: 1.38; max-height: 20vh; margin-top: 6px; }   /* pequeño en la pantalla de trabajo */
.script-pop { float: right; padding: 2px 8px; font-size: .78rem; }
.script-dlg { width: min(860px, 94vw); max-height: 88vh; border: 0; border-radius: 14px; padding: 18px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.script-dlg::backdrop { background: rgba(30, 20, 50, .55); }
.script-dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; font-size: 1.05rem; }
.script-body.script-big { font-size: 1.12rem; line-height: 1.65; max-height: calc(88vh - 90px); margin-top: 4px; }
.script-big h4 { font-size: .85rem; }
.script-body h4 { margin: 12px 0 4px; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-d); }
.script-body p { margin: 4px 0; } .script-body ul { margin: 4px 0 4px 18px; padding: 0; } .script-body li { margin: 2px 0; }
.script-body .gap { height: 8px; }
.script-body mark { background: var(--brand-l); color: var(--brand-d); padding: 0 3px; border-radius: 4px; font-weight: 600; }
.script-preview { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; min-height: 300px; margin-top: 0; background: #fcfbfe; }
