/*
 * Estilo del CRM Datavoip (CRMV4, Tailwind): morado #3c085d, grises "slate",
 * tarjetas blancas muy redondeadas, encabezados de tabla y de modal en morado.
 * Solo modo claro, igual que el CRM.
 */
:root {
  --brand: #3c085d;
  --brand-hover: #5a188f;
  --brand-dark: #2e0547;

  --bg: #ecebf2;            /* gris lavanda suave: menos blanco que el slate-50 del CRM */
  --surface: #ffffff;
  --surface-2: #f6f5fa;     /* gris muy claro con tinte morado */
  --surface-3: #f1f5f9;     /* slate-100 */
  --border: #e2e8f0;        /* slate-200 */
  --border-soft: #e9e6f0;
  --heading: #0f172a;       /* slate-900 */
  --text: #1e293b;          /* slate-800 */
  --text-2: #475569;        /* slate-600 */
  --muted: #64748b;         /* slate-500 */
  --subtle: #94a3b8;        /* slate-400 */

  --accent: var(--brand);
  --accent-strong: var(--brand-hover);
  --accent-soft: #faf5ff;   /* purple-50 */
  --accent-soft-2: #f3e8ff; /* purple-100 */
  --accent-border: #e9d5ff; /* purple-200 */
  --on-accent: #ffffff;
  --ring: 0 0 0 3px rgb(168 85 247 / 0.2); /* focus:ring-purple-500/20 */
  --danger: #e11d48;        /* rose-600 */

  --chat-bg: #f1eff6;
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(59 7 100 / 0.1), 0 2px 4px -2px rgb(59 7 100 / 0.1);
  --shadow-xl: 0 10px 25px -5px rgb(60 8 93 / 0.08), 0 4px 10px -6px rgb(60 8 93 / 0.06);
  --shadow-lg: 0 25px 50px -12px rgb(15 23 42 / 0.25);

  /* Estados (badges con punto como en el CRM) */
  --st-nuevo-bg: #faf5ff;     --st-nuevo-fg: #3c085d;     --st-nuevo-dot: #7c3aed;     --st-nuevo-bd: #f3e8ff;
  --st-abierto-bg: #ecfdf5;   --st-abierto-fg: #047857;   --st-abierto-dot: #10b981;   --st-abierto-bd: #a7f3d0;
  --st-pendiente-bg: #fffbeb; --st-pendiente-fg: #b45309; --st-pendiente-dot: #f59e0b; --st-pendiente-bd: #fde68a;
  --st-cerrado-bg: #f1f5f9;   --st-cerrado-fg: #475569;   --st-cerrado-dot: #94a3b8;   --st-cerrado-bd: #e2e8f0;

  --radius: 16px;     /* rounded-2xl */
  --radius-sm: 12px;  /* rounded-xl */
  --font: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
h1 { font-size: 24px; font-weight: 800; color: var(--heading); margin: 0; letter-spacing: -0.025em; }
h2 { font-size: 16px; font-weight: 700; color: var(--heading); margin: 0; }
p { margin: 0; }
code { background: var(--surface-3); color: var(--brand); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; color: var(--muted); }
[hidden] { display: none !important; }

/* Scrollbars como en el CRM */
* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.sidebar ::-webkit-scrollbar-thumb { background: rgb(255 255 255 / 0.3); }

/* ---------- Layout ---------- */
/* Solo en el celular: barra superior y fondo del menú deslizable (ver @media 760px). */
.mobile-bar, .nav-backdrop, .mobile-only { display: none; }
/* Botones solo del celular (con más prioridad que .btn / .icon-btn, que les dan display). */
.btn.mobile-inline, .icon-btn.chat-back { display: none; }
/* La celda tipo "lista de chats" solo existe en el celular. */
.table td.c-mobile { display: none; }
.mobile-notice { margin: 0 0 14px; padding: 10px 14px; font-size: 13px; color: var(--st-pendiente-fg); background: var(--st-pendiente-bg); border: 1px solid var(--st-pendiente-bd); border-radius: var(--radius-sm); }
.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--brand);
  color: #fff;
  display: flex; flex-direction: column;
  padding: 0 0 12px;
  position: sticky; top: 0; height: 100vh;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 16px; border-bottom: 1px solid rgb(255 255 255 / 0.1); }
