/* Chat Component Styles */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    max-width: 900px;
    margin: 1rem auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;
    gap: 0.75rem;
    min-height: 60px;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-label {
    font-size: 0.9rem;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
}

.model-dropdown {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    color: white;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    min-width: 200px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-dropdown:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.model-dropdown:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.model-dropdown:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.model-dropdown option {
    background: #333;
    color: white;
    padding: 0.5rem;
}

/* Prompt Selector Styles */
.prompt-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.prompt-label {
    font-size: 0.9rem;
    font-weight: 500;
    margin: 0;
    white-space: nowrap;
}

.prompt-dropdown {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    color: white;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    min-width: 250px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.prompt-dropdown:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.prompt-dropdown:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.prompt-dropdown:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.prompt-dropdown option {
    background: #333;
    color: white;
    padding: 0.5rem;
}

.chat-title {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    font-weight: 600;
}

.chat-icon {
    font-size: 1.4rem;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.reset-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-chat-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.reset-chat-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.reset-chat-btn i {
    font-size: 0.9rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    background: #f8f9fa;
    scroll-behavior: smooth;
    min-height: 0;
}

.welcome-message {
    text-align: center;
    padding: 2rem 1rem;
    color: #666;
}

.welcome-content {
    max-width: 500px;
    margin: 0 auto;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.welcome-content h4 {
    color: #333;
    margin-bottom: 1rem;
}

.welcome-content p {
    margin-bottom: 2rem;
    line-height: 1.6;
}

.suggested-prompts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.prompt-button {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-family: inherit;
    font-size: inherit;
}

.prompt-button:hover {
    background: #f0f0f0;
    border-color: #667eea;
}

.message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    flex-shrink: 0;
}

.user-avatar, .ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.user-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-avatar {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.user-message .message-content {
    text-align: right;
}

.message-text {
    background: white;
    padding: 1rem 1.25rem;
    border-radius: 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
    word-wrap: break-word;
}

.user-message .message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-time {
    font-size: 0.75rem;
    color: #888;
    margin-top: 0.5rem;
    padding: 0 0.5rem;
}

.message-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.action-btn:hover {
    background: #f0f0f0;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 1rem 1.25rem;
    background: white;
    border-radius: 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

.chat-input {
    background: white;
    border-top: 1px solid #e0e0e0;
    padding: 0.75rem;
}

.input-container {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 0.6rem 0.9rem;
    border: 1px solid #e0e0e0;
    transition: border-color 0.2s ease;
}

.input-container:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.message-input {
    flex: 1;
    border: none;
    background: none;
    resize: vertical;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    outline: none;
    max-height: 200px;
    min-height: 60px;
    overflow-y: auto;
}

.message-input::placeholder {
    color: #999;
}

.send-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
}

.send-button:not(.disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.send-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
}

.send-icon {
    font-size: 1.1rem;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.input-footer {
    text-align: center;
    margin-top: 0.375rem;
}

.disclaimer {
    color: #888;
    font-size: 0.7rem;
}

/* Responsive design */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 140px);
        margin: 0;
        border-radius: 0;
    }

    .chat-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .chat-title {
        font-size: 1.1rem;
        text-align: center;
    }

    .chat-controls {
        justify-content: space-between;
        gap: 1rem;
    }

    .model-selector {
        flex: 1;
    }

    .prompt-selector {
        flex: 1;
    }

    .model-dropdown {
        min-width: auto;
        flex: 1;
    }

    .prompt-dropdown {
        min-width: auto;
        flex: 1;
    }

    .chat-status {
        flex-shrink: 0;
    }

    .welcome-message {
        padding: 2rem 1rem;
    }

    .suggested-prompts {
        gap: 0.75rem;
    }

    .message-content {
        max-width: 85%;
    }

    .input-container {
        padding: 0.5rem 0.75rem;
    }
}

/* Error Message Styles */
.error-message {
    background: #fee;
    color: #d32f2f;
    padding: 12px 16px;
    margin: 10px 15px;
    border-radius: 8px;
    border-left: 4px solid #d32f2f;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

.error-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.close-error {
    background: none;
    border: none;
    color: #d32f2f;
    font-size: 1.4em;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-error:hover {
    background: rgba(211, 47, 47, 0.1);
    transform: scale(1.1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Markdown Styles - Más específicos y efectivos */
.message-text .markdown-content {
    width: 100%;
}

.message-text .markdown-content h1,
.message-text .markdown-content h2,
.message-text .markdown-content h3,
.message-text .markdown-content h4,
.message-text .markdown-content h5,
.message-text .markdown-content h6 {
    margin: 0.8rem 0 0.5rem 0;
    font-weight: 600;
    line-height: 1.3;
    color: #333;
}

.message-text .markdown-content h1 { 
    font-size: 1.5rem; 
    border-bottom: 2px solid #eee;
    padding-bottom: 0.3rem;
}
.message-text .markdown-content h2 { 
    font-size: 1.3rem; 
    border-bottom: 1px solid #eee;
    padding-bottom: 0.2rem;
}
.message-text .markdown-content h3 { font-size: 1.1rem; }
.message-text .markdown-content h4 { font-size: 1rem; }
.message-text .markdown-content h5,
.message-text .markdown-content h6 { font-size: 0.9rem; }

.message-text .markdown-content p {
    margin: 0.8rem 0;
    line-height: 1.6;
}

.message-text .markdown-content p:first-child {
    margin-top: 0;
}

.message-text .markdown-content p:last-child {
    margin-bottom: 0;
}

.message-text .markdown-content ul,
.message-text .markdown-content ol {
    margin: 0.8rem 0;
    padding-left: 1.5rem;
}

.message-text .markdown-content li {
    margin: 0.3rem 0;
    line-height: 1.5;
}

.message-text .markdown-content code {
    background: #f1f3f4;
    border: 1px solid #e1e4e8;
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    color: #d73a49;
}

.message-text .markdown-content pre {
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.45;
}

.message-text .markdown-content pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.message-text .markdown-content blockquote {
    border-left: 4px solid #667eea;
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: #f9f9fb;
    font-style: italic;
    color: #666;
}

.message-text .markdown-content table {
    border-collapse: collapse;
    margin: 1rem 0;
    width: 100%;
    font-size: 0.9em;
}

.message-text .markdown-content th,
.message-text .markdown-content td {
    border: 1px solid #dfe2e5;
    padding: 0.6rem;
    text-align: left;
}

.message-text .markdown-content th {
    background: #f6f8fa;
    font-weight: 600;
}

.message-text .markdown-content tr:nth-child(even) {
    background: #f9f9f9;
}

.message-text .markdown-content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.message-text .markdown-content a:hover {
    color: #764ba2;
    border-bottom-color: #764ba2;
}

.message-text .markdown-content strong {
    font-weight: 600;
    color: #24292e;
}

.message-text .markdown-content em {
    font-style: italic;
    color: #586069;
}

.message-text .markdown-content hr {
    border: none;
    border-top: 1px solid #e1e4e8;
    margin: 1.5rem 0;
}

/* Error de markdown */
.message-text .markdown-error {
    background: #fff2f2;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 1rem;
    color: #721c24;
}

.message-text .markdown-error pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 0.5rem;
    margin: 0.5rem 0 0 0;
    font-size: 0.8em;
}

/* ================================
   RESPONSIVE DESIGN - MOBILE FIRST
   ================================ */

/* Mobile Devices (up to 768px) */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 100px);
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-header {
        padding: 0.6rem 0.75rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
        min-height: 50px;
    }

    .chat-title {
        font-size: 1.2rem;
        margin: 0;
    }

    .chat-controls {
        width: 100%;
        justify-content: space-between;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .model-selector {
        flex: 1;
        min-width: 200px;
    }

    .prompt-selector {
        flex: 1;
        min-width: 200px;
    }

    .model-dropdown {
        flex: 1;
        min-width: 150px;
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .prompt-dropdown {
        flex: 1;
        min-width: 150px;
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .reset-chat-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
        min-width: auto;
    }

    .reset-chat-btn span {
        display: none; /* Ocultar texto en móvil, solo mostrar ícono */
    }

    .chat-status {
        font-size: 0.8rem;
    }

    .chat-messages {
        padding: 0.5rem;
    }

    .welcome-message {
        padding: 1.5rem 0.75rem;
    }

    .welcome-content {
        max-width: 100%;
    }

    .welcome-icon {
        font-size: 3rem;
    }

    .suggested-prompts {
        flex-direction: column;
        gap: 0.75rem;
    }

    .prompt-button {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .message {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .message-avatar {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

    .message-content {
        flex: 1;
        min-width: 0;
    }

    .message-text {
        padding: 0.75rem;
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .message-actions {
        flex-direction: column;
        gap: 0.25rem;
        align-self: flex-start;
        margin-top: 0.5rem;
    }

    .action-btn {
        padding: 0.4rem;
        font-size: 0.8rem;
    }

    .chat-input {
        padding: 0.75rem;
    }

    .input-container {
        gap: 0.5rem;
    }

    .message-input {
        padding: 0.75rem;
        font-size: 0.9rem;
        min-height: 55px;
        max-height: 150px;
    }

    .send-button {
        padding: 0.75rem;
        min-width: 50px;
        width: 50px;
    }

    .typing-indicator {
        padding: 0.75rem;
    }

    .error-message {
        margin: 0.5rem;
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* Small Mobile Devices (up to 480px) */
@media (max-width: 480px) {
    .chat-container {
        height: calc(100vh - 100px);
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
    }

    .chat-title {
        font-size: 1.1rem;
    }

    .chat-controls {
        gap: 0.5rem;
    }

    .model-selector {
        min-width: 150px;
    }

    .prompt-selector {
        min-width: 150px;
    }

    .model-dropdown {
        min-width: 120px;
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    .prompt-dropdown {
        min-width: 120px;
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    .reset-chat-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }

    .chat-messages {
        padding: 0.5rem;
    }

    .welcome-message {
        padding: 1.5rem 0.75rem;
    }

    .welcome-icon {
        font-size: 2.5rem;
    }

    .welcome-content h4 {
        font-size: 1.1rem;
    }

    .welcome-content p {
        font-size: 0.9rem;
    }

    .message-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }

    .message-text {
        padding: 0.6rem;
        font-size: 0.85rem;
    }

    .message-time {
        font-size: 0.7rem;
    }

    .chat-input {
        padding: 0.5rem;
    }

    .message-input {
        padding: 0.6rem;
        font-size: 0.85rem;
        min-height: 50px;
        max-height: 120px;
    }

    .send-button {
        padding: 0.6rem;
        min-width: 45px;
        width: 45px;
    }

    .input-footer {
        margin-top: 0.25rem;
    }

    .disclaimer {
        font-size: 0.7rem;
    }
}

/* Tablet Landscape (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-container {
        max-width: 90%;
        height: calc(100vh - 150px);
    }

    .chat-header {
        padding: 1rem 1.25rem;
    }

    .model-dropdown {
        min-width: 180px;
    }

    .prompt-dropdown {
        min-width: 220px;
    }
}
