*, *::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: 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: 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: max(72px, calc(var(--logo-h, 34px) * 2)); width: auto; 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(--muted); font-size: 14px; margin-bottom: 24px; }
#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 */
#cdt-chat-window,
#cdt-chat-fab,
.cdt-chat-fab,
.cdt-acc-chip,
.cdt-bell-wrap,
#ev-user-slot,
#cdt-acc-overlay { display: none !important; }

[data-theme="dark"] {
    --bg:       var(--bg-dark, #0b1220);
    --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; }
}

@media (min-width: 900px) {
    #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; }
