/* Variables Globales y Resets */
:root {
    --bg-app: #0f172a;        /* Azul muy oscuro */
    --bg-header: #1e293b;     /* Azul oscuro */
    --border-color: #334155;
    --accent: #38bdf8;        /* Azul claro brillante */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    /* Usar 100dvh para que se ajuste real en móviles/barras de sistema */
    height: 100dvh; 
    overflow: hidden; /* Evitar scroll general, el chat hará su propio scroll */
}

/* Cabecera Premium */
.header {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.robot-icon {
    color: var(--accent);
    filter: drop-shadow(0 0 5px rgba(56, 189, 248, 0.4));
}

.title-group h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.badge {
    font-size: 0.65rem;
    background: rgba(16, 185, 129, 0.15); /* Verde suave */
    color: #34d399;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    border: 1px solid rgba(16, 185, 129, 0.3);
    margin-top: 2px;
    display: inline-block;
}

.domain {
    font-family: monospace;
    color: var(--text-muted);
    font-size: 0.85rem;
    background: rgba(15, 23, 42, 0.6);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.header-actions {
    display: flex; 
    align-items: center; 
    gap: 15px;
}

.btn-logout {
    background: rgba(239, 68, 68, 0.1); 
    color: #ef4444; 
    border: 1px solid rgba(239, 68, 68, 0.3); 
    padding: 6px 14px; 
    border-radius: 6px; 
    font-size: 0.8rem; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.2s;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.2); 
}

/* Contenedor Principal Centrado */
.main-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Reducimos el padding inferior en móviles para que no se coma la pantalla, usamos min-height: 0 para que flex asimile recortes */
    padding: 1rem;
    min-height: 0; 
    background: radial-gradient(circle at 50% 0%, #1e293b 0%, #0f172a 70%);
}

.chat-wrapper {
    position: relative;
    width: 100%;
    max-width: 900px; /* Ancho máximo para que quede centrado y premium */
    height: 100%;
    max-height: 800px;
    min-height: 0; /* Asegurar que no expanda su propio flex parent */
    background-color: var(--bg-header);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    overflow: hidden;
    /* Efecto Glow Sutil */
    box-shadow: 0 0 40px rgba(56, 189, 248, 0.05);
}

/* =========================================================
   ESTILOS CHAT CUSTOMIZADO (AIBOTS)
   ========================================================= */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    min-height: 0;
    background-color: var(--bg-header);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

/* Scrollbar fina tipo OS premium */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
}

/* Mensajes en formato Burbuja/Tarjeta */
.message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.1);
    background-color: rgba(30, 41, 59, 0.5);
    transition: background-color 0.2s;
    width: fit-content;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out forwards;
}

.message:hover {
    background-color: rgba(30, 41, 59, 0.8);
}

.message.bot {
    align-self: flex-start;
    border-bottom-left-radius: 0.25rem;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    background-color: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.3);
    border-bottom-right-radius: 0.25rem;
}

.message.user .msg-header {
    flex-direction: row-reverse;
}

.message.user .msg-content {
    text-align: right;
}

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

.avatar {
    padding: 0.375rem;
    border-radius: 9999px;
    flex-shrink: 0;
    margin-top: 0.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar svg {
    width: 1rem;
    height: 1rem;
}

.message.bot .avatar {
    background-color: rgba(16, 185, 129, 0.1); /* Emerald */
    color: #10b981;
}

.message.user .avatar {
    background-color: rgba(59, 130, 246, 0.1); /* Blue */
    color: #3b82f6;
}

.msg-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    gap: 0.25rem;
}

.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.msg-author {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.7;
}

.msg-time {
    font-size: 0.6rem;
    color: rgba(148, 163, 184, 0.5);
    font-family: monospace;
}

.msg-content {
    font-size: 0.85rem;
    color: var(--text-main);
    opacity: 0.9;
    font-weight: 500;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

/* Animaciones y Puntos de Escritura */
@keyframes chatDotBounce {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.3); }
}

@keyframes chatBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    height: 1rem;
    margin-left: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #22d3ee; /* Cyan-400 */
}

.typing-dots span:nth-child(1) { animation: chatDotBounce 1.2s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation: chatDotBounce 1.2s ease-in-out 0.2s infinite; }
.typing-dots span:nth-child(3) { animation: chatDotBounce 1.2s ease-in-out 0.4s infinite; }

.cursor-blink {
    display: inline-block;
    width: 2px;
    height: 12px;
    background-color: currentColor;
    margin-left: 2px;
    vertical-align: middle;
    opacity: 0.7;
    animation: chatBlink 0.8s step-end infinite;
}

/* Área de Input */
.chat-input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-header);
}

.input-wrapper {
    display: flex;
    align-items: flex-end; /* Alinear abajo para textareas que crecen */
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.5rem;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3);
}

.chat-input-area textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    padding: 0.5rem;
    resize: none; /* No permitir resize manual */
    outline: none;
    max-height: 150px;
}

.chat-input-area textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background-color: rgba(56, 189, 248, 0.1);
    color: var(--accent);
    border: none;
    padding: 0.6rem;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    height: 38px;
    width: 38px;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background-color: var(--accent);
    color: #fff;
}

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

.btn-send svg {
    width: 18px;
    height: 18px;
}

/* =========================================================
   ESTILOS MARKDOWN Y TABLAS PREMIUM
   ========================================================= */

.markdown-body {
    line-height: 1.6;
    font-weight: 400;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--accent);
}

.markdown-body p {
    margin-bottom: 1rem;
}

.markdown-body ul, .markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.25rem;
}

.markdown-body strong {
    color: var(--accent);
    font-weight: 600;
}

/* Tablas con Scroll Horizontal */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin: 1.5rem 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: rgba(15, 23, 42, 0.3);
}

/* Scrollbar para las tablas */
.table-responsive::-webkit-scrollbar {
    height: 6px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    color: var(--text-main);
}

th {
    background-color: rgba(56, 189, 248, 0.1);
    color: var(--accent);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}
