/* ═══════════════════════════════════════════════════════════════════
   EBrain — main.css v4
   Complete rewrite. Refined dark luxury aesthetic.
   ═══════════════════════════════════════════════════════════════════

   Architecture:
     1. Tokens (variables)
     2. Reset and base
     3. Typography helpers
     4. Animations and motion
     5. Utilities (toast, glass, scrollbar, line-clamp, etc.)
     6. Inputs / textarea / focus
     7. Status dot
     8. Toggle switch
     9. App shell — desktop (≥ 768px)
    10. App shell — mobile (< 768px)
    11. Mobile topbar
    12. Drawer dialog (HTML5 <dialog>, top layer)
    13. Profile dialog (HTML5 <dialog>, top layer, bottom-sheet on mobile)
    14. Chat header / messages / compose
    15. Conversation list with swipe
    16. Icon button + popover (chat header actions)
    17. Page-specific tweaks (CRM collapsibles, etc.)

   Critical decisions:
     - All overlays use HTML5 <dialog>. No z-index gymnastics.
     - --app-h is set by JS from visualViewport.height. Body uses it
       directly so the chat compose stays pinned above the keyboard.
     - Mobile and desktop layouts are SEPARATED by @media. They share
       only tokens; no rule overrides another between modes.
     - The conversation-list swipe uses a __content layer with the
       same background as the body, padding moved INTO it (not on
       .conv-item) so the actions layer is fully covered until the
       user actually drags.
   ═══════════════════════════════════════════════════════════════════ */


/* ─── 1. Tokens ─────────────────────────────────────────────────── */

:root {
  /* Surface colors */
  --bg-0:        #08090D;   /* deepest — body */
  --bg-1:        #0C0E14;   /* surface 1 — cards */
  --bg-2:        #131620;   /* surface 2 — elevated */
  --bg-3:        #1A1E2A;   /* surface 3 — hover */
  --bg-4:        #242938;   /* surface 4 — input */
  --bg-5:        #343A4D;   /* surface 5 — divider+ */

  --line:        rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.10);

  --text-1: rgba(255, 255, 255, 0.95);   /* primary */
  --text-2: rgba(255, 255, 255, 0.70);   /* secondary */
  --text-3: rgba(255, 255, 255, 0.45);   /* tertiary */
  --text-4: rgba(255, 255, 255, 0.25);   /* hint */

  /* Brand accent — gold */
  --gold:       #C9A84C;
  --gold-soft:  rgba(201, 168, 76, 0.12);
  --gold-glow:  rgba(201, 168, 76, 0.30);
  --gold-bg:    rgba(201, 168, 76, 0.06);

  /* Semantic */
  --ok:    #34D399;
  --warn:  #FBBF24;
  --err:   #F87171;
  --info:  #60A5FA;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* Motion */
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* Mobile shell */
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Visual viewport (set by shell.js) */
  --app-h: 100dvh;
  --vv-top: 0px;
}


/* ─── 2. Reset and base ─────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; }


/* ─── 3. Scrollbar ─────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-5); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #4A5168; }


/* ─── 4. Animations and motion ─────────────────────────────────── */

@keyframes fadeIn   { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: translateY(0) } }
@keyframes scaleIn  { from { opacity: 0; transform: scale(0.96) } to { opacity: 1; transform: scale(1) } }
@keyframes pulseRing {
  0%   { box-shadow: 0 0 0 0 var(--gold-glow); }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes bounceDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1;   }
}
@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes slideRightDrawer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
@keyframes fadeInBackdrop {
  from { background: rgba(0,0,0,0); backdrop-filter: blur(0); }
  to   { background: rgba(0,0,0,0.55); backdrop-filter: blur(8px); }
}

.pulse-ring   { animation: pulseRing 2s ease-in-out infinite; }
.typing-dot   { animation: bounceDot 1.4s ease-in-out infinite both; }
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }


/* ─── 5. Utilities ─────────────────────────────────────────────── */

