:root { --bg:#0b1020; --panel:#121a2f; --soft:#1b2540; --text:#eef4ff; --muted:#98a6c3; --line:#25314f; --accent:#7c9cff; --good:#43d19e; --bad:#ff6b6b; --warn:#f5c15c; }
* { box-sizing: border-box; }
body { margin:0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif; background:var(--bg); color:var(--text); }
a { color: inherit; text-decoration: none; }
.app-shell { display:flex; min-height:100vh; }
.sidebar { width:260px; background:#080d1a; border-right:1px solid var(--line); padding:22px; position:sticky; top:0; height:100vh; display:flex; flex-direction:column; gap:24px; }
.brand { font-weight:900; font-size:24px; letter-spacing:-.06em; }
.brand span { color:var(--accent); }
.brand.big { font-size:42px; text-align:center; margin-bottom:12px; }
.sidebar nav { display:flex; flex-direction:column; gap:8px; }
.sidebar nav a, .logout-form button { padding:12px 14px; border-radius:14px; color:var(--muted); border:1px solid transparent; background:transparent; text-align:left; width:100%; cursor:pointer; font-size:15px; }
.sidebar nav a:hover, .logout-form button:hover { background:var(--soft); color:var(--text); border-color:var(--line); }
.logout-form { margin-top:auto; }
.main { flex:1; padding:28px; min-width:0; }
.topbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:22px; }
.topbar h1 { margin:0; font-size:30px; letter-spacing:-.04em; }
.topbar p { margin:4px 0 0; color:var(--muted); }
.user-pill { padding:10px 14px; background:var(--soft); border:1px solid var(--line); border-radius:999px; color:var(--muted); }
.grid { display:grid; gap:18px; margin-bottom:18px; }
.cards-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.cards-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.card, .stat-card { background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02)); border:1px solid var(--line); border-radius:22px; padding:20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.stat-card span { display:block; color:var(--muted); font-size:14px; }
.stat-card strong { display:block; font-size:38px; margin-top:8px; }
.section-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
h2 { margin:0 0 12px; letter-spacing:-.03em; }
p { color:var(--muted); line-height:1.5; }
.table-wrap { overflow:auto; }
table { width:100%; border-collapse:collapse; min-width:700px; }
th, td { padding:12px; border-bottom:1px solid var(--line); text-align:left; vertical-align:top; }
th { color:var(--muted); font-weight:600; }
.badge { padding:5px 9px; border-radius:999px; background:var(--soft); color:var(--good); font-size:12px; }
button, .button { border:1px solid var(--line); background:var(--soft); color:var(--text); padding:10px 14px; border-radius:13px; cursor:pointer; display:inline-block; }
button.primary, .button.primary, .primary { background:var(--accent); border-color:var(--accent); color:white; }
.danger-button { background:rgba(255,107,107,.12); border-color:rgba(255,107,107,.35); color:#ffd1d1; }
.flash { padding:14px 16px; border-radius:16px; margin-bottom:16px; background:var(--soft); border:1px solid var(--line); }
.flash.success { border-color:rgba(67,209,158,.45); color:#c6ffe8; }
.flash.error, .danger { border-color:rgba(255,107,107,.45); color:#ffbcbc; }
.warning-card { border-color:rgba(245,193,92,.35); }
.inline-form { display:inline-flex; gap:8px; align-items:center; margin:4px 6px 4px 0; }
.form-grid { display:grid; gap:10px; }
label { color:var(--muted); font-size:14px; }
input, textarea, select { width:100%; background:#0e162b; color:var(--text); border:1px solid var(--line); border-radius:13px; padding:11px 12px; font:inherit; }
textarea { resize:vertical; }
.check { display:flex; align-items:center; gap:10px; }
.check input { width:auto; }
.qr-card img { width:min(320px,100%); background:white; padding:10px; border-radius:18px; }
.empty-qr, .connected-box, .empty-state { min-height:220px; display:grid; place-items:center; color:var(--muted); background:#0e162b; border:1px dashed var(--line); border-radius:18px; }
.connected-box { color:var(--good); }
.chat-layout { display:grid; grid-template-columns: 340px minmax(0,1fr); gap:18px; height:calc(100vh - 130px); }
.chat-list { overflow:auto; }
.chat-item { display:block; padding:13px; border-radius:14px; border:1px solid transparent; margin-bottom:8px; background:#0e162b; }
.chat-item.active, .chat-item:hover { border-color:var(--accent); }
.chat-item span { display:block; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:4px; }
.chat-window { display:flex; flex-direction:column; min-height:0; }
.chat-header { display:flex; justify-content:space-between; gap:12px; border-bottom:1px solid var(--line); padding-bottom:12px; margin-bottom:12px; }
.messages { flex:1; overflow:auto; padding:6px; display:flex; flex-direction:column; gap:10px; }
.bubble { max-width:70%; padding:12px 14px; border-radius:18px; background:#0e162b; }
.bubble.out { align-self:flex-end; background:#21345f; }
.bubble.in { align-self:flex-start; }
.bubble.system { align-self:center; }
.bubble p { color:var(--text); margin:0; white-space:pre-wrap; }
.bubble small { display:block; color:var(--muted); margin-top:6px; font-size:11px; }
.send-box { display:flex; gap:10px; border-top:1px solid var(--line); padding-top:12px; }
.send-box textarea { min-height:50px; }
.login-page { display:grid; place-items:center; min-height:100vh; padding:24px; }
.login-card { width:min(440px,100%); background:var(--panel); border:1px solid var(--line); border-radius:28px; padding:30px; }
.login-card h1 { text-align:center; margin:0; }
.login-card p { text-align:center; }
pre { overflow:auto; background:#0e162b; padding:18px; border-radius:16px; border:1px solid var(--line); color:#d7e1ff; }
.muted { color:var(--muted); }
.mini-calendar { display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.mini-day { min-height:62px; border:1px solid var(--line); border-radius:12px; padding:8px; background:#0e162b; font-size:12px; }
.mini-day.has { border-color:var(--accent); }
@media (max-width: 920px) { .app-shell { display:block; } .sidebar { position:relative; width:100%; height:auto; } .cards-4,.cards-2,.chat-layout { grid-template-columns:1fr; } .main { padding:18px; } .chat-layout { height:auto; } .chat-window { min-height:620px; } }


/* ===== V1.1 modern UI: day/night, agenda, clients ===== */
:root {
  --bg:#0b1020; --panel:#121a2f; --soft:#1b2540; --text:#eef4ff; --muted:#98a6c3; --line:#25314f; --accent:#7c9cff; --accent-2:#46e0b0;
  --good:#43d19e; --bad:#ff6b6b; --warn:#f5c15c; --shadow: rgba(0,0,0,.25);
}
body.theme-light {
  --bg:#f4f7fb; --panel:#ffffff; --soft:#eef3ff; --text:#152039; --muted:#61708e; --line:#dbe4f4; --accent:#315be8; --accent-2:#099268;
  --good:#087f5b; --bad:#d94848; --warn:#b7791f; --shadow: rgba(30, 55, 90, .12);
}
body.theme-light .sidebar { background:#ffffff; }
body.theme-light input, body.theme-light textarea, body.theme-light select,
body.theme-light .empty-qr, body.theme-light .connected-box, body.theme-light .empty-state,
body.theme-light .chat-item, body.theme-light .bubble.in, body.theme-light pre,
body.theme-light .mini-day, body.theme-light .calendar-day { background:#f8fbff; }
body.theme-light .bubble.out { background:#dfe8ff; }
body.theme-light .brand, body.theme-light h1, body.theme-light h2, body.theme-light td { color:var(--text); }
body.theme-light .card, body.theme-light .stat-card { background:linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.84)); }
body.theme-light .warning-card { background:#fff9eb; }

.top-actions { display:flex; align-items:center; gap:10px; }
.theme-toggle { white-space:nowrap; border-radius:999px; padding:10px 14px; }

.cards-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-row { display:grid; gap:12px; }
.form-row.two { grid-template-columns:repeat(2,minmax(0,1fr)); }
.form-row.three { grid-template-columns:repeat(3,minmax(0,1fr)); }
.agenda-form-card, .calendar-card { margin-bottom:18px; }
.appointment-form { gap:14px; }
.small, button.small, .button.small { padding:8px 11px; border-radius:11px; font-size:13px; }

.search-input { display:flex; align-items:center; gap:8px; background:#0e162b; border:1px solid var(--line); border-radius:14px; padding:0 10px; }
body.theme-light .search-input { background:#f8fbff; }
.search-input input { border:0; background:transparent; padding:11px 4px; outline:0; }
.search-input button { margin-left:auto; }
.table-search { min-width:min(420px,100%); }

.modern-calendar { display:grid; grid-template-columns:repeat(7, minmax(0,1fr)); gap:10px; }
.calendar-weekday { color:var(--muted); font-size:12px; font-weight:800; text-transform:uppercase; letter-spacing:.08em; padding:4px 6px; }
.calendar-day { min-height:118px; border:1px solid var(--line); border-radius:18px; padding:10px; background:#0e162b; position:relative; overflow:hidden; transition:.18s ease; }
.calendar-day:hover { transform:translateY(-2px); border-color:var(--accent); box-shadow:0 18px 40px var(--shadow); }
.calendar-day.blank { opacity:.45; }
.calendar-day.today { border-color:var(--accent-2); box-shadow:inset 0 0 0 1px rgba(70,224,176,.35); }
.calendar-day.has { border-color:rgba(124,156,255,.75); }
.calendar-number { display:flex; justify-content:space-between; align-items:center; font-weight:800; margin-bottom:8px; }
.calendar-count { font-size:11px; color:white; background:var(--accent); border-radius:999px; padding:3px 7px; }
.calendar-chip { display:block; font-size:11px; color:var(--text); border:1px solid var(--line); background:rgba(124,156,255,.12); border-radius:10px; padding:5px 6px; margin-top:5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.calendar-legend span { display:flex; align-items:center; gap:8px; color:var(--muted); font-size:13px; }
.calendar-legend i { width:11px; height:11px; background:var(--accent); border-radius:999px; display:inline-block; }

.actions-cell { min-width:360px; }
.actions-cell .inline-form { vertical-align:middle; }
.badge.status-confirmada { color:var(--good); }
.badge.status-pendiente { color:var(--warn); }
.badge.status-cancelada { color:var(--bad); }
.badge.status-reprogramada { color:var(--accent); }
.badge.status-atendida { color:var(--accent-2); }

.clients-layout { grid-template-columns: 360px minmax(0,1fr); align-items:start; }
.client-page-search { margin-bottom:14px; }
.client-list { max-height:calc(100vh - 235px); overflow:auto; padding-right:4px; }
.client-item { display:block; padding:14px; border:1px solid var(--line); border-radius:16px; margin-bottom:10px; background:#0e162b; }
body.theme-light .client-item { background:#f8fbff; }
.client-item.active, .client-item:hover { border-color:var(--accent); box-shadow:0 16px 32px var(--shadow); }
.client-item strong, .client-item span, .client-item small { display:block; }
.client-item span { color:var(--muted); margin-top:4px; }
.client-item small { color:var(--muted); margin-top:7px; }
.client-detail { min-height:70vh; }
.compact-stats .stat-card { padding:16px; }
.compact-stats .stat-card strong { font-size:28px; }
.compact-stats .stat-card .small-stat { font-size:14px; line-height:1.35; word-break:break-word; }
.client-edit-form { margin:18px 0; }
.client-section { margin-top:22px; }
.client-conversations { display:grid; gap:10px; }
.conversation-row { display:block; border:1px solid var(--line); border-radius:16px; padding:14px; background:#0e162b; }
body.theme-light .conversation-row { background:#f8fbff; }
.conversation-row strong, .conversation-row span, .conversation-row small { display:block; }
.conversation-row span { color:var(--muted); margin-top:5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.conversation-row small { color:var(--muted); margin-top:7px; }

@media (max-width: 1100px) {
  .form-row.two, .form-row.three, .cards-3, .clients-layout { grid-template-columns:1fr; }
  .table-search { width:100%; }
  .section-head { align-items:flex-start; flex-direction:column; }
  .modern-calendar { grid-template-columns:repeat(2, minmax(0,1fr)); }
}

/* ===== V1.2 realtime conversations + WhatsApp status checks ===== */
.compact-head { margin-bottom:14px; }
.live-indicator { font-size:12px; color:var(--good); background:rgba(67,209,158,.12); border:1px solid rgba(67,209,158,.25); padding:5px 9px; border-radius:999px; white-space:nowrap; }
.live-indicator.off { color:var(--warn); background:rgba(245,193,92,.12); border-color:rgba(245,193,92,.28); }
.message-status { display:inline-flex; align-items:center; justify-content:center; min-width:22px; margin-left:6px; font-weight:900; letter-spacing:-.12em; color:var(--muted); font-size:13px; vertical-align:middle; }
.message-status.status-sent { color:var(--muted); }
.message-status.status-delivered { color:var(--muted); }
.message-status.status-read { color:#2f9cff; }
.message-status.status-pending { color:var(--warn); letter-spacing:0; }
.message-status.status-failed { color:var(--bad); letter-spacing:0; }
.send-box button:disabled { opacity:.65; cursor:wait; }
.bubble.out[data-status="failed"] { border:1px solid rgba(255,107,107,.4); }
.bubble.out[data-status="pending"] { opacity:.85; }


/* ===== V1.3 multiempresa ===== */
.company-box {
  border:1px solid var(--line);
  background:var(--soft);
  border-radius:18px;
  padding:12px;
}
.company-box small {
  display:block;
  color:var(--muted);
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.08em;
  margin-bottom:4px;
}
.company-box strong {
  display:block;
  line-height:1.2;
}
.company-switch { margin-top:10px; }
.company-switch select { padding:8px 10px; border-radius:12px; font-size:13px; }
.user-pill { text-decoration:none; }
.role-super_admin { color:var(--accent); }
.profile-summary { display:grid; gap:8px; }
.actions-cell { min-width:240px; }
body.theme-light .company-box { background:#f7faff; }


/* ===== V1.4 CRM modules ===== */
.inline-actions { display:flex; flex-wrap:wrap; gap:8px; justify-content:flex-end; }
.card.nested { box-shadow:none; background:rgba(255,255,255,.025); }
body.theme-light .card.nested { background:#f8fbff; }
.status-nuevo,.status-contactado,.status-interesado,.status-cotizado,.status-borrador,.status-enviada,.status-pendiente,.status-abierto { color:var(--warn); }
.status-ganado,.status-aceptada,.status-pagado,.status-activo,.status-completada,.status-resuelto,.status-cerrado { color:var(--good); }
.status-perdido,.status-rechazada,.status-vencida,.status-cancelado,.status-anulado { color:var(--bad); }
.status-pausado,.status-en_proceso,.status-parcial,.status-reprogramada { color:var(--accent); }
.sidebar nav { max-height:65vh; overflow:auto; padding-right:4px; }
.sidebar nav::-webkit-scrollbar, .client-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width:8px; height:8px; }
.sidebar nav::-webkit-scrollbar-thumb, .client-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background:var(--line); border-radius:999px; }
.actions-cell select { min-width:130px; }
td a { color:var(--accent); font-weight:700; }
@media (max-width: 1200px) { .cards-4 { grid-template-columns:repeat(2,minmax(0,1fr)); } }

/* ===== V1.4.1 Responsive mobile navigation and fixed chat viewport ===== */
html { overflow-x:hidden; }
body { overflow-x:hidden; }
.sidebar-head { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.mobile-menu-btn, .sidebar-close, .mobile-overlay { display:none; }
.top-title-row { display:flex; align-items:center; gap:12px; min-width:0; }
.top-title-row > div { min-width:0; }
.topbar h1, .topbar p { overflow:hidden; text-overflow:ellipsis; }

.chat-window.card { overflow:hidden; }
.messages { min-height:0; scroll-behavior:smooth; }
#conversation-list { min-height:0; }
.chat-list.card { display:flex; flex-direction:column; min-height:0; }

@media (max-width: 920px) {
  .app-shell { display:block; min-height:100dvh; }
  .main { padding:14px; width:100%; max-width:100vw; }
  .topbar { gap:12px; align-items:flex-start; margin-bottom:14px; position:relative; }
  .topbar h1 { font-size:24px; line-height:1.1; }
  .topbar p { font-size:13px; max-width:62vw; white-space:nowrap; }
  .top-actions { gap:8px; flex-shrink:0; }
  .theme-toggle { padding:8px 10px; font-size:13px; }
  .user-pill { padding:8px 10px; font-size:13px; max-width:128px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

  .mobile-menu-btn {
    display:inline-flex; align-items:center; justify-content:center; flex:0 0 auto;
    width:42px; height:42px; padding:0; border-radius:14px;
    background:var(--soft); border:1px solid var(--line); color:var(--text);
    font-size:24px; line-height:1;
  }
  .sidebar-close {
    display:inline-flex; align-items:center; justify-content:center;
    width:38px; height:38px; padding:0; border-radius:13px;
    background:var(--soft); border:1px solid var(--line); color:var(--text);
    font-size:26px; line-height:1;
  }
  .mobile-overlay {
    display:none; position:fixed; inset:0; z-index:999;
    background:rgba(0,0,0,.48); backdrop-filter:blur(2px);
  }
  body.mobile-menu-open .mobile-overlay { display:block; }
  body.mobile-menu-open { overflow:hidden; }
  .sidebar {
    position:fixed; top:0; left:0; z-index:1000;
    width:min(86vw, 330px); height:100dvh;
    transform:translateX(-110%); transition:transform .22s ease;
    overflow:auto; padding:18px; gap:16px;
    box-shadow:0 24px 80px rgba(0,0,0,.45);
  }
  body.mobile-menu-open .sidebar { transform:translateX(0); }
  .sidebar nav { max-height:none; overflow:visible; gap:6px; }
  .sidebar nav a, .logout-form button { padding:11px 12px; font-size:14px; }
  .company-box { padding:10px; }

  .grid, .cards-4, .cards-3, .cards-2, .clients-layout, .form-row.two, .form-row.three { grid-template-columns:1fr !important; }
  .card, .stat-card { border-radius:18px; padding:16px; }
  .stat-card strong { font-size:30px; }
  .table-wrap { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  table { min-width:720px; }

  .chat-layout {
    display:flex !important; flex-direction:column;
    grid-template-columns:none !important;
    height:auto !important; min-height:0; gap:14px;
  }
  #conversation-page .chat-list.card {
    height:auto; max-height:32dvh; min-height:185px;
    overflow:auto; padding:14px;
  }
  #conversation-page .chat-list .section-head { position:sticky; top:0; z-index:2; background:var(--panel); padding-bottom:8px; }
  body.theme-light #conversation-page .chat-list .section-head { background:#ffffff; }
  #conversation-page #conversation-list { overflow:auto; }
  .chat-item { padding:12px; }

  #conversation-page .chat-window.card {
    height:72dvh !important;
    min-height:520px;
    max-height:760px;
    padding:14px;
    overflow:hidden;
  }
  .chat-header { gap:10px; align-items:flex-start; margin-bottom:10px; padding-bottom:10px; }
  .chat-header h2 { font-size:22px; line-height:1.15; margin-bottom:6px; }
  .chat-header p { font-size:13px; margin:0; word-break:break-word; }
  .chat-header form { flex:0 0 auto; }
  .chat-header button { padding:9px 10px; font-size:13px; white-space:nowrap; }
  .messages {
    flex:1 1 auto;
    min-height:0;
    overflow-y:auto;
    -webkit-overflow-scrolling:touch;
    padding:4px;
    overscroll-behavior:contain;
  }
  .bubble { max-width:88%; border-radius:16px; padding:11px 12px; }
  .bubble p { font-size:14px; line-height:1.42; }
  .bubble small { font-size:10.5px; }
  .send-box { flex:0 0 auto; gap:8px; padding-top:10px; }
  .send-box textarea { min-height:48px; max-height:120px; font-size:14px; }
  .send-box button { padding:10px 12px; }

  .modern-calendar { grid-template-columns:repeat(2, minmax(0,1fr)) !important; gap:8px; }
  .calendar-day { min-height:104px; border-radius:15px; }
  .client-list { max-height:320px; }
}

@media (max-width: 520px) {
  .main { padding:12px; }
  .topbar { flex-wrap:wrap; }
  .top-title-row { width:100%; }
  .top-actions { width:100%; justify-content:space-between; }
  .topbar p { max-width:calc(100vw - 92px); }
  #conversation-page .chat-list.card { max-height:30dvh; min-height:170px; }
  #conversation-page .chat-window.card { height:70dvh !important; min-height:500px; }
  .bubble { max-width:94%; }
  .send-box { align-items:stretch; }
  .send-box button { min-width:64px; }
  .modern-calendar { grid-template-columns:1fr !important; }
  .calendar-day { min-height:88px; }
  .actions-cell { min-width:220px; }
}

/* ===== V1.4.2 Company module switcher / plans ===== */
.company-module-shortcut {
  display:block;
  margin-top:8px;
  font-size:12px;
  color:var(--accent);
  padding:7px 9px;
  border:1px solid var(--line);
  border-radius:12px;
  background:rgba(124,156,255,.08);
}
.super-company-menu { position:relative; }
.super-company-toggle { white-space:nowrap; }
.super-company-panel {
  display:none;
  position:absolute;
  right:0;
  top:calc(100% + 10px);
  z-index:500;
  width:min(380px, 92vw);
  max-height:70vh;
  overflow:auto;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:0 28px 80px rgba(0,0,0,.35);
  padding:12px;
}
.super-company-panel.open { display:block; }
.super-company-head { padding:8px 10px 12px; border-bottom:1px solid var(--line); margin-bottom:8px; }
.super-company-head strong { display:block; }
.super-company-head span { display:block; color:var(--muted); font-size:12px; margin-top:3px; }
.super-company-row { display:grid; grid-template-columns:1fr auto; gap:8px; align-items:center; padding:7px; border-radius:14px; }
.super-company-row:hover, .super-company-row.active { background:var(--soft); }
.super-company-row form { margin:0; }
.super-company-row button { width:100%; text-align:left; background:transparent; border:0; padding:8px; }
.super-company-row a { color:var(--accent); font-size:13px; padding:8px; border-radius:10px; border:1px solid var(--line); }
.button.full { display:block; text-align:center; margin-top:8px; }
.compact-note { margin:0 0 4px; font-size:13px; }
.module-flow { display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin:16px 0; }
.module-flow span { background:var(--soft); border:1px solid var(--line); border-radius:999px; padding:10px 12px; color:var(--text); }
.preset-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; margin:14px 0 18px; }
.preset-card { display:flex; flex-direction:column; gap:8px; background:var(--soft); border:1px solid var(--line); border-radius:18px; padding:14px; }
.preset-card span { color:var(--muted); font-size:13px; min-height:52px; }
.module-form { margin-top:12px; }
.module-group { border:1px solid var(--line); border-radius:20px; padding:16px; background:rgba(255,255,255,.02); }
.module-group h3 { margin:0 0 12px; font-size:18px; }
.module-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; }
.module-toggle { display:flex; align-items:flex-start; gap:10px; padding:12px; border:1px solid var(--line); border-radius:16px; background:var(--soft); color:var(--text); cursor:pointer; }
.module-toggle input { width:auto; margin-top:4px; }
.module-toggle span { display:block; min-width:0; }
.module-toggle strong { display:block; }
.module-toggle small { display:block; color:var(--muted); margin-top:3px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.module-toggle.required { opacity:.85; border-style:dashed; }
.small-empty { min-height:100px; }
@media (max-width: 1200px) { .preset-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } .module-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media (max-width: 920px) {
  .super-company-menu { position:static; }
  .super-company-panel { position:fixed; left:12px; right:12px; top:72px; width:auto; max-height:72vh; }
  .preset-grid, .module-grid { grid-template-columns:1fr; }
  .super-company-toggle { padding:8px 10px; font-size:13px; }
}

/* ===== V1.4.3 Modales de edición y detalle ===== */
body.modal-open { overflow:hidden; }
.form-actions { display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
.form-actions .primary, .form-actions .button { width:auto; }
.button, button.button { display:inline-flex; align-items:center; justify-content:center; gap:6px; text-decoration:none; }
.table-link {
  border:0;
  background:transparent;
  color:var(--text);
  padding:0;
  margin:0;
  text-align:left;
  cursor:pointer;
  font:inherit;
  max-width:100%;
}
.table-link:hover { color:var(--accent); text-decoration:underline; }
.table-link.strong { font-weight:800; }
.modal {
  display:none;
  position:fixed;
  inset:0;
  z-index:2000;
  padding:22px;
  align-items:center;
  justify-content:center;
}
.modal.open { display:flex; }
.modal-backdrop {
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.62);
  backdrop-filter:blur(4px);
}
.modal-card {
  position:relative;
  z-index:1;
  width:min(760px, 96vw);
  max-height:88dvh;
  overflow:auto;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:24px;
  box-shadow:0 32px 120px rgba(0,0,0,.45);
  padding:22px;
}
.modal-card.wide { width:min(980px, 96vw); }
.modal-head { display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:16px; padding-bottom:12px; border-bottom:1px solid var(--line); }
.modal-head h2 { margin:0; }
.modal-head button {
  width:40px;
  height:40px;
  border-radius:14px;
  padding:0;
  font-size:24px;
  background:var(--soft);
}
.detail-grid { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:12px; margin-bottom:14px; }
.detail-grid > div, .detail-block {
  background:var(--soft);
  border:1px solid var(--line);
  border-radius:16px;
  padding:13px;
}
.detail-grid small, .detail-block small { display:block; color:var(--muted); margin-bottom:5px; text-transform:uppercase; letter-spacing:.04em; font-size:11px; }
.detail-grid strong { word-break:break-word; }
.detail-block p, .detail-block pre { margin:0; white-space:pre-wrap; word-break:break-word; color:var(--text); font-family:inherit; }
.modal .form-grid { gap:12px; }
.modal .form-actions { margin-top:6px; }
@media (max-width: 720px) {
  .modal { padding:10px; align-items:flex-end; }
  .modal-card, .modal-card.wide { width:100%; max-height:92dvh; border-radius:22px 22px 0 0; padding:16px; }
  .detail-grid { grid-template-columns:1fr; }
  .form-actions .primary, .form-actions .button { width:100%; }
}


.live-search-count {
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  padding: 0 4px;
}

.live-search-empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 22px;
}

.search-input.table-search,
.search-input.client-page-search {
  gap: 8px;
}

@media (max-width: 720px) {
  .search-input.table-search,
  .search-input.client-page-search {
    width: 100%;
    flex-wrap: wrap;
  }
  .search-input.table-search input,
  .search-input.client-page-search input {
    min-width: 180px;
  }
}

/* ===== V1.4.5 Detalle de citas al hacer clic en día del calendario ===== */
.calendar-day-button {
  width: 100%;
  text-align: left;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: block;
}
.calendar-day-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.calendar-day-button.has::after {
  content: 'Ver citas';
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 10px;
  color: var(--muted);
  opacity: 0;
  transition: .18s ease;
}
.calendar-day-button.has:hover::after,
.calendar-day-button.has:focus-visible::after {
  opacity: 1;
}
.calendar-day-detail-modal { max-width: 1040px; }
.day-appointment-list { display: grid; gap: 14px; }
.day-appointment-card {
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 18px;
  padding: 14px;
}
.day-appointment-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.day-appointment-head strong,
.day-appointment-head span { display: block; }
.day-appointment-head span { color: var(--muted); margin-top: 3px; }
.detail-grid.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-actions { margin-top: 12px; }
@media (max-width: 920px) {
  .detail-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .detail-grid.compact { grid-template-columns: 1fr; }
  .day-appointment-head { flex-direction: column; }
  .compact-actions .button { width: 100%; }
}

/* ===== V1.4.6 Agenda: buscador de cliente con coincidencias y modal de éxito ===== */
.client-search-wrapper { position:relative; }
.client-suggestions {
  position:absolute;
  z-index:60;
  top:calc(100% + 8px);
  left:0;
  right:0;
  max-height:280px;
  overflow:auto;
  padding:8px;
  border:1px solid var(--line);
  border-radius:16px;
  background:var(--card);
  box-shadow:0 24px 60px var(--shadow);
}
.client-suggestion {
  width:100%;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  text-align:left;
  padding:11px 12px;
  border:1px solid transparent;
  border-radius:12px;
  background:transparent;
  color:var(--text);
  cursor:pointer;
}
.client-suggestion:hover,
.client-suggestion.active {
  background:var(--soft);
  border-color:var(--accent);
}
.client-suggestion strong { display:block; font-size:14px; }
.client-suggestion span { color:var(--muted); font-size:13px; white-space:nowrap; }
.client-suggestion.empty,
.client-suggestion.more {
  display:block;
  color:var(--muted);
  cursor:default;
}
.client-suggestion.empty:hover,
.client-suggestion.more:hover { border-color:transparent; background:transparent; }
.success-modal-card { max-width:460px; text-align:center; }
.success-modal-icon {
  width:66px;
  height:66px;
  border-radius:999px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  margin:0 auto 14px;
  background:rgba(67,209,158,.14);
  color:var(--good);
  border:1px solid rgba(67,209,158,.28);
  font-size:36px;
  font-weight:900;
}
.center-actions { justify-content:center; }
body.theme-light .client-suggestions { background:#fff; }
body.theme-light .client-suggestion:hover,
body.theme-light .client-suggestion.active { background:#f3f7ff; }

@media (max-width: 700px) {
  .client-suggestion { align-items:flex-start; flex-direction:column; gap:4px; }
  .client-suggestion span { white-space:normal; }
}

/* ===== V1.4.7 UX: solid autocomplete, fixed menu, active module, pagination ===== */
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.sidebar nav {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding-right: 6px;
}
.sidebar nav a.active {
  background: linear-gradient(135deg, rgba(124,156,255,.22), rgba(70,224,176,.08));
  color: var(--text);
  border-color: rgba(124,156,255,.65);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 800;
}
body.theme-light .sidebar nav a.active {
  background: #edf3ff;
  border-color: #b8c9ff;
}
.client-suggestions {
  background: #10182d !important;
  border-color: rgba(124,156,255,.45);
  box-shadow: 0 26px 70px rgba(0,0,0,.62);
}
.client-suggestion {
  background: #141f3a;
  margin-bottom: 7px;
  opacity: 1;
}
.client-suggestion:last-child { margin-bottom: 0; }
.client-suggestion:hover,
.client-suggestion.active {
  background: #20315b;
  border-color: var(--accent);
}
.client-suggestion.empty,
.client-suggestion.more {
  background: #10182d;
}
body.theme-light .client-suggestions { background: #ffffff !important; box-shadow: 0 24px 60px rgba(30,55,90,.2); }
body.theme-light .client-suggestion { background: #f8fbff; }
body.theme-light .client-suggestion:hover,
body.theme-light .client-suggestion.active { background: #edf3ff; }
.table-pagination {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding-top:14px;
  flex-wrap:wrap;
}
.table-pagination-info { color: var(--muted); font-size: 13px; }
.table-pagination-actions { display:flex; align-items:center; gap:8px; }
.table-pagination-actions button[disabled] { opacity:.45; cursor:not-allowed; }
@media (max-width: 920px) {
  .sidebar { position:fixed; overflow:auto; }
}

/* ===== V1.4.8 FIX: sidebar realmente fijo en escritorio ===== */
@media (min-width: 921px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    max-height: 100vh;
    z-index: 50;
    overflow: hidden;
  }

  .main {
    margin-left: 260px;
    width: calc(100% - 260px);
    min-height: 100vh;
  }

  .sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
  }

  .logout-form {
    flex: 0 0 auto;
    margin-top: 10px;
  }
}

@media (max-width: 920px) {
  .main {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
  }
}


/* ===== V1.4.9 Calendario optimizado para celular ===== */
.calendar-mobile-label,
.calendar-empty-mobile {
  display: none;
}

@media (max-width: 720px) {
  .calendar-card {
    overflow: hidden;
  }

  .calendar-card .section-head {
    gap: 10px;
  }

  .calendar-legend {
    width: 100%;
  }

  .modern-calendar {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
  }

  .calendar-weekday,
  .calendar-day.blank {
    display: none !important;
  }

  .calendar-day {
    width: 100%;
    min-height: auto !important;
    border-radius: 16px;
    padding: 12px 14px;
    display: block;
    overflow: visible;
  }

  .calendar-day:not(.has) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 54px !important;
  }

  .calendar-day.today {
    box-shadow: inset 0 0 0 1px rgba(70,224,176,.45);
  }

  .calendar-number {
    margin-bottom: 0;
    gap: 12px;
  }

  .calendar-day.has .calendar-number {
    margin-bottom: 8px;
  }

  .calendar-number > span:first-child {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  .calendar-mobile-label {
    display: inline-flex;
    min-width: 48px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
  }

  .calendar-empty-mobile {
    display: inline-flex;
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .calendar-chip {
    font-size: 12px;
    padding: 7px 8px;
    border-radius: 12px;
    margin-top: 6px;
  }

  .calendar-count {
    font-size: 11px;
    padding: 4px 8px;
  }

  .calendar-day-button.has::after {
    display: none;
  }
}

@media (max-width: 420px) {
  .calendar-day {
    padding: 11px 12px;
  }

  .calendar-mobile-label {
    min-width: 42px;
    font-size: 10px;
  }

  .calendar-chip {
    white-space: normal;
    line-height: 1.35;
  }
}

/* ===== V1.5.0 Navegación de meses en agenda ===== */
.calendar-section-head {
  align-items: flex-start;
}
.calendar-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.calendar-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(124,156,255,.08);
}
.calendar-nav strong {
  min-width: 150px;
  text-align: center;
  text-transform: capitalize;
  color: var(--text);
}
.calendar-nav .button.small {
  text-decoration: none;
  min-width: 36px;
  text-align: center;
  justify-content: center;
}
.calendar-nav .button.small:first-child,
.calendar-nav .button.small:nth-child(3) {
  font-size: 20px;
  line-height: 1;
  padding: 7px 12px;
}

@media (max-width: 720px) {
  .calendar-section-head {
    flex-direction: column;
    align-items: stretch;
  }
  .calendar-tools {
    align-items: stretch;
    width: 100%;
  }
  .calendar-nav {
    width: 100%;
    justify-content: space-between;
    border-radius: 16px;
    gap: 6px;
  }
  .calendar-nav strong {
    min-width: 0;
    flex: 1;
    font-size: 13px;
  }
  .calendar-nav .button.small {
    padding: 8px 10px;
  }
}

/* ===== V1.5.2 Navegación de agenda sin recargar toda la página ===== */
#calendar-section.is-loading,
#appointments-list-section.is-loading {
  opacity: .62;
  pointer-events: none;
  transition: opacity .16s ease;
}
.calendar-nav a {
  cursor: pointer;
}


/* ===== V1.5.3 Dashboard layout improvement ===== */
.eyebrow { display:inline-block; margin-bottom:8px; color:var(--accent); font-size:12px; font-weight:800; text-transform:uppercase; letter-spacing:.08em; }
.dashboard-hero {
  display:flex; justify-content:space-between; align-items:center; gap:22px; margin-bottom:20px;
  padding:24px 26px;
}
.dashboard-hero h2 { margin:0 0 10px; font-size:34px; letter-spacing:-.04em; }
.dashboard-hero p { margin:0; max-width:760px; }
.dashboard-hero-actions { display:flex; flex-wrap:wrap; gap:10px; justify-content:flex-end; }
.dashboard-stats {
  display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:18px; margin-bottom:20px;
}
.dashboard-stat-card { min-height:156px; display:flex; flex-direction:column; justify-content:space-between; }
.dashboard-stat-card strong { font-size:46px; line-height:1; }
.dashboard-stat-card small { color:var(--muted); font-size:13px; line-height:1.4; }
.dashboard-grid { display:grid; grid-template-columns:minmax(0, 1.7fr) minmax(320px, .9fr); gap:20px; align-items:start; }
.dashboard-primary-card { min-height:100%; }
.dashboard-side-column { display:grid; gap:20px; }
.dashboard-info-card { min-height:210px; }
.dashboard-head-inline { margin-bottom:16px; }
.dashboard-head-inline h2 { margin-bottom:6px; }
.small-paragraph { margin:0; font-size:14px; }
.muted { color:var(--muted); }

@media (max-width: 1280px) {
  .dashboard-grid { grid-template-columns:1fr; }
}
@media (max-width: 920px) {
  .dashboard-hero { flex-direction:column; align-items:flex-start; padding:18px; }
  .dashboard-hero h2 { font-size:28px; }
  .dashboard-hero-actions { width:100%; justify-content:flex-start; }
  .dashboard-stats { grid-template-columns:1fr; }
  .dashboard-stat-card { min-height:auto; }
}
body.theme-light .dashboard-hero,
body.theme-light .dashboard-primary-card,
body.theme-light .dashboard-info-card,
body.theme-light .dashboard-stat-card {
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(247,250,255,.98));
}

/* ===== V1.5.4 Roles multiempresa + panel administrativo por pestañas ===== */
.admin-hero {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:22px;
  margin-bottom:20px;
  padding:24px 26px;
}
.admin-hero h2 { margin:0 0 10px; font-size:34px; letter-spacing:-.04em; }
.admin-hero p { margin:0; max-width:780px; }
.admin-hero-summary {
  display:grid;
  grid-template-columns:repeat(2, minmax(150px, 1fr));
  gap:12px;
  min-width:340px;
}
.admin-hero-summary > div {
  border:1px solid var(--line);
  border-radius:18px;
  background:rgba(124,156,255,.08);
  padding:14px;
}
.admin-hero-summary small { display:block; color:var(--muted); font-size:12px; margin-bottom:6px; }
.admin-hero-summary strong { display:block; font-size:18px; line-height:1.2; }
.admin-tabs { padding:0; overflow:hidden; }
.tab-nav {
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  padding:16px;
  border-bottom:1px solid var(--line);
  background:rgba(255,255,255,.025);
  position:sticky;
  top:0;
  z-index:4;
}
.tab-button {
  border-radius:999px;
  color:var(--muted);
  background:transparent;
}
.tab-button.active {
  color:white;
  background:var(--accent);
  border-color:var(--accent);
  box-shadow:0 10px 30px rgba(124,156,255,.25);
}
.tab-panel { display:none; padding:22px; }
.tab-panel.active { display:block; }
.admin-split { align-items:start; margin-bottom:0; }
.admin-note-card {
  border:1px solid var(--line);
  border-radius:20px;
  background:rgba(124,156,255,.08);
  padding:20px;
}
.admin-note-card h3 { margin-top:0; }
.admin-note-card ol { margin:0; padding-left:20px; color:var(--muted); line-height:1.65; }
.role-grid, .plan-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(260px, 1fr));
  gap:14px;
  margin:16px 0;
}
.role-card, .plan-card {
  border:1px solid var(--line);
  border-radius:18px;
  padding:16px;
  background:#0e162b;
}
.role-card div { display:flex; justify-content:space-between; align-items:flex-start; gap:10px; }
.role-card small, .plan-card small { color:var(--muted); font-size:12px; word-break:break-word; }
.role-card p, .plan-card p { margin-bottom:0; }
.admin-details {
  border:1px solid var(--line);
  border-radius:18px;
  padding:14px;
  background:rgba(255,255,255,.02);
  margin-bottom:14px;
}
.admin-details summary {
  cursor:pointer;
  font-size:18px;
  font-weight:800;
  margin-bottom:12px;
}
.admin-details[open] summary { margin-bottom:14px; }
.role-company_admin, .role-admin, .role-super_admin { color:var(--accent); }
.role-sales { color:var(--warn); }
.role-support { color:var(--good); }
.role-agent { color:var(--muted); }

@media (max-width: 920px) {
  .admin-hero { flex-direction:column; align-items:flex-start; padding:18px; }
  .admin-hero h2 { font-size:28px; }
  .admin-hero-summary { grid-template-columns:1fr; min-width:0; width:100%; }
  .tab-nav { position:relative; overflow-x:auto; flex-wrap:nowrap; }
  .tab-button { white-space:nowrap; }
  .tab-panel { padding:16px; }
}
body.theme-light .admin-hero,
body.theme-light .role-card,
body.theme-light .plan-card,
body.theme-light .admin-note-card,
body.theme-light .admin-details {
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(247,250,255,.98));
}
body.theme-light .tab-nav { background:#f8fbff; }
body.theme-light .tab-button.active { color:white; }

/* ===== V1.5.5 WhatsApp stability panel ===== */
.wa-health-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:10px; margin:16px 0; }
.wa-health-grid > div { background:rgba(124,156,255,.08); border:1px solid var(--line); border-radius:16px; padding:12px; min-height:74px; }
.wa-health-grid span { display:block; color:var(--muted); font-size:12px; margin-bottom:6px; }
.wa-health-grid strong { display:block; font-size:13px; word-break:break-word; }
.left-actions { justify-content:flex-start; margin-top:12px; }
body.theme-light .wa-health-grid > div { background:#f7faff; }
@media (max-width: 920px) { .wa-health-grid { grid-template-columns:1fr; } }

/* ===== V1.6.3 Control inteligente de flujo del bot ===== */
.chat-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.flow-pill { display:inline-flex; align-items:center; gap:6px; margin-top:8px; padding:5px 9px; border-radius:999px; font-size:12px; border:1px solid var(--line); color:var(--muted); background:var(--soft); }
.flow-pill::before { content:'●'; color:var(--good); font-size:10px; }
.flow-date_waiting::before, .flow-time_waiting::before, .flow-name_waiting::before, .flow-service_waiting::before { color:var(--warn); }
.flow-humano::before { color:var(--accent); }
@media (max-width: 920px) {
  .chat-header { flex-direction:column; align-items:flex-start; }
  .chat-actions { width:100%; justify-content:flex-start; }
}

/* ===== V1.6.4 Estados visuales de conversación ===== */
.chat-item {
  position:relative;
  border-left:4px solid transparent;
}
.chat-item-top {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:4px;
}
.chat-item-top strong { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-status-badge,
.conversation-status-pill {
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 8px;
  border-radius:999px;
  font-size:11px;
  font-style:normal;
  font-weight:800;
  white-space:nowrap;
  border:1px solid var(--line);
  background:var(--soft);
  color:var(--muted);
}
.badge-ai { color:#85ffca; border-color:rgba(67,209,158,.35); background:rgba(67,209,158,.10); }
.badge-needs-human { color:#ffd2d2; border-color:rgba(255,107,107,.65); background:rgba(255,107,107,.18); }
.badge-human { color:#ffe3a1; border-color:rgba(245,193,92,.65); background:rgba(245,193,92,.15); }
.badge-resolved { color:#b8c7e8; border-color:rgba(152,166,195,.45); background:rgba(152,166,195,.12); }
.badge-ai-off { color:#d8c6ff; border-color:rgba(124,156,255,.4); background:rgba(124,156,255,.11); }
.chat-status-ai { border-left-color:var(--good); }
.chat-status-needs-human { border-left-color:var(--bad); background:linear-gradient(90deg, rgba(255,107,107,.14), rgba(14,22,43,.96)); }
.chat-status-human { border-left-color:var(--warn); background:linear-gradient(90deg, rgba(245,193,92,.14), rgba(14,22,43,.96)); }
.chat-status-resolved { border-left-color:var(--muted); opacity:.82; }
.chat-status-ai-off { border-left-color:var(--accent); }
.chat-status-needs-human.active,
.chat-status-needs-human:hover { border-color:rgba(255,107,107,.8); box-shadow:0 12px 32px rgba(255,107,107,.14); }
.chat-status-human.active,
.chat-status-human:hover { border-color:rgba(245,193,92,.8); box-shadow:0 12px 32px rgba(245,193,92,.12); }
.conversation-status-line { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-top:8px; }
.status-reason { margin:8px 0 0; color:var(--muted); font-size:13px; }
.chat-header { border-radius:18px; padding:14px; margin-bottom:12px; border:1px solid transparent; }
.chat-header-status-needs-human { border-color:rgba(255,107,107,.55); background:rgba(255,107,107,.08); }
.chat-header-status-human { border-color:rgba(245,193,92,.55); background:rgba(245,193,92,.08); }
.chat-header-status-ai { border-color:rgba(67,209,158,.35); background:rgba(67,209,158,.05); }
.chat-header-status-resolved { border-color:rgba(152,166,195,.35); background:rgba(152,166,195,.07); }
.needs-human-stat { border-color:rgba(255,107,107,.45); }
.needs-human-stat strong { color:#ffbcbc; }
body.theme-light .chat-status-needs-human { background:linear-gradient(90deg, rgba(255,107,107,.16), #f8fbff); }
body.theme-light .chat-status-human { background:linear-gradient(90deg, rgba(245,193,92,.20), #f8fbff); }
body.theme-light .chat-header-status-needs-human { background:rgba(255,107,107,.10); }
body.theme-light .chat-header-status-human { background:rgba(245,193,92,.15); }
@media (max-width: 920px) {
  .chat-item-top { align-items:flex-start; flex-direction:column; gap:5px; }
  .chat-status-badge { font-size:10px; }
  .conversation-status-line { align-items:flex-start; }
}

/* ===== V1.6.7 Premium UI estilo Tailwind Admin =====
   Rediseño visual sin cambiar lógica ni base de datos.
   Mantiene EJS + CSS propio; no requiere instalar Tailwind.
*/
:root {
  --bg:#070b16;
  --panel:#0d1424;
  --soft:#111b30;
  --soft-2:#17233c;
  --text:#f7fbff;
  --muted:#8fa1bf;
  --line:rgba(148,163,184,.16);
  --line-strong:rgba(148,163,184,.28);
  --accent:#5b7cfa;
  --accent-2:#20e3b2;
  --accent-3:#8b5cf6;
  --good:#22c55e;
  --bad:#ef4444;
  --warn:#f59e0b;
  --shadow:rgba(0,0,0,.32);
  --glow:rgba(91,124,250,.28);
  --radius-lg:24px;
  --radius-md:18px;
  --radius-sm:14px;
}

html { scroll-behavior:smooth; }
body {
  background:
    radial-gradient(circle at 18% -10%, rgba(32,227,178,.14), transparent 34%),
    radial-gradient(circle at 80% 0%, rgba(91,124,250,.17), transparent 30%),
    linear-gradient(135deg, #050812 0%, #08111f 45%, #070b16 100%);
  color:var(--text);
  letter-spacing:.005em;
}
body::before {
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size:48px 48px;
  mask-image:linear-gradient(to bottom, rgba(0,0,0,.42), transparent 72%);
  z-index:-1;
}

.app-shell { background:transparent; }
.main {
  padding:30px;
  position:relative;
}

.sidebar {
  width:276px;
  padding:22px 18px;
  background:rgba(5,10,22,.78);
  backdrop-filter:blur(22px);
  border-right:1px solid rgba(148,163,184,.14);
  box-shadow:22px 0 70px rgba(0,0,0,.24);
}
.brand {
  font-size:25px;
  letter-spacing:-.08em;
  display:flex;
  align-items:center;
  gap:2px;
}
.brand::before {
  content:"";
  width:13px;
  height:13px;
  border-radius:999px;
  margin-right:5px;
  background:linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow:0 0 28px rgba(32,227,178,.52);
}
.brand span {
  background:linear-gradient(135deg, var(--accent-2), var(--accent), var(--accent-3));
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}
.brand.big { font-size:46px; }

.company-box {
  background:linear-gradient(180deg, rgba(91,124,250,.12), rgba(32,227,178,.04));
  border:1px solid rgba(148,163,184,.16);
  border-radius:22px;
  padding:15px;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04), 0 18px 46px rgba(0,0,0,.20);
}
.company-box small {
  display:block;
  color:#94a3b8;
  text-transform:uppercase;
  letter-spacing:.10em;
  font-size:10px;
  font-weight:900;
  margin-bottom:7px;
}
.company-box strong { display:block; line-height:1.25; }
.company-switch select { margin-top:10px; border-radius:14px; }
.company-module-shortcut {
  display:block;
  margin-top:10px;
  padding:9px 10px;
  border-radius:13px;
  background:rgba(91,124,250,.12);
  color:#c9d5ff;
  font-size:12px;
  font-weight:700;
}

.sidebar nav {
  gap:6px;
  padding-right:6px;
}
.sidebar nav a,
.logout-form button {
  min-height:44px;
  display:flex;
  align-items:center;
  gap:10px;
  padding:11px 13px;
  border-radius:15px;
  color:#9fb0cc;
  transition:transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.sidebar nav a:hover,
.logout-form button:hover {
  transform:translateX(3px);
  background:rgba(91,124,250,.11);
  color:#ffffff;
  border-color:rgba(91,124,250,.22);
}
.sidebar nav a.active {
  color:#ffffff;
  background:linear-gradient(135deg, rgba(91,124,250,.30), rgba(32,227,178,.11));
  border-color:rgba(91,124,250,.42);
  box-shadow:0 16px 34px rgba(91,124,250,.13), inset 0 1px 0 rgba(255,255,255,.08);
}
.logout-form button { color:#ffb4b4; }

.topbar {
  position:sticky;
  top:0;
  z-index:30;
  padding:13px 14px;
  margin:-10px -4px 24px;
  border:1px solid rgba(148,163,184,.12);
  border-radius:22px;
  background:rgba(7,11,22,.72);
  backdrop-filter:blur(18px);
  box-shadow:0 18px 46px rgba(0,0,0,.18);
}
.topbar h1 {
  font-size:32px;
  letter-spacing:-.055em;
  line-height:1.08;
}
.topbar p { font-size:13px; color:#94a3b8; }
.user-pill,
.theme-toggle,
.super-company-toggle {
  border-radius:999px;
  background:rgba(15,23,42,.82);
  border:1px solid rgba(148,163,184,.18);
  color:#e7eeff;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04);
}
.user-pill:hover,
.theme-toggle:hover,
.super-company-toggle:hover {
  border-color:rgba(91,124,250,.46);
  box-shadow:0 12px 30px rgba(91,124,250,.12);
}

.card,
.stat-card,
.login-card,
.admin-hero,
.dashboard-hero,
.dashboard-primary-card,
.dashboard-info-card,
.dashboard-stat-card,
.role-card,
.plan-card,
.admin-note-card,
.admin-details {
  background:
    linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.022)),
    rgba(13,20,36,.88);
  border:1px solid rgba(148,163,184,.16);
  border-radius:var(--radius-lg);
  box-shadow:0 24px 70px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.045);
}
.card:hover,
.stat-card:hover,
.dashboard-stat-card:hover {
  border-color:rgba(91,124,250,.27);
}

.dashboard-hero,
.admin-hero {
  overflow:hidden;
  position:relative;
  background:
    radial-gradient(circle at 88% 20%, rgba(32,227,178,.18), transparent 28%),
    radial-gradient(circle at 0% 0%, rgba(91,124,250,.22), transparent 32%),
    linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02)),
    rgba(13,20,36,.90);
}
.dashboard-hero::after,
.admin-hero::after {
  content:"";
  position:absolute;
  right:-90px;
  top:-90px;
  width:240px;
  height:240px;
  border-radius:999px;
  border:1px solid rgba(32,227,178,.16);
  background:radial-gradient(circle, rgba(32,227,178,.12), transparent 62%);
}
.eyebrow {
  color:#8eeed8;
  background:rgba(32,227,178,.09);
  border:1px solid rgba(32,227,178,.18);
  border-radius:999px;
  padding:6px 10px;
  margin-bottom:12px;
}
.dashboard-hero h2,
.admin-hero h2,
h2 {
  letter-spacing:-.05em;
}
.dashboard-hero h2,
.admin-hero h2 { font-size:38px; }

.dashboard-stats { gap:16px; }
.dashboard-stat-card,
.stat-card {
  position:relative;
  overflow:hidden;
}
.dashboard-stat-card::before,
.stat-card::before {
  content:"";
  position:absolute;
  inset:0 0 auto 0;
  height:3px;
  background:linear-gradient(90deg, var(--accent-2), var(--accent), var(--accent-3));
  opacity:.75;
}
.dashboard-stat-card span,
.stat-card span {
  color:#9fb0cc;
  font-weight:700;
}
.dashboard-stat-card strong,
.stat-card strong {
  background:linear-gradient(135deg, #ffffff, #c8d4ff);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}
.needs-human-stat::before { background:linear-gradient(90deg, #ef4444, #f59e0b); }
.needs-human-stat strong { color:#ffc4c4; background:none; }

button,
.button,
.primary,
button.primary,
.button.primary,
.danger-button {
  border-radius:14px;
  font-weight:800;
  letter-spacing:.005em;
  transition:transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
button:hover,
.button:hover {
  transform:translateY(-1px);
  box-shadow:0 16px 36px rgba(0,0,0,.20);
}
button.primary,
.button.primary,
.primary {
  background:linear-gradient(135deg, var(--accent), var(--accent-3));
  border-color:rgba(139,92,246,.55);
  box-shadow:0 16px 38px rgba(91,124,250,.22);
}
.danger-button {
  background:rgba(239,68,68,.13);
  border-color:rgba(239,68,68,.38);
}

input,
textarea,
select,
.search-input {
  background:rgba(8,13,26,.72);
  border:1px solid rgba(148,163,184,.18);
  border-radius:15px;
  color:#f8fbff;
  outline:none;
  transition:border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:focus,
textarea:focus,
select:focus,
.search-input:focus-within {
  border-color:rgba(91,124,250,.58);
  box-shadow:0 0 0 4px rgba(91,124,250,.12);
  background:rgba(8,13,26,.92);
}
label { font-weight:700; color:#9fb0cc; }

.table-wrap {
  border:1px solid rgba(148,163,184,.12);
  border-radius:20px;
  background:rgba(8,13,26,.24);
}
table { border-collapse:separate; border-spacing:0; }
th {
  color:#9fb0cc;
  text-transform:uppercase;
  letter-spacing:.08em;
  font-size:11px;
  background:rgba(255,255,255,.025);
}
td { color:#eef4ff; }
th, td { border-bottom:1px solid rgba(148,163,184,.12); }
tbody tr { transition:background .15s ease; }
tbody tr:hover { background:rgba(91,124,250,.055); }
tbody tr:last-child td { border-bottom:0; }
.badge {
  border:1px solid rgba(148,163,184,.16);
  background:rgba(17,27,48,.88);
  font-weight:900;
}

.flash {
  border-radius:18px;
  background:rgba(17,27,48,.84);
  border-color:rgba(148,163,184,.18);
  box-shadow:0 16px 42px rgba(0,0,0,.20);
}
.flash.success { background:rgba(34,197,94,.10); border-color:rgba(34,197,94,.30); }
.flash.error { background:rgba(239,68,68,.10); border-color:rgba(239,68,68,.30); }

.chat-layout { gap:20px; }
.chat-list.card,
.chat-window.card { padding:16px; }
.chat-item {
  border-radius:18px;
  background:rgba(10,16,31,.78);
  border-color:rgba(148,163,184,.12);
  box-shadow:0 10px 28px rgba(0,0,0,.14);
}
.chat-item.active,
.chat-item:hover {
  transform:translateY(-1px);
  border-color:rgba(91,124,250,.45);
  box-shadow:0 18px 44px rgba(91,124,250,.13);
}
.chat-status-needs-human {
  background:linear-gradient(90deg, rgba(239,68,68,.18), rgba(10,16,31,.92));
}
.chat-status-human {
  background:linear-gradient(90deg, rgba(245,158,11,.18), rgba(10,16,31,.92));
}
.chat-header {
  background:rgba(8,13,26,.54);
  border-color:rgba(148,163,184,.14);
}
.messages {
  background:
    radial-gradient(circle at 100% 0%, rgba(91,124,250,.055), transparent 30%),
    rgba(8,13,26,.22);
  border:1px solid rgba(148,163,184,.10);
  border-radius:22px;
  padding:14px;
}
.bubble {
  border:1px solid rgba(148,163,184,.12);
  background:rgba(15,23,42,.88);
  box-shadow:0 10px 26px rgba(0,0,0,.16);
}
.bubble.out {
  background:linear-gradient(135deg, rgba(91,124,250,.92), rgba(139,92,246,.82));
  border-color:rgba(255,255,255,.12);
}
.bubble.in {
  background:rgba(15,23,42,.86);
}
.bubble.system {
  background:rgba(32,227,178,.10);
  border-color:rgba(32,227,178,.22);
}
.send-box {
  background:rgba(8,13,26,.45);
  border:1px solid rgba(148,163,184,.12);
  border-radius:20px;
  padding:12px;
  margin-top:12px;
}

.modern-calendar { gap:9px; }
.calendar-day,
.mini-day {
  background:rgba(10,16,31,.78);
  border-color:rgba(148,163,184,.14);
}
.calendar-day:hover {
  border-color:rgba(91,124,250,.48);
  box-shadow:0 18px 44px rgba(91,124,250,.12);
}
.calendar-day.today {
  border-color:rgba(32,227,178,.58);
  box-shadow:inset 0 0 0 1px rgba(32,227,178,.28), 0 16px 38px rgba(32,227,178,.10);
}
.calendar-chip {
  background:rgba(91,124,250,.12);
  border-color:rgba(91,124,250,.25);
}

.login-page {
  background:
    radial-gradient(circle at 50% 0%, rgba(91,124,250,.22), transparent 35%),
    radial-gradient(circle at 20% 90%, rgba(32,227,178,.12), transparent 32%),
    #050812;
}
.login-card {
  background:rgba(10,16,31,.84);
  backdrop-filter:blur(22px);
  box-shadow:0 30px 90px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.06);
}

.super-company-panel,
.modal-box,
.client-detail-box,
.day-detail-box {
  background:rgba(10,16,31,.96);
  border:1px solid rgba(148,163,184,.18);
  box-shadow:0 28px 80px rgba(0,0,0,.42);
  border-radius:24px;
}

body.theme-light {
  --bg:#f4f7fb;
  --panel:#ffffff;
  --soft:#eef3ff;
  --soft-2:#e8eefc;
  --text:#0f172a;
  --muted:#64748b;
  --line:rgba(100,116,139,.20);
  --line-strong:rgba(100,116,139,.32);
  --accent:#3861f6;
  --accent-2:#089f7d;
  --accent-3:#7c3aed;
  --shadow:rgba(15,23,42,.12);
  background:
    radial-gradient(circle at 15% -10%, rgba(8,159,125,.10), transparent 34%),
    radial-gradient(circle at 85% 0%, rgba(56,97,246,.12), transparent 30%),
    #f4f7fb;
}
body.theme-light .sidebar {
  background:rgba(255,255,255,.84);
  border-right:1px solid rgba(100,116,139,.18);
}
body.theme-light .topbar,
body.theme-light .card,
body.theme-light .stat-card,
body.theme-light .login-card,
body.theme-light .admin-hero,
body.theme-light .dashboard-hero,
body.theme-light .dashboard-primary-card,
body.theme-light .dashboard-info-card,
body.theme-light .dashboard-stat-card,
body.theme-light .role-card,
body.theme-light .plan-card,
body.theme-light .admin-note-card,
body.theme-light .admin-details {
  background:rgba(255,255,255,.88);
  border-color:rgba(100,116,139,.18);
  box-shadow:0 22px 56px rgba(15,23,42,.10), inset 0 1px 0 rgba(255,255,255,.70);
}
body.theme-light .dashboard-hero,
body.theme-light .admin-hero {
  background:
    radial-gradient(circle at 88% 20%, rgba(8,159,125,.12), transparent 28%),
    radial-gradient(circle at 0% 0%, rgba(56,97,246,.14), transparent 32%),
    rgba(255,255,255,.90);
}
body.theme-light input,
body.theme-light textarea,
body.theme-light select,
body.theme-light .search-input,
body.theme-light .empty-qr,
body.theme-light .connected-box,
body.theme-light .empty-state,
body.theme-light .chat-item,
body.theme-light .bubble.in,
body.theme-light pre,
body.theme-light .mini-day,
body.theme-light .calendar-day {
  background:rgba(248,251,255,.92);
  color:#0f172a;
}
body.theme-light .table-wrap,
body.theme-light .messages,
body.theme-light .send-box,
body.theme-light .chat-header {
  background:rgba(248,251,255,.78);
}
body.theme-light th { background:rgba(15,23,42,.035); color:#64748b; }
body.theme-light td { color:#0f172a; }
body.theme-light .dashboard-stat-card strong,
body.theme-light .stat-card strong {
  background:linear-gradient(135deg, #0f172a, #3861f6);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}
body.theme-light .user-pill,
body.theme-light .theme-toggle,
body.theme-light .super-company-toggle {
  background:rgba(255,255,255,.82);
  color:#0f172a;
}

@media (max-width: 920px) {
  .main { padding:14px; }
  .topbar { position:relative; margin:0 0 14px; border-radius:18px; }
  .sidebar { width:320px; max-width:86vw; }
  .dashboard-hero h2,
  .admin-hero h2 { font-size:28px; }
  .dashboard-hero,
  .admin-hero,
  .card,
  .stat-card { border-radius:20px; }
  .send-box { flex-direction:column; }
}

/* ===== V1.6.8 UI Premium Ajustes: sidebar ocultable, scroll estable, iconos y modo claro ===== */
.brand {
  display:flex;
  align-items:center;
  gap:10px;
  min-height:32px;
}
.brand strong { font-weight:950; letter-spacing:-.08em; }
.brand-dot {
  width:14px;
  height:14px;
  flex:0 0 14px;
  border-radius:999px;
  background:linear-gradient(135deg, #20e3b2, #5b7cfa 70%, #8b5cf6);
  box-shadow:0 0 22px rgba(32,227,178,.52);
}
.sidebar-head-actions {
  display:flex;
  align-items:center;
  gap:8px;
}
.sidebar-collapse-btn,
.desktop-sidebar-toggle {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:7px;
  min-width:42px;
  height:38px;
  padding:0 12px;
  border-radius:14px;
  border:1px solid rgba(148,163,184,.16);
  background:rgba(15,23,42,.58);
  color:#dbe7ff;
  font-weight:850;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05);
}
.desktop-sidebar-toggle { min-width:auto; }
.sidebar-collapse-btn:hover,
.desktop-sidebar-toggle:hover {
  border-color:rgba(91,124,250,.45);
  box-shadow:0 14px 34px rgba(91,124,250,.16);
}
.sidebar {
  overflow:hidden;
  transition:width .22s ease, padding .22s ease, transform .22s ease;
}
.sidebar nav {
  flex:1 1 auto;
  min-height:0;
  max-height:none !important;
  overflow-y:auto !important;
  overflow-x:hidden;
  padding-right:6px;
  overscroll-behavior:contain;
  scroll-behavior:smooth;
}
.sidebar nav a,
.logout-form button {
  position:relative;
  display:flex !important;
  align-items:center;
  gap:12px;
  min-height:46px;
  overflow:hidden;
}
.nav-icon {
  width:26px;
  height:26px;
  flex:0 0 26px;
  display:inline-grid;
  place-items:center;
  border-radius:10px;
  background:rgba(255,255,255,.045);
  font-size:15px;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05);
}
.nav-label {
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.sidebar nav a.active .nav-icon {
  background:linear-gradient(135deg, rgba(32,227,178,.18), rgba(91,124,250,.25));
  box-shadow:0 0 24px rgba(91,124,250,.18), inset 0 1px 0 rgba(255,255,255,.08);
}
.logout-form { flex:0 0 auto; padding-top:10px; }

body.sidebar-collapsed .sidebar {
  width:92px;
  padding:18px 14px;
}
body.sidebar-collapsed .brand strong,
body.sidebar-collapsed .company-box,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .logout-form .nav-label,
body.sidebar-collapsed .sidebar-close {
  display:none !important;
}
body.sidebar-collapsed .sidebar-head {
  justify-content:center;
}
body.sidebar-collapsed .sidebar-head-actions {
  flex-direction:column;
}
body.sidebar-collapsed .sidebar nav {
  padding-right:0;
}
body.sidebar-collapsed .sidebar nav a,
body.sidebar-collapsed .logout-form button {
  justify-content:center;
  padding:11px;
}
body.sidebar-collapsed .nav-icon {
  width:34px;
  height:34px;
  flex-basis:34px;
  font-size:17px;
}
body.sidebar-collapsed .main {
  padding-left:24px;
}

.stat-card.dashboard-stat-card {
  position:relative;
  overflow:hidden;
}
.stat-card.dashboard-stat-card::before {
  content:'';
  position:absolute;
  inset:0 0 auto 0;
  height:3px;
  background:linear-gradient(90deg, #20e3b2, #5b7cfa, #8b5cf6);
  opacity:.85;
}
.stat-icon {
  position:absolute;
  top:18px;
  right:18px;
  width:42px;
  height:42px;
  display:grid;
  place-items:center;
  border-radius:16px;
  background:linear-gradient(135deg, rgba(32,227,178,.13), rgba(91,124,250,.18));
  border:1px solid rgba(148,163,184,.14);
  box-shadow:0 14px 34px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.07);
  font-size:20px;
}
.stat-icon.danger-icon {
  background:linear-gradient(135deg, rgba(239,68,68,.16), rgba(245,158,11,.18));
}
.title-icon {
  display:inline-grid;
  place-items:center;
  width:34px;
  height:34px;
  margin-right:10px;
  border-radius:13px;
  background:rgba(91,124,250,.12);
  border:1px solid rgba(91,124,250,.20);
  vertical-align:middle;
  font-size:17px;
}

/* Modo claro más legible: evita textos perdidos y cards lavadas */
body.theme-light {
  color:#111827;
}
body.theme-light p,
body.theme-light .muted,
body.theme-light small,
body.theme-light label,
body.theme-light .stat-card span,
body.theme-light .dashboard-stat-card small,
body.theme-light .topbar p {
  color:#475569 !important;
}
body.theme-light h1,
body.theme-light h2,
body.theme-light h3,
body.theme-light strong,
body.theme-light .brand,
body.theme-light .brand strong,
body.theme-light td,
body.theme-light .section-head h2 {
  color:#0f172a !important;
}
body.theme-light .sidebar {
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(245,249,255,.94));
  box-shadow:10px 0 38px rgba(15,23,42,.08);
}
body.theme-light .sidebar nav a,
body.theme-light .logout-form button {
  color:#52627a;
}
body.theme-light .sidebar nav a:hover,
body.theme-light .logout-form button:hover {
  color:#0f172a;
  background:#eef4ff;
}
body.theme-light .sidebar nav a.active {
  color:#0f172a !important;
  background:linear-gradient(135deg, rgba(56,97,246,.12), rgba(8,159,125,.09));
  border-color:rgba(56,97,246,.28);
  box-shadow:0 14px 32px rgba(56,97,246,.12);
}
body.theme-light .nav-icon {
  background:#eef4ff;
  color:#0f172a;
}
body.theme-light .company-box,
body.theme-light input,
body.theme-light textarea,
body.theme-light select,
body.theme-light .search-input,
body.theme-light .table-wrap,
body.theme-light .messages,
body.theme-light .send-box,
body.theme-light .chat-header,
body.theme-light .chat-item,
body.theme-light .calendar-day,
body.theme-light .mini-day,
body.theme-light .empty-state,
body.theme-light .empty-qr,
body.theme-light .connected-box,
body.theme-light pre {
  background:#ffffff !important;
  border-color:rgba(100,116,139,.20) !important;
  color:#0f172a !important;
}
body.theme-light .card,
body.theme-light .stat-card,
body.theme-light .dashboard-primary-card,
body.theme-light .dashboard-info-card,
body.theme-light .dashboard-stat-card {
  background:linear-gradient(180deg, #ffffff, #f8fbff) !important;
  border-color:rgba(100,116,139,.18) !important;
}
body.theme-light th {
  background:#f1f5fb !important;
  color:#334155 !important;
}
body.theme-light tbody tr:hover {
  background:#f4f7ff !important;
}
body.theme-light .badge {
  background:#eef4ff;
  color:#1e3a8a;
  border-color:rgba(56,97,246,.20);
}
body.theme-light .button,
body.theme-light button,
body.theme-light .user-pill,
body.theme-light .theme-toggle,
body.theme-light .desktop-sidebar-toggle,
body.theme-light .sidebar-collapse-btn,
body.theme-light .super-company-toggle {
  background:#ffffff;
  color:#0f172a;
  border-color:rgba(100,116,139,.22);
}
body.theme-light .button.primary,
body.theme-light button.primary,
body.theme-light .primary {
  background:linear-gradient(135deg, #3861f6, #7c3aed) !important;
  color:#ffffff !important;
  border-color:transparent !important;
}
body.theme-light .danger-button {
  background:#fff1f2 !important;
  color:#b91c1c !important;
  border-color:#fecdd3 !important;
}
body.theme-light .bubble.out {
  color:#ffffff;
  background:linear-gradient(135deg, #3861f6, #7c3aed) !important;
}
body.theme-light .bubble.out p,
body.theme-light .bubble.out small { color:#ffffff !important; }

@media (max-width: 920px) {
  .desktop-sidebar-toggle { display:none; }
  body.sidebar-collapsed .sidebar {
    width:320px;
    max-width:86vw;
    padding:22px;
  }
  body.sidebar-collapsed .brand strong,
  body.sidebar-collapsed .company-box,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .logout-form .nav-label,
  body.sidebar-collapsed .sidebar-close {
    display:initial !important;
  }
  body.sidebar-collapsed .sidebar-head-actions { flex-direction:row; }
  body.sidebar-collapsed .sidebar nav a,
  body.sidebar-collapsed .logout-form button { justify-content:flex-start; padding:11px 12px; }
  body.sidebar-collapsed .nav-icon { width:26px; height:26px; flex-basis:26px; font-size:15px; }
  .sidebar-collapse-btn { display:none; }
  .sidebar { overflow:auto; }
  .sidebar nav { max-height:none !important; overflow:visible !important; }
}

@media (min-width: 921px) {
  body.sidebar-collapsed .main {
    margin-left:92px !important;
    width:calc(100% - 92px) !important;
  }
  body:not(.sidebar-collapsed) .main {
    margin-left:276px;
    width:calc(100% - 276px);
  }
}
.brand::before { content:none !important; display:none !important; }
.brand .brand-dot {
  background:linear-gradient(135deg, #20e3b2, #5b7cfa 70%, #8b5cf6) !important;
  color:transparent !important;
}


/* ===== V1.6.9 Ajuste conversaciones + servicios numerados ===== */
#conversation-page.chat-layout {
  align-items:stretch;
}
#conversation-page .chat-list.card {
  overflow:hidden !important;
  min-height:0;
}
#conversation-page #conversation-list {
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto !important;
  overflow-x:hidden;
  padding-right:6px;
  overscroll-behavior:contain;
}
#conversation-page #conversation-list::-webkit-scrollbar { width:8px; }
#conversation-page #conversation-list::-webkit-scrollbar-thumb {
  background:rgba(148,163,184,.22);
  border-radius:999px;
}
.chat-history-count {
  display:block;
  margin-top:7px;
  font-size:11px;
  color:var(--muted);
  opacity:.82;
}
body.theme-light .chat-history-count { color:#64748b !important; }
.chat-item.active .chat-history-count { color:#bcd2ff !important; }
body.theme-light .chat-item.active .chat-history-count { color:#3359b8 !important; }


/* ===== V1.7.0 Hotfix: botones del hero clicables ===== */
.dashboard-hero,
.admin-hero { isolation:isolate; }
.dashboard-hero::after,
.admin-hero::after { pointer-events:none; z-index:0; }
.dashboard-hero > *,
.admin-hero > * { position:relative; z-index:1; }
.dashboard-hero-actions,
.admin-hero-actions,
.dashboard-hero .button,
.admin-hero .button { pointer-events:auto; }


/* ===== V1.7.1 Hotfix real: botones y modales siempre clicables ===== */
.dashboard-hero,
.admin-hero {
  isolation: isolate !important;
}
.dashboard-hero::after,
.admin-hero::after {
  pointer-events: none !important;
  z-index: 0 !important;
}
.dashboard-hero > *,
.admin-hero > * {
  position: relative !important;
  z-index: 2 !important;
}
.dashboard-hero-actions,
.dashboard-hero-actions *,
.admin-hero-actions,
.admin-hero-actions *,
button[data-modal-open],
.button[data-modal-open] {
  pointer-events: auto !important;
  position: relative;
  z-index: 5;
}
.modal.open {
  display: flex !important;
}
#bot-rule-create.open {
  display: flex !important;
}

/* ===== V1.7.4 UI Premium Pro: login, logo, sidebar default recogido y anti-parpadeo ===== */
:root {
  --jss-sidebar-open: 276px;
  --jss-sidebar-closed: 92px;
  --jss-glow-a: rgba(32, 227, 178, .18);
  --jss-glow-b: rgba(91, 124, 250, .20);
  --jss-glow-c: rgba(139, 92, 246, .16);
}

.brand-link {
  text-decoration:none;
  min-width:0;
  flex:1 1 auto;
}
.brand-logo {
  display:block;
  max-width:100%;
  height:auto;
  filter: drop-shadow(0 10px 22px rgba(91,124,250,.18));
}
.brand-logo-full { width:118px; }
.brand-logo-icon { display:none; width:42px; height:42px; }

.login-page {
  position:relative;
  overflow:hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(91,124,250,.18), transparent 28%),
    radial-gradient(circle at 42% 68%, rgba(32,227,178,.13), transparent 30%),
    linear-gradient(135deg, #030712 0%, #08111f 42%, #050816 100%) !important;
}
.login-page::before,
.login-page::after {
  content:'';
  position:absolute;
  width:460px;
  height:460px;
  border-radius:999px;
  pointer-events:none;
  filter:blur(24px);
  opacity:.55;
}
.login-page::before {
  left:17%;
  bottom:4%;
  background:radial-gradient(circle, rgba(32,227,178,.18), transparent 64%);
}
.login-page::after {
  right:20%;
  top:12%;
  background:radial-gradient(circle, rgba(91,124,250,.18), transparent 66%);
}
.login-card {
  position:relative;
  z-index:1;
  width:min(465px,100%) !important;
  padding:38px 36px 34px !important;
  border-radius:30px !important;
  background:linear-gradient(180deg, rgba(15,23,42,.86), rgba(8,13,26,.78)) !important;
  border:1px solid rgba(148,163,184,.20) !important;
  box-shadow:0 34px 120px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.055);
  backdrop-filter:blur(16px);
}
.login-card::before {
  content:'';
  position:absolute;
  inset:0;
  border-radius:inherit;
  padding:1px;
  background:linear-gradient(135deg, rgba(32,227,178,.36), rgba(91,124,250,.22), rgba(139,92,246,.30));
  -webkit-mask:linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite:xor;
  mask-composite:exclude;
  pointer-events:none;
}
.login-logo-wrap {
  display:flex;
  justify-content:center;
  margin-bottom:22px;
}
.login-logo {
  width:155px;
  max-width:72%;
  height:auto;
  filter:drop-shadow(0 18px 34px rgba(91,124,250,.26));
}
.login-card h1 {
  font-size:29px;
  line-height:1.1;
  letter-spacing:-.045em;
  margin:0 0 14px !important;
}
.login-card p {
  max-width:330px;
  margin:0 auto 24px !important;
  color:#9fb0cf !important;
}
.login-card form {
  display:grid;
  gap:12px;
  margin-top:8px;
}
.login-card label {
  font-weight:850;
  font-size:13px;
  color:#b9c7e3;
  margin-top:2px;
}
.login-card input {
  min-height:48px;
  border-radius:16px;
  background:rgba(3,7,18,.56) !important;
  border-color:rgba(148,163,184,.20) !important;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04);
}
.login-card input:focus {
  outline:none;
  border-color:rgba(91,124,250,.65) !important;
  box-shadow:0 0 0 4px rgba(91,124,250,.14), inset 0 1px 0 rgba(255,255,255,.04);
}
.login-submit {
  margin-top:16px !important;
  min-height:48px;
  padding:0 22px !important;
  border-radius:16px !important;
  font-weight:950;
  background:linear-gradient(135deg, #5b7cfa, #7c3aed) !important;
  box-shadow:0 16px 34px rgba(91,124,250,.28);
}
.login-submit:hover { transform:translateY(-1px); box-shadow:0 20px 42px rgba(91,124,250,.36); }

/* Layout estable en escritorio para evitar parpadeo del panel izquierdo */
@media (min-width: 921px) {
  .app-shell { display:block !important; min-height:100vh; }
  .sidebar {
    position:fixed !important;
    top:0 !important;
    left:0 !important;
    bottom:0 !important;
    z-index:1000 !important;
    width:var(--jss-sidebar-open) !important;
    height:100dvh !important;
    max-height:100dvh !important;
    padding:22px 18px !important;
    overflow:hidden !important;
    background:linear-gradient(180deg, rgba(4,10,22,.98), rgba(5,11,23,.96)) !important;
    border-right:1px solid rgba(148,163,184,.14) !important;
    box-shadow:16px 0 46px rgba(0,0,0,.20);
    transform:none !important;
    transition:width .18s ease, padding .18s ease !important;
    will-change:width;
  }
  .sidebar::before {
    content:'';
    position:absolute;
    inset:0;
    pointer-events:none;
    background:
      radial-gradient(circle at 12% 10%, rgba(32,227,178,.10), transparent 24%),
      radial-gradient(circle at 92% 38%, rgba(91,124,250,.10), transparent 26%);
  }
  .sidebar > * { position:relative; z-index:1; }
  .sidebar-head { flex:0 0 auto; min-height:46px; }
  .company-box { flex:0 0 auto; }
  .sidebar nav {
    flex:1 1 auto !important;
    min-height:0 !important;
    max-height:none !important;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    padding-right:7px !important;
    scrollbar-gutter:stable;
  }
  .logout-form { flex:0 0 auto !important; margin-top:0 !important; }
  .main {
    margin-left:var(--jss-sidebar-open) !important;
    width:calc(100% - var(--jss-sidebar-open)) !important;
    max-width:none !important;
    padding:18px 24px 28px !important;
    transition:margin-left .18s ease, width .18s ease !important;
  }
  body.sidebar-collapsed .sidebar,
  html.jss-sidebar-collapsed body .sidebar {
    width:var(--jss-sidebar-closed) !important;
    padding:18px 14px !important;
  }
  body.sidebar-collapsed .main,
  html.jss-sidebar-collapsed body .main {
    margin-left:var(--jss-sidebar-closed) !important;
    width:calc(100% - var(--jss-sidebar-closed)) !important;
  }
  body.sidebar-collapsed .brand-logo-full,
  html.jss-sidebar-collapsed body .brand-logo-full { display:none !important; }
  body.sidebar-collapsed .brand-logo-icon,
  html.jss-sidebar-collapsed body .brand-logo-icon { display:block !important; }
  body.sidebar-collapsed .brand-link,
  html.jss-sidebar-collapsed body .brand-link { justify-content:center; flex:0 0 auto; }
  body.sidebar-collapsed .company-box,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .logout-form .nav-label,
  html.jss-sidebar-collapsed body .company-box,
  html.jss-sidebar-collapsed body .nav-label,
  html.jss-sidebar-collapsed body .logout-form .nav-label { display:none !important; }
  body.sidebar-collapsed .sidebar-head,
  html.jss-sidebar-collapsed body .sidebar-head { justify-content:center !important; }
  body.sidebar-collapsed .sidebar-head-actions,
  html.jss-sidebar-collapsed body .sidebar-head-actions { flex-direction:column !important; }
  body.sidebar-collapsed .sidebar nav a,
  body.sidebar-collapsed .logout-form button,
  html.jss-sidebar-collapsed body .sidebar nav a,
  html.jss-sidebar-collapsed body .logout-form button {
    justify-content:center !important;
    padding:11px !important;
  }
  body.sidebar-collapsed .nav-icon,
  html.jss-sidebar-collapsed body .nav-icon {
    width:36px !important;
    height:36px !important;
    flex-basis:36px !important;
  }
}

/* Vistas más limpias y premium sin tocar lógica */
.topbar {
  position:sticky;
  top:10px;
  z-index:80;
  border:1px solid rgba(148,163,184,.13);
  background:rgba(6,12,26,.78);
  backdrop-filter:blur(16px);
  border-radius:24px;
  padding:18px 20px;
  box-shadow:0 18px 60px rgba(0,0,0,.18);
}
.topbar h1::before {
  content:'✦';
  display:inline-grid;
  place-items:center;
  width:30px;
  height:30px;
  margin-right:10px;
  border-radius:12px;
  font-size:14px;
  color:#bfe7ff;
  background:linear-gradient(135deg, rgba(32,227,178,.15), rgba(91,124,250,.20));
  border:1px solid rgba(148,163,184,.14);
  vertical-align:middle;
}
.card, .stat-card, .dashboard-primary-card, .dashboard-info-card {
  box-shadow:0 24px 80px rgba(0,0,0,.20), inset 0 1px 0 rgba(255,255,255,.045) !important;
}
.card:hover, .stat-card:hover {
  border-color:rgba(91,124,250,.26);
}
button, .button, .user-pill, .theme-toggle, .super-company-toggle, .desktop-sidebar-toggle {
  transition:transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
button:hover, .button:hover, .user-pill:hover, .theme-toggle:hover, .super-company-toggle:hover {
  transform:translateY(-1px);
}

/* Modo claro reforzado para conservar contraste y color */
body.theme-light .topbar {
  background:rgba(255,255,255,.84) !important;
  border-color:rgba(100,116,139,.18) !important;
  box-shadow:0 18px 50px rgba(15,23,42,.08) !important;
}
body.theme-light .login-card { background:#ffffff !important; }
body.theme-light .login-card input { background:#f8fafc !important; color:#0f172a !important; }
body.theme-light .login-card p { color:#475569 !important; }
body.theme-light .sidebar {
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(243,247,255,.96)) !important;
  border-right-color:rgba(100,116,139,.18) !important;
}
body.theme-light .sidebar::before {
  background:
    radial-gradient(circle at 12% 10%, rgba(8,159,125,.10), transparent 24%),
    radial-gradient(circle at 92% 38%, rgba(56,97,246,.10), transparent 26%);
}

@media (max-width: 920px) {
  html.jss-sidebar-collapsed body .sidebar { width:320px !important; max-width:86vw !important; padding:22px !important; }
  html.jss-sidebar-collapsed body .brand-logo-full { display:block !important; width:116px; }
  html.jss-sidebar-collapsed body .brand-logo-icon { display:none !important; }
  html.jss-sidebar-collapsed body .company-box,
  html.jss-sidebar-collapsed body .nav-label,
  html.jss-sidebar-collapsed body .logout-form .nav-label { display:initial !important; }
  html.jss-sidebar-collapsed body .sidebar nav a,
  html.jss-sidebar-collapsed body .logout-form button { justify-content:flex-start !important; padding:11px 12px !important; }
  .topbar { top:0; border-radius:18px; padding:14px; }
}

/* ===== V1.7.5 Branding JSSolutions y login sin palabra IA ===== */
.login-card {
  width:min(520px,100%) !important;
  padding-top:36px !important;
}
.login-logo-wrap {
  margin-bottom:24px !important;
  padding:14px 18px;
  border-radius:24px;
  background:linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.025));
  border:1px solid rgba(148,163,184,.18);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.06), 0 18px 44px rgba(0,0,0,.18);
}
.login-logo.jssolutions-login-logo {
  width:min(380px, 92%) !important;
  max-width:92% !important;
  filter:drop-shadow(0 18px 34px rgba(32,227,178,.18)) drop-shadow(0 10px 22px rgba(91,124,250,.22));
}
.login-card h1 {
  margin-top:2px !important;
}
.login-submit {
  width:100%;
  margin-top:20px !important;
}
.brand-logo-jssolutions {
  width:142px !important;
  max-height:48px !important;
  object-fit:contain;
  object-position:left center;
}
.brand-logo-icon {
  object-fit:contain;
  border-radius:16px;
  filter:drop-shadow(0 10px 22px rgba(32,227,178,.18)) drop-shadow(0 8px 18px rgba(91,124,250,.20));
}
@media (min-width: 921px) {
  body.sidebar-collapsed .brand-logo-icon,
  html.jss-sidebar-collapsed body .brand-logo-icon {
    width:44px !important;
    height:44px !important;
  }
  body.sidebar-collapsed .sidebar-head-actions,
  html.jss-sidebar-collapsed body .sidebar-head-actions {
    margin-top:6px;
  }
  .sidebar {
    backface-visibility:hidden;
    transform:translateZ(0) !important;
  }
}
body.theme-light .login-logo-wrap {
  background:linear-gradient(135deg, rgba(255,255,255,.95), rgba(241,245,249,.88));
  border-color:rgba(100,116,139,.16);
}
body.theme-light .brand-logo,
body.theme-light .login-logo.jssolutions-login-logo {
  filter:drop-shadow(0 14px 28px rgba(37,99,235,.16));
}

/* ===== V1.7.6 Branding administrable por super usuario ===== */
.brand-text-full {
  display:inline-flex;
  align-items:center;
  gap:9px;
  min-height:42px;
  font-size:18px;
  font-weight:950;
  letter-spacing:-.04em;
  color:#f8fafc;
  white-space:nowrap;
}
.brand-text-full::before {
  content:'';
  width:11px;
  height:11px;
  border-radius:999px;
  background:linear-gradient(135deg, #20e3b2, #5b7cfa);
  box-shadow:0 0 22px rgba(32,227,178,.45);
}
body.theme-light .brand-text-full { color:#0f172a; }
.brand-logo-uploaded {
  width:138px;
  max-height:52px;
  object-fit:contain;
  object-position:left center;
  filter:drop-shadow(0 12px 24px rgba(91,124,250,.20));
}
.brand-logo-text-icon {
  display:none;
  place-items:center;
  width:42px;
  height:42px;
  border-radius:16px;
  color:#eaf5ff;
  font-weight:950;
  letter-spacing:-.06em;
  background:linear-gradient(135deg, rgba(32,227,178,.23), rgba(91,124,250,.35));
  border:1px solid rgba(148,163,184,.18);
  box-shadow:0 14px 34px rgba(91,124,250,.18);
}
body.sidebar-collapsed .brand-logo-text-icon,
html.jss-sidebar-collapsed body .brand-logo-text-icon { display:grid !important; }
body.sidebar-collapsed .brand-text-full,
html.jss-sidebar-collapsed body .brand-text-full { display:none !important; }
.login-brand-text {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:235px;
  min-height:78px;
  padding:18px 26px;
  border-radius:24px;
  font-size:34px;
  line-height:1;
  font-weight:950;
  letter-spacing:-.06em;
  color:#f8fafc;
  background:linear-gradient(180deg, rgba(15,23,42,.82), rgba(8,13,26,.62));
  border:1px solid rgba(148,163,184,.18);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05), 0 20px 50px rgba(0,0,0,.20);
}
.login-brand-text::before {
  content:'';
  width:13px;
  height:13px;
  margin-right:12px;
  border-radius:999px;
  background:linear-gradient(135deg, #20e3b2, #5b7cfa);
  box-shadow:0 0 22px rgba(32,227,178,.50);
}
.uploaded-login-logo {
  width:min(310px, 86%);
  max-height:112px;
  object-fit:contain;
  padding:14px 18px;
  border-radius:24px;
  background:linear-gradient(180deg, rgba(15,23,42,.80), rgba(8,13,26,.58));
  border:1px solid rgba(148,163,184,.16);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05), 0 20px 50px rgba(0,0,0,.20);
}
.branding-admin-grid {
  display:grid;
  grid-template-columns:minmax(220px, 330px) minmax(0, 1fr);
  gap:20px;
  align-items:start;
}
.branding-preview-card,
.branding-upload-preview {
  border:1px solid var(--line);
  border-radius:22px;
  background:rgba(8,13,26,.34);
  padding:18px;
  min-height:130px;
  display:grid;
  place-items:center;
  text-align:center;
}
body.theme-light .branding-preview-card,
body.theme-light .branding-upload-preview { background:#f8fbff; }
.branding-preview-card small,
.branding-upload-preview small {
  display:block;
  width:100%;
  margin-bottom:12px;
  color:var(--muted);
  font-weight:850;
  text-align:left;
}
.branding-current-logo,
.branding-upload-preview img {
  max-width:100%;
  max-height:110px;
  object-fit:contain;
  border-radius:16px;
}
.branding-empty-logo {
  width:100%;
  min-height:86px;
  border-radius:18px;
  display:grid;
  place-items:center;
  color:var(--text);
  font-size:25px;
  font-weight:950;
  letter-spacing:-.05em;
  background:linear-gradient(135deg, rgba(32,227,178,.12), rgba(91,124,250,.13));
  border:1px dashed rgba(148,163,184,.26);
}
.branding-upload-form input[type="file"] {
  padding:14px;
  min-height:auto;
}
button.danger,
.button.danger {
  color:#fecaca !important;
  border-color:rgba(239,68,68,.35) !important;
  background:rgba(239,68,68,.10) !important;
}
body.theme-light button.danger,
body.theme-light .button.danger {
  color:#991b1b !important;
  background:#fff1f2 !important;
}
@media (max-width: 920px) {
  .branding-admin-grid { grid-template-columns:1fr; }
  .uploaded-login-logo { width:min(270px, 90%); }
  .login-brand-text { min-width:0; width:100%; font-size:28px; }
}
