/* Área de cliente de Niber. Mismo mundo que niber.es (TikTok Sans, tinta, cobalto, rosa), en tono de herramienta. */
@font-face {
  font-family: "TikTok Sans";
  font-style: normal; font-weight: 300 900; font-stretch: 75% 150%; font-display: swap;
  src: url("/fonts/tiktok-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "TikTok Sans";
  font-style: normal; font-weight: 300 900; font-stretch: 75% 150%; font-display: swap;
  src: url("/fonts/tiktok-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #ffffff;
  --wash: #f1f2f6;
  --wash-2: #e6e8ef;
  --line: #dfe2ea;
  --ink: #0b0c10;
  --ink-soft: #454a57;
  --ink-mute: #6b7080;
  --cobalt: #1f3fbf;
  --cobalt-deep: #18329a;
  --cobalt-soft: #dfe4fa;
  --rose: #e9879b;
  --rose-soft: #fbe3e8;
  --rose-ink: #8a2340;
  --green-soft: #dcf1e4;
  --green-ink: #1c5e37;
  --danger: #b4233c;
  --r: 10px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --side: 248px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  font: 400 15px/1.5 "TikTok Sans", system-ui, sans-serif;
  color: var(--ink); background: var(--wash);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.625rem; line-height: 1.2; font-weight: 650; font-stretch: 105%; letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
a { color: var(--cobalt); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
::selection { background: var(--cobalt-soft); color: var(--ink); }
html { accent-color: var(--cobalt); caret-color: var(--cobalt); scrollbar-color: #c3c7d2 transparent; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lbl-short { display: none; }
.card-label { display: none; }
.wrap { overflow-wrap: anywhere; }
.boot { padding: 40px; color: var(--ink-soft); }
.muted { color: var(--ink-soft); }
.small { font-size: 0.8125rem; }
.num { font-variant-numeric: tabular-nums; }
.vh, .field .vh { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 22px 16px; background: var(--paper); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; padding: 0 10px; text-decoration: none; color: var(--ink); }
.brand b { font-size: 1.5rem; font-weight: 800; font-stretch: 112%; letter-spacing: -0.03em; }
.brand span { font-size: 0.8125rem; color: var(--ink-soft); }
.botpick { display: flex; flex-direction: column; gap: 4px; padding: 0 2px; }
.botpick label { font-size: 0.8125rem; color: var(--ink-soft); padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-more {
  display: flex; align-items: center; gap: 12px; min-height: 40px;
  padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav .ico { color: var(--ink-soft); }
.nav [aria-current="page"] .ico { color: var(--cobalt); }
.nav .lbl { flex: 1; min-width: 0; }
.nav-more { display: none; border: 0; background: none; cursor: pointer; font: inherit; }
@media (hover: hover) { .nav a:hover { background: var(--wash); } }
.nav a[aria-current="page"] { background: var(--cobalt-soft); color: var(--cobalt-deep); }
.nav .count { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--rose); color: var(--ink); font-size: 0.75rem; font-weight: 650; text-align: center; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 0.875rem; }
.side-foot .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.linkbtn { padding: 0; border: 0; background: none; color: var(--cobalt); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; }

.main { min-width: 0; padding: 32px clamp(20px, 3.5vw, 48px) 80px; }
.main:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head p { margin-top: 6px; color: var(--ink-soft); max-width: 70ch; }
.crumb { display: inline-block; margin-bottom: 8px; font-size: 0.875rem; }

/* ---------- Paneles ---------- */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); }
.panel-pad { padding: 20px 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Servicios activos ---------- */
.services { margin-bottom: 16px; }
.svc-list { list-style: none; margin: 0; padding: 8px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.svc { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 8px; }
.svc-mark { flex: none; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--wash-2); }
.svc-mark .ico { width: 14px; height: 14px; stroke-width: 2.6; }
.svc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.svc-text strong { font-weight: 600; color: var(--ink-soft); }
.svc-text span { font-size: 0.8125rem; color: var(--ink-mute); }
.svc .pill { flex: none; }
.svc-more { flex: none; font-size: 0.8125rem; white-space: nowrap; }
.svc.is-active { background: var(--cobalt-soft); }
.svc.is-active .svc-mark { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.svc.is-active .svc-text strong { color: var(--ink); }
.svc.is-active .svc-text span { color: var(--cobalt-deep); }
.svc.is-active .pill { background: var(--paper); }
.svc-checks { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; border: 0; }
.svc-checks legend { margin-bottom: 8px; padding: 0; font-weight: 550; }

/* ---------- Cifras ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { padding: 18px 22px; }
.kpi .label { color: var(--ink-soft); font-size: 0.875rem; }
.kpi .value { margin-top: 4px; font-size: 2rem; font-weight: 650; font-stretch: 105%; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .hint { margin-top: 4px; color: var(--ink-soft); font-size: 0.8125rem; }

.bars { display: grid; grid-template-columns: repeat(30, 1fr); align-items: end; gap: 3px; height: 140px; padding-top: 8px; }
.bars span { display: block; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--wash-2); }
.bars span.has-lead { background: var(--cobalt); }
.bars-empty { display: grid; place-items: center; height: 140px; color: var(--ink-soft); background: var(--wash); border-radius: 8px; }
.bars-axis { display: flex; justify-content: space-between; margin-top: 8px; color: var(--ink-soft); font-size: 0.8125rem; }

.pipeline { display: flex; flex-direction: column; gap: 8px; }
.pipeline a { display: grid; grid-template-columns: 110px 1fr 36px; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; padding: 4px 0; }
.pipeline .track { height: 8px; border-radius: 4px; background: var(--wash); overflow: hidden; }
.pipeline .fill { display: block; height: 100%; border-radius: 4px; background: var(--cobalt); }
.pipeline .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Tablas y listas ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 10px 14px; text-align: left; font-size: 0.8125rem; font-weight: 500; color: var(--ink-soft); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; transition: background-color 120ms ease; }
@media (hover: hover) { .table tbody tr:hover { background: #f7f8fb; } .table.static tbody tr:hover { background: none; } }
.table.static tbody tr { cursor: default; }
.table .primary { font-weight: 600; color: var(--ink); text-decoration: none; }
.table .sub { color: var(--ink-soft); font-size: 0.875rem; }
.clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 46ch; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 22px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.empty { padding: 36px 22px; text-align: center; color: var(--ink-soft); }
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.8125rem; font-weight: 550; white-space: nowrap; }
.pill.nuevo { background: var(--rose-soft); color: var(--rose-ink); }
.pill.contactado { background: var(--cobalt-soft); color: var(--cobalt-deep); }
.pill.cualificado { background: #e8e1fb; color: #4b2a9a; }
.pill.ganado { background: var(--green-soft); color: var(--green-ink); }
.pill.perdido { background: var(--wash); color: var(--ink-soft); }
.pill.muted { background: var(--wash); color: var(--ink-soft); }

/* ---------- Filtros ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 9px; background: var(--wash); max-width: 100%; }
.seg button { flex: none; white-space: nowrap; padding: 6px 11px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 0.875rem; color: var(--ink-soft); }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(11, 12, 16, 0.08); }
.toolbar .search { flex: 1; min-width: 200px; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 550; font-size: 0.9375rem; }
.field small { color: var(--ink-soft); font-size: 0.8125rem; }
.field .error { color: var(--danger); font-size: 0.8125rem; }
.input, .field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  font-size: 0.9375rem; line-height: 1.45;
  transition: border-color 150ms ease;
}
.field textarea { resize: vertical; min-height: 88px; }
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.logo-preview { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); overflow: hidden; }
.logo-preview img { width: 44px; height: 44px; object-fit: contain; }
.logo-preview .small { font-size: 0.6875rem; text-align: center; }
label.btn { cursor: pointer; }
.logo-row:has(#logo-file:focus-visible) label.btn { outline: 2px solid var(--cobalt); outline-offset: 2px; }
.field input[type="color"] { width: 88px; height: 44px; padding: 4px; cursor: pointer; }
.field textarea.tall { min-height: 360px; font-size: 0.875rem; line-height: 1.55; }
.input:hover, .field input:hover, .field select:hover, .field textarea:hover { border-color: #c9cdd8; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--cobalt); outline-offset: -1px; border-color: transparent; }
.field.has-error input, .field.has-error textarea { border-color: var(--danger); }
.form { display: flex; flex-direction: column; gap: 18px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--cobalt); flex: none; }
.check small { display: block; color: var(--ink-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 1px solid transparent; border-radius: var(--r);
  background: var(--cobalt); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 150ms ease, transform 160ms var(--ease);
}
.btn:hover { background: var(--cobalt-deep); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn.ghost { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--wash); }
.btn.danger { background: var(--paper); color: var(--danger); border-color: #f0c7cf; }
.btn.danger:hover { background: #fdf0f2; }
.btn.small { padding: 6px 11px; font-size: 0.875rem; border-radius: 8px; }
.btn .ico { width: 18px; height: 18px; margin-left: -2px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- Ficha de lead ---------- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.timeline li { padding-left: 14px; border-left: 2px solid var(--line); }
.timeline .meta { color: var(--ink-soft); font-size: 0.8125rem; }
.timeline .note { margin-top: 4px; white-space: pre-wrap; }

/* ---------- Conversación ---------- */
.transcript { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px; }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--cobalt); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--wash); border-bottom-left-radius: 4px; }
.bubble .when { display: block; margin-top: 4px; font-size: 0.75rem; opacity: 0.7; }
.bubble p { margin: 0; }
.bubble p + p, .bubble ul + p, .bubble p + ul { margin-top: 6px; }
.bubble ul { margin: 0; padding-left: 18px; }
.bubble.user a { color: #fff; }
.bubble { white-space: normal; }
.bubble .tag { display: inline-block; margin-top: 6px; padding: 1px 8px; border-radius: 999px; background: var(--paper); color: var(--ink-soft); font-size: 0.75rem; }

/* ---------- Editor del chatbot ---------- */
.tabs {
  display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; scroll-padding-inline: 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; white-space: nowrap; padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--ink-soft); text-decoration: none; font-weight: 550; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--cobalt); }
.topic { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); }
.topic + .topic { margin-top: 12px; }
.topic-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topic-head .n { color: var(--ink-mute); font-variant-numeric: tabular-nums; font-size: 0.875rem; }
.topic-head .grow { flex: 1; }
.iconbtn.danger { color: var(--danger); border-color: #f0c7cf; }
.iconbtn .ico { width: 18px; height: 18px; }
.iconbtn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: pointer; color: var(--ink-soft); }
.iconbtn:hover { background: var(--wash); color: var(--ink); }
.iconbtn:disabled { opacity: 0.4; cursor: default; }
.savebar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin: 24px calc(-1 * clamp(20px, 3.5vw, 48px)) -80px; padding: 14px clamp(20px, 3.5vw, 48px);
  background: var(--paper); border-top: 1px solid var(--line);
}
.savebar .grow { flex: 1; min-width: 200px; }
.savebar .state { color: var(--ink-soft); font-size: 0.875rem; }
.savebar .state.dirty { color: var(--rose-ink); font-weight: 600; }
.errors { padding: 12px 16px; border-radius: var(--r); background: #fdecee; color: #7c1b2d; }
.errors ul { margin: 6px 0 0; padding-left: 18px; }
.code { display: block; padding: 14px 16px; border-radius: var(--r); background: var(--ink); color: #e9ebf2; font: 0.875rem/1.5 ui-monospace, "SF Mono", Menlo, monospace; overflow-x: auto; white-space: pre; }
.notice { padding: 14px 16px; border-radius: var(--r); background: var(--cobalt-soft); color: var(--cobalt-deep); }
.notice.warn { background: var(--rose-soft); color: var(--rose-ink); }

/* ---------- Acceso ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 400px); padding: 32px; }
.auth-card .brand { padding: 0; margin-bottom: 22px; }
.auth-card h1 { font-size: 1.375rem; margin-bottom: 6px; }
.auth-card > p { color: var(--ink-soft); margin-bottom: 22px; }
.auth-card .btn { width: 100%; padding: 12px 16px; }
.auth-foot { margin-top: 18px; font-size: 0.875rem; text-align: center; }

/* ---------- Avisos ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  padding: 11px 18px; border-radius: var(--r);
  background: var(--ink); color: #fff; font-weight: 500;
  transform: translateX(-50%);
  animation: toast-in 220ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
dialog { width: min(92vw, 480px); padding: 24px; border: 0; border-radius: 12px; box-shadow: 0 24px 64px rgba(11, 12, 16, 0.25); }
dialog::backdrop { background: rgba(11, 12, 16, 0.35); }
dialog h2 { margin-bottom: 8px; }
dialog p { color: var(--ink-soft); margin-bottom: 16px; }

/* ---------- Esqueleto de carga ---------- */
.skeleton { display: flex; flex-direction: column; gap: 14px; }
.sk { display: block; border-radius: 8px; background: var(--wash-2); animation: sk-pulse 1.2s ease-in-out infinite; }
.sk-title { width: 220px; max-width: 60%; height: 30px; }
.sk-line { width: 380px; max-width: 85%; height: 16px; margin-bottom: 10px; }
.sk-block { height: 140px; border-radius: var(--r); background: var(--paper); border: 1px solid var(--line); }
.sk-block.short { height: 240px; }
@keyframes sk-pulse { 50% { opacity: 0.55; } }

/* ---------- Hoja inferior «Más» (móvil) ---------- */
dialog.sheet { padding: 8px 8px max(12px, env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px 14px; border-bottom: 1px solid var(--line); }
.sheet-head strong { display: block; }
.sheet-list { display: flex; flex-direction: column; padding-top: 6px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 12px;
  border: 0; border-radius: 10px; background: none; font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.sheet-item:active, .sheet-item.is-current { background: var(--cobalt-soft); color: var(--cobalt-deep); }
.sheet-item .ico { color: var(--ink-soft); }

/* =====================================================
   Tamaños de pantalla
   - 1100+: menú lateral completo
   - 760–1099: menú lateral estrecho
   - <760: barra superior fina + barra de pestañas abajo
   ===================================================== */
@media (max-width: 1099px) {
  :root { --side: 216px; }
  .grid-2 { grid-template-columns: 1fr; }
  .svc-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Ficha de lead en una columna: datos, seguimiento, conversación y, al final, borrar */
  .lead-grid { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .lead-grid > .stack { display: contents; }
  .p-facts { order: 1; } .p-follow { order: 2; } .p-conv { order: 3; } .p-danger { order: 4; }
  .main { padding: 28px 28px 80px; }
  .savebar { margin: 24px -28px -80px; padding: 14px 28px; }
  .table .hide-md { display: none; }
  .seg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
}

/* Táctil: zonas de toque de 44 px y campos de 16 px (el iPhone no amplía al enfocarlos) */
@media (pointer: coarse) {
  .btn, .btn.small { min-height: 44px; }
  .iconbtn { width: 44px; height: 44px; }
  .seg button { min-height: 40px; }
  .nav a, .nav-more { min-height: 44px; }
  .input, .field input, .field select, .field textarea, .toolbar .search { font-size: 16px; }
  .check input { width: 22px; height: 22px; margin-top: 0; }
}

@media (max-width: 759px) {
  :root { --bar: 64px; }
  .shell { padding-bottom: calc(var(--bar) + env(safe-area-inset-bottom)); }
  .input, .field input, .field select, .field textarea { font-size: 16px; }
  h1 { font-size: 1.375rem; }

  /* Barra superior: marca y selector de chatbot */
  .shell { display: block; }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; align-items: center; gap: 12px;
    padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .brand b { font-size: 1.375rem; }
  .brand span, .side-foot, .botpick label { display: none; }
  .botpick { flex: 1; min-width: 0; padding: 0; }
  .botpick select { min-height: 40px; padding: 7px 10px; font-size: 15px; text-overflow: ellipsis; }

  /* Barra de pestañas inferior, al alcance del pulgar */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    flex-direction: row; gap: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--paper); border-top: 1px solid var(--line);
  }
  .nav a, .nav-more {
    position: relative; flex: 1 1 0; flex-direction: column; justify-content: center; gap: 3px;
    min-height: var(--bar); padding: 6px 2px; border-radius: 0;
    font-size: 0.75rem; font-weight: 550; color: var(--ink-soft); text-align: center;
  }
  .nav a[aria-current="page"], .nav-more[aria-current="page"] { background: none; color: var(--cobalt-deep); }
  .nav a:active, .nav-more:active { background: var(--wash); }
  .nav .ico { width: 24px; height: 24px; }
  .nav .lbl { flex: none; }
  .nav .lbl-long, .nav .nav-secondary { display: none; }
  .nav .lbl-short { display: inline; }
  .nav-more { display: flex; }
  .nav .count { position: absolute; top: 5px; left: calc(50% + 6px); margin: 0; min-width: 18px; padding: 0 5px; font-size: 0.6875rem; line-height: 18px; }

  .main {
    padding: 20px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
  }
  .page-head { gap: 12px; margin-bottom: 18px; }
  .page-head > .actions, .page-head > .actions > * { width: 100%; }
  .page-head > .actions .btn { flex: 1; }
  .quick { margin: -6px 0 18px; }
  .quick .btn { flex: 1 1 0; padding-inline: 10px; }

  /* Servicios: una columna; la descripción solo en los activos */
  .svc-list { grid-template-columns: 1fr; padding: 6px; }
  .svc { padding: 10px 10px; align-items: center; }
  .svc:not(.is-active) .svc-text span { display: none; }

  /* Resumen: tres cifras en una fila */
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.5rem; }
  .kpi .hint, .kpi .lbl-long { display: none; }
  .kpi .lbl-short { display: inline; }
  .panel-pad { padding: 16px; }
  .panel-head { padding: 14px 16px; }
  .list li { padding: 12px 16px; }
  .pipeline a { grid-template-columns: 96px 1fr 28px; min-height: 36px; }
  .bars { height: 110px; gap: 2px; }

  /* Tablas → tarjetas */
  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody { display: block; }
  .table.cards tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: start;
    padding: 14px 16px; border-bottom: 1px solid var(--line);
  }
  .table.cards tr:last-child { border-bottom: 0; }
  .table.cards td { display: block; padding: 0; border: 0; min-width: 0; }
  .table.cards .c-main { grid-column: 1; grid-row: 1; }
  .table.cards .c-side { grid-column: 2; grid-row: 1; justify-self: end; text-align: right; }
  .table.cards .c-full { grid-column: 1 / -1; }
  .table.cards .c-meta { grid-column: 2; grid-row: 2; justify-self: end; white-space: nowrap; }
  .table.cards .c-stat { grid-row: 2; }
  .table.cards .hide-md { display: block; }
  .table.cards .card-label { display: inline; }
  .table.cards .clip { max-width: none; }
  .table.cards .c-full .actions { margin-top: 4px; }

  /* Filtros: una fila que se desplaza; la búsqueda debajo, a lo ancho */
  .toolbar { padding: 12px; gap: 10px; }
  .seg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; }
  .seg::-webkit-scrollbar { display: none; }
  .toolbar .search { min-width: 0; flex-basis: 100%; }

  /* Ficha de lead: datos, seguimiento, conversación y, al final, borrar */
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  .transcript { padding: 16px; }
  .bubble { max-width: 88%; }

  /* Editor del chatbot */
  .tabs { margin-inline: calc(-1 * max(16px, env(safe-area-inset-left))); padding-inline: 8px; }
  .tabs a { padding: 12px 12px; }
  .form-row { grid-template-columns: 1fr; }
  .topic { padding: 14px; }
  .topic-head { gap: 6px; }
  .savebar {
    bottom: calc(var(--bar) + env(safe-area-inset-bottom));
    margin: 20px calc(-1 * max(16px, env(safe-area-inset-left))) -32px;
    padding: 10px max(16px, env(safe-area-inset-left));
    gap: 8px;
  }
  .savebar .grow { flex-basis: 100%; order: -1; min-width: 0; }
  .savebar.is-clean, .savebar .state { display: none; }
  .savebar .btn { flex: 1; }
  .code { font-size: 0.8125rem; white-space: pre-wrap; word-break: break-all; }

  /* Diálogos como hoja inferior */
  dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; padding: 22px 18px max(18px, env(safe-area-inset-bottom)); animation: sheet-in 260ms var(--ease); }
  dialog .actions { flex-direction: column-reverse; align-items: stretch; }
  dialog .actions .btn { width: 100%; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

  .toast { bottom: calc(var(--bar) + 16px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); }
  .auth { padding: 16px; align-items: start; padding-top: max(40px, env(safe-area-inset-top)); }
  .auth-card { padding: 24px 20px; }
}

@media (max-width: 359px) {
  .btn { white-space: normal; text-align: center; }
  .kpis { grid-template-columns: 1fr; }
  .quick .btn { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