.glass {
  background: rgba(19, 22, 32, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toast-container {
  position: fixed;
  top: max(20px, var(--safe-top));
  right: 20px;
  z-index: 2147483646;       /* near max — toasts must be above dialogs */
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast-container > * { pointer-events: auto; }
.toast {
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: scaleIn 0.25s var(--ease-out);
}
.toast-success { background: rgba(34, 197, 94, 0.92); color: #fff; }
.toast-error   { background: rgba(239, 68, 68, 0.92); color: #fff; }


/* ─── 6. Forms ─────────────────────────────────────────────────── */

input:focus, select:focus, textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--gold-glow);
  border-color: var(--gold) !important;
}
textarea.auto-resize {
  resize: none;
  overflow: hidden;
  min-height: 40px;
  max-height: 120px;
}


/* ─── 7. Status dot ────────────────────────────────────────────── */

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}


/* ─── 8. Toggle switch ─────────────────────────────────────────── */

.toggle-track {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: var(--bg-5);
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}
.toggle-track.active { background: var(--gold); }
.toggle-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-track.active .toggle-thumb { transform: translateX(20px); }


/* ─── 9. APP SHELL — DESKTOP (≥ 768px) ─────────────────────────── */
/*
   On desktop the layout is exactly what each page already declares
   in HTML: a flex row with a sidebar aside and a main area. We don't
   need to override anything — Tailwind classes do the job. We just
   make sure the mobile-only elements stay hidden.
*/
.ebrain-topbar { display: none; }


/* ─── 10. APP SHELL — MOBILE (< 768px) ─────────────────────────── */

@media (max-width: 767px) {

  /*
     Strategy: html and body are pinned to the visual viewport.

     We use position: fixed on body so iOS Safari can't auto-scroll
     the document when an input is focused.  Body height is set
     from --app-h (which JS keeps in sync with
     window.visualViewport.height).  Body top is set from --vv-top
     (window.visualViewport.offsetTop) so that when iOS shifts the
     visual viewport down to reveal a focused input, the body
     follows it — preventing the "empty gap below the chat" bug.

     The body becomes a flex column whose first child is the topbar
     (flex-shrink:0) and whose second child absorbs the rest
     (.flex.h-screen, .min-h-screen or main, depending on the page).
  */
  html {
    height: 100%;
    overflow: hidden;
  }
  body {
    position: fixed;
    top: var(--vv-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: var(--app-h);
    max-height: var(--app-h);
    overflow: hidden;
    overscroll-behavior: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    -webkit-text-size-adjust: 100%;
  }

  /* Override Tailwind h-screen / min-h-screen on body, since they
     would force a height that doesn't match --app-h. */
  body.h-screen,
  body.min-h-screen,
  body.overflow-hidden {
    height: var(--app-h) !important;
    max-height: var(--app-h) !important;
    min-height: 0 !important;
  }

  /* The first content child of body (after the topbar) absorbs the
     remaining space. Each page uses a slightly different wrapper, so
     we cover all the variants. */
  body > .flex.h-screen,
  body > div.h-screen,
  body > div.flex,
  body > .min-h-screen,
  body > main,
  body > div.min-h-screen {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    width: 100% !important;
    overflow: hidden;
  }

  /* The desktop sidebar gets HIDDEN on mobile. The drawer dialog
     contains a copy of the nav links, built by shell.js from this
     same aside. */
  body > .flex.h-screen > aside:first-of-type,
  body > div.h-screen > aside:first-of-type,
  body > .flex > aside:first-of-type,
  body > .min-h-screen > aside:first-of-type {
    display: none !important;
  }

  /* Tap targets bigger by default */
  button, a {
    -webkit-tap-highlight-color: transparent;
  }

  /* Inputs: 16px to disable iOS auto-zoom on focus */
  input[type="text"],
  input[type="email"],
  input[type="search"],
  input[type="tel"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input:not([type]),
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Make sure the chat compose / bottom bars respect safe-area-bottom */
  #chatCompose,
  .ebrain-bottom-bar {
    padding-bottom: calc(var(--safe-bot) + 12px) !important;
    flex-shrink: 0 !important;
  }

  /* Filter chips wrap on narrow screens */
  #filterChips {
    flex-wrap: wrap;
    gap: 6px !important;
  }
}


/* ─── 11. Mobile topbar ─────────────────────────────────────────── */

@media (max-width: 767px) {
  .ebrain-topbar {
    display: flex !important;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-grow: 0;
    width: 100%;
    height: calc(var(--topbar-h) + var(--safe-top));
    padding-top: var(--safe-top);
    padding-left: max(8px, var(--safe-left));
    padding-right: max(14px, var(--safe-right));
    background: var(--bg-0);
    border-bottom: 1px solid var(--line);
    color: var(--text-1);
    z-index: 10;
  }
  .ebrain-topbar__btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: transparent;
    border: 0;
    color: var(--text-1);
    cursor: pointer;
    transition: background 0.18s var(--ease-out);
    touch-action: manipulation;
  }
  .ebrain-topbar__btn:active { background: rgba(255, 255, 255, 0.08); }
  .ebrain-topbar__title {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
  }
  .ebrain-topbar__logo {
    height: 30px;
    width: auto;
    flex-shrink: 0;
    opacity: 0.95;
  }
}


/* ─── 12. Drawer dialog ─────────────────────────────────────────── */
/*
   <dialog id="drawerDialog">  → promoted to top layer when .showModal()
   So z-index, stacking contexts, and transforms in ancestors don't
   affect it at all.  We only need to style the dialog itself + its
   ::backdrop pseudo-element.
*/

.ebrain-drawer {
  position: fixed;
  inset: 0 auto 0 0;            /* pin left edge, full height */
  margin: 0;
  padding: 0;
  border: 0;
  width: 280px;
  max-width: 86vw;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg-1);
  color: var(--text-1);
  overflow: hidden;
  box-shadow: 24px 0 80px -10px rgba(0, 0, 0, 0.9);
}
.ebrain-drawer[open] {
  display: flex;
  flex-direction: column;
  animation: slideRightDrawer 0.32s var(--ease-spring);
}
.ebrain-drawer::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeInBackdrop 0.32s var(--ease-out);
}

