:root {
    --primary-orange: #F05032;
    --dark-orange: #da5000;
    --bg-dark: #000;
    --bg-secondary: #111;
    --bg-tertiary: #1a1a1a;
    --text-light: #fff;
    --text-muted: rgba(255, 255, 255, 0.5);
    --text-secondary: #aaa;
    --border-color: #333;
}

[data-theme="light"] {
    --bg-dark: #f5f5f5;
    --bg-secondary: #fff;
    --bg-tertiary: #e8e8e8;
    --text-light: #1a1a1a;
    --text-muted: rgba(0, 0, 0, 0.5);
    --text-secondary: #555;
    --border-color: #ddd;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Rubik', sans-serif;
    background-color: var(--bg-dark) !important;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
}

/* Navbar - Always dark regardless of theme */
.navbar {
    background-color: #000 !important;
    border-bottom: 1px solid #333;
    padding: 0.5rem 1rem;
    flex-shrink: 0;
}

.navbar-brand img {
    height: 40px;
    width: auto;
}

.nav-link {
    color: rgba(255, 255, 255, 0.5) !important;
    font-size: 0.9rem;
    padding: 0.5rem 1rem !important;
    transition: color 0.3s ease;
}

.nav-link:hover {
    color: #fff !important;
}

.site-title {
    border-left: 2px solid #CCCCCC;
    padding-left: 1rem;
    margin-left: 1rem;
}

.site-title .main-title {
    color: var(--primary-orange) !important;
    font-weight: 500;
}

.site-title .sub-title {
    color: var(--dark-orange) !important;
}

/* Main content area - fills remaining space */
.container-fluid {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container-fluid>.row {
    flex: 1;
    overflow: hidden;
}

.col-lg-3 {
    height: 100%;
    overflow-y: auto;
}

.col-lg-9 {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.main-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    padding: 0.5rem 1rem 1rem;
    overflow: hidden;
}

.chat-header {
    text-align: center;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
}

.chat-header h1 {
    color: var(--primary-orange) !important;
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.chat-container,
#chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.message {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-items: flex-end;
}

.bot-message {
    align-items: flex-start;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-orange);
    border-radius: 8px;
    padding: 1rem;
}

.message p,
.message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
}

