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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #2c3e50;
    color: white;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar-header {
    margin-bottom: 30px;
}

.sidebar-title {
    font-size: 24px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-title i {
    color: #3498db;
}

.models-section {
    margin-bottom: 30px;
}

.models-section h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #bdc3c7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.models-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-button {
    background: transparent;
    border: 2px solid #34495e;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

.model-button:hover {
    background: #34495e;
    border-color: #3498db;
}

.model-button.active {
    background: #3498db;
    border-color: #3498db;
}

.model-button i {
    font-size: 16px;
}

.sidebar-actions {
    margin-top: auto;
}

.clear-button {
    background: #e74c3c;
    border: none;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    width: 100%;
}

.clear-button:hover {
    background: #c0392b;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 45px; /* Aumentado para dar espacio a los botones de feedback */
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #7f8c8d;
}

.welcome-icon {
    font-size: 48px;
    color: #3498db;
    margin-bottom: 20px;
}

.welcome-message h3 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #2c3e50;
}

.welcome-message p {
    font-size: 16px;
    line-height: 1.5;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
    position: relative; /* Para posicionar los botones de feedback */
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #3498db;
    color: white;
}

.message.assistant .message-avatar {
    background: #95a5a6;
    color: white;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-text {
    background: #ecf0f1;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.assistant .message-text {
    padding-left: 20px;
}

.message.user .message-text {
    background: #3498db;
    color: white;
}

.message-time {
    font-size: 12px;
    color: #95a5a6;
    margin-top: 4px;
    text-align: right;
}

.message.user .message-time {
    text-align: left;
}

.streaming-cursor {
    animation: blink 1s infinite;
    color: #3498db;
    font-weight: bold;
}

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

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #95a5a6;
    animation: typing 1.4s infinite ease-in-out;
}

.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);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input */
.input-container {
    padding: 20px;
    background: white;
    border-top: 1px solid #ecf0f1;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}

#message-input {
    flex: 1;
    border: 2px solid #ecf0f1;
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.3s ease;
    font-family: inherit;
    max-height: 120px;
}

#message-input:focus {
    border-color: #3498db;
}

#message-input:disabled {
    background: #f8f9fa;
    color: #6c757d;
}

#send-button {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #3498db;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

#send-button:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.05);
}

#send-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

/* Responsive */
@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 15px;
        overflow-x: auto;
    }
    
    .models-section {
        margin-bottom: 0;
        margin-right: 20px;
    }
    
    .models-list {
        flex-direction: row;
        gap: 10px;
    }
    
    .model-button {
        white-space: nowrap;
        min-width: 120px;
    }
    
    .sidebar-actions {
        margin-top: 0;
        margin-left: auto;
    }
    
    .message {
        max-width: 95%;
    }
}

/* Scrollbar */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Estilos para Markdown */
.message-text h1 {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 16px 0 8px 0;
    color: #2c3e50;
}

.message-text h2 {
    font-size: 1.3rem;
    font-weight: bold;
    margin: 14px 0 6px 0;
    color: #2c3e50;
}

.message-text h3 {
    font-size: 1.1rem;
    font-weight: bold;
    margin: 12px 0 4px 0;
    color: #2c3e50;
}

.message-text p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-text ul, .message-text ol {
    margin: 8px 0;
    padding-left: 24px;
    list-style-position: outside;
}

.message-text ul {
    list-style-type: disc;
}

.message-text ol {
    list-style-type: disc; /* Forzar bullets también en listas ordenadas */
}

.message-text li {
    margin: 4px 0;
    margin-left: 4px;
    line-height: 1.5;
}

.message-text strong {
    font-weight: bold;
    color: #2c3e50;
}

.message-text em {
    font-style: italic;
    color: #3498db;
}

.message-text code {
    background: #f8f9fa;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #e74c3c;
}

.message-text pre {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border-left: 4px solid #3498db;
}

.message-text pre code {
    background: none;
    padding: 0;
    color: #2c3e50;
}

.message-text blockquote {
    border-left: 4px solid #3498db;
    padding-left: 16px;
    margin: 12px 0;
    font-style: italic;
    color: #555;
    background: rgba(52, 152, 219, 0.05);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
}

/* Cursor de streaming */
.streaming-cursor {
    animation: blink 1s infinite;
    color: #3498db;
    font-weight: bold;
}

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

/* ========== MODAL DE NOMBRE ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

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

.modal-content h2 {
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 24px;
}

.modal-content p {
    color: #7f8c8d;
    margin-bottom: 24px;
    font-size: 14px;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ecf0f1;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

.modal-input:focus {
    border-color: #3498db;
}

.modal-button {
    width: 100%;
    padding: 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
    margin-top: 16px;
}

.modal-button:hover {
    background: #2980b9;
}

.modal-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* ========== HEADER CON SELECTOR DE MODELOS ========== */
.chat-header {
    background: white;
    border-bottom: 1px solid #ecf0f1;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #7f8c8d;
    font-size: 14px;
}

.user-info i {
    color: #3498db;
}

.user-name {
    font-weight: 600;
    color: #2c3e50;
}

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

.model-selector-label {
    color: #7f8c8d;
    font-size: 14px;
    font-weight: 500;
}

.model-select {
    padding: 8px 32px 8px 12px;
    border: 2px solid #ecf0f1;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.3s ease;
    background: white;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237f8c8d' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.model-select:hover {
    border-color: #3498db;
}

.model-select:focus {
    border-color: #3498db;
}

/* ========== CONVERSACIONES EN SIDEBAR ========== */
.conversations-section {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

.conversations-section h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: #bdc3c7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.conversations-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conversation-item {
    background: transparent;
    border: 1px solid #34495e;
    color: white;
    padding: 12px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-size: 13px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-item:hover {
    background: #34495e;
    border-color: #3498db;
}

.conversation-item.active {
    background: #3498db;
    border-color: #3498db;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.conversation-title {
    font-weight: 500;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conversation-title input {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    width: 100%;
    font-size: 13px;
    font-weight: 500;
}

.conversation-title input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.3);
    border-color: white;
}

.conversation-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
}

.conversation-item.active .conversation-actions {
    opacity: 1;
}

.conversation-action-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.conversation-action-btn.delete-btn:hover {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.conversation-preview {
    font-size: 11px;
    color: #bdc3c7;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.conversation-item.active .conversation-preview {
    color: rgba(255, 255, 255, 0.8);
}

.new-chat-button {
    background: #27ae60;
    border: none;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    width: 100%;
    font-weight: 500;
}

.new-chat-button:hover {
    background: #229954;
}

/* ========== BOTONES DE FEEDBACK ========== */
.feedback-container {
    position: absolute;
    left: 52px; /* Alinear con el inicio del globo (avatar 40px + gap 12px) */
    bottom: -32px; /* Debajo del mensaje */
}

.feedback-buttons {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    opacity: 0;
    animation: fadeInFeedback 0.5s ease forwards;
    animation-delay: 0.3s;
}

@keyframes fadeInFeedback {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 32px;
}

.feedback-btn:hover:not(:disabled) {
    transform: scale(1.05);
    border-color: #999;
}

.feedback-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.feedback-btn.liked {
    border-color: #4CAF50;
    background-color: rgba(76, 175, 80, 0.1);
    transform: scale(1.05);
}

.feedback-btn.disliked {
    border-color: #f44336;
    background-color: rgba(244, 67, 54, 0.1);
    transform: scale(1.05);
}

.feedback-status {
    font-size: 11px;
    color: #999;
    text-align: left;
    margin-top: 3px;
    font-style: italic;
}