/* ============================================================
   Asistente IA · Cadoso
   Diseño moderno, animaciones suaves, alineación impecable
   ============================================================ */

:root {
    --bg-app: #f4f6fb;
    --bg-chat: #ffffff;
    --bg-ai-bubble: #f1f5f9;
    --bg-user-bubble-start: #4f46e5;
    --bg-user-bubble-end: #7c3aed;
    --bg-input: #ffffff;
    --bg-input-focus: #ffffff;
    --border: #e5e7eb;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-soft: #475569;
    --text-muted: #94a3b8;
    --accent: #4f46e5;
    --accent-soft: #eef2ff;
    --accent-strong: #4338ca;
    --success: #10b981;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
    --shadow-focus: 0 0 0 4px rgba(79, 70, 229, 0.18);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    /* Single-value tokens para usar dentro de shorthand animation */
    --d-fast: 150ms;
    --d: 220ms;
    --d-slow: 380ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 12% 0%, rgba(99, 102, 241, 0.10), transparent 40%),
        radial-gradient(circle at 88% 100%, rgba(236, 72, 153, 0.08), transparent 45%),
        var(--bg-app);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}


/* ---------------- Layout principal ---------------- */

.app {
    max-width: 980px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

@media (min-width: 1024px) {
    .app {
        margin: 24px auto;
        height: calc(100vh - 48px);
        height: calc(100dvh - 48px);
        border-radius: var(--radius-xl);
    }
}


/* ---------------- Header ---------------- */

.app-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.85)),
        linear-gradient(90deg, rgba(99, 102, 241, 0.04), rgba(236, 72, 153, 0.04));
    backdrop-filter: blur(8px);
    flex-shrink: 0;
}

.logo {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow:
        0 2px 6px rgba(99, 102, 241, 0.30),
        inset 0 1px 0 rgba(255, 255, 255, 0.20);
    flex-shrink: 0;
    transition: transform var(--d) var(--ease);
}

.logo:hover {
    transform: scale(1.05) rotate(-3deg);
}

.logo svg {
    display: block;
    width: 100%;
    height: 100%;
}

.header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-soft);
    font-size: 12.5px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
    animation: pulse-dot 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.header-spacer {
    flex: 1;
}

@media (max-width: 720px) {
    .app-header { padding: 14px 18px; }
    h1 { font-size: 16px; }
}


/* ---------------- Chat ---------------- */

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.chat::-webkit-scrollbar {
    width: 8px;
}

.chat::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}

.chat::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (max-width: 720px) {
    .chat { padding: 20px 18px; }
}


/* ---------------- Mensajes ---------------- */

.message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
    opacity: 0;
    transform: translateY(8px);
    animation: message-in var(--d-slow) var(--ease-out) forwards;
}

@keyframes message-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.ai {
    justify-content: flex-start;
}

.message.user {
    justify-content: flex-end;
}


/* ----- Avatares ----- */

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.ai-avatar {
    background: linear-gradient(135deg, #6366f1, #8b5cf6 60%, #ec4899);
}

.user-avatar {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
}

.avatar svg {
    width: 22px;
    height: 22px;
}


/* ----- Burbujas ----- */

.bubble {
    max-width: 72%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.55;
    overflow-wrap: break-word;
    word-wrap: break-word;
    position: relative;
    font-size: 14.5px;
    animation: bubble-pop var(--d) var(--ease-out);
}

@keyframes bubble-pop {
    from {
        transform: scale(0.97);
    }
    to {
        transform: scale(1);
    }
}

.bubble p {
    margin: 0;
}

.bubble p + p {
    margin-top: 6px;
}

.bubble.welcome {
    background: linear-gradient(135deg, #fafbff, #f1f5fb);
    border: 1px solid #e0e7ff;
}

.bubble.welcome p + p {
    margin-top: 10px;
}

.inline-icon {
    width: 16px;
    height: 16px;
    vertical-align: -3px;
    color: var(--accent);
    display: inline-block;
}

.message.ai .bubble {
    background: var(--bg-ai-bubble);
    color: var(--text);
    border-bottom-left-radius: 6px;
}

.message.user .bubble {
    background: linear-gradient(135deg, var(--bg-user-bubble-start), var(--bg-user-bubble-end));
    color: #ffffff;
    border-bottom-right-radius: 6px;
    box-shadow:
        0 2px 8px rgba(79, 70, 229, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}


/* ----- Indicador de "pensando" ----- */

.thinking {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.thinking-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.35;
    animation: thinking-bounce 1.2s ease-in-out infinite;
}

.thinking-dot:nth-child(2) { animation-delay: 0.18s; }
.thinking-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes thinking-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* Cuando llega texto, se reemplaza el cursor */
.typing::after {
    content: "▍";
    animation: blink 0.9s steps(1) infinite;
    color: var(--accent);
    margin-left: 1px;
}

@keyframes blink {
    50% { opacity: 0; }
}


/* ---------------- Adjuntos (chips) ---------------- */

.chips {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 32px 0;
}

.chips:not(:empty) {
    display: flex;
}

@media (max-width: 720px) {
    .chips { padding-left: 32px; padding-right: 18px; }
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    border: 1px solid #c7d2fe;
    color: #1e293b;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    max-width: 360px;
    animation: chip-in var(--d) var(--ease-out);
}

@keyframes chip-in {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chip.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.chip .chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chip .chip-close {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #64748b;
    padding: 2px;
    width: 18px;
    height: 18px;
    line-height: 1;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--d-fast) var(--ease);
    flex-shrink: 0;
}

.chip .chip-close:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text);
}

.chip .spinner {
    width: 13px;
    height: 13px;
    border: 2px solid #c7d2fe;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* ---------------- Input area ---------------- */

.input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.95));
    flex-shrink: 0;
}

@media (max-width: 720px) {
    .input-area { padding: 12px 16px 16px; }
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

textarea {
    width: 100%;
    resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-input);
    outline: none;
    max-height: 200px;
    transition:
        border-color var(--d) var(--ease),
        box-shadow var(--d) var(--ease),
        background var(--d) var(--ease);
    box-shadow: var(--shadow-sm);
}

textarea::placeholder {
    color: var(--text-muted);
}

textarea:hover {
    border-color: var(--border-strong);
}

textarea:focus {
    border-color: var(--accent);
    background: var(--bg-input-focus);
    box-shadow: var(--shadow-focus);
}


/* ---------------- Botones ---------------- */

.icon-btn {
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        background var(--d) var(--ease),
        transform var(--d-fast) var(--ease),
        box-shadow var(--d) var(--ease),
        opacity var(--d) var(--ease);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.attach-btn {
    width: 44px;
    height: 44px;
    background: var(--bg-app);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

.attach-btn:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: #c7d2fe;
    transform: translateY(-1px);
}

.attach-btn:active:not(:disabled) {
    transform: translateY(0);
}

.attach-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), var(--bg-user-bubble-end));
    color: #ffffff;
    box-shadow:
        0 2px 8px rgba(79, 70, 229, 0.30),
        inset 0 1px 0 rgba(255, 255, 255, 0.20);
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow:
        0 6px 14px rgba(79, 70, 229, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.20);
}

.send-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow:
        0 2px 4px rgba(79, 70, 229, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.20);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.send-btn.spinning svg {
    animation: spin 1s linear infinite;
}


/* ---------------- Estados vacíos / detalles ---------------- */

.empty-chat {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}


/* ---------------- Reducción de movimiento ---------------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}