/* CatNote — chat.css (tramo 3/11 de styles.css). No reordenar los <link>. */
/* ===== CHAT PANEL ===== */
#chat-panel {
position: fixed;
    bottom: 40px;
    right: 35px;
    width: 340px;
    height: 460px;
    background: var(--cat-bg);
    color: var(--cat-fg);
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    z-index: 100;
    opacity: 0;
    transform: translateY(18px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

#chat-panel.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* Fondo borroso al abrir el chat del gato (Eder, 2026-09-27: "cuando abres
   configuración en movil se blurea el fondo, asi quiero que se haga cuando
   abro el chat del gato"): el MISMO tratamiento de Configuración
   (--overlay-bg + blur 4px, misma regla de .config-modal) pero SIN bloquear
   la app —pointer-events: none— porque el chat no es modal: sigue pudiendo
   tocarse lo de atrás. Va en un body::after (libre) detrás del panel
   (z-index 100) y solo existe mientras el chat está abierto. */
body:has(#chat-panel.open)::after {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
    z-index: 99;
}

#chat-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 12px;
}

/* ===== CHAT ARRASTRABLE (escritorio) ===== */
@media (min-width: 641px) {
    #chat-header { cursor: grab; touch-action: none; }
    #chat-header:active { cursor: grabbing; }
    #close-chat-btn { cursor: pointer; }
    #main-bubble-btn {
        touch-action: none;
        /* El long-press de 5 segundos del huevo "Motivación" no debe traerse
           el menú/callout del sistema (sobre todo iOS) ni seleccionar nada. */
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
}
body.chat-dragging { user-select: none; cursor: grabbing !important; }
#chat-panel.dragging,
#chat-bubble-container.dragging { transition: none !important; }

#chat-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--cat-fg);
    letter-spacing: -0.01em;
}

#close-chat-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    /* Esquina superior derecha: empuja la × al extremo derecho del header y
       la pega arriba. En base, así aplica igual en web y móvil (Eder,
       2026-09-27). */
    margin-left: auto;
    align-self: flex-start;
    /* Un poco de aire SOBRE la × (Eder, 2026-09-27: "la ventana del chat,
       subir un poco el padding sobre la x"): la × baja ese tanto respecto
       del borde superior del panel. En base: web y móvil por igual. */
}

#close-chat-btn:hover {
    background: var(--bg-surface);
    color: var(--text);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    /* Igual por los cuatro lados (2026-10-15: antes 16px + 51px a la derecha
       para esconderse de los botones de .chat-actions, y el aire se notaba).
       El hueco de esos botones lo deja ahora .user-message con su margin-right. */
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 2px;
}

/* Entrada de un elemento NUEVO dentro de una lista que ya estaba pintada:
   un mensaje del chat, un aviso del panel de la campana, una fila del archivo.
   La lista/historial inicial NO la usa: al abrir se pinta todo de golpe y
   animarlo sería un parpadeo de la lista completa. Solo entra lo que de verdad
   acaba de llegar, y las filas que ya estaban se deslizan con FLIP (utils.js). */
@keyframes listItemIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.message.is-entering,
.notif-item.is-entering,
.vault-row.is-entering {
    animation: listItemIn var(--motion-base) var(--ease-out) both;
}

/* Separador de día en el chat ("Hoy", "Ayer", "5 de Julio"): marca dónde
   empiezan los mensajes de otro día. Misma píldora que el divisor de
   "Completadas" en las listas, pero pasiva (no es un botón). */
.chat-day-separator {
    align-self: center;
    background: #000000;
    color: #ffffff;
    border: none;
    border-radius: 999px;
    padding: 5px 12px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    margin: 10px 0 2px;
    flex-shrink: 0;
    user-select: none;
    pointer-events: none;
}

/* Tema oscuro: la píldora negra se fundiría con el fondo; invertida
   (clara con letra oscura), como la de las listas. */
[data-theme="dark"] .chat-day-separator {
    background: #e8eaed;
    color: #202124;
}