.brand-img { height: 40px; max-width: 100%; object-fit: contain; }
.brand-name { font-size: 20px; font-weight: 700; color: #fff; line-height: 1.2; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 16px 8px 0; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: 6px;
  color: #fff; text-decoration: none;
}
.nav a:hover { background: rgb(255 255 255 / 0.1); }
.nav a.active { background: rgb(255 255 255 / 0.15); font-weight: 600; }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 9999px; background: #fff; color: var(--brand);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.bot-status {
  display: flex; gap: 10px; align-items: center;
  padding: 12px; border-radius: var(--radius-sm); background: rgb(255 255 255 / 0.1); border: 1px solid rgb(255 255 255 / 0.1);
}
.bot-status div { display: flex; flex-direction: column; min-width: 0; }
.bot-status strong { font-size: 13px; }
.bot-status small { color: rgb(255 255 255 / 0.7); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: rgb(255 255 255 / 0.5); flex-shrink: 0; }
.bot-status.ok .status-dot { background: #34d399; box-shadow: 0 0 0 3px rgb(52 211 153 / 0.25); }
.bot-status.warn .status-dot { background: #fbbf24; box-shadow: 0 0 0 3px rgb(251 191 36 / 0.25); }
.bot-status.error .status-dot { background: #fb7185; }

.main { padding: 24px 32px 96px; min-width: 0; }
/* Las vistas van directo sobre el fondo gris; solo tarjetas, KPIs y tablas son blancas. */
.view { max-width: 1600px; margin: 0 auto; padding: 8px 0 0; }
.view-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid #dcd8e6;
}
.view-title { display: flex; align-items: center; gap: 12px; }
.view-icon { padding: 12px; background: var(--surface); box-shadow: var(--shadow); color: var(--brand); border-radius: var(--radius); display: grid; place-items: center; }
.view-icon svg { width: 24px; height: 24px; }
.view-header p { margin-top: 2px; font-size: 14px; font-weight: 500; color: var(--muted); }

/* ---------- Tarjetas / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 20px; border-bottom: 1px solid var(--border-soft); }
.card-head p { margin-top: 4px; max-width: 60ch; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; gap: 8px; }
.kpi span i { width: 8px; height: 8px; border-radius: 50%; }
.kpi strong { display: block; font-size: 30px; font-weight: 800; color: var(--heading); font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: -0.025em; }

.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); padding: 6px 14px; border-radius: 9999px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--subtle); }
.conn.online .conn-dot { background: #10b981; animation: pulse 2s infinite; }
.conn.offline .conn-dot { background: var(--danger); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(16 185 129 / 0.5); } 70% { box-shadow: 0 0 0 7px rgb(16 185 129 / 0); } 100% { box-shadow: 0 0 0 0 rgb(16 185 129 / 0); } }

/* ---------- Controles ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.select, .search input, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], input[type="tel"], input[type="date"], input[type="time"], textarea, .sim-name input {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
::placeholder { color: var(--subtle); }
.select { padding-right: 32px; color: #334155; }
.select.sm { padding: 5px 28px 5px 10px; font-size: 13px; border-radius: 10px; }
:is(.select, input, textarea):not([type="checkbox"]):not([type="color"]):focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
input[type="checkbox"] { accent-color: var(--brand); width: 16px; height: 16px; }
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
#live-count { margin-left: auto; white-space: nowrap; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--subtle); width: 16px; height: 16px; }
.search input { width: 100%; padding-left: 36px; }

.segmented { display: inline-flex; background: rgb(241 245 249 / 0.8); border: 1px solid rgb(226 232 240 / 0.5); border-radius: var(--radius); padding: 4px; gap: 2px; }
.segmented button { font: inherit; font-size: 13px; font-weight: 600; border: 1px solid transparent; background: none; color: var(--text-2); padding: 7px 14px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.2s; }
.segmented button:hover { color: var(--brand); }
.segmented button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); border-color: rgb(226 232 240 / 0.3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: #334155;
  padding: 8px 16px; border-radius: var(--radius-sm); white-space: nowrap; transition: all 0.15s;
}
.btn:hover { background: var(--surface-2); color: var(--heading); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--shadow-md); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.primary.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.icon-btn { border: 0; background: none; color: var(--muted); padding: 7px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; transition: all 0.15s; }
.icon-btn:hover { background: var(--surface-3); color: var(--heading); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: none; }

/* ---------- Tablas (encabezado morado como en el CRM) ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 14px; white-space: nowrap; }
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.table tbody tr { cursor: pointer; transition: background 0.15s; }
.table tbody tr:hover { background: rgb(248 250 252 / 0.7); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.time { white-space: nowrap; color: var(--muted); font-size: 13px; }
.table tr.unread .who strong { font-weight: 800; }
.table tr.row-new { animation: rowNew 2.4s ease-out; }
.table tr.row-flash { animation: rowFlash 1.6s ease-out; }
@keyframes rowNew { 0% { background: var(--accent-soft-2); transform: translateY(-4px); opacity: 0; } 15% { opacity: 1; transform: none; } 100% { background: transparent; } }
@keyframes rowFlash { 0% { background: var(--accent-soft-2); } 100% { background: transparent; } }
.id-badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-size: 13px; font-weight: 700; background: var(--accent-soft); color: var(--brand); border: 1px solid rgb(243 232 255 / 0.5); font-variant-numeric: tabular-nums; }

.who { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.who div { display: flex; flex-direction: column; min-width: 0; }
.who strong { color: var(--brand); font-weight: 700; white-space: nowrap; }
.who small { color: var(--muted); font-size: 12px; }
.unread-badge { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 9999px; display: grid; place-items: center; }
.last-msg { max-width: 240px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.last-msg b { color: var(--text); font-weight: 600; }
.subject { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-soft-2); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; text-transform: uppercase; flex-shrink: 0;
}
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 50px; height: 50px; font-size: 17px; border-radius: 50%; }
.bot-avatar { background: var(--brand); color: #fff; }

/* Badges de estado con punto */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 9999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot); }
.pill-nuevo { --dot: var(--st-nuevo-dot); background: var(--st-nuevo-bg); color: var(--st-nuevo-fg); border-color: var(--st-nuevo-bd); }
.pill-abierto { --dot: var(--st-abierto-dot); background: var(--st-abierto-bg); color: var(--st-abierto-fg); border-color: rgb(167 243 208 / 0.4); }
.pill-abierto::before { animation: blink 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }
.pill-pendiente { --dot: var(--st-pendiente-dot); background: var(--st-pendiente-bg); color: var(--st-pendiente-fg); border-color: rgb(253 230 138 / 0.4); }
.pill-cerrado { --dot: var(--st-cerrado-dot); background: var(--st-cerrado-bg); color: var(--st-cerrado-fg); border-color: var(--st-cerrado-bd); }
@keyframes blink { 50% { opacity: 0.5; } }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip-empty { color: var(--subtle); font-style: italic; }

.empty { text-align: center; padding: 48px 20px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty svg { width: 40px; height: 40px; color: var(--brand); background: var(--accent-soft); padding: 10px; border-radius: var(--radius); box-sizing: content-box; margin-bottom: 10px; stroke-width: 1.75; }
.empty strong { color: var(--heading); }

/* ---------- Pestañas (como el selector de sede del CRM) ---------- */
.tabs { display: inline-flex; gap: 2px; background: rgb(241 245 249 / 0.8); border: 1px solid rgb(226 232 240 / 0.5); border-radius: var(--radius); padding: 4px; margin-bottom: 20px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs button { font: inherit; font-size: 14px; font-weight: 600; color: var(--text-2); background: none; border: 1px solid transparent; padding: 8px 16px; cursor: pointer; border-radius: var(--radius-sm); white-space: nowrap; transition: all 0.2s; }
.tabs button:hover { color: var(--brand); }
.tabs button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); border-color: rgb(226 232 240 / 0.3); }

