*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand-blue: #16418e;
    --brand-red:  #e30613;
    --grad:     linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-red) 100%);
    --electric:  #2e6bff;
    --btn-grad:  linear-gradient(180deg,
        color-mix(in srgb, var(--electric) 88%, #fff) 0%,
        color-mix(in srgb, var(--electric) 82%, #000) 100%);
    --bg:       var(--bg-light, #f8fafc);
    --surface:  #ffffff;
    --text:     #0f172a;
    --muted:    #94a3b8;
    --border:   rgba(0,0,0,.08);
    --accent:   var(--brand-blue);
    --ai-bg:    #f1f5f9;
    --user-bg:  var(--brand-blue);
    --user-txt: #ffffff;
    --header-h: max(56px, calc(var(--logo-h, 34px) + 22px));
    --pdfs-h:   0px;
    --input-h:  64px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* ── App shell ── */
#mob-app {
    display: flex;
    flex-direction: column;
    height: 100vh;    /* fallback navegadores antiguos */
    height: 100dvh;
    position: relative;
}

/* ── Header ── */
#mob-header {
    height: var(--header-h);
    background: var(--header-bg, transparent);
    border-bottom: 2px solid transparent;
    border-image: linear-gradient(90deg, var(--brand-blue), var(--brand-red)) 1;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    flex-shrink: 0;
    z-index: 100;
}

.mob-logo { height: var(--logo-h, 34px); width: auto; flex-shrink: 0; cursor: pointer; }
.mob-logo-light { display: block; }
.mob-logo-dark  { display: none; }
[data-theme="dark"] .mob-logo-light { display: none; }
[data-theme="dark"] .mob-logo-dark  { display: block; }
.mob-logo-invert { filter: brightness(0) invert(1); }

#mob-menu-btn, #mob-new-chat-btn, #mob-theme-btn {
    width: 40px; height: 40px;
    border: none; background: none;
    color: var(--muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border-radius: 10px;
    flex-shrink: 0;
}
#mob-menu-btn:hover, #mob-new-chat-btn:hover, #mob-theme-btn:hover { color: var(--text); background: var(--ai-bg); }

#mob-header-info {
    flex: 1;
    min-width: 0;
    text-align: center;
}
#mob-exp-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Drawer ── */
#mob-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 200;
    transition: opacity .2s;
}
#mob-overlay.hidden { display: none; }

#mob-drawer {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(300px, 85vw);
    background: var(--panel-bg, color-mix(in srgb, var(--surface) 88%, transparent));
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
}
#mob-drawer.open { transform: translateX(0); }

#mob-drawer-head {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}
#mob-drawer-close {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    width: 36px; height: 36px;
    border: none; background: none;
    color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
}
#mob-drawer-close:hover { background: var(--ai-bg); color: var(--text); }

#mob-search-wrap {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
#mob-search {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}
#mob-search:focus { border-color: var(--accent); }

#mob-exp-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.mob-exp-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 12px 16px 4px;
}

.mob-exp-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    gap: 12px;
    transition: background .12s;
}
.mob-exp-item:hover, .mob-exp-item.active {
    background: var(--ai-bg);
}
.mob-exp-item.active .mob-exp-model { color: var(--accent); font-weight: 700; }
.mob-exp-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    flex-shrink: 0;
}
.mob-exp-info { min-width: 0; }
.mob-exp-marca { font-size: 11px; color: var(--muted); }
.mob-exp-model { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mob-exp-pdfs-count { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ── Barra de PDFs ── */
#mob-pdfs-bar {
    background: color-mix(in srgb, var(--brand-blue) 6%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--brand-blue) 18%, transparent);
    flex-shrink: 0;
    overflow: hidden;
}
#mob-pdfs-bar.hidden { display: none; }
#mob-pdfs-scroll {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#mob-pdfs-scroll::-webkit-scrollbar { display: none; }

.mob-pdf-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--ai-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text);
}
.mob-pdf-chip-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mob-pdf-action {
    width: 26px; height: 26px;
    border: none; background: none;
    color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    padding: 0;
}
.mob-pdf-action:hover { color: var(--text); background: var(--border); }