.ebrain-drawer__header {
  flex-shrink: 0;
  padding: calc(var(--safe-top) + 18px) 20px 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.ebrain-drawer__logo { height: 32px; width: auto; }
.ebrain-drawer__brand {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-1);
  text-transform: uppercase;
}
.ebrain-drawer__agent {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.ebrain-drawer__nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ebrain-drawer__nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  min-height: 50px;
  transition: background 0.18s var(--ease-out), color 0.18s var(--ease-out);
}
.ebrain-drawer__nav a:hover,
.ebrain-drawer__nav a:active {
  background: var(--bg-3);
  color: var(--text-1);
}
.ebrain-drawer__nav a.is-current {
  background: var(--gold-bg);
  color: var(--gold);
}
.ebrain-drawer__nav svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}
.ebrain-drawer__footer {
  flex-shrink: 0;
  padding: 12px 14px calc(var(--safe-bot) + 14px) 14px;
  border-top: 1px solid var(--line);
}
.ebrain-drawer__logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-3);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.ebrain-drawer__logout:active { background: var(--bg-3); color: var(--text-1); }
.ebrain-drawer__logout svg { width: 16px; height: 16px; }


/* ─── 13. Profile dialog (bottom-sheet on mobile) ──────────────── */

.ebrain-profile-dialog {
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg-1);
  color: var(--text-1);
  overflow: hidden;
  box-shadow: 0 -24px 80px -10px rgba(0, 0, 0, 0.9);
}
.ebrain-profile-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeInBackdrop 0.32s var(--ease-out);
}

/* Desktop: side panel attached to the right */
@media (min-width: 768px) {
  .ebrain-profile-dialog {
    position: fixed;
    inset: 0 0 0 auto;       /* pin right edge */
    width: 360px;
    height: 100dvh;
    max-height: 100dvh;
    border-left: 1px solid var(--line);
    box-shadow: -16px 0 60px -10px rgba(0, 0, 0, 0.5);
  }
  .ebrain-profile-dialog[open] {
    display: flex;
    flex-direction: column;
    animation: scaleIn 0.22s var(--ease-out);
  }
}