/* ---------- Formularios ---------- */
.form { padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field > legend { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field label small, .field legend small { font-weight: 500; color: var(--subtle); margin-left: 6px; text-transform: none; letter-spacing: 0; }
.field textarea { resize: vertical; min-height: 44px; }
.field .check, .check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--text); text-transform: none; letter-spacing: 0; }
.hint { font-size: 12.5px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: var(--danger); font-size: 13px; font-weight: 500; background: #fff1f2; border: 1px solid #ffe4e6; border-radius: 10px; padding: 8px 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.list li:hover { background: rgb(248 250 252 / 0.7); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow strong { color: var(--heading); }
.list .grow p { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-line; margin-top: 2px; }
.list .actions { display: flex; gap: 2px; }
.list .empty-row { justify-content: center; color: var(--muted); padding: 32px; }
.dept-swatch { width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0; }
.tag-muted { font-size: 12px; color: var(--subtle); white-space: nowrap; }

/* ---------- Burbujas estilo Telegram (simulador) ---------- */
.phone-body { background: var(--chat-bg); padding: 14px 12px; min-height: 380px; max-height: 560px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.tg-msg { max-width: 85%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; }
.tg-msg.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.tg-msg.out { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.tg-buttons { align-self: flex-start; display: flex; flex-direction: column; gap: 4px; width: 85%; }
.tg-buttons button { font: inherit; font-size: 13px; font-weight: 600; border: 1px solid var(--accent-border); border-radius: 10px; padding: 7px; cursor: pointer; background: var(--surface); color: var(--brand); }
.tg-buttons button:hover { background: var(--accent-soft); }
.tg-hint { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 4px 12px; border-radius: 9999px; text-align: center; }

/* ---------- Modales (encabezado morado como en el CRM) ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgb(15 23 42 / 0.6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fadeIn 0.15s ease-out; }
.modal { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; animation: popIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.95); } }
.chat { height: min(820px, calc(100vh - 40px)); width: min(1180px, 100%); }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 18px 20px; background: var(--brand); color: #fff; }
.chat-header .avatar { background: rgb(255 255 255 / 0.1); color: #fff; border: 1px solid rgb(255 255 255 / 0.1); border-radius: var(--radius-sm); }
.chat-header h2 { color: #fff; font-size: 18px; }
.chat-header .muted { color: rgb(255 255 255 / 0.7); }
.chat-header .icon-btn { color: rgb(255 255 255 / 0.8); }
.chat-header .icon-btn:hover { background: rgb(255 255 255 / 0.1); color: #fff; }
.chat-header .btn { background: rgb(255 255 255 / 0.1); border-color: rgb(255 255 255 / 0.15); color: #fff; }
.chat-who { flex: 1; min-width: 0; }
.chat-who h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-controls label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.chat-controls .btn { margin-left: auto; }
.chat-body { flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 20px; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 3px 12px; border-radius: 9999px; margin: 10px 0 6px; }
.msg { max-width: 72%; display: flex; flex-direction: column; margin-top: 4px; }
.msg .bubble { padding: 9px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.msg .meta { font-size: 11.5px; color: var(--subtle); margin-top: 3px; padding: 0 4px; }
.msg.user { align-self: flex-start; }
.msg.user .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; color: var(--text); }
.msg.agent, .msg.bot { align-self: flex-end; align-items: flex-end; }
.msg.agent .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.agent .meta { color: var(--brand); font-weight: 600; }
.msg.bot .bubble { background: var(--accent-soft); border: 1px solid var(--accent-soft-2); color: var(--text); border-bottom-right-radius: 4px; }
.msg .btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.msg .btns span { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 8px; background: var(--surface); border: 1px solid var(--accent-border); color: var(--brand); }
.msg.system { align-self: center; max-width: 90%; }
.msg.system .bubble { background: none; box-shadow: none; font-size: 12px; color: var(--subtle); padding: 4px; text-align: center; }
/* Adjuntos dentro del chat */
.msg .atts { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.msg.agent .atts, .msg.bot .atts { align-items: flex-end; }
.att-image { display: block; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); box-shadow: var(--shadow); }
.att-image img { display: block; width: 280px; max-width: 100%; height: auto; max-height: 360px; object-fit: contain; }
.att-sticker { display: block; width: 140px; height: 140px; object-fit: contain; }
.att-video { display: block; width: 320px; max-width: 100%; max-height: 360px; border-radius: var(--radius); background: #000; }
.att-audio { display: block; width: 280px; max-width: 100%; }
.att-file {
  display: flex; align-items: center; gap: 10px; max-width: 300px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--heading); text-decoration: none; transition: border-color 0.15s;
}
.att-file:hover { border-color: var(--brand); }
.att-file svg { width: 22px; height: 22px; color: var(--brand); }
.att-file span { display: flex; flex-direction: column; font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.att-file small { font-size: 12px; font-weight: 400; color: var(--muted); }

/* Archivo por enviar (arriba del compositor) */
.pending-file { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.pending-file img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.pending-icon { width: 44px; font-size: 22px; text-align: center; }
.pending-file div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pending-file strong { font-size: 13.5px; color: var(--heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file small { font-size: 12px; color: var(--muted); }
.attach-trigger { align-self: center; color: var(--muted); }
.attach-trigger:hover { color: var(--brand); background: var(--accent-soft); }
.attach-trigger svg { width: 20px; height: 20px; }
.chat-column.dropping { outline: 2px dashed var(--brand); outline-offset: -6px; }
.chat-column.dropping .chat-body { background: var(--accent-soft); }

.composer { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); align-items: flex-end; background: var(--surface); }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: 42px; padding: 10px 14px; }
.closed-bar { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 14px; text-align: center; border-top: 1px solid var(--border); color: var(--muted); background: var(--surface-2); }

/* ---------- Diálogo de formularios ---------- */
.dialog { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 0; width: min(540px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow: hidden; }
.dialog::backdrop { background: rgb(15 23 42 / 0.6); backdrop-filter: blur(4px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 80px); }
.dialog h2 { background: var(--brand); color: #fff; font-size: 18px; padding: 18px 24px; }
#form-dialog-fields { padding: 24px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.dialog .form-error { margin: 0 24px 16px; }
.dialog .form-actions { padding: 16px 24px; background: var(--surface-2); border-top: 1px solid var(--border-soft); }
.dialog .field input[type="color"] { width: 64px; height: 38px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.dialog .field input:not([type="checkbox"]):not([type="color"]), .dialog .field textarea, .dialog .field .select { width: 100%; }

/* ---------- Simulador ---------- */
.sim-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 40;
  display: flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--brand); color: #fff; border: 0;
  padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md), 0 10px 15px -3px rgb(59 7 100 / 0.2);
  transition: all 0.15s;
}
.sim-fab:hover { background: var(--brand-hover); }
.sim-fab:active { transform: scale(0.98); }
.sim {
  position: fixed; right: 24px; bottom: 24px; z-index: 45;
  width: min(380px, calc(100vw - 32px)); height: min(620px, calc(100vh - 48px));
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
  animation: popIn 0.2s ease-out;
}
.sim-head { display: flex; align-items: center; gap: 4px; padding: 14px 10px 14px 18px; background: var(--brand); color: #fff; }
.sim-head div { flex: 1; display: flex; flex-direction: column; }
.sim-head small { color: rgb(255 255 255 / 0.7); font-size: 12px; }
.sim-head .icon-btn { color: rgb(255 255 255 / 0.8); }
.sim-head .icon-btn:hover { background: rgb(255 255 255 / 0.1); color: #fff; }
.sim-name { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid var(--border); }
.sim-name input { flex: 1; padding: 5px 10px; font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.sim-body { flex: 1; max-height: none; min-height: 0; }
.sim-composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.sim-composer input { flex: 1; min-width: 0; }
.sim-composer .icon-btn { align-self: center; color: var(--muted); }
.tg-msg.media { display: flex; flex-direction: column; gap: 4px; padding: 4px; }
.tg-msg.media img { display: block; max-width: 200px; max-height: 220px; border-radius: 10px; }
.tg-msg.media span { padding: 2px 8px 4px; }

/* ---------- Avisos ---------- */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow-lg); width: 320px; max-width: calc(100vw - 32px);
  cursor: pointer; animation: slideIn 0.2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: #10b981; }
.toast strong { display: block; font-size: 14px; color: var(--heading); }
.toast p { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } }

/* ---------- Editor de flujo ---------- */
.card.narrow { max-width: 760px; }
.tab-panel { min-width: 0; }

.node-start { --nc: #059669; --nc-fg: #fff; }
.node-message { --nc: #3c085d; --nc-fg: #fff; }
.node-buttons { --nc: #5a188f; --nc-fg: #fff; }
.node-input { --nc: #7c3aed; --nc-fg: #fff; }
.node-lookup { --nc: #2563eb; --nc-fg: #fff; }
.node-condition { --nc: #d97706; --nc-fg: #fff; }
.node-department { --nc: #0891b2; --nc-fg: #fff; }
.node-handoff { --nc: #047857; --nc-fg: #fff; }
.node-end { --nc: #64748b; --nc-fg: #fff; }

.fnode-icon {
  width: 30px; height: 30px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--nc); color: var(--nc-fg);
}
.fnode-icon svg { width: 16px; height: 16px; }

.flow-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.flow-add { display: flex; flex-wrap: wrap; gap: 6px; }
.add-block {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 13px; font-weight: 600; color: #334155;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 12px 4px 4px; cursor: pointer; box-shadow: var(--shadow); transition: all 0.15s;
}
.add-block:hover { border-color: var(--nc); background: var(--surface-2); }
.add-block:active { transform: scale(0.98); }
.add-block .fnode-icon { width: 26px; height: 26px; border-radius: 8px; }
.add-block .fnode-icon svg { width: 14px; height: 14px; }
.flow-actions { display: flex; align-items: center; gap: 8px; }
.flow-dirty { font-size: 12px; font-weight: 600; color: var(--st-pendiente-fg); background: var(--st-pendiente-bg); border: 1px solid var(--st-pendiente-bd); padding: 3px 10px; border-radius: 9999px; }

.flow-editor {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px;
  height: max(520px, calc(100vh - 300px));
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
}
.flow-canvas {
  --grid-size: 24px; --grid-x: 0px; --grid-y: 0px;
  position: relative; overflow: hidden; cursor: grab; touch-action: none; outline: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #cbd5e1 1.1px, transparent 1.2px);
  background-size: var(--grid-size) var(--grid-size);
  background-position: var(--grid-x) var(--grid-y);
}
.flow-canvas.panning { cursor: grabbing; }
.flow-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--brand); }
.flow-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.flow-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.edge { fill: none; stroke: #94a3b8; stroke-width: 2; }
.edge.active { stroke: var(--brand); stroke-width: 2.5; }
.edge.temp { stroke: var(--brand); stroke-dasharray: 6 4; }

.fnode {
  position: absolute; width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--nc);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); cursor: grab; user-select: none;
}
.fnode:hover { box-shadow: var(--shadow-md); }
.fnode.selected { outline: 2px solid var(--brand); outline-offset: 2px; }
.fnode.orphan { opacity: 0.6; }
.fnode-head { position: relative; display: flex; align-items: center; gap: 9px; padding: 10px 12px; }
.fnode-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.fnode-title small { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.fnode-title strong { font-size: 13px; color: var(--heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fnode-body { padding: 0 12px 10px; font-size: 12.5px; color: var(--muted); }
.fnode-body .clamp { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; color: var(--text-2); }
.fnode-body .meta { margin-top: 4px; }
.fnode-body code { font-size: 11px; }
.fnode-outs { border-top: 1px solid var(--border-soft); padding: 4px 0; background: rgb(248 250 252 / 0.6); border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.fnode-out { position: relative; padding: 4px 22px 4px 12px; font-size: 12px; color: var(--text-2); text-align: right; }
.fnode-out > span:first-child { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fnode-end { border-top: 1px solid var(--border-soft); padding: 6px 12px; font-size: 12px; color: var(--subtle); font-style: italic; }
.fnode-orphan { display: none; position: absolute; top: -22px; left: 0; font-size: 11px; font-weight: 600; color: var(--subtle); white-space: nowrap; }
.fnode.orphan .fnode-orphan { display: block; }
.port { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); translate: 0 -50%; }
.port.in { left: -8px; border: 2px solid var(--subtle); }
.port.out { right: -8px; border: 2px solid var(--nc); cursor: crosshair; transition: transform 0.1s; }
.port.out::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; } /* área de agarre más grande */
.port.out.linked { background: var(--nc); }
.port.out:hover { transform: scale(1.35); }

.flow-zoom {
  position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; box-shadow: var(--shadow);
}
.flow-zoom span { font-size: 12px; font-weight: 600; min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text-2); }
.flow-hint { position: absolute; right: 12px; bottom: 12px; max-width: 420px; font-size: 11.5px; color: var(--muted); text-align: right; pointer-events: none; }

.flow-inspector { border-left: 1px solid var(--border); overflow-y: auto; background: var(--surface); }
.insp-head { display: flex; gap: 12px; padding: 18px; background: var(--accent-soft); border-bottom: 1px solid var(--accent-soft-2); }
.insp-head strong { color: var(--brand); }
.insp-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.insp-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.insp-body input[type="text"], .insp-body input[type="number"], .insp-body textarea, .insp-body .select { width: 100%; }
.insp-body input[type="number"] { max-width: 110px; }
.insp-actions { display: flex; justify-content: space-between; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.sub-list { display: flex; flex-direction: column; gap: 6px; }
.sub-item { display: flex; gap: 2px; align-items: center; }
.sub-item input { flex: 1; min-width: 0; }
.sub-list + .btn { align-self: flex-start; margin-top: 4px; }
.conn-list { display: flex; flex-direction: column; gap: 10px; }
.conn-row { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.insp-empty { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.insp-empty h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--heading); }
.type-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.type-list li { display: flex; gap: 10px; align-items: flex-start; }
.type-list strong { color: var(--heading); }
.type-list p { font-size: 12.5px; color: var(--muted); }

/* ---------- Chat con panel del cliente ---------- */
.chat-layout { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 320px; }
.chat-column { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* Formularios al CRM: pestañas tipo marcapáginas a la izquierda del chat, con el texto en horizontal */
.crm-forms { display: flex; min-height: 0; }
.crm-tabs { width: 104px; padding: 14px 0; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; background: var(--surface-2); border-right: 1px solid var(--border); }
.crm-tab {
  --tab: var(--brand);
  position: relative; width: 94px; padding: 10px 8px 10px 10px;
  font: inherit; font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: left; color: var(--text-2); cursor: pointer;
  background: color-mix(in srgb, var(--tab) 8%, var(--surface));
  border: 1px solid var(--border); border-left: 4px solid var(--tab); border-right: 0; border-radius: 10px 0 0 10px;
  transition: width 0.15s, background 0.15s, color 0.15s;
}
.crm-tab:hover { width: 98px; color: var(--heading); }
.crm-tab:focus-visible { outline: none; box-shadow: var(--ring); }
.crm-tab[aria-selected="true"] { width: 98px; margin-right: -1px; background: var(--surface); color: var(--heading); }
.crm-tab[data-form="cashea"] { --tab: #eab308; }
.crm-tab[data-form="pago"] { --tab: #10b981; }
.crm-tab[data-form="venta"] { --tab: #7c3aed; }
.crm-tab[data-form="visita"] { --tab: #2563eb; }
.crm-panel { width: 320px; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); border-right: 1px solid var(--border); }
.crm-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.crm-head h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--heading); }
.crm-head .icon-btn { margin: -4px -6px 0 0; }
.crm-form { display: flex; flex-direction: column; gap: 12px; }
.crm-form .btn { align-self: stretch; margin-top: 4px; }
.chat-info { border-left: 1px solid var(--border); overflow-y: auto; background: var(--surface); }

/* Pestañas del panel derecho: Cliente | Historial */
.info-tabs { position: sticky; top: 0; z-index: 1; display: flex; gap: 4px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.info-tabs button {
  flex: 1; font: inherit; font-size: 13px; font-weight: 700; color: var(--text-2); cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 10px; padding: 7px 10px; transition: all 0.15s;
}
.info-tabs button:hover { color: var(--brand); }
.info-tabs button[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--brand); }

/* Historial del ticket */
.history-summary { display: grid; gap: 8px; margin: 0; }
.history-summary div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
.history-summary dt { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.history-summary dd { margin: 0; font-size: 13px; font-weight: 700; color: var(--heading); text-align: right; font-variant-numeric: tabular-nums; }
.history-list { list-style: none; margin: 0; padding: 0; position: relative; }
.history-day { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 0 4px; }
.history-day:first-child { padding-top: 0; }
.history-item { --tone: var(--subtle); position: relative; display: flex; gap: 10px; padding: 0 0 12px; }
.history-item::before { content: ""; position: absolute; left: 4px; top: 12px; bottom: -2px; width: 2px; background: var(--border-soft); }
.history-item:has(+ .history-day)::before, .history-item:last-child::before { display: none; }
.history-dot { width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--tone); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent); flex-shrink: 0; }
.history-item p { margin: 0; font-size: 13px; line-height: 1.4; color: var(--text); }
.history-item p b { color: var(--heading); font-weight: 700; }
.history-item time { font-size: 11.5px; color: var(--subtle); }
.tone-brand { --tone: var(--brand); }
.tone-status { --tone: var(--st-abierto-dot); }
.tone-closed { --tone: var(--st-cerrado-dot); }
.tone-dept { --tone: #0891b2; }
.tone-assign { --tone: #7c3aed; }
.tone-reply { --tone: #2563eb; }
.tone-bot { --tone: #a78bfa; }
.tone-warn { --tone: var(--st-pendiente-dot); }
.tone-muted { --tone: var(--subtle); }
.info-toggle { display: none; align-items: center; gap: 6px; }
.info-toggle svg { width: 16px; height: 16px; }
.bot-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; background: var(--accent-soft); color: var(--brand); border: 1px solid var(--accent-soft-2); white-space: nowrap; }

.info-section { padding: 18px 20px; border-bottom: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 10px; }
.info-section:last-child { border-bottom: 0; }
.info-section h3 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.info-customer { display: flex; flex-direction: column; gap: 4px; padding: 14px; background: var(--accent-soft); border: 1px solid var(--accent-soft-2); border-radius: var(--radius); }
.info-name { font-size: 16px; font-weight: 800; color: var(--brand); line-height: 1.3; }
.info-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.state-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 9999px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.state-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state-pill.good { background: var(--st-abierto-bg); color: var(--st-abierto-fg); border-color: rgb(167 243 208 / 0.4); }
.state-pill.bad { background: #fff1f2; color: #be123c; border-color: rgb(254 205 211 / 0.4); }
.demo-badge { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--st-pendiente-bg); color: var(--st-pendiente-fg); border: 1px solid var(--st-pendiente-bd); }
.info-fields { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 8px 12px; margin: 0; font-size: 13px; }
.info-fields dt { color: var(--muted); font-weight: 500; }
.info-fields dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.info-fields.nested { grid-column: 1 / -1; font-size: 12px; }
.info-items { margin: 0; padding-left: 16px; }
.info-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.info-state { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); padding: 14px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius); }
.info-state strong { color: var(--heading); }
.info-state.error { background: #fff1f2; border-color: #ffe4e6; }
.info-state.error strong { color: var(--danger); }
.info-state:has(.spinner) { flex-direction: row; align-items: center; gap: 8px; }
.info-lookup { display: flex; gap: 6px; }
.info-lookup input { flex: 1; min-width: 0; font-size: 13px; padding: 6px 10px; }
.info-other summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--brand); margin-bottom: 8px; }

/* Notas internas del cliente: en amarillo, para distinguirlas de lo que ve el cliente */
.notes-section h3 { display: flex; align-items: center; gap: 6px; }
.note-count { font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 9999px; background: var(--st-pendiente-bg); color: var(--st-pendiente-fg); border: 1px solid var(--st-pendiente-bd); letter-spacing: 0; }
.note-form { display: flex; flex-direction: column; gap: 6px; }
.note-form textarea { font-size: 13px; padding: 8px 10px; resize: vertical; min-height: 56px; }
.note-form .btn { align-self: flex-end; }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note-list li { padding: 10px 12px; background: var(--st-pendiente-bg); border: 1px solid var(--st-pendiente-bd); border-radius: var(--radius-sm); }
.note-list p { margin: 0; font-size: 13px; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.note-delete { font: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; }
.note-delete:hover { color: var(--danger); text-decoration: underline; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent-soft-2); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Inicio de sesión (como el login del CRM) ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--brand); }
.auth-card { width: min(448px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 32px; display: flex; flex-direction: column; gap: 20px; }
.auth-logo { display: block; width: 240px; height: 96px; object-fit: contain; margin: 0 auto; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form h1 { font-size: 30px; color: var(--brand); text-align: center; }
.auth-form p.muted { margin-top: -8px; font-size: 13px; text-align: center; }
.auth-form .field input { width: 100%; }
.btn.block { width: 100%; padding: 10px; }

/* ---------- Usuario en la barra lateral ---------- */
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 12px; }
.user-box { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: var(--radius-sm); background: rgb(255 255 255 / 0.1); border: 1px solid rgb(255 255 255 / 0.1); }
.user-box .avatar { background: #fff; color: var(--brand); }
.user-box-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.user-box-text strong { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box-text small { font-size: 11.5px; color: rgb(255 255 255 / 0.7); }
.user-box .icon-btn { color: rgb(255 255 255 / 0.8); padding: 5px; }
.user-box .icon-btn:hover { background: rgb(255 255 255 / 0.1); color: #fff; }
.user-box .icon-btn svg { width: 16px; height: 16px; }

/* ---------- Ajustes ---------- */
.settings-card { margin-bottom: 20px; overflow: visible; }
.settings-section { padding: 18px 20px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 10px; }
.settings-section h3 { margin: 0; font-size: 14px; color: var(--heading); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 260px; min-width: 0; }
.origin-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.origin-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border-soft); }
.origin-list li:last-child { border-bottom: 0; }
.origin-list .origin { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; color: var(--heading); overflow-wrap: anywhere; }
.origin-list .empty-row { color: var(--muted); font-size: 13px; padding: 12px 14px; }
.snippet { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.snippet code { flex: 1; min-width: 0; background: none; padding: 0; font-size: 13px; color: var(--heading); overflow-wrap: anywhere; }
.settings-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn.disabled { opacity: 0.5; pointer-events: none; }
/* Interruptor */
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 40px; height: 22px; border-radius: 9999px; background: #cbd5e1; transition: background 0.15s; flex-shrink: 0; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }

/* ---------- Reportes ---------- */
.report-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 20px; }
.rp-custom { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
#view-reports.refreshing .report-kpis, #view-reports.refreshing .card { opacity: 0.55; transition: opacity 0.15s; }
.report-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.report-kpi strong { font-variant-numeric: normal; }
.report-kpi small { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.report-card { margin-bottom: 20px; padding: 18px 20px; overflow: visible; }
.report-card .table-wrap { margin: 0 -20px -18px; }
.report-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.report-card-head h2 { font-size: 15px; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.report-table { max-height: 360px; overflow-y: auto; }
.agent-cell { display: flex; align-items: center; gap: 4px; }
.agent-cell div { display: flex; flex-direction: column; }
.agent-cell small { font-size: 12px; color: var(--muted); }
.report-card .num { font-variant-numeric: tabular-nums; }

/* Gráficos: marcas finas, cuadrícula y ejes en hairline, texto en tinta (nunca en el color de la serie) */
.chart-box { position: relative; min-height: 240px; }
/* Anula la regla general de íconos (svg con trazo): en el gráfico cada marca define el suyo. */
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; stroke: none; fill: none; stroke-width: 0; }
.chart-svg:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
.chart-grid { stroke: #ecebe6; stroke-width: 1; }
.chart-axis { stroke: #c3c2b7; stroke-width: 1; }
.chart-tick { font-size: 11px; fill: #898781; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-cross { stroke: #c3c2b7; stroke-width: 1; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; min-width: 140px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-md); font-size: 12.5px;
}
.chart-tip-title { color: var(--muted); margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip-row i { width: 12px; height: 2px; border-radius: 1px; }
.chart-tip-row b { color: var(--heading); font-variant-numeric: tabular-nums; min-width: 24px; }
.chart-tip-row span { color: var(--text-2); }
.chart-note { padding: 24px 0; }
.chart-legend { display: flex; gap: 14px; margin-top: 4px; font-size: 12.5px; color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 2px; border-radius: 1px; }
.bar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bar-list li { display: grid; grid-template-columns: minmax(90px, 34%) 1fr; align-items: center; gap: 10px; border-radius: 6px; }
.bar-list li:hover .bar-fill, .bar-list li:focus-visible .bar-fill { filter: brightness(1.12); }
.bar-list li:focus-visible { outline: none; box-shadow: var(--ring); }
.bar-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label i { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-fill { height: 12px; border-radius: 0 4px 4px 0; flex-shrink: 0; }
.bar-value { font-size: 12.5px; color: var(--heading); font-variant-numeric: tabular-nums; }

/* ---------- Guardias ---------- */
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.guards-toolbar { gap: 8px; }
.guards-toolbar strong { min-width: 200px; text-align: center; color: var(--heading); font-size: 15px; }
.guards-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.guard-dow { padding: 8px 10px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.guard-cell { display: flex; flex-direction: column; gap: 4px; min-height: 112px; min-width: 0; padding: 6px; border-right: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.guard-cell:nth-child(7n) { border-right: 0; }
.guard-cell.out { background: var(--surface-2); }
.guard-cell.out .guard-num { color: var(--subtle); font-weight: 600; }
.guard-cell.today { background: var(--accent-soft); }
.guard-cell-head { display: flex; align-items: center; gap: 6px; min-height: 24px; }
.guard-num { font-size: 13px; font-weight: 800; color: var(--heading); padding-left: 2px; }
.guard-wd { display: none; }
.guard-cell-head em { font-style: normal; font-size: 10.5px; font-weight: 700; color: var(--brand); background: var(--accent-soft-2); padding: 1px 7px; border-radius: 9999px; }
.guard-add { margin-left: auto; padding: 3px; opacity: 0; transition: opacity 0.15s; }
.guard-add svg { width: 15px; height: 15px; }
.guard-cell:hover .guard-add, .guard-add:focus-visible { opacity: 1; }
.guard-chip {
  position: relative; display: flex; flex-direction: column; gap: 1px; min-width: 0; cursor: pointer;
  padding: 4px 6px 4px 7px; font-size: 11.5px; line-height: 1.3;
  background: var(--surface); border: 1px solid var(--border-soft); border-left: 3px solid var(--brand); border-radius: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.guard-chip:hover, .guard-chip:focus-visible { outline: none; border-color: var(--accent-border); border-left-color: var(--brand); box-shadow: var(--shadow-md); }
.guard-chip.now { border-left-color: var(--st-abierto-dot); background: var(--st-abierto-bg); }
.guard-chip.inactive { opacity: 0.55; }
.guard-chip-top { display: flex; align-items: center; gap: 3px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; white-space: nowrap; }
.guard-chip.now .guard-chip-top { color: var(--st-abierto-fg); }
.guard-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.guard-chip-top .guard-dot:first-of-type { margin-left: 2px; }
.guard-chip-name { color: var(--heading); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guard-del { position: absolute; top: 1px; right: 1px; padding: 2px; background: var(--surface); opacity: 0; transition: opacity 0.15s; }
.guard-del svg { width: 13px; height: 13px; }
.guard-chip:hover .guard-del, .guard-del:focus-visible { opacity: 1; }

/* ---------- Usuarios ---------- */
.role-help { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.role-help div { background: var(--accent-soft); border: 1px solid var(--accent-soft-2); border-radius: var(--radius); padding: 16px 20px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.role-help strong { color: var(--brand); }
.role-help span { color: var(--muted); font-size: 13px; }
.role-pill { display: inline-flex; align-items: center; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.role-pill.role-admin { background: var(--accent-soft); color: var(--brand); border-color: var(--accent-soft-2); }
.role-pill.role-supervisor { background: #eff6ff; color: #1d4ed8; border-color: #dbeafe; }
.role-pill.role-agente { background: var(--st-abierto-bg); color: var(--st-abierto-fg); border-color: rgb(167 243 208 / 0.4); }
.table.static tbody tr { cursor: default; }
.table tr.inactive td { opacity: 0.55; }
.table td.depts { max-width: 280px; }
.table td.depts .chip { margin-right: 8px; }
.actions-cell { white-space: nowrap; text-align: right; }
.assignee { display: inline-flex; align-items: center; font-size: 13px; color: var(--text-2); white-space: nowrap; }

/* Presencia: punto verde en línea, gris desconectado */
.presence-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; vertical-align: middle; }
.presence-dot.on { background: #10b981; box-shadow: 0 0 0 3px rgb(16 185 129 / 0.18); }
.ctl-btn b .presence-dot { margin-right: 5px; }
.presence-cell { white-space: nowrap; font-size: 13px; color: var(--muted); }
.presence-cell.on { color: var(--st-abierto-fg); font-weight: 600; }
.team-online {
  display: inline-flex; align-items: center; gap: 4px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); padding: 6px 14px; border-radius: 9999px; transition: border-color 0.15s;
}
.team-online:hover { border-color: var(--brand); color: var(--brand); }
.team-online b { color: var(--heading); }
.assignee.mine { font-weight: 700; color: var(--brand); }
.assignee-text { font-size: 13px; color: var(--text-2); font-weight: 500; }
.checkgroup { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.checkgroup legend { margin-bottom: 6px; padding: 0; }

/* ---------- Respuestas rápidas ---------- */
.composer { position: relative; }
.qr-trigger { align-self: center; color: var(--brand); background: var(--accent-soft); }
.qr-trigger:hover { background: var(--accent-soft-2); color: var(--brand); }
.qr-trigger svg { width: 20px; height: 20px; }
.qr-popup {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% + 6px); z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; max-height: 340px; overflow: hidden;
}
.qr-popup-search { margin: 10px; font-size: 13px; }
.qr-popup ul { list-style: none; margin: 0; padding: 4px 6px; overflow-y: auto; }
.qr-popup li { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 10px; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.qr-popup li.active, .qr-popup li:hover { background: var(--accent-soft); }
.qr-popup li p { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-popup li.qr-empty { display: block; color: var(--muted); font-size: 13px; cursor: default; background: none; }
.qr-popup-foot { display: flex; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border-soft); background: var(--surface-2); font-size: 11.5px; color: var(--muted); }
.qr-popup-foot a, .qr-empty a { color: var(--brand); font-weight: 600; }
.qr-shortcut { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }
.qr-scope { justify-self: end; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 9999px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.qr-scope.qr-personal { background: var(--accent-soft); color: var(--brand); border-color: var(--accent-soft-2); }
.qr-scope.qr-global { background: var(--st-abierto-bg); color: var(--st-abierto-fg); border-color: rgb(167 243 208 / 0.4); }
.qr-scope.qr-department { background: #eff6ff; color: #1d4ed8; border-color: #dbeafe; }
#qr-list .grow p { -webkit-line-clamp: 3; }

/* ---------- Acciones sobre tickets (botones en lugar de selectores) ---------- */
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.bulk-count { font-size: 13px; font-weight: 600; color: var(--muted); }
.bulk-bar.has-selection .bulk-count { color: var(--brand); }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.bulk-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit; font-size: 13.5px; font-weight: 600; color: #fff; cursor: pointer;
  background: var(--brand); border: 0; border-radius: 10px; padding: 8px 14px;
  box-shadow: var(--shadow-md); transition: all 0.15s; white-space: nowrap;
}
.bulk-btn svg { width: 16px; height: 16px; }
.bulk-btn:hover { background: var(--brand-hover); }
.bulk-btn:active { transform: scale(0.98); }
.bulk-btn.danger { background: #f43f5e; }
.bulk-btn.danger:hover { background: #e11d48; }
.bulk-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; transform: none; }
.bulk-btn:disabled:hover { background: var(--brand); }
.bulk-btn.danger:disabled:hover { background: #f43f5e; }
.bulk-btn[aria-expanded="true"] { background: var(--brand-dark); }

.check-col { width: 44px; text-align: center; padding-right: 0 !important; }
.table th.check-col input { accent-color: #fff; }
.table tbody tr:has(input[data-select]:checked) { background: var(--accent-soft); }

/* Botones del chat: etiqueta + valor actual */
.ctl-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px;
  transition: all 0.15s; max-width: 280px;
}
.ctl-btn span { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ctl-btn b { font-weight: 600; color: var(--brand); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctl-btn svg { width: 14px; height: 14px; color: var(--subtle); }
.ctl-btn:hover, .ctl-btn[aria-expanded="true"] { border-color: var(--brand); background: var(--accent-soft); }
.ctl-btn:disabled { cursor: not-allowed; opacity: 0.6; background: var(--surface-2); border-color: var(--border); }
.ctl-btn:disabled svg { display: none; }
.ctl-btn[data-value="urgente"] b { color: #be123c; }
.ctl-btn[data-value="alta"] b { color: #b45309; }
.ctl-btn[data-value="abierto"] b { color: var(--st-abierto-fg); }
.ctl-btn[data-value="pendiente"] b { color: var(--st-pendiente-fg); }
.chat-controls .bulk-btn { margin-left: auto; padding: 6px 12px; font-size: 13px; }

/* Menú flotante */
.menu-pop {
  position: fixed; z-index: 70; max-height: 360px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 6px; animation: popIn 0.12s ease-out;
}
.menu-section + .menu-section { border-top: 1px solid var(--border-soft); margin-top: 4px; padding-top: 4px; }
.menu-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 10px 4px; }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  font: inherit; font-size: 13.5px; color: var(--text); text-align: left; cursor: pointer;
  background: none; border: 0; border-radius: 8px; padding: 8px 10px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); outline: none; color: var(--brand); }
.menu-item.current { font-weight: 700; color: var(--brand); }
.menu-item span { flex: 1; }
.menu-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.menu-tick { width: 16px; height: 16px; color: var(--brand); }
.menu-check { width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--subtle); flex-shrink: 0; display: grid; place-items: center; }
.menu-check.on { background: var(--brand); border-color: var(--brand); }
.menu-check.on::after { content: ""; width: 8px; height: 4px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.menu-empty { font-size: 13px; color: var(--muted); padding: 8px 10px; }

/* Prioridad y etiquetas */
.prio { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 9999px; white-space: nowrap; border: 1px solid transparent; }
.prio::before { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 7px solid currentColor; }
.prio-urgente { background: #fff1f2; color: #be123c; border-color: #ffe4e6; }
.prio-alta { background: #fffbeb; color: #b45309; border-color: #fef3c7; }
.prio-media { background: #eff6ff; color: #1d4ed8; border-color: #dbeafe; }
.prio-baja { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.prio-baja::before { transform: rotate(180deg); }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag {
  display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; line-height: 1.4;
  padding: 1px 8px; border-radius: 6px; white-space: nowrap;
  color: var(--tag); background: color-mix(in srgb, var(--tag) 10%, white); border: 1px solid color-mix(in srgb, var(--tag) 25%, white);
}
.tag.tag-lg { font-size: 13px; padding: 4px 12px; border-radius: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis.report-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .flow-editor { grid-template-columns: 1fr; grid-template-rows: minmax(420px, 60vh) auto; height: auto; }
  .flow-inspector { border-left: 0; border-top: 1px solid var(--border); max-height: none; }
  .flow-hint { display: none; }
}
@media (max-width: 1000px) {
  .chat-layout { grid-template-columns: auto minmax(0, 1fr); }
  .crm-panel { position: absolute; top: 0; bottom: 0; left: var(--crm-rail, 104px); width: min(340px, calc(100% - var(--crm-rail, 104px))); box-shadow: var(--shadow-lg); z-index: 3; }
  .info-toggle { display: inline-flex; }
  .chat-info { display: none; position: absolute; inset: 0 0 0 auto; width: min(340px, 100%); box-shadow: var(--shadow-lg); z-index: 2; }
  .chat.show-info .chat-info { display: block; }
}
@media (max-width: 760px) {
  .report-grid { grid-template-columns: 1fr; }
  /* En el teléfono el mes se ve como lista de días. */
  .guards-month { grid-template-columns: 1fr; }
  .guard-dow, .guard-cell.out { display: none; }
  .guard-cell { min-height: 0; border-right: 0; padding: 8px 12px; }
  .guard-cell.free .guard-num { color: var(--muted); font-weight: 600; }
  .guard-wd { display: inline; }
  .guard-add, .guard-del { opacity: 1; }
  .guard-chip { font-size: 13px; }
  .guards-toolbar strong { min-width: 0; flex: 1; font-size: 14px; }
  /* --- Estructura: barra superior + menú lateral deslizable --- */
  .app { display: block; }
  .mobile-bar {
    position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px;
    height: 56px; padding: 0 12px 0 6px; background: var(--brand); color: #fff; box-shadow: 0 4px 10px -4px rgb(0 0 0 / 0.3);
  }
  .mobile-bar .icon-btn { position: relative; color: #fff; padding: 9px; }
  .mobile-bar .icon-btn svg { width: 22px; height: 22px; }
  .mobile-bar strong { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; font-size: 10.5px; }
  .mobile-bar .status-dot { width: 10px; height: 10px; }
  .mobile-bar[data-bot="ok"] .status-dot { background: #34d399; box-shadow: 0 0 0 3px rgb(52 211 153 / 0.25); }
  .mobile-bar[data-bot="warn"] .status-dot { background: #fbbf24; }
  .mobile-bar[data-bot="error"] .status-dot { background: #fb7185; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70; width: min(290px, 85vw); height: 100dvh; overflow-y: auto;
    transform: translateX(-100%); visibility: hidden; transition: transform 0.2s ease-out, visibility 0s 0.2s;
  }
  body.nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease-out; }
  body.nav-open { overflow: hidden; }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 65; background: rgb(15 23 42 / 0.5); animation: fadeIn 0.15s ease-out; }
  .nav a { padding: 12px 16px; }

  /* --- Contenido --- */
  .mobile-only { display: block; }
  .role-help { grid-template-columns: 1fr; }
  .main { padding: 14px 12px 96px; }
  .view { padding: 0; }
  .view-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; padding-bottom: 14px; }
  .view-header h1 { font-size: 21px; }
  .view-icon { padding: 9px; }
  .header-actions { flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
  .kpi { padding: 12px 14px; }
  .kpi strong { font-size: 24px; }
  .kpi span { font-size: 11px; }
  /* Sin zoom automático del iPhone al escribir: los campos de texto van a 16 px. */
  input:not([type="checkbox"]):not([type="color"]), select, textarea { font-size: 16px; }

  /* Barras de filtros: los botones de estado se deslizan; la búsqueda ocupa todo el ancho. */
  .toolbar { padding: 12px; gap: 8px; }
  .toolbar .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmented button { white-space: nowrap; padding: 7px 12px; }
  .toolbar .search { flex-basis: 100%; max-width: none; }
  .toolbar .select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  #live-count { margin-left: 0; }
  .bulk-bar { padding: 10px 12px; }
  .bulk-count { flex-basis: 100%; }
  .bulk-actions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .bulk-btn { font-size: 12.5px; padding: 7px 10px; white-space: nowrap; }

  /* Listas de tickets como app de mensajería (WhatsApp/Telegram): una conversación por fila. */
  .table.cards, .table.cards tbody { display: block; }
  .table.cards thead { display: none; }
  .table.cards tbody tr { display: flex; align-items: center; gap: 4px; padding: 0 12px 0 0; border-bottom: 0; }
  .table.cards tbody tr:active { background: var(--accent-soft); }
  .table.cards td { display: none; padding: 0; border: 0; }
  .table.cards td.c-mobile { display: block; flex: 1; min-width: 0; }
  .chat-item { display: flex; align-items: center; gap: 12px; padding: 10px 0 0 14px; }
  .chat-item .avatar { flex-shrink: 0; margin-bottom: 10px; }
  .ci-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }
  .ci-top, .ci-mid { display: flex; align-items: center; gap: 8px; }
  .ci-top strong { flex: 1; min-width: 0; font-size: 15.5px; font-weight: 600; color: var(--heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ci-top time { flex-shrink: 0; font-size: 12px; color: var(--muted); }
  .ci-msg { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ci-msg b { font-weight: 600; color: var(--text-2); }
  .ci-unread {
    flex-shrink: 0; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 9999px;
    display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: var(--brand);
  }
  .chat-item.unread .ci-top strong { font-weight: 800; }
  .chat-item.unread .ci-top time { color: var(--brand); font-weight: 700; }
  .chat-item.unread .ci-msg { color: var(--text); font-weight: 600; }
  .ci-meta { display: flex; align-items: center; flex-wrap: nowrap; gap: 5px; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; }
  .ci-meta .presence-dot { width: 7px; height: 7px; margin-right: 3px; }
  .ci-sep { font-style: normal; color: var(--subtle); }
  .ci-state { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
  .ci-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--subtle)); }
  .ci-state.st-nuevo { --dot: var(--st-nuevo-dot); color: var(--st-nuevo-fg); }
  .ci-state.st-abierto { --dot: var(--st-abierto-dot); color: var(--st-abierto-fg); }
  .ci-state.st-pendiente { --dot: var(--st-pendiente-dot); color: var(--st-pendiente-fg); }
  .ci-state.st-cerrado { --dot: var(--st-cerrado-dot); color: var(--st-cerrado-fg); }
  .ci-state.bot { color: var(--brand); }
  .ci-state.bot::before { display: none; }
  .ci-prio { font-weight: 700; }
  .ci-prio.urgente { color: #be123c; }
  .ci-prio.alta { color: #b45309; }

  /* La lista ocupa todo el ancho de la pantalla, como en las apps de mensajería. */
  .card:has(.table.cards) { margin: 0 -12px; border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; }

  /* Barra de arriba: búsqueda y fichas de estado a la vista; el resto, tras "Filtros". */
  .card:has(.table.cards) .toolbar .select, .card:has(.table.cards) #live-count, .card:has(.table.cards) #tk-count { display: none; }
  .card.show-filters .toolbar .select:not([hidden]) { display: block; }
  .card.show-filters #live-count, .card.show-filters #tk-count { display: inline; }
  .card:has(.table.cards) .toolbar .search { order: -1; }
  /* Modo selección: casillas a la izquierda y barra de acciones en lote. */
  .card:has(.table.cards) .bulk-bar { display: none; }
  .card.selecting:has(.table.cards) .bulk-bar { display: flex; }
  .card.selecting .table.cards td.check-col { display: block; padding-left: 14px; }
  .card.selecting .table.cards thead { display: block; }
  .card.selecting .table.cards thead tr { display: flex; }
  .card.selecting .table.cards thead th:not(.check-col) { display: none; }
  .card.selecting .table.cards thead th.check-col { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; }
  .card.selecting .table.cards thead th.check-col::after { content: "Seleccionar todos"; font-size: 11.5px; }
  .btn.mobile-inline { display: inline-flex; }
  /* En "En vivo", los indicadores se deslizan en una fila compacta. */
  #kpis { display: flex; overflow-x: auto; scrollbar-width: none; gap: 8px; margin: 0 -12px 12px; padding: 0 12px; }
  #kpis .kpi { flex: 0 0 auto; min-width: 118px; padding: 8px 12px; }
  #kpis .kpi strong { font-size: 20px; margin-top: 2px; }
  /* El título de la sección ya está en la barra superior. */
  .view-header .view-title { display: none; }
  .view-header:not(:has(> :not(.view-title))) { display: none; }
  .view-header { margin-bottom: 12px; padding-bottom: 0; border-bottom: 0; }

  /* Usuarios: tarjetas (nombre y acciones arriba; estado, rol, departamentos y datos debajo). */
  .table.user-cards, .table.user-cards tbody { display: block; }
  .table.user-cards thead { display: none; }
  .table.user-cards tbody tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.user-cards td { display: block; padding: 0; border: 0; }
  .table.user-cards .u-user { order: 1; flex: 1 1 0; min-width: 0; }
  .table.user-cards .u-user .who { min-width: 0; }
  .table.user-cards .u-user strong, .table.user-cards .u-user small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .table.user-cards .u-actions { order: 2; }
  .table.user-cards .u-state { order: 3; flex-basis: 100%; }
  .table.user-cards .u-role, .table.user-cards .u-depts, .table.user-cards .u-auto { order: 4; }
  .table.user-cards .u-open, .table.user-cards .u-last { order: 5; font-size: 12.5px; color: var(--muted); text-align: left; }
  .table.user-cards .u-open::before { content: "Tickets abiertos: "; }
  .table.user-cards .u-last::before { content: "Último acceso: "; }
  .table.user-cards .u-auto::before { content: "Asignación automática "; font-size: 12px; color: var(--muted); }

  /* Desempeño por agente: el nombre queda fijo mientras se desplazan los números. */
  .agent-table th:first-child, .agent-table td:first-child { position: sticky; left: 0; z-index: 1; }
  .agent-table td:first-child { background: var(--surface); box-shadow: 1px 0 0 var(--border); }

  /* --- Chat a pantalla completa --- */
  .modal-backdrop { padding: 0; }
  .modal.chat { height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .chat-header { padding: 10px 12px; gap: 10px; }
  .chat-header h2 { font-size: 16px; }
  .chat-header { padding-left: 4px; }
  .chat-header .avatar { border-radius: 50%; }
  .icon-btn.chat-back { display: grid; }
  #chat-x { display: none; }
  /* Controles del ticket en una sola fila deslizable. */
  .chat-controls { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px; padding: 8px 12px; }
  .ctl-btn, .bot-chip, .assignee-text { flex-shrink: 0; }
  .chat-controls .btn, .chat-controls .bulk-btn { margin-left: 0; flex-shrink: 0; }
  /* Pestañas de formularios (Cashea, pago…) arriba del chat, como fichas; el formulario lo cubre. */
  .chat-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .crm-forms { display: block; }
  .crm-tabs {
    width: auto; height: 42px; flex-direction: row; align-items: flex-end; gap: 6px; padding: 6px 10px 0;
    overflow-x: auto; scrollbar-width: none; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .crm-tab, .crm-tab:hover, .crm-tab[aria-selected="true"] {
    width: auto; flex-shrink: 0; white-space: nowrap; padding: 6px 12px; margin: 0 0 -1px; font-size: 12.5px;
    border: 1px solid var(--border); border-top: 3px solid var(--tab); border-bottom: 0; border-radius: 10px 10px 0 0;
  }
  .crm-tab[aria-selected="true"] { background: var(--surface); }
  .crm-panel { top: 42px; left: 0; right: 0; width: auto; border-right: 0; }
  .chat-info { width: 100%; }
  .chat-body { padding: 12px; }
  .msg { max-width: 88%; }
  .att-image img, .att-video { width: 240px; }
  .composer { padding: 8px 10px; gap: 6px; }
  .composer .btn { padding: 8px 14px; }

  /* --- Ventanas y avisos --- */
  .dialog { width: calc(100vw - 16px); }
  .dialog form { max-height: calc(100dvh - 32px); }
  .toasts { top: 64px; left: 12px; right: 12px; }
  .toast { width: auto; max-width: none; }
  .list li { flex-wrap: wrap; }
  .sim { inset: 0; width: auto; height: 100dvh; border-radius: 0; border: 0; }
  .sim-fab { right: 14px; bottom: 14px; padding: 11px 15px; }
}