/* ── Chat ── */
#mob-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Fondo dinámico: blobs de marca en órbita continua */
#mob-app::before, .mob-login::after {
    content: '';
    position: fixed;
    inset: -25%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(55% 50% at 18% 70%, color-mix(in srgb, var(--brand-blue) 75%, transparent), transparent 72%),
        radial-gradient(50% 45% at 85% 75%, color-mix(in srgb, var(--brand-red) 60%, transparent), transparent 72%),
        radial-gradient(45% 40% at 55% 25%, color-mix(in srgb, var(--brand-blue) 45%, transparent), transparent 72%);
    animation: mob-orbit 9s linear infinite;
    will-change: translate, scale;
}
[data-theme="dark"] #mob-app::before,
[data-theme="dark"] .mob-login::after {
    background:
        radial-gradient(55% 50% at 18% 70%, color-mix(in srgb, var(--brand-blue) 50%, transparent), transparent 72%),
        radial-gradient(50% 45% at 85% 75%, color-mix(in srgb, var(--brand-red) 32%, transparent), transparent 72%),
        radial-gradient(45% 40% at 55% 25%, color-mix(in srgb, var(--brand-blue) 35%, transparent), transparent 72%);
}
@keyframes mob-orbit {
    0%   { translate: 0% 0%;     scale: 1; }
    25%  { translate: 12% -7%;   scale: 1.15; }
    50%  { translate: 0% -12%;   scale: 1.28; }
    75%  { translate: -12% -6%;  scale: 1.12; }
    100% { translate: 0% 0%;     scale: 1; }
}

#mob-header, #mob-input-wrap, #mob-img-preview, #mob-pdfs-bar { position: relative; z-index: 2; }

/* Bienvenida */
#mob-welcome {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 24px;
    z-index: 1;
}
#mob-welcome.hidden { display: none; }
#mob-welcome img { height: calc(var(--logo-h, 34px) * 1.5); width: auto; }

#mob-welcome-title {
    font-size: 30px;
    font-weight: 300;
    background: linear-gradient(90deg, var(--brand-blue), var(--brand-red));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
[data-theme="dark"] #mob-welcome-title {
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--brand-blue) 55%, #fff),
        color-mix(in srgb, var(--brand-red) 60%, #fff));
    -webkit-background-clip: text;
    background-clip: text;
}
#mob-welcome-sub { font-size: 14px; color: var(--muted); }

.mob-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 10px;
    word-break: break-word;
}
.mob-msg-ai {
    background: var(--ai-bg);
    color: var(--text);
    align-self: flex-start;
    white-space: pre-line;
}
.mob-msg-user {
    background: var(--user-bg);
    color: var(--user-txt);
    margin-left: auto;
}
.mob-msg-thinking {
    background: var(--ai-bg);
    color: var(--muted);
    font-style: italic;
    font-size: 13px;
}

/* ── Input — píldora estilo Gemini ── */
#mob-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    margin: 8px 12px calc(10px + env(safe-area-inset-bottom));
    padding: 6px 6px 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: 0 2px 12px rgba(0,0,0,.06);
    flex-shrink: 0;
}

#mob-input {
    flex: 1;
    padding: 11px 6px;
    border: none;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    background: transparent;
    color: var(--text);
    font-family: inherit;
}

#mob-send {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--btn-grad);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--electric) 45%, transparent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity .15s;
}
#mob-send:disabled { opacity: .4; cursor: default; }

/* ── Modal visor PDF ── */
#mob-viewer-modal {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 400;
    display: flex;
    flex-direction: column;
}
#mob-viewer-modal.hidden { display: none; }

#mob-viewer-head {
    height: 52px;
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    flex-shrink: 0;
}
#mob-viewer-title {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#mob-viewer-close {
    width: 36px; height: 36px;
    border: none; background: none;
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
}
#mob-viewer-iframe {
    flex: 1;
    border: none;
    width: 100%;
}