/* Mobile: bottom sheet, full height */
@media (max-width: 767px) {
  .ebrain-profile-dialog {
    position: fixed;
    inset: 0 0 0 0;
    width: 100%;
    max-width: none;
    height: var(--app-h);
    max-height: var(--app-h);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
  }
  .ebrain-profile-dialog[open] {
    display: flex;
    flex-direction: column;
    animation: slideUpSheet 0.36s var(--ease-spring);
  }
}

.ebrain-profile-dialog__header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 14px) 18px 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.ebrain-profile-dialog__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: 0.01em;
}
.ebrain-profile-dialog__close {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--bg-3);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.ebrain-profile-dialog__close:active { background: var(--bg-4); color: var(--text-1); }
.ebrain-profile-dialog__close svg { width: 22px; height: 22px; }
.ebrain-profile-dialog__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  padding-bottom: calc(var(--safe-bot) + 24px);
}


/* ─── 14. Chat header / messages / compose ─────────────────────── */

/* Chat header (only on mobile show the simplified version) */
#chatHeader {
  align-items: center;
}

/* The "context line" inside the header is hidden on mobile —
   the data lives in the profile dialog instead. */
@media (max-width: 767px) {
  #chatHeaderContext {
    display: none !important;
  }
  #chatHeader {
    padding: 10px 12px !important;
    gap: 10px !important;
    flex-wrap: nowrap !important;
  }
  #chatHeader > div:first-child {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    overflow: hidden;
  }
  #chatHeader > div:last-child {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    flex-wrap: nowrap !important;
    width: auto !important;
    gap: 6px !important;
  }
  #chatHeader #chatName {
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #chatHeader .ebrain-icon-btn {
    width: 36px;
    height: 36px;
  }
  #chatHeader .ebrain-icon-btn svg { width: 17px; height: 17px; }
}

/* Compose bar */
@media (max-width: 767px) {
  #chatCompose {
    padding: 10px 14px !important;
    gap: 10px !important;
  }
  #chatCompose #msgInput { font-size: 16px !important; }
  #chatCompose #btnSend {
    min-width: 68px;
    height: 44px !important;
  }
}

/* Critical: ensure the flex chain inside the chat panel can shrink
   when the keyboard opens. Without these min-h-0 the messages area
   pushes the compose down off-screen. */
@media (max-width: 767px) {
  #chatPanel,
  #chatMessages,
  main,
  body > main,
  body > div.h-screen,
  body > .flex.h-screen,
  body > .flex.h-screen > main,
  body > .flex.h-screen > main > div {
    min-height: 0 !important;
  }
  #chatHeader {
    flex-shrink: 0 !important;
  }
}

/* Imágenes del chat y lightbox (panel.js renderiza .msg-image y crea
   .image-lightbox). Vivían en panel.css, que ninguna página carga, así que el
   lightbox se añadía al final del body sin posicionar y no se veía
   (auditoría 2026-11, H454). */
.msg-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
    object-fit: contain;
}

.msg-image:hover {
    opacity: 0.85;
}

.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
    padding: 20px;
}

.image-lightbox img {
    max-width: 90%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}


/* ─── 15. Conversation list with swipe ─────────────────────────── */
/*
   Layout:
     .conv-item                 ← position:relative, padding:0, transparent
       .conv-item__actions      ← absolute right, hidden by default
       .conv-item__content      ← opaque background, padding lives here
         (the visible row content)
*/

