/* Kioko - Refined UI */

:root {
    --radius: 16px;
    --radius-sm: 8px;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--background);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100dvh; /* Dynamic Viewport Height */
    width: 100vw;
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    /* Bloqueo de selección en UI general, permitido en mensajes */
    user-select: none;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    background-color: var(--chat-bg);
    box-shadow: 0 0 50px rgba(0,0,0,0.05);
    border: none;
}

/* --- Chat er --- */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px 120px 16px; /* Padding bottom extra para el input */
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* --- Mensajes Estilizados --- */
.message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: fadeIn 0.3s ease-out;
    user-select: text;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-content-wrapper {
    padding: 14px 18px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Estilo Usuario */
.message.user {
    align-self: flex-end;
}

.message.user .message-content-wrapper {
    background-color: var(--user-bg);
    color: var(--user-text);
    border: 1px solid var(--user-border);
    border-bottom-right-radius: 4px;
}

/* Estilo Asistente */
.message.assistant {
    align-self: flex-start;
}

.message.assistant .message-content-wrapper {
    background-color: var(--assistant-bg);
    color: var(--assistant-text);
    border: 1px solid var(--assistant-border);
    border-bottom-left-radius: 4px;
}

/* Adjuntos Elegantes */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.attachment-card {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
    max-width: 120px;
    max-height: 120px;
}

.attachment-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Input Area */
.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: transparent;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.input-capsule {
    display: flex;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 4px;
    box-shadow: var(--shadow);
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    min-height: 48px;
    max-height: 150px;
    outline: none;
    background-color: transparent;
    color: var(--text-primary);
    border-radius: 0;
}

.file-btn, .send-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    padding: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.file-btn:hover, .send-btn:hover {
    background: var(--primary-dim);
    color: var(--primary);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Loading Indicator */
.loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 10000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        margin: 0;
        border-radius: 0;
    }
    
    .chat-container {
        padding: 16px 12px 100px 12px;
        gap: 16px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-container {
        padding: 12px;
    }
}