/* ── Utilidades ── */
.mob-loading { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.mob-empty   { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Login ── */
.mob-login {
    height: 100vh;    /* fallback navegadores antiguos */
    height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    padding: 24px;
    position: relative;
    overflow: hidden;
}
.mob-login-inner, #mob-login-theme { z-index: 1; }
/* Login sin tarjeta, estilo bienvenida */
.mob-login-inner { width: min(360px, 100%); text-align: center; position: relative; }
.mob-login-logo {
    height: clamp(56px, 18vw, 92px);
    max-width: 70%;
    width: auto;
    object-fit: contain;
    margin: 0 auto 18px;
}
.mob-login-inner .mob-logo-light { display: block; }
.mob-login-inner .mob-logo-dark  { display: none; }
[data-theme="dark"] .mob-login-inner .mob-logo-light { display: none; }
[data-theme="dark"] .mob-login-inner .mob-logo-dark  { display: block; }
.mob-login-title {
    font-size: 34px; font-weight: 300; margin-bottom: 6px;
    background: linear-gradient(90deg, var(--brand-blue), var(--brand-red));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="dark"] .mob-login-title {
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--brand-blue) 55%, #fff),
        color-mix(in srgb, var(--brand-red) 60%, #fff));
    -webkit-background-clip: text; background-clip: text;
}
.mob-login-sub { color: var(--text); opacity: .72; font-size: 14px; margin-bottom: 24px; }
/* Etiquetas del formulario: heredan el color del tema (claro/oscuro) con contraste suficiente */
.mob-login label { color: var(--text); opacity: .78; font-size: 13px; }
.mob-login .login-remember label { color: var(--text); opacity: .78; }
.mob-login input:not([type=submit]):not([type=checkbox]) { background: var(--bg); color: var(--text); }
#mob-login-theme {
    position: fixed; top: 14px; right: 14px;
    width: 40px; height: 40px; border-radius: 50%;
    border: none; background: none; color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
#mob-login-theme:hover { color: var(--text); background: var(--ai-bg); }
.mob-login input {
    width: 100%; padding: 11px 14px;
    border: 1px solid var(--border); border-radius: 10px;
    font-size: 14px; margin-bottom: 10px; outline: none;
}
.mob-login input:focus { border-color: var(--accent); }
.mob-login input[type=submit] {
    background: var(--btn-grad); color: #fff; border: none;
    box-shadow: 0 2px 12px color-mix(in srgb, var(--electric) 45%, transparent);
    font-weight: 600; cursor: pointer; margin-top: 4px;
}
.mob-login input { background: var(--surface); color: var(--text); border-color: var(--border); }
.mob-login label { color: var(--muted); font-size: 13px; }

/* Ocultar el chat flotante de escritorio en la vista movil
   (la campana .cdt-bell-wrap y #ev-user-slot SÍ se muestran: viven en el header) */
#cdt-chat-window,
#cdt-chat-fab,
.cdt-chat-fab,
.cdt-acc-chip,
#cdt-acc-overlay { display: none !important; }

[data-theme="dark"] {
    --bg:       var(--bg-dark, #0b1220);
    --surface:  #1c2b49;  /* fallback si el navegador no soporta color-mix */
    --surface:  color-mix(in srgb, var(--bg) 88%, #fff);
    --text:     #f5f7fa;
    --muted:    #64748b;
    --border:   rgba(255,255,255,.08);
    --accent:   var(--brand-blue);
    --ai-bg:    color-mix(in srgb, var(--bg) 82%, #fff);
    --user-bg:  color-mix(in srgb, var(--brand-blue) 78%, #fff);
    --user-txt: #ffffff;
}

[data-theme="dark"] #mob-input-wrap { background: #1e293b; box-shadow: none; }
[data-theme="dark"] #mob-input { color: #f1f5f9; }


#mob-msgs { position: relative; z-index: 1; }

/* Botones imagen y micro (dentro de la píldora) */
#mob-img-btn, #mob-mic-btn {
    width: 42px; height: 42px; flex-shrink: 0;
    border: none; background: none;
    color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    transition: color .15s, background .15s;
}
#mob-img-btn:hover, #mob-mic-btn:hover { color: var(--text); background: var(--ai-bg); }
#mob-mic-btn.recording { color: var(--brand-red); background: color-mix(in srgb, var(--brand-red) 35%, transparent); animation: mob-pulse .8s infinite; }
@keyframes mob-pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

/* ── Pantallas anchas: contenido centrado y drawer que empuja ── */
#mob-msgs, #mob-welcome { max-width: 760px; margin-left: auto; margin-right: auto; width: 100%; }
#mob-input-wrap, #mob-img-preview { max-width: 760px; width: calc(100% - 24px); margin-left: auto; margin-right: auto; }


@media (min-width: 900px) {
    body.drawer-open #mob-app { margin-left: 320px; transition: margin-left .25s ease; }
    #mob-app { transition: margin-left .25s ease; }
    body.drawer-open #mob-overlay { display: none; }
    #mob-drawer { width: 320px; box-shadow: none; border-right: 1px solid var(--border); }
}

/* ── Escritorio: visor PDF lateral, chat siempre visible ── */
@media (min-width: 900px) {
    #mob-viewer-modal {
        inset: auto 0 0 auto;
        top: 0;
        width: min(46vw, 780px);
        border-left: 1px solid var(--border);
        box-shadow: -8px 0 24px rgba(0,0,0,.25);
    }
    body.viewer-open #mob-app { margin-right: min(46vw, 780px); transition: margin-right .25s ease; }
}

/* El logo solo se muestra en el drawer de expedientes (en todas las pantallas) */
#mob-header .mob-logo { display: none; }

@media (prefers-reduced-motion: reduce) {
    #mob-app::before, .mob-login::after, #mob-burst { animation: none !important; }
}

/* ── Pase de contraste ── */
/* Documentos: chips en azul de marca con letra blanca */
.mob-pdf-chip {
    background: var(--doc-chip, var(--brand-blue));
    border: none;
    color: #fff;
    font-weight: 500;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--doc-chip, var(--brand-blue)) 40%, transparent);
}
.mob-pdf-action { color: rgba(255,255,255,.85); }
.mob-pdf-action:hover { color: #fff; background: rgba(255,255,255,.18); border-radius: 50%; }
[data-theme="dark"] .mob-pdf-chip {
    background: color-mix(in srgb, var(--doc-chip, var(--brand-blue)) 82%, var(--bg));
    color: #fff;
}
[data-theme="dark"] .mob-pdf-action { color: rgba(255,255,255,.85); }

/* Burbujas con borde definido sobre el fondo vivo */
.mob-msg-ai, .cdt-beta-msg {
    border: 1px solid var(--border);
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
[data-theme="dark"] .mob-msg-ai {
    background: color-mix(in srgb, var(--bg) 76%, #fff);
    border-color: rgba(255,255,255,.18);
    color: #f5f7fa;
}
[data-theme="dark"] .mob-msg-user { box-shadow: 0 2px 10px rgba(0,0,0,.3); }

/* Superficies principales más firmes en oscuro */
[data-theme="dark"] { --muted: #8ea0b8; --border: rgba(255,255,255,.14); }
[data-theme="dark"] #mob-drawer { background: var(--panel-bg, color-mix(in srgb, var(--surface) 88%, transparent)); }

[data-theme="dark"] #mob-input-wrap {
    background: color-mix(in srgb, var(--surface) 95%, transparent);
    border-color: rgba(255,255,255,.18);
}

/* Expediente activo bien marcado */
.mob-exp-item.active {
    background: color-mix(in srgb, var(--brand-blue) 12%, transparent);
    border-left: 3px solid var(--brand-blue);
}
[data-theme="dark"] .mob-exp-item.active {
    background: color-mix(in srgb, var(--brand-blue) 30%, transparent);
    border-left-color: #9db9ec;
}

/* Scrollbar sutil (drawer y chat) */
#mob-exp-list, #mob-chat {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}
#mob-exp-list:hover, #mob-chat:hover {
    scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent;
}
#mob-exp-list::-webkit-scrollbar, #mob-chat::-webkit-scrollbar { width: 6px; }
#mob-exp-list::-webkit-scrollbar-thumb, #mob-chat::-webkit-scrollbar-thumb {
    background: transparent; border-radius: 3px;
}
#mob-exp-list:hover::-webkit-scrollbar-thumb, #mob-chat:hover::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--muted) 45%, transparent);
}

/* ── Footer siempre visible ── */
#mob-footer {
    flex-shrink: 0;
    padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
    text-align: center;
    font-size: 11.5px;
    color: var(--muted);
    background: var(--footer-bg, transparent);
    position: relative; z-index: 2;
}
#mob-footer a { color: var(--electric); text-decoration: none; margin: 0 8px; }
#mob-footer a:hover { text-decoration: underline; }
.mob-login #mob-footer { position: fixed; bottom: 0; left: 0; right: 0; z-index: 1; }

/* Sugerencias de expediente en el chat */
.mob-exp-suggest {
    display: inline-block;
    margin-top: 6px;
    padding: 6px 14px;
    border: 1.5px solid var(--brand-blue);
    border-radius: 16px;
    background: none;
    color: var(--brand-blue);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
}
.mob-exp-suggest:hover { background: var(--brand-blue); color: #fff; }
[data-theme="dark"] .mob-exp-suggest { border-color: #9db9ec; color: #9db9ec; }
[data-theme="dark"] .mob-exp-suggest:hover { background: #9db9ec; color: #0b1220; }

/* ── Navegación por marcas (drill-down) ── */
.mob-brand-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    gap: 12px;
    transition: background .12s;
}
.mob-brand-item:hover { background: rgba(30,64,175,.06); }
.mob-brand-chevron {
    margin-left: auto;
    font-size: 20px;
    color: #94a3b8;
    line-height: 1;
}
.mob-brand-back {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #1e40af;
    cursor: pointer;
    user-select: none;
}
.mob-brand-back:hover { background: rgba(30,64,175,.06); }

@keyframes mobSlideLeft  { from { transform: translateX(24px);  opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes mobSlideRight { from { transform: translateX(-24px); opacity: .4; } to { transform: none; opacity: 1; } }
.mob-slide-left  { animation: mobSlideLeft  .18s ease-out; }
.mob-slide-right { animation: mobSlideRight .18s ease-out; }

/* ── Slot de usuario + campana (compatible con CDT Notifications) ── */
#ev-user-slot {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 2px;
    position: relative;
}
#mob-user-btn {
    width: 36px; height: 36px;
    border: none; background: none; cursor: pointer;
    border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center;
}
.mob-user-avatar { width: 28px; height: 28px; border-radius: 50%; display: block; }
#mob-user-panel {
    position: fixed;
    top: calc(var(--header-h, 56px) + 8px);
    right: 8px;
    min-width: 210px;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
    padding: 12px 14px;
    display: none;
    z-index: 300;
}
#mob-user-panel.open { display: block; }
.mob-user-name { font-weight: 600; color: var(--text); font-size: 14px; }
.mob-user-mail { color: var(--muted, #94a3b8); font-size: 12px; margin: 2px 0 10px; word-break: break-all; }
.mob-user-logout {
    display: block; text-align: center;
    padding: 8px 10px; border-radius: 8px;
    background: var(--ai-bg, rgba(30,64,175,.08));
    color: var(--text); text-decoration: none; font-size: 13px; font-weight: 500;
}
.mob-user-logout:hover { background: var(--border); }

/* Campana de CDT Notifications: "body ." da más especificidad (0,1,1) que el
   selector plano del <style> inline del plugin (0,1,0) — gana sin !important
   aunque el inline cargue después. */
#ev-user-slot .cdt-bell-wrap { position: relative; margin-right: 0; }
#ev-user-slot .cdt-bell-btn  { width: 36px; height: 36px; }
body .cdt-notif-panel {
    position: fixed;
    top: calc(var(--header-h, 56px) + 6px);
    right: 8px;
    left: auto;
    width: min(360px, calc(100vw - 16px));
    max-height: 70vh;
    overflow: auto;
    z-index: 300;
}


/* ── Paneles del header como bottom-sheet en móvil (una sola capa a la vez) ── */
#mob-sheet-overlay {
    position: fixed; inset: 0;
    background: rgba(8,14,28,.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none;
    visibility: hidden; /* en reposo no existe para el compositor: el blur no cuesta nada */
    transition: opacity .15s, visibility 0s .15s;
    z-index: 400;
}
#mob-sheet-overlay.show {
    opacity: 1; pointer-events: auto;
    visibility: visible;
    transition: opacity .15s;
}
@media (min-width: 900px) { #mob-sheet-overlay { display: none; } }

@media (max-width: 899px) {
    body .cdt-notif-panel,
    body #mob-user-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        border-radius: 18px 18px 0 0;
        max-height: 75vh;
        height: auto;
        overflow: hidden;
        z-index: 410;
        /* Siempre en el DOM, deslizando: cerrado abajo, abierto arriba */
        transform: translateY(105%);
        transition: transform .28s cubic-bezier(.32,.72,.33,1), visibility 0s .28s;
        visibility: hidden;
        pointer-events: none;
        /* Superficie elevada: contraste claro contra el fondo oscurecido */
        background: #ffffff;
        border: none;
        border-top: 1px solid rgba(0,0,0,.08);
        padding: 26px 18px calc(18px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -14px 44px rgba(0,0,0,.45);
    }
    [data-theme="dark"] body .cdt-notif-panel,
    [data-theme="dark"] body #mob-user-panel {
        background: #2b3f6b;
        border-top: 1px solid rgba(255,255,255,.18);
        box-shadow: 0 -14px 44px rgba(0,0,0,.75);
    }
    /* Ficha de usuario: cuerpo y tacto */
    #mob-user-panel {
        min-height: 220px;
    }
    #mob-user-panel .mob-user-name { font-size: 17px; }
    #mob-user-panel .mob-user-mail { font-size: 13px; margin: 4px 0 18px; }
    #mob-user-panel .mob-user-logout { padding: 13px 12px; font-size: 15px; border-radius: 12px; }
    /* El sheet siempre está renderizado; el estado abierto solo lo desliza a su sitio */
    body .cdt-notif-panel { display: flex; flex-direction: column; }
    body #mob-user-panel  { display: block; }
    body .cdt-notif-panel.open,
    body #mob-user-panel.open {
        transform: none;
        visibility: visible;
        pointer-events: auto;
        transition: transform .28s cubic-bezier(.32,.72,.33,1);
    }

    /* Cabecera y pie fijos; la lista interna es el único scroller */
    .cdt-notif-panel #cdt-notif-body {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    /* El panel de usuario es corto: scroll propio por si acaso */
    body #mob-user-panel { overflow-y: auto; }
    /* Asa de arrastre */
    .cdt-notif-panel::before,
    #mob-user-panel::before {
        content: '';
        position: absolute;
        top: 9px; left: 50%;
        transform: translateX(-50%);
        width: 44px; height: 5px;
        border-radius: 3px;
        background: rgba(130,145,170,.5);
    }
}