.conv-item {
  position: relative;
  overflow: hidden;
  background: transparent !important;     /* override Tailwind bg classes */
  padding: 0 !important;                  /* override Tailwind p-* classes */
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.conv-item__content {
  position: relative;
  z-index: 2;
  padding: 14px 16px;
  background: var(--bg-0);
  transform: translate3d(0, 0, 0);
  transition: transform 0.32s var(--ease-spring),
              background-color 0.18s ease;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}
.conv-item.is-dragging > .conv-item__content {
  transition: none;
}
.conv-item.bg-gold-50 > .conv-item__content,
.conv-item.is-active > .conv-item__content {
  background: rgba(201, 168, 76, 0.06);
}
@media (hover: hover) {
  .conv-item:hover > .conv-item__content {
    background: rgba(255, 255, 255, 0.025);
  }
  .conv-item.bg-gold-50:hover > .conv-item__content,
  .conv-item.is-active:hover > .conv-item__content {
    background: rgba(201, 168, 76, 0.09);
  }
}

/*
   Actions layer is display:none until the user starts a real horizontal
   drag.  We add .has-actions to the .conv-item from JS the moment the
   pointer crosses the threshold.  This guarantees zero visual flash on
   tap.
*/
.conv-item__actions {
  position: absolute;
  inset: 0 0 0 auto;
  display: none;
  align-items: stretch;
  z-index: 1;
}
.conv-item.has-actions > .conv-item__actions,
.conv-item.is-open > .conv-item__actions {
  display: flex;
}
.conv-item__action {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  width: 76px;
  border: 0;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.15s ease;
}
.conv-item__action:active { filter: brightness(0.85); }
.conv-item__action--state  { background: #1d4ed8; }
.conv-item__action--assign { background: var(--gold); color: var(--bg-0); }
.conv-item__action svg { width: 20px; height: 20px; }


/* ─── 16. Icon button + popover (chat header actions) ─────────── */

.ebrain-icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.08s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ebrain-icon-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-1);
}
.ebrain-icon-btn:active { transform: scale(0.94); }