.message {
    max-width: 84%;
    padding: 14px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.2;
    word-break: break-word;
    position: relative;
    user-select: text;
}

.msg-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    opacity: 1;
    pointer-events: none;
    gap: 8px;
}
.bot-message .msg-actions { flex-direction: row-reverse; }

.msg-time {
    font-size: 10px;
    opacity: 0.45;
    white-space: nowrap;
    pointer-events: none;
    line-height: 1;
}

.msg-btns {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.message:hover .msg-btns {
    opacity: 1;
    pointer-events: all;
}

.msg-action-btn {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 0px 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
    color: inherit;
    opacity: 0.5;
}
.msg-action-btn:hover { background: rgba(0,0,0,0.08); opacity: 1; }
.user-message .msg-action-btn:hover { background: rgba(255,255,255,0.15); }
.msg-action-btn svg { display: block; }

.msg-selected {
    opacity: 0.55;
    outline: 2px solid #e53e3e44;
    border-radius: 12px;
}

.msg-delete-btn {
    position: fixed;
    background: #e53e3e;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 5px 16px;
    font-size: 12px;
    cursor: pointer;
    z-index: 9999;
    white-space: nowrap;
    animation: fadeInUp 0.15s ease;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.msg-delete-btn:hover { background: #c53030; }

.msg-delete-dismiss {
    position: fixed;
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 15px;
    cursor: pointer;
    padding: 4px 6px;
    z-index: 9999;
    line-height: 1;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.message strong { font-weight: 600; }
.message em { font-style: italic; }
.message code {
    background: rgba(0,0,0,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 13px;
}
.user-message code { background: rgba(255,255,255,0.2); color: #fff; }
.message ul, .message ol { margin: 4px 0; padding-left: 20px; }
.message li { margin: 2px 0; margin-left: 8px;}
.message p { margin: 0; }
.message p + p { margin-top: 6px; }

.bot-message {
    background: var(--bg-surface);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.user-message {
    background: var(--text);
    color: var(--bg-app);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    /* El estrechado al entrar/salir de la tira de botones se ve animado, no
       de golpe: son las dos propiedades que cambia .msg-evita-acciones. */
    transition: margin-right var(--motion-base) var(--ease-out),
                max-width var(--motion-base) var(--ease-out);
}

/* Solo el mensaje que HOY solapa la tira de .chat-actions (enviar + los 3
   ópticos, ~44px pegados a la derecha del panel) se estrecha de ese lado.
   Los demás van a todo su ancho: según la altura, cada burbuja puede tener
   un ancho distinto (Eder, 2026-10-15). La clase la pone/quita
   refrescarAnchosMensajes() en chat.js, que compara el solape vertical.
   El max-width baja en la misma cuantía o el mensaje se desborda a la
   izquierda (90% + 44px > 100%). */
.user-message.msg-evita-acciones {
    margin-right: 44px;
    max-width: calc(90% - 44px);
}

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
}

.thinking-indicator span {
    width: 7px;
    height: 7px;
    background: #888;
    border-radius: 50%;
    animation: thinking-bounce 1s infinite;
}

.thinking-indicator span:nth-child(2) { animation-delay: 0.15s; }
.thinking-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

#hadron-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #111;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
}

#hadron-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.file-message {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #444;
    background: #f8f8f8;
    border: 1px solid #e8e8e8;
    padding: 8px 14px;
    border-radius: 14px;
    align-self: flex-end;
    max-width: 82%;
}

.file-message span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

#chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    overflow: visible;
}

#chat-text-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 9px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: var(--bg-surface);
    color: var(--text);
    transition: border-color 0.2s, background 0.2s;
    resize: none;
    overflow-y: hidden;
    line-height: 1.45;
    max-height: calc(1.45em * 2 + 18px);
    display: block;
}

#chat-text-input:focus {
    border-color: var(--text);
    background: var(--bg-app);
}

#chat-text-input::placeholder {
    color: #bbb;
}

#send-btn {
    position: absolute;
    right: 0px;
    bottom: 4px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #111;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
    z-index: 3;
}