/* Bot messages without bubble - clean text display */
.bot-message>p {
    max-width: 100%;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.nl-response {
    max-width: 100%;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1.7;
    background-color: transparent;
    border: none;
}

/* Section Headers with Icon + Left Border */
.nl-response h1,
.nl-response h2,
.nl-response h3,
.nl-response h4 {
    color: var(--primary-orange);
    margin: 1.5rem 0 0.75rem 0;
    padding: 0.5rem 0;
    padding-left: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    background: transparent;
    border-left: 3px solid var(--primary-orange);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nl-response h1:first-child,
.nl-response h2:first-child,
.nl-response h3:first-child {
    margin-top: 0;
}

.nl-response h1 {
    font-size: 1.3rem;
}

.nl-response h2 {
    font-size: 1.15rem;
}

.nl-response h3 {
    font-size: 1.05rem;
}

.nl-response h4 {
    font-size: 0.95rem;
}

/* Paragraphs */
.nl-response p {
    margin: 0 0 1rem 0;
    color: var(--text-light);
    max-width: none;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.nl-response p:last-child {
    margin-bottom: 0;
}

/* Lists */
.nl-response ul,
.nl-response ol {
    margin: 0.5rem 0 1rem 0;
    padding-left: 1.5rem;
    list-style-position: outside;
}

.nl-response li {
    margin-bottom: 0.75rem;
    line-height: 1.6;
    color: var(--text-light);
}

.nl-response li:last-child {
    margin-bottom: 0;
}

.nl-response li strong {
    color: var(--text-light);
}

/* Text Formatting */
.nl-response strong {
    color: var(--text-light);
    font-weight: 600;
}

.nl-response em {
    font-style: italic;
    color: var(--text-secondary);
}

.nl-response code {
    background-color: var(--bg-dark);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--primary-orange);
    font-family: 'Consolas', 'Monaco', monospace;
}

/* Horizontal Rule */
.nl-response hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

/* Blockquote - Dato Destacado Style */
.nl-response blockquote {
    border-left: 3px solid #e74c3c;
    background-color: rgba(231, 76, 60, 0.08);
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
    border-radius: 0 8px 8px 0;
}

.nl-response blockquote p {
    margin: 0;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-style: italic;
}

.nl-response blockquote strong,
.nl-response blockquote em strong {
    color: #e74c3c;
    font-style: normal;
}

/* Links — italic blue */
.nl-response a {
    color: #4a9edd;
    font-style: italic;
    text-decoration: underline;
    text-decoration-color: rgba(74, 158, 221, 0.45);
    text-underline-offset: 2px;
    transition: color 0.15s, text-decoration-color 0.15s;
}

.nl-response a:hover {
    color: #1f6fa6;
    text-decoration-color: #1f6fa6;
}

/* PDF embed toggle button */
.pdf-embed-toggle {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    padding: 1px 7px;
    margin-left: 7px;
    background: rgba(74, 158, 221, 0.1);
    border: 1px solid rgba(74, 158, 221, 0.3);
    border-radius: 4px;
    color: #4a9edd;
    cursor: pointer;
    vertical-align: middle;
    font-style: normal;
    transition: background 0.15s, border-color 0.15s;
}

.pdf-embed-toggle:hover {
    background: rgba(74, 158, 221, 0.2);
    border-color: rgba(74, 158, 221, 0.55);
}

/* PDF inline embed container */
.pdf-embed-container {
    margin: 0.6rem 0 0.9rem 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.pdf-embed-frame {
    width: 100%;
    height: 460px;
    border: none;
    display: block;
    background: #fff;
}

/* Summary Card Sections */
.nl-response .summary-card {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}

.nl-response .summary-card p {
    margin-bottom: 0.5rem;
}

.nl-response .summary-card p:last-child {
    margin-bottom: 0;
}

.user-message p,
.user-message .message-content {
    background: linear-gradient(135deg, var(--primary-orange), var(--dark-orange));
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Keep bot message text clean - no bubbles */
.bot-message .message-content {
    max-width: 100%;
    background-color: transparent;
    color: var(--text-light);
    border: none;
    padding: 0;
}

.input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#user-input {
    flex: 1;
    background-color: var(--bg-tertiary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-light) !important;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-family: 'Rubik', sans-serif;
    font-size: 0.95rem;
    transition: border-color 0.3s ease;
}

#user-input:focus {
    outline: none;
    border-color: var(--primary-orange) !important;
    box-shadow: 0 0 0 2px rgba(240, 80, 50, 0.2);
}

#user-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: linear-gradient(135deg, var(--primary-orange), var(--dark-orange)) !important;
    border: none !important;
    color: #fff !important;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-family: 'Rubik', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(240, 80, 50, 0.4);
}

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

.btn-clear {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-clear:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.btn-clear .clear-text {
    display: none;
}

.input-buttons-row {
    display: contents;
}

.loading-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.loading-text {
    color: var(--text-secondary);
    font-style: italic;
    transition: opacity 0.3s ease;
}

.loading-text.fade-out {
    opacity: 0;
}

.loading-text.fade-in {
    opacity: 1;
}

.welcome-message {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.welcome-message i {
    font-size: 2.5rem;
    color: var(--primary-orange);
    margin-bottom: 0.75rem;
}

.welcome-message h3 {
    color: var(--text-light);
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.welcome-message p {
    font-size: 0.9rem;
    line-height: 1.6;
}

.sidebar-info {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
}

.sidebar-info h5 {
    color: var(--primary-orange) !important;
    font-weight: 600;
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.sidebar-info p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

.sidebar-info a {
    color: var(--primary-orange) !important;
    text-decoration: underline;
}

.sidebar-info a:hover {
    color: var(--dark-orange) !important;
}

.sidebar-divider {
    border-color: var(--border-color);
}

.sidebar-link {
    font-size: 0.85rem;
}

.sidebar-controls {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.control-group {
    margin-bottom: 0.75rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    accent-color: var(--primary-orange);
}

.language-selector {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.language-selector.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.lang-flag {
    background: transparent;
    border: 2px solid transparent;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.lang-flag:hover {
    border-color: var(--border-color);
}

.lang-flag.active {
    border-color: var(--primary-orange);
}

/* Footer - Always dark regardless of theme */
.footer {
    background-color: #000 !important;
    border-top: 1px solid #333;
    padding: 0.75rem;
    text-align: center;
    flex-shrink: 0;
}

.footer p {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    margin: 0;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    overflow: auto;
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: var(--primary-orange);
    margin-bottom: 1.5rem;
}

.close {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: var(--primary-orange);
}

.tab-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-button {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-button.active {
    background: var(--primary-orange);
    border-color: var(--primary-orange);
    color: #fff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.session-item {
    background-color: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-color);
}

.session-item strong {
    color: var(--text-light);
}

.session-item p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0.25rem 0;
}

.session-item button {
    margin-top: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: var(--primary-orange);
    border: none;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}

.session-item button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#feedback-text {
    width: 100%;
    min-height: 150px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text-light);
    font-family: 'Rubik', sans-serif;
    resize: vertical;
    margin-bottom: 1rem;
}

#feedback-text:focus {
    outline: none;
    border-color: var(--primary-orange);
}

.debug-section {
    margin-top: 0.75rem;
    width: 100%;
}

.debug-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    width: 100%;
    text-align: left;
}

.debug-toggle:hover {
    border-color: var(--primary-orange);
}

.debug-toggle.collapsed::after {
    content: " ▼";
}

.debug-toggle:not(.collapsed)::after {
    content: " ▲";
}

.debug-content {
    display: none;
    margin-top: 0.5rem;
    padding: 1rem;
    background-color: var(--bg-dark);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.debug-content.show {
    display: block;
}

.debug-item {
    margin-bottom: 1rem;
}

.debug-item strong {
    color: var(--primary-orange);
    display: block;
    margin-bottom: 0.5rem;
}

.debug-item code {
    display: block;
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    overflow-x: auto;
    color: var(--text-light);
}

.feedback-section {
    margin-top: 0.5rem;
    width: 100%;
}

.feedback-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.feedback-btn:hover {
    border-color: var(--primary-orange);
    color: var(--primary-orange);
}

.error-message {
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid #e74c3c;
    border-radius: 8px;
    padding: 1rem;
}

.error-message strong {
    color: #e74c3c;
}

.error-code {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.context-info {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 0.5rem;
}

.context-subsection {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.context-subsection:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (max-width: 992px) {
    .main-container {
        height: 100%;
    }
}

@media (max-width: 768px) {
    .main-container {
        padding: 0.5rem 0.5rem 1rem;
    }

    .chat-container,
    #chat-box {
        border-radius: 0;
        margin-bottom: 0.5rem;
    }

    /* Mobile language dropdown in header */
    .mobile-lang-dropdown {
        display: inline-block;
        position: relative;
        margin-left: 0.5rem;
        vertical-align: middle;
    }

    .lang-dropdown-btn {
        background: transparent;
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        padding: 0.3rem 0.6rem;
        border-radius: 6px;
        font-size: 0.75rem;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .lang-dropdown-btn:hover {
        border-color: var(--primary-orange);
        color: var(--primary-orange);
    }

    .lang-dropdown-content {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 6px;
        padding: 0.5rem;
        z-index: 100;
        min-width: 120px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .lang-dropdown-content.show {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .lang-dropdown-content .lang-flag {
        background: transparent;
        border: none;
        color: var(--text-light);
        padding: 0.4rem 0.5rem;
        text-align: left;
        border-radius: 4px;
        font-size: 0.85rem;
        cursor: pointer;
        transition: background 0.2s ease;
    }

    .lang-dropdown-content .lang-flag:hover {
        background-color: var(--bg-tertiary);
    }

    .lang-dropdown-content .lang-flag.active {
        background-color: var(--primary-orange);
        color: #fff;
    }

    /* Hide language dropdown after chat starts */
    .mobile-lang-dropdown.hidden {
        display: none !important;
    }

    /* Nav theme toggle styling */
    .toggle-label-nav {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        cursor: pointer;
        margin: 0;
    }

    .toggle-label-nav input[type="checkbox"] {
        accent-color: var(--primary-orange);
    }

    .nav-theme-toggle {
        padding: 0.5rem 0;
        border-top: 1px solid #333;
        margin-top: 0.5rem;
    }

    .chat-header h1 {
        font-size: 1.1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .message p,
    .message-content {
        max-width: 85%;
    }

    .site-title {
        display: none;
    }

    .input-area {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem;
        border-radius: 8px;
        background-color: var(--bg-secondary);
    }

    #user-input {
        width: 100%;
        margin-bottom: 0;
        min-height: 48px;
    }

    .input-buttons-row {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    .btn-clear {
        flex: 1;
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    .btn-send {
        flex: 1;
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    /* Hide 'Enviar' text on mobile, show only icon */
    .btn-send .send-text {
        display: none;
    }

    /* Show 'Limpiar contexto' text on mobile */
    .btn-clear .clear-text {
        display: inline;
    }

    /* Hide footer on mobile */
    .footer {
        display: none;
    }
}

@media (max-width: 576px) {
    .main-container {
        padding: 0.25rem 0.25rem 0.75rem;
    }

    .chat-container,
    #chat-box {
        padding: 0.75rem;
    }

    .navbar-brand img {
        height: 30px;
    }

    .chat-header h1 {
        font-size: 1rem;
    }

    .welcome-message {
        padding: 1.5rem 0.5rem;
    }

    .welcome-message i {
        font-size: 2rem;
    }

    .message p,
    .message-content {
        max-width: 95%;
        font-size: 0.9rem;
    }

    .input-area {
        padding: 0.5rem;
        gap: 0.4rem;
    }

    .btn-clear,
    .btn-send {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .modal-content {
        margin: 2% auto;
        padding: 1rem;
        width: 95%;
    }
}