.ebrain-icon-btn[data-state="bot_activo"]      { color: #60a5fa; background: rgba(96, 165, 250, 0.10); border-color: rgba(96, 165, 250, 0.30); }
.ebrain-icon-btn[data-state="esperando_humano"]{ color: #fbbf24; background: rgba(251, 191, 36, 0.10); border-color: rgba(251, 191, 36, 0.30); }
.ebrain-icon-btn[data-state="humano_activo"]   { color: #34d399; background: rgba(52, 211, 153, 0.10); border-color: rgba(52, 211, 153, 0.30); }
.ebrain-icon-btn[data-state="cerrada"]         { color: var(--text-3); background: rgba(255, 255, 255, 0.02); }
.ebrain-icon-btn[data-channel="whatsapp"]      { color: #25D366; border-color: rgba(37, 211, 102, 0.30); background: rgba(37, 211, 102, 0.08); }
.ebrain-icon-btn[data-channel="web"]           { color: var(--gold); border-color: rgba(201, 168, 76, 0.30); background: var(--gold-bg); }
.ebrain-icon-btn[data-channel="email"]         { color: #818cf8; border-color: rgba(129, 140, 248, 0.30); background: rgba(129, 140, 248, 0.08); }
.ebrain-icon-btn[data-channel="instagram"]     { color: #f472b6; border-color: rgba(244, 114, 182, 0.30); background: rgba(244, 114, 182, 0.08); }
.ebrain-icon-btn[data-state="assigned"]        { color: var(--gold); border-color: rgba(201, 168, 76, 0.30); background: var(--gold-bg); }

.ebrain-icon-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  max-width: calc(100vw - 24px);
  z-index: 240;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: 0 16px 48px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
  padding: 6px;
  display: none;
  animation: scaleIn 0.16s var(--ease-out);
}
.ebrain-icon-popover.open { display: block; }
.ebrain-icon-popover button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 0;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.ebrain-icon-popover button:hover,
.ebrain-icon-popover button:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-1);
  outline: none;
}
.ebrain-icon-popover button.is-current {
  color: var(--gold);
  background: var(--gold-bg);
}
.ebrain-icon-popover button .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}


/* ─── 17. Page-specific tweaks ─────────────────────────────────── */

.crm-section { border-top: 1px solid rgba(255, 255, 255, 0.04); }
.crm-section button { background: none; border: none; cursor: pointer; }
.crm-section button:hover { background: rgba(255, 255, 255, 0.02); border-radius: 6px; }
.crm-section .rotate-180 { transform: rotate(180deg); }


/* ─── 18. Modal overlay (legacy generic modals) ────────────────── */

.modal-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-overlay .modal-content {
  transform: scale(0.95) translateY(8px);
  transition: transform 0.25s var(--ease-out);
}
.modal-overlay.active .modal-content { transform: scale(1) translateY(0); }


/* ─── 19. Stagger animations (used by lists) ───────────────────── */

.stagger > * { opacity: 0; animation: slideUp 0.35s ease-out forwards; }
.stagger > *:nth-child(1) { animation-delay: 0.03s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.09s; }
.stagger > *:nth-child(4) { animation-delay: 0.12s; }
.stagger > *:nth-child(5) { animation-delay: 0.15s; }
.stagger > *:nth-child(6) { animation-delay: 0.18s; }
.stagger > *:nth-child(7) { animation-delay: 0.21s; }
.stagger > *:nth-child(8) { animation-delay: 0.24s; }
.stagger > *:nth-child(n+9) { animation-delay: 0.27s; }


/* ─── 20. Mesh background utility ──────────────────────────────── */

.mesh-bg {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(201, 168, 76, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.03) 0%, transparent 50%),
    var(--bg-0);
}

/* ═══════════════════════════════════════════════════════════════════
   v15 — Shared shell (sidebar / page header / subtabs / cards / actions)
   Apple HIG-inspired refinements: SF system fonts, frosted glass, soft
   elevation, generous spacing, refined micro-typography.
   Used by all pages refactored to the shared-sidebar.js model.
   ═══════════════════════════════════════════════════════════════════ */

/* Apple system stack fallback. Plus Jakarta Sans is the brand fallback. */
:where(body, .ebrain-page-title, .ebrain-nav-link, .ebrain-subtab,
       .ebrain-action-btn, .ebrain-card__label, .ebrain-card__value,
       .ebrain-action-sheet__item) {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Plus Jakarta Sans", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

/* Sidebar — Apple-HIG refined: 200px wide, generous padding, vibrancy. */
.ebrain-sidebar { position: relative; }
.ebrain-sidebar::after {
  content: ''; position: absolute; inset: 0 0 0 auto; width: 1px;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.05) 18%, rgba(255,255,255,0.05) 82%, transparent);
  pointer-events: none;
}
.ebrain-sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ebrain-brand-logo {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f0c977 0%, #d4af6a 45%, #a07f31 100%);
  box-shadow: 0 8px 20px rgba(201, 168, 76, 0.22),
              inset 0 1px 0 rgba(255,255,255,0.18),
              inset 0 -1px 0 rgba(0,0,0,0.10);
  overflow: hidden;
}
.ebrain-brand-logo-img {
  width: 78%; height: 78%; object-fit: contain;
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.30));
}
.ebrain-brand-fallback {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #1a1306; font-size: 15px;
}
.ebrain-sidebar-nav {
  flex: 1; padding: 12px 10px; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: none;
}
.ebrain-sidebar-nav::-webkit-scrollbar { width: 0; display: none; }
.ebrain-nav-link {
  position: relative;
  letter-spacing: -0.005em;
  font-weight: 500;
}
.ebrain-nav-link::before {
  /* Soft pill indicator on active. */
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 0; border-radius: 2px;
  background: linear-gradient(180deg, #f0c977, #c9a84c);
  transition: height 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ebrain-nav-link[aria-current="page"]::before { height: 20px; }
.ebrain-nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.78; transition: opacity 160ms ease; }
.ebrain-nav-link:hover .ebrain-nav-icon { opacity: 1; }
.ebrain-nav-link[aria-current="page"] .ebrain-nav-icon { opacity: 1; }
.ebrain-sidebar-foot {
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* Page header — Apple-HIG: large title style, frosted on scroll */
.ebrain-page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 16px 28px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: linear-gradient(180deg, rgba(20,23,32,0.65), rgba(20,23,32,0.35));
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  position: sticky; top: 0; z-index: 10;
  flex-shrink: 0;
}
.ebrain-page-header__left {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.ebrain-page-title {
  font-size: 22px; font-weight: 700; letter-spacing: -0.022em;
  color: rgba(255,255,255,0.96);
  margin: 0; line-height: 1.1;
}
.ebrain-page-header__actions {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: nowrap;
}
.ebrain-badge {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.78);
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* Sub-tabs — segmented control style (iOS) */
.ebrain-subtabs {
  display: flex; align-items: stretch; gap: 2px;
  padding: 10px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex-shrink: 0;
  background: rgba(255,255,255,0.008);
  -webkit-overflow-scrolling: touch;
}
.ebrain-subtabs::-webkit-scrollbar { display: none; }
.ebrain-subtab {
  position: relative;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13.5px; font-weight: 500;
  letter-spacing: -0.005em;
  color: rgba(255,255,255,0.58);
  background: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: color 160ms ease, background-color 160ms ease, box-shadow 200ms ease;
  cursor: pointer;
  flex-shrink: 0;
}
.ebrain-subtab:hover {
  color: rgba(255,255,255,0.92);
  background: rgba(255,255,255,0.04);
}
.ebrain-subtab.is-active {
  background: linear-gradient(180deg, rgba(240,201,119,0.18), rgba(201,168,76,0.10));
  color: #f5d390;
  box-shadow: inset 0 0 0 1px rgba(240,201,119,0.28),
              0 1px 0 rgba(255,255,255,0.05) inset;
}
.ebrain-subtab.hidden { display: none; }

/* Cards estándar (estadísticas, tarjetas de contenido) */
.ebrain-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.012));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.18);
  transition: border-color 180ms ease, transform 180ms ease;
}
.ebrain-card:hover {
  border-color: rgba(255,255,255,0.10);
  transform: translateY(-1px);
}
.ebrain-card__label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: rgba(255,255,255,0.45);
  margin-bottom: 6px;
  font-weight: 600;
}
.ebrain-card__value {
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
  color: rgba(255,255,255,0.96);
  line-height: 1.2;
}
.ebrain-card__hint {
  font-size: 12px; color: rgba(255,255,255,0.55); margin-top: 4px;
}

