:root {
    --blue-900: #2c3e50;
    --blue-800: #34495e;
    --blue-700: #3c5a76;
    --blue-500: #3498db;
    --blue-600: #2f86c2;
    --green-500: #2ecc71;
    --green-600: #27ae60;
    --red-500: #e74c3c;
    --red-600: #c0392b;
    --text-900: #1f2a36;
    --text-700: #4a5563;
    --text-500: #6b7785;
    --bg: #f5f5f5;
    --bg-soft: #eef3f8;
    --card: #ffffff;
    --card-muted: #f7f9fc;
    --shadow-lg: 0 20px 45px rgba(44, 62, 80, 0.18);
    --shadow-md: 0 12px 28px rgba(44, 62, 80, 0.14);
    --shadow-sm: 0 6px 14px rgba(44, 62, 80, 0.12);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

body {
    background: radial-gradient(circle at top left, #ffffff 0%, #eef3f8 45%, #e7eef6 100%);
    color: var(--text-900);
}

.container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 320px;
    background: linear-gradient(160deg, #2c3e50 0%, #34495e 55%, #2f455e 100%);
    color: white;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: var(--shadow-lg);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar h2 {
    font-size: 1.3rem;
    letter-spacing: 0.3px;
}

.assistants-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.assistant-item {
    padding: 10px 12px;
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: all 0.25s ease;
    color: #eef3f8;
    text-align: left;
    font-weight: 500;
}

.assistant-item:hover {
    background-color: rgba(52, 152, 219, 0.25);
    border-color: rgba(52, 152, 219, 0.35);
    transform: translateX(2px);
}

.assistant-item.active {
    background: linear-gradient(120deg, rgba(52, 152, 219, 0.9), rgba(46, 204, 113, 0.35));
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--card);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(44, 62, 80, 0.05);
}

.header {
    padding: 16px 20px;
    background: linear-gradient(120deg, #3498db 0%, #2f86c2 50%, #2ecc71 120%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.header-left h1 {
    font-size: 1.4rem;
    letter-spacing: 0.3px;
}

.current-assistant {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 4px;
}

.clear-btn {
    padding: 10px 16px;
    background-color: var(--red-500);
    color: white;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.clear-btn:hover {
    background-color: var(--red-600);
    transform: translateY(-1px);
}

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, rgba(244, 248, 252, 0.9) 0%, rgba(255, 255, 255, 0.98) 100%);
}

.message {
    max-width: 70%;
    padding: 14px 16px;
    border-radius: 16px;
    position: relative;
    line-height: 1.6;
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.25s ease;
    overflow: visible;
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(120deg, #3498db, #2f86c2);
    color: white;
    border-bottom-right-radius: 6px;
}

.user-message[data-tooltip]::after,
.user-message[data-tooltip]::before {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.user-message[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    background: #0f1b2a;
    color: #f4f7fb;
    padding: 10px 12px;
    border-radius: 10px;
    box-shadow: 0 12px 24px rgba(15, 27, 42, 0.25);
    font-size: 0.75rem;
    line-height: 1.35;
    white-space: pre-wrap;
    min-width: 220px;
    max-width: 320px;
    z-index: 20;
    transform: translateY(-6px);
}

.user-message[data-tooltip]::before {
    content: "";
    position: absolute;
    right: 14px;
    top: calc(100% + 4px);
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #0f1b2a transparent;
    z-index: 21;
    transform: translateY(-6px);
}

.user-message[data-tooltip]:hover::after,
.user-message[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateY(0);
}

.assistant-message {
    align-self: flex-start;
    background-color: #f0f4f8;
    color: #2b3440;
    border-bottom-left-radius: 6px;
}

.error-message {
    align-self: flex-start;
    background-color: rgba(231, 76, 60, 0.15);
    color: #7a1d14;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.input-area {
    padding: 16px 20px;
    display: flex;
    gap: 12px;
    background-color: var(--card-muted);
    border-top: 1px solid rgba(44, 62, 80, 0.08);
}

#userInput {
    flex: 1;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(44, 62, 80, 0.12);
    resize: none;
    min-height: 54px;
    max-height: 180px;
    overflow-y: auto;
    background-color: white;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#userInput:focus {
    outline: none;
    border-color: rgba(52, 152, 219, 0.6);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.send-btn {
    padding: 0 22px;
    background-color: var(--green-500);
    color: white;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease;
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.send-btn:hover {
    background-color: var(--green-600);
    transform: translateY(-1px);
}

.loader {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(52, 152, 219, 0.2);
    border-radius: 50%;
    border-top-color: #3498db;
    animation: spin 1s ease-in-out infinite;
    margin-left: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loading-indicator {
    align-self: flex-start;
    color: #5c6570;
    font-style: italic;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background-color: #f0f4f8;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.assistant-message strong,
.assistant-message b {
    font-weight: 600;
}

.assistant-message em,
.assistant-message i {
    font-style: italic;
}

.assistant-message code {
    background-color: #e9eff5;
    padding: 2px 6px;
    border-radius: 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.9rem;
}

.assistant-message pre {
    background-color: #e9eff5;
    padding: 12px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 10px 0;
}

.assistant-message a {
    color: #2f86c2;
    text-decoration: underline;
}

/* ===== MESSAGE META & ACTIONS ===== */

.message-meta {
    font-size: 0.7rem;
    color: var(--text-500);
    margin-top: 6px;
}

.user-message .message-meta {
    color: rgba(255, 255, 255, 0.6);
}

.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.msg-action-btn {
    padding: 3px 10px;
    border: 1px solid rgba(44, 62, 80, 0.18);
    border-radius: 999px;
    background: white;
    color: var(--text-700);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.msg-action-btn:hover {
    background: var(--bg-soft);
}

.copy-btn.copied {
    color: var(--green-600);
    border-color: var(--green-500);
}

.rate-btn.active.good {
    background: rgba(46, 204, 113, 0.12);
    color: var(--green-600);
    border-color: var(--green-500);
}

.rate-btn.active.bad {
    background: rgba(231, 76, 60, 0.1);
    color: var(--red-600);
    border-color: var(--red-500);
}

/* ===== RATING LABEL (visible en meta y en impresión) ===== */

.rating-label {
    font-weight: 600;
}

.rating-label.rating-good {
    color: var(--green-600);
}

.rating-label.rating-bad {
    color: var(--red-500);
}

.assistant-message .chat-image {
    max-width: 100%;
    max-height: 480px;
    border-radius: var(--radius-md);
    margin: 10px 0;
    display: block;
    box-shadow: var(--shadow-md);
    cursor: zoom-in;
    object-fit: contain;
}

.assistant-message ul,
.assistant-message ol {
    margin-left: 20px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.assistant-message blockquote {
    border-left: 4px solid #c9d6e2;
    padding-left: 12px;
    margin-left: 0;
    color: #5c6570;
}

.assistant-message h1,
.assistant-message h2,
.assistant-message h3,
.assistant-message h4 {
    margin-top: 15px;
    margin-bottom: 10px;
}

.assistant-message table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.assistant-message th,
.assistant-message td {
    border: 1px solid #dbe3ec;
    padding: 8px;
    text-align: left;
}

.assistant-message th {
    background-color: #edf2f7;
}

.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 20, 30, 0.65);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
}

.login-container {
    background-color: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 360px;
    max-width: 92%;
}

.login-container h2 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #2c3e50;
    text-align: center;
}

.input-group {
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #2c3e50;
}

.input-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d8e0ea;
    border-radius: 10px;
    font-size: 16px;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 999px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.login-btn:hover {
    background-color: #2f86c2;
}

.login-error {
    color: #e74c3c;
    text-align: center;
    margin-top: 15px;
    font-size: 14px;
}

.thread-info {
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.thread-info h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: #f0f0f0;
}

#threadIdDisplay {
    font-size: 12px;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 8px;
    border-radius: 8px;
    word-break: break-all;
    color: #d8e0ea;
}

.sidebar-panel {
    background: rgba(15, 25, 36, 0.35);
    border-radius: var(--radius-md);
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.panel-header h3 {
    font-size: 1rem;
    color: #f7f9fc;
}

.panel-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-panel.collapsed .panel-body {
    display: none;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.info-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.85rem;
}

.info-label {
    color: rgba(255, 255, 255, 0.65);
}

.info-value {
    color: #ffffff;
    font-weight: 500;
    text-align: right;
    word-break: break-word;
}

.info-section {
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.info-section summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    color: #f0f4f8;
}

.info-pre {
    margin-top: 8px;
    white-space: pre-wrap;
    max-height: 220px;
    overflow: auto;
    background: rgba(10, 18, 28, 0.35);
    border-radius: 10px;
    padding: 8px;
    font-size: 0.75rem;
    color: #dbe3ec;
}

.disabled {
    opacity: 0.6;
    cursor: not-allowed !important;
    pointer-events: none;
}

.cancel-btn {
    margin-left: 10px;
    padding: 4px 8px;
    background-color: var(--red-500);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

.cancel-btn:hover {
    background-color: var(--red-600);
}

.assistant-category-title {
    font-weight: 600;
    margin: 6px 0 4px 0;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.08);
}

::-webkit-scrollbar-thumb {
    background: rgba(52, 152, 219, 0.35);
    border-radius: 999px;
}

@media print {
    body {
        background: white;
    }

    .sidebar,
    .header,
    .input-area,
    .login-modal {
        display: none !important;
    }

    .container {
        display: block;
        height: auto;
    }

    .chat-container {
        display: block;
        height: auto;
        overflow: visible;
        box-shadow: none;
    }

    .chat-messages {
        display: block;
        height: auto;
        max-height: none;
        overflow: visible;
        padding: 0;
        background: white;
    }

    .message {
        max-width: 100%;
        box-shadow: none;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .user-message[data-tooltip]::after,
    .user-message[data-tooltip]::before {
        display: none;
    }

    .assistant-message .chat-image {
        max-height: none;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .message-actions {
        display: none !important;
    }

    .message-meta {
        color: #888;
    }
}

@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 45vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }

    .chat-container {
        border-top-left-radius: 0;
    }
}