/* ── Drawer de expedientes: fondo opaco garantizado ──
   El tinte configurable (--panel-bg, con su opacidad) se apoya sobre una base
   sólida del tema: el conjunto nunca es transparente, el tono sigue siendo el
   configurado en CDT Elevamon → Movil. */
#mob-drawer {
    background:
        linear-gradient(var(--panel-bg, rgba(255,255,255,0)), var(--panel-bg, rgba(255,255,255,0))),
        var(--bg, #ffffff);
}

/* ── Header despejado ── */
/* Nueva conversación: en el composer, y solo con un expediente abierto */
#mob-new-chat-btn { display: none; }
body.has-exp #mob-input-wrap #mob-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: none;
    background: none;
    color: var(--muted, #94a3b8);
    cursor: pointer;
    border-radius: 50%;
    padding: 0;
}
body.has-exp #mob-input-wrap #mob-new-chat-btn:hover { color: var(--text); background: var(--ai-bg, rgba(30,64,175,.08)); }



/* ── Ficha de usuario: identidad / acciones / salida ── */
.mob-user-id {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
}
.mob-user-id-av { width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; }
.mob-user-id-txt { flex: 1; min-width: 0; }
.mob-user-rol {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--ai-bg, rgba(30,64,175,.1));
    color: var(--electric, #1e40af);
}
.mob-user-sec {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.mob-user-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 4px;
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
}
.mob-user-row + .mob-user-row { border-top: 1px solid var(--border); }
.mob-user-row svg { flex-shrink: 0; color: var(--muted, #94a3b8); }
.mob-user-row > span:not(.mob-user-chev):not(.mob-user-row-ico) { flex: 1; }
.mob-user-chev { font-size: 20px; color: var(--muted, #94a3b8); line-height: 1; }
.mob-user-row-ico { display: flex; }
#mob-user-theme-row #mob-theme-btn { position: static; display: flex; }
.mob-user-logout {
    display: block;
    text-align: center;
    padding: 13px 10px;
    border-radius: 12px;
    background: rgba(239,68,68,.1);
    color: #ef4444;
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
}
.mob-user-logout:hover { background: rgba(239,68,68,.18); }

/* Zona de agarre de los sheets: el gesto vertical es nuestro en la franja superior */
@media (max-width: 899px) {
    body .cdt-notif-panel,
    body #mob-user-panel { touch-action: pan-y; }
}