/* Botones de acción (header contextual + dentro del contenido) */
.ebrain-action-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  transition: all 180ms ease;
  cursor: pointer;
  white-space: nowrap;
}
.ebrain-action-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
  color: rgba(255,255,255,1);
}
.ebrain-action-btn--primary {
  background: linear-gradient(180deg, #f0c977, #c9a84c);
  border-color: transparent;
  color: #1a1306;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(201,168,76,0.18);
}
.ebrain-action-btn--primary:hover {
  background: linear-gradient(180deg, #f5d188, #d6b15a);
  color: #1a1306;
}
.ebrain-action-btn--danger {
  background: rgba(244,63,94,0.12);
  border-color: rgba(244,63,94,0.28);
  color: rgba(254,205,211,0.95);
}
.ebrain-action-btn--danger:hover {
  background: rgba(244,63,94,0.18);
  border-color: rgba(244,63,94,0.45);
}

/* Selects con la misma estética que action-btn */
.ebrain-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 32px 8px 12px;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.04) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff80' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 10px center;
  background-size: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  transition: all 180ms ease;
}
.ebrain-select:hover { border-color: rgba(255,255,255,0.18); }
.ebrain-select:focus { outline: none; border-color: rgba(201,168,76,0.55); box-shadow: 0 0 0 3px rgba(201,168,76,0.15); }

/* Página content area */
.ebrain-page-content {
  background:
    radial-gradient(1200px 600px at 50% -200px, rgba(201,168,76,0.025), transparent 60%),
    transparent;
}

/* Action overflow trigger (móvil "···") y bottom-sheet */
.ebrain-action-overflow {
  display: none; /* visible solo en mobile, ver mobile.css */
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.85);
}
.ebrain-action-overflow svg { width: 18px; height: 18px; }
.ebrain-action-overflow:hover { background: rgba(255,255,255,0.10); }