#send-btn:hover {
    background: #333;
}

#send-btn:active {
    transform: scale(0.92);
}

/* ===== CHAT BUBBLE CONTAINER ===== */
/* En escritorio el gato, la franja de beta y la cápsula del menú inferior
   quedan alineados por su CENTRO (Eder, 2026-11-11: "Enviar sugerencia y
   beta, navbar inferior y gato, alineados a la misma altura tomando como
   referencia su centro"). La cápsula mide 58px a bottom 18 → centro a 47 del
   fondo; el contenedor del gato mide 64px, así que va a bottom 15 (15 + 32 =
   47). El dibujo del SVG no llena la caja (viewBox 220x150 con aire abajo,
   más el scale(1.3) de .cat-icon), pero su centro visual cae a menos de 1px
   del centro de la caja, de modo que el gato también queda centrado.
   Antes iba a bottom 10, alineado por la base (las patas ~8px sobre el borde
   de la caja). En MÓVIL no aplica: responsive.css lo sube sobre la franja. */
#chat-bubble-container {
    position: fixed;
    bottom: 15px;
    right: 32px;
    width: 64px;
    height: 64px;
    z-index: 100;
    pointer-events: none;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}

#chat-bubble-container.ready {
    visibility: visible;
    opacity: 1;
    pointer-events: all;
    transition: opacity 0.25s ease;
}

#chat-bubble-container.hidden {
    opacity: 0;
    pointer-events: none;
}