.ebrain-action-sheet {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0;
  transition: opacity 200ms ease;
}
.ebrain-action-sheet.is-open { opacity: 1; }
.ebrain-action-sheet__inner {
  width: 100%; max-width: 480px;
  background: #14171f;
  border-top: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  transform: translateY(20px);
  transition: transform 240ms cubic-bezier(0.2, 0.9, 0.25, 1);
}
.ebrain-action-sheet.is-open .ebrain-action-sheet__inner { transform: translateY(0); }
.ebrain-action-sheet__title {
  text-align: center; font-size: 12px; color: rgba(255,255,255,0.45);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 12px 0 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  margin-bottom: 4px;
}
.ebrain-action-sheet__item {
  display: block; width: 100%; text-align: center;
  padding: 14px 10px;
  font-size: 15px; font-weight: 500;
  color: rgba(255,255,255,0.92);
  background: transparent; border: 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.ebrain-action-sheet__item.is-disabled {
  color: rgba(255,255,255,0.30); pointer-events: none;
}
.ebrain-action-sheet__item:active { background: rgba(255,255,255,0.05); }
.ebrain-action-sheet__cancel {
  display: block; width: 100%;
  padding: 14px 10px;
  margin-top: 6px;
  font-size: 15px; font-weight: 600;
  color: #f0c977;
  background: transparent; border: 0;
  border-radius: 12px;
}
.ebrain-action-sheet__cancel:active { background: rgba(255,255,255,0.05); }

/* Mobile-only chrome: en desktop estos elementos están en el DOM (los inyecta
   mobile-shell.js si el viewport empezó como móvil) pero NO deben renderizar.
   Sus estilos completos viven scopeados a html.is-mobile en mobile.css; aquí
   nos aseguramos de que en desktop estén siempre ocultos para evitar que
   imágenes/elementos salgan a tamaño nativo si el viewport cambia. */
.ebrain-mtopbar,
.ebrain-mdrawer,
#ebrainMDrawer { display: none; }
html.is-mobile .ebrain-mtopbar,
html.is-mobile .ebrain-mdrawer { display: flex; }
html.is-mobile #ebrainMDrawer[open] { display: block; }

/* ════════════════════════════════════════════════════════════════════
   Responsive table → cards (mobile)
   Marca un <table> con .ebrain-tablecards y los <td> con data-label="…"
   y en móvil cada <tr> se renderiza apilado tipo card con label en cada celda.
   En desktop se mantiene la tabla normal.
   ════════════════════════════════════════════════════════════════════ */
.ebrain-table-wrap {
  background: linear-gradient(180deg, rgba(255,255,255,0.020), rgba(255,255,255,0.008));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
@media (max-width: 768px) {
  .ebrain-table-wrap { background: transparent; border: 0; box-shadow: none; }
}
.ebrain-tablecards { width: 100%; border-collapse: collapse; }
.ebrain-tablecards th { text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: rgba(255,255,255,0.50); padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06); font-weight: 600; }
.ebrain-tablecards td { padding: 10px 12px; font-size: 13.5px;
  border-bottom: 1px solid rgba(255,255,255,0.04); vertical-align: middle;
  color: rgba(255,255,255,0.85); }
.ebrain-tablecards tbody tr:hover { background: rgba(255,255,255,0.02); }
.ebrain-tablecards tbody tr.is-clickable { cursor: pointer; }

/* En móvil cada fila se vuelve un card; los labels se inyectan via data-label */
@media (max-width: 768px) {
  .ebrain-tablecards thead { display: none; }
  .ebrain-tablecards, .ebrain-tablecards tbody, .ebrain-tablecards tr,
  .ebrain-tablecards td { display: block; width: 100%; }
  .ebrain-tablecards tbody tr {
    background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.012));
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    padding: 10px 14px;
    margin-bottom: 10px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.16);
  }
  .ebrain-tablecards td {
    border-bottom: 1px dashed rgba(255,255,255,0.05);
    padding: 6px 0;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
  }
  .ebrain-tablecards td:last-child { border-bottom: 0; }
  .ebrain-tablecards td::before {
    content: attr(data-label);
    color: rgba(255,255,255,0.5);
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    font-weight: 600;
    flex-shrink: 0;
  }
  .ebrain-tablecards td > * { text-align: right; }
}

/* Long-press tooltip (mobile-shell.js setupTooltipLongPress) */
.ebrain-mtooltip {
  position: fixed; z-index: 10000;
  padding: 7px 10px;
  font-size: 12px; font-weight: 500;
  color: #fff;
  background: rgba(0,0,0,0.86);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  opacity: 0; transform: translateY(4px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  max-width: 240px;
}
.ebrain-mtooltip.is-open { opacity: 1; transform: translateY(0); }

/* DM de Instagram con la ventana de 24h cerrada. En móvil #chatCompose lleva
   display:flex !important, y por eso no basta con la clase .hidden. */
#chatCompose.is-bloqueado,
html.is-mobile #chatCompose.is-bloqueado {
  display: none !important;
}