/* CTA "Mejora tu plan" dentro del mensaje de límite alcanzado */
.chat-upgrade-cta {
    display: inline-block;
    margin-top: 10px;
    padding: 9px 14px;
    border: none;
    border-radius: 14px;
    background: var(--accent, #1d72f3);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
}

.chat-upgrade-cta:hover {
    filter: brightness(1.08);
}

.chat-upgrade-cta:active {
    transform: scale(0.97);
}

/* Permiso para que el asistente use el Baúl (Eder, 2026-10-14). Dos botones
   bajo el mensaje del gato; el primario reutiliza .chat-upgrade-cta. */
.chat-consent-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.chat-consent-row .chat-upgrade-cta {
    margin-top: 0;
}

.chat-consent-no {
    margin-top: 0;
    padding: 9px 14px;
    border: 1px solid color-mix(in srgb, var(--text) 28%, transparent);
    border-radius: 14px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-consent-no:hover {
    background: color-mix(in srgb, var(--text) 10%, transparent);
}

.chat-consent-row button:disabled {
    opacity: 0.5;
    cursor: default;
}

.chat-consent-done {
    margin-top: 10px;
    display: inline-block;
    font-size: 12px;
    opacity: 0.65;
}

/* Avisos: solo la entidad (tarea/proyecto/pago) es un enlace clickeable */
.notice-entity {
    color: var(--accent, #1d72f3);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.notice-entity:hover {
    filter: brightness(1.12);
}

/* Resaltado de la tarea/pago al navegar desde un aviso */
@keyframes entity-focus-flash {
    0%   { box-shadow: 0 0 0 2px var(--accent, #1d72f3), 0 0 14px rgba(29, 114, 243, 0.55); }
    70%  { box-shadow: 0 0 0 2px var(--accent, #1d72f3), 0 0 14px rgba(29, 114, 243, 0.30); }
    100% { box-shadow: 0 0 0 0 rgba(29, 114, 243, 0); }
}

.entity-focus-flash {
    animation: entity-focus-flash 1.9s ease-out;
}

/* ===== MAIN BUBBLE BUTTON =====
   Fondo del todo TRANSPARENTE (Eder, 2026-09-27: primero el "cuadrado" del
   SVG, ahora "hay un círculo también ahí atrás" = el disco del propio botón
   (--panel-bg con 3 esquinas a 32px y una recta, que por eso se leía como un
   círculo con punta). Detrás del gato NO queda nada: ni disco, ni cuadrado
   (el del SVG va al 35% de opacidad, ver más abajo). La forma y el hover se
   quedan: solo pintan al pasar el ratón. */
#main-bubble-btn {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 64px;
    height: 64px;
    border-radius: 32px 32px 32px 0px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
    transition: background 0.25s, transform 0.25s, box-shadow 0.25s, opacity 0.2s, width 0.25s, height 0.25s, border-radius 0.25s;
}

#main-bubble-btn svg {
    width: 32px;
    height: 32px;
}

/* Gato acostado (animación nueva, Eder 2026-11-09). El SVG ya no trae el
   cuadrado de fondo del icono anterior: cuerpo, cabeza y orejas se pintan con
   --cat-body, y los ojos con --cat-eye. Al ser variables CSS, el cambio de
   tema repinta las tres instancias sin reiniciar la animación. */
svg.cat-icon .cat-shape {
    fill: var(--cat-body, #000000);
}

svg.cat-icon .cat-eye-fill {
    fill: var(--cat-eye, #ffffff);
}

/* Borde superior del ojo cuando el párpado lo corta a la mitad. Es parte
   del ojo: mismo grosor que el anillo y sin sobresalir del círculo. */
svg.cat-icon .cat-lid-band {
    fill: #000000;
}

/* ===== CAT ICON ===== */
.cat-icon {
    display: block;
    /* Gato 1.3x (Eder, 2026-11-09): se escala el SVG COMPLETO con transform.
       Así el dibujo crece desde el centro, la silueta nunca se recorta y la
       caja sigue midiendo lo mismo (84/40/64), de modo que el layout no se
       mueve. Con el zoom metido en el viewBox, el gato se salía de la caja y
       se cortaba a los lados. */
    transform: scale(1.3);
    transform-origin: center;
}

#main-bubble-btn svg.cat-icon {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.cat-icon-sm {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-title-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

#main-bubble-btn:hover {
    /* Hover en transparente también (Eder, 2026-09-27: "hover en transparente
       también"): no se pinta disco ni nada al pasar el ratón. */
    background: transparent;
    transform: scale(1.00);
}

#main-bubble-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.75);
}

#main-bubble-btn.opening {
    width: 320px;
    height: 420px;
    border-radius: 20px;
    background: #ffffff;
}

#main-bubble-btn.opening svg {
    opacity: 0;
}

/* ===== UNREAD BADGE ===== */
#chat-unread-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e53e3e;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    font-family: 'Helvetica Now Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 20px;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 110;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

#chat-unread-badge.has-unread {
    opacity: 1;
    transform: scale(1);
}

/* ===== OPTION BUTTONS ===== */
#bubble-options {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 38px;
    height: 38px;
    pointer-events: none;
}

.chat-actions {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    overflow: visible;
}

.opt-btn {
    position: absolute;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #888;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.22);
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s;
}

.opt-btn:hover {
    background: #2a2a2a;
}

/* Posiciones de cada botón (relativas a la esquina inferior-derecha del contenedor) */
#opt-mic {
    bottom: 64px;
    right: 0;
}

#opt-camera {
    bottom: 101px;
    right: 0;
}

#opt-doc {
    bottom: 138px;
    right: 0;
}

/* Estado visible con entrada escalonada */
.opt-btn.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

#opt-mic.visible    { transition-delay: 0.00s; }
#opt-camera.visible { transition-delay: 0.06s; }
#opt-doc.visible    { transition-delay: 0.12s; }

/* Selector de micrófono: vive en el modal de Configuración (se oculta si hay ≤1) */

/* Tooltips */
.opt-btn::after {
    content: attr(aria-label);
    position: absolute;
    right: 52px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 11px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.opt-btn:hover::after {
    opacity: 1;
}

/* Image preview strip */
#chat-image-preview {
    padding: 8px 14px 4px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.image-preview-thumb {
    position: relative;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.image-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.image-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.65);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    color: white;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

/* Recording state */
#opt-mic.recording {
    background: #ef4444;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3);
    transform-origin: center;
    transition: transform 0.05s linear;
}

/* ===== HIDDEN FILE INPUTS ===== */
#file-camera,
#file-doc {
    display: none;
}

