/*
========================================
  GLOBAL STYLES
========================================
*/
:root {
    --primary-color: #1b1b1b;
    --secondary-color: #242527;
    --accent-color: #e40712;
    --accent-gradient: linear-gradient(135deg, #e40712, #ff3b3b);
    --text-color: #ffffff;
    --border-color: #383838;
    --input-bg: #2f2f2f;
    --hover-color: #e61624;
    --user-msg-bg: #2d353e;
    --assistant-msg-bg: #2a2a2e;
    --shadow-color: rgba(0, 0, 0, 0.25);
    --sidebar-width: 300px;
    overflow: hidden; /* Prevent body scrolling */
}

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--primary-color);
    color: var(--text-color);
    line-height: 1.6;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: fixed; /* This prevents iOS safari from bouncing */
}

/*
========================================
  LAYOUT CONTAINER
========================================
*/
.layout-container {
    display: flex;
    height: 100vh; /* Standard height */
    width: 100%;
    background-color: var(--primary-color);
    overflow: hidden;
}

/*
========================================
  SIDEBAR
========================================
*/
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    padding-bottom: 2.5rem; /* Add extra padding at the bottom to compensate for removed footer */
}

.sidebar-header {
    margin-bottom: 2rem;
}

.sidebar-header h1 {
    color: var(--text-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

.sidebar-header p {
    color: #a0a0a0;
    font-size: 1rem;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: #a0a0a0;
}

/* Vector store selector styles */
.vector-store-container {
    margin: 1rem 0;
    padding: 0.75rem;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.05);
}

.vector-store-container h4 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #a0a0a0;
}

.vector-store-selector {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Dropdown styles */
.vector-store-dropdown {
    flex: 1;
    padding: 8px 12px;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.vector-store-dropdown:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.vector-store-dropdown:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Disabled dropdown styling */
.vector-store-dropdown:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background-image: none;
    pointer-events: none;
}

/* Info button styles */
.vector-store-info-btn {
    background: none;
    border: none;
    color: #a0a0a0;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.vector-store-info-btn:hover {
    color: var(--text-color);
}

.vector-store-info-btn:focus {
    outline: none;
}

/* About Project Container and Button */
.about-project-container {
    padding: 0.5rem;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Use ID and Class for higher specificity */
button#about-project-button.about-project-button {
    width: 100%;
    padding: 10px 12px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(228, 7, 18, 0.2);
}

/* Use ID and Class for higher specificity */
button#about-project-button.about-project-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(228, 7, 18, 0.3);
}

/* Use ID and Class for higher specificity */
button#about-project-button.about-project-button i {
    font-size: 1.1rem;
}

/* Sidebar bottom content container */
.sidebar-bottom-content {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Sidebar divider */
.sidebar-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
    opacity: 0.5;
}

/* About Project Modal styles */
#about-project-modal .admin-tab-pane {
    padding: 1rem;
    display: none;
    overflow-y: auto;
}

#about-project-modal .admin-tab-pane.active {
    display: block !important;
}

#about-project-modal .admin-tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#about-project-modal .about-section {
    max-width: 100%;
    margin-bottom: 2rem;
}

#about-project-modal .about-section h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
    font-size: 1.2rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

#about-project-modal .about-section h3:first-child {
    margin-top: 0;
}

#about-project-modal .about-section h4 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 500;
}

#about-project-modal .about-section p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

#about-project-modal .about-section ul,
#about-project-modal .about-section ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

#about-project-modal .about-section li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

#about-project-modal .about-section strong {
    color: var(--accent-color);
    font-weight: 600;
}

#about-project-modal .feature-item,
#about-project-modal .roadmap-section {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background-color: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid var(--accent-color);
}

/* Modal styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 999;
    backdrop-filter: blur(2px);
}

/* Admin Modal specific overlay */
#admin-modal-overlay {
    z-index: 999;
}

.vector-store-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    max-width: 90%;
    width: 500px;
    max-height: 90vh;
    background-color: var(--secondary-color);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.modal-content {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    padding: 1rem;
    background-color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-color);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.5rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--accent-color);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-body h4 {
    margin: 1rem 0 0.5rem;
    color: var(--text-color);
    font-size: 1rem;
}

.modal-body h4:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 1rem;
    line-height: 1.5;
}

.modal-body ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.modal-body code {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

/* Remove old selector button styles that are no longer needed */
.vector-store-option {
    display: none; /* Hide the old button style selector */
}

/*
========================================
  MAIN CONTENT WRAPPER
========================================
*/
.main-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/*
========================================
  CHAT CONTAINER & MESSAGES
========================================
*/
.chat-container {
    flex: 1;
    background: var(--secondary-color);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--secondary-color);
    -webkit-overflow-scrolling: touch;
}

/* When chat only contains the initial welcome message */
.chat-messages:only-child,
.chat-messages:has(.message.system:only-child) {
    justify-content: center;
}

/* Message Styles */
.message {
    margin-bottom: 1rem;
    padding: 0.9rem;
    border-radius: 12px;
    max-width: 90%;
    position: relative;
    animation: messageSlideIn 0.3s ease-out;
    box-shadow: 0 2px 8px var(--shadow-color);
}

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

.message:hover {
    box-shadow: 0 2px 8px var(--shadow-color);
    transform: none;
}

.message.user {
    background-color: var(--user-msg-bg);
    margin-left: auto;
    border-radius: 12px 12px 3px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.message.assistant {
    background-color: var(--assistant-msg-bg);
    margin-right: auto;
    border-radius: 12px 12px 12px 3px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    border-left: 1px solid rgba(255, 255, 255, 0.07);
}

.message.system {
    background: var(--accent-gradient);
    margin: 0 auto 1.5rem;
    text-align: center;
    max-width: 90%;
    color: white;
    box-shadow: 0 4px 15px rgba(228, 7, 18, 0.3);
}

/* Welcome message with improved styling */
.message.system.welcome-message {
    background: rgba(228, 7, 18, 0.15);
    border: 2px solid rgba(228, 7, 18, 0.3);
    color: var(--text-color);
    max-width: 80%;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 16px;
    text-align: center;
    font-size: 1.05rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    position: relative;
    overflow: hidden;
}

.message.system.welcome-message::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
}

.welcome-icon {
    font-size: 2.4rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
    background: rgba(228, 7, 18, 0.15);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Setting change notifications - more subtle than the welcome message */
.message.system.setting-change {
    background: rgba(228, 7, 18, 0.05);
    color: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(228, 7, 18, 0.1);
    box-shadow: 0 1px 3px rgba(228, 7, 18, 0.05);
    max-width: 70%;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    margin: 0.4rem auto;
    border-radius: 4px;
}

/* Input Container */
.input-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--secondary-color);
    border-top: 1px solid var(--border-color);
    width: 100%;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    min-height: 46px;
    max-height: 120px;
    overflow-y: auto;
    resize: none;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    transition: all 0.3s;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

#send-button {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(228, 7, 18, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
}

#send-button:hover {
    box-shadow: 0 4px 12px rgba(228, 7, 18, 0.4);
    transform: translateY(-3px);
}

#send-button:active {
    transform: translateY(0);
}

/*
========================================
  SOURCE PANEL
========================================
*/
.source-panel {
    width: 0;
    background: var(--secondary-color);
    box-shadow: -4px 0 12px var(--shadow-color);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    transition: none; /* No default transition, animations are controlled by classes */
    position: relative;
    height: 100%;
    opacity: 1;
    z-index: 5; /* Base z-index for source panel */
}

/* Source Panel Animations
--------------------------------------- */

/* 1. Opening and Closing Small Panel */
@media (min-width: 769px) {
    .source-panel.open {
        width: 325px !important;
        animation: slideInFromRight 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards !important;
    }

    .source-panel.closing {
        width: 325px !important;
        animation: slideOutToRight 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards !important;
    }

    @keyframes slideInFromRight {
        0% {
            width: 0;
            opacity: 0.5;
        }
        100% {
            width: 325px;
            opacity: 1;
        }
    }

    @keyframes slideOutToRight {
        0% {
            width: 325px;
            opacity: 1;
        }
        100% {
            width: 0;
            opacity: 0.5;
        }
    }

    /* 2. Expanding and Collapsing Panel */
    .source-panel.expanded {
        width: 100% !important;
        max-width: 100%;
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        z-index: 1000 !important;
    }

    .source-panel.expanded .source-panel-header {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .source-panel.expanded .source-content-wrapper {
        display: flex;
        width: 100%;
        height: calc(100vh - 60px); /* Full height minus header */
        overflow: hidden;
    }

    .source-panel.expanded .source-content {
        width: 100%;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .source-panel.expanded #source-image-container {
        width: 100%;
        height: calc(100vh - 110px);
        max-height: calc(100vh - 110px);
        overflow: auto;
    }

    /* Important: We use higher specificity to ensure width is maintained */
    .source-panel.collapsing {
        position: relative;
        width: 35% !important; /* Use !important to ensure it takes precedence */
        min-width: 325px;
        animation: collapsePanel 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    }

    /* Ensure the panel maintains the correct width even when closing after collapsing */
    .source-panel.collapsing.closing,
    .source-panel.collapsing + .source-panel.closing {
        width: 35% !important;
        min-width: 325px;
    }

    /* Ensure proper open state after animation completes */
    .source-panel.collapsing.open,
    .source-panel.open:not(.expanded):not(.closing) {
        width: 35% !important;
        min-width: 325px;
    }

    @keyframes expandPanel {
        0% {
            width: 325px;
        }
        100% {
            width: 100%;
        }
    }

    @keyframes collapsePanel {
        0% {
            width: 100%;
            opacity: 1;
        }
        100% {
            width: 325px;
            opacity: 1;
        }
    }
}

/* Tablet-specific behavior - Make source panel behave like mobile for tablet sizes */
@media (min-width: 769px) and (max-width: 950px) {
    /* Override ALL desktop panel behavior states for tablets with maximum specificity */
    .source-panel.open,
    .source-panel.expanded,
    .source-panel.collapsing,
    .source-panel.collapsing.open,
    .source-panel.open:not(.expanded):not(.closing),
    .source-panel.collapsing.closing,
    .source-panel.expanded.open,
    html body .source-panel.open,
    html body .source-panel.collapsing.open {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        z-index: 1000 !important;
        animation: tabletSlideInFromRight 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards !important;
        transform: none !important;
    }

    .source-panel.closing {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        animation: tabletSlideOutToRight 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards !important;
    }

    @keyframes tabletSlideInFromRight {
        0% {
            transform: translateX(100%);
            opacity: 0.5;
        }
        100% {
            transform: translateX(0);
            opacity: 1;
        }
    }

    @keyframes tabletSlideOutToRight {
        0% {
            transform: translateX(0);
            opacity: 1;
        }
        100% {
            transform: translateX(100%);
            opacity: 0.5;
        }
    }

    /* Hide the expand button on tablets */
    .source-panel .expand-button {
        display: none !important;
    }

    /* Ensure content fills the width correctly */
    .source-panel.open .source-content,
    html body .source-panel.open .source-content,
    html body .source-panel.collapsing.open .source-content {
        width: 100% !important;
        height: calc(100vh - 110px) !important;
        max-width: 100% !important;
    }

    .source-panel.open .source-content-wrapper,
    html body .source-panel.open .source-content-wrapper,
    html body .source-panel.collapsing.open .source-content-wrapper {
        width: 100% !important;
        height: calc(100vh - 60px) !important;
        max-width: 100% !important;
    }

    /* Hide the source sidebar section that appears in expanded view */
    .source-panel .source-sources {
        display: none !important;
    }

    /* This is a critical override to prevent size conflicts */
    .source-panel.collapsing.open,
    .source-panel.collapsing,
    .source-panel.expanded {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        position: fixed !important;
        animation: none !important;
        transform: none !important;
    }
}

/* 3. Mobile Panel Animation - This part is kept outside so mobile.css can override it */

.source-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
}

.source-panel-header h3 {
    margin: 0;
    color: var(--text-color);
    flex: 1;
}

.source-panel-header .zoom-controls {
    display: none;
}

@media (min-width: 769px) {
    .source-panel.expanded .source-panel-header .zoom-controls {
        display: none;
    }
}

.close-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.close-button:hover {
    color: var(--accent-color);
}

.source-content {
    padding: 0;
    overflow-y: auto;
    height: calc(100% - 110px); /* Adjust to account for header and navigation bar */
    position: relative;
    z-index: 1;
}

/* Style for the image container itself */
#source-image-container {
    position: relative;
    width: 100%;
    height: calc(100% - 110px); /* Account for header and navigation */
    background-color: var(--primary-color);
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1;
}

/* Placeholder to maintain size while loading */
.image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    z-index: 1;
}

.source-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
    transform-origin: center center;
    padding: 10px;
    z-index: 2;
}

/* Loading indicator centered */
.image-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    color: var(--text-color);
    font-style: italic;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 4px;
}

/* Error message styling */
.error-source {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ff5252;
    font-style: italic;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 4px;
    z-index: 3;
}

.no-source {
    color: #aaa;
    font-style: italic;
}

.source-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    align-items: center;
    position: relative;
    z-index: 2;
}

.source-pills-label {
    font-size: 0.85rem;
    color: #a0a0a0;
    font-weight: 500;
    margin-right: 0.25rem;
}

.source-pill {
    background-color: rgba(228, 7, 18, 0.1);
    border: 1px solid rgba(228, 7, 18, 0.3);
    color: #e6e6e6;
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease-out;
    white-space: nowrap;
    font-weight: 500;
}

.source-pill:hover {
    background-color: rgba(228, 7, 18, 0.2);
    border-color: rgba(228, 7, 18, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(228, 7, 18, 0.2);
    z-index: 100 !important;  /* Ensure hovered pill is above other pills */
}

.source-pill.active {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 2px 6px rgba(228, 7, 18, 0.4);
}

/* Enhanced tooltip styling */
.source-pill[data-tooltip] {
    position: relative;
}

.source-pill[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: var(--tooltip-top, 125%);
    bottom: var(--tooltip-bottom, auto);
    left: var(--tooltip-left, 50%);
    right: var(--tooltip-right, auto);
    transform: var(--tooltip-transform, translateX(-50%));
    white-space: pre-wrap;
    z-index: 999999 !important; /* Force with !important */
    background-color: rgba(20, 20, 20, 0.95);
    color: white;
    text-align: left;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    line-height: 1.4;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    min-width: 200px;
    max-width: 300px;
    margin: var(--tooltip-margin, 0); /* Default to 0 margin */
    visibility: hidden;
    word-break: break-word;
}

.source-pill[data-tooltip]::before {
    content: '';
    position: absolute;
    top: var(--tooltip-arrow-top, calc(100% + 2px));
    bottom: var(--tooltip-arrow-bottom, auto);
    left: var(--tooltip-arrow-left, 50%);
    right: var(--tooltip-arrow-right, auto);
    margin-top: 0; /* Remove the negative margin */
    border-width: 5px;
    border-style: solid;
    border-color: var(--tooltip-arrow-border-color, transparent transparent rgba(20, 20, 20, 0.95) transparent);
    opacity: 0;
    transition: opacity 0.2s;
    transform: var(--tooltip-arrow-transform, translateX(-50%));
    z-index: 999999 !important; /* Force with !important */
    visibility: hidden;
}

.source-pill[data-tooltip]:hover::after,
.source-pill[data-tooltip]:hover::before {
    opacity: 1;
    visibility: visible;
    z-index: 999999 !important;
}

/* Show More Sources Button */
.show-more-sources-button {
    background: none;
    border: none;
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.3rem 0; /* Align roughly with pills */
    margin-left: 0.5rem; /* Add some space after the first pill */
    transition: color 0.3s;
}

.show-more-sources-button:hover {
    color: var(--hover-color);
}

/* Visibility logic for extra pills and hide button */
.extra-source-pill,
.hide-sources-button {
    display: none; /* Hide extra pills and hide button by default */
}

.source-pills.extra-sources-visible .extra-source-pill {
    display: inline-block; /* Show extra pills when container class is present */
}

.source-pills.extra-sources-visible .show-more-sources-button {
    display: none; /* Hide the show more button when extra sources are visible */
}

.source-pills.extra-sources-visible .hide-sources-button {
    display: inline-block; /* Show the hide button when extra sources are visible */
    /* Add specific styling if needed, can inherit from show-more or have its own */
    background: none;
    border: none;
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.3rem 0; 
    margin-left: 0.5rem; 
    transition: color 0.3s;
}

.source-pills.extra-sources-visible .hide-sources-button:hover {
    color: var(--hover-color);
}

@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
}

/* Source Navigation */
.source-nav {
    display: flex;
    justify-content: center;
    padding: 0.75rem;
    margin-top: 0;
    gap: 1rem;
    align-items: center;
    background: var(--secondary-color);
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
}

.source-nav button {
    min-width: 100px;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.source-nav button:hover:not(:disabled) {
    background: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

.source-nav button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Source Panel Navigation */
.source-navigation {
    display: flex;
    justify-content: center;
    padding: 0.75rem;
    margin-top: 0;
    gap: 1rem;
    align-items: center;
    background: var(--secondary-color);
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
}

.nav-button {
    min-width: 100px;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-button:hover:not(:disabled) {
    background: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

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

.nav-button i {
    margin: 0 4px;
}

.page-indicator {
    font-size: 0.9rem;
    color: var(--text-color);
}

footer {
    margin-top: 0;
    padding: 1rem;
    background-color: var(--primary-color);
    color: #a0a0a0;
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

/* Styling for the new "Show more sources" link */
a.show-more-sources {
    display: block; /* Change to block for placement below */
    margin-top: 0.5rem; /* Add space above */
    margin-left: 0; /* Remove left margin */
    font-size: 0.85em; /* Can adjust size */
    color: var(--text-color); 
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s;
    /* Remove properties not needed for block display */
    /* vertical-align: middle; */
    /* line-height: 1; */ 
    /* padding: 0.3rem 0; */ 
}

a.show-more-sources:hover {
    color: var(--accent-color);
}

/* Thinking Indicator Styles */
.thinking-indicator {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
}

.thinking-indicator span {
    width: 6px;
    height: 6px;
    margin: 0 2px;
    background-color: var(--accent-color);
    border-radius: 50%;
    display: inline-block;
    animation: thinking-dots 1.4s infinite;
    opacity: 0.7;
}

/* Status Text Styling - matching thinking indicator */
.status-text {
    display: inline-block;
    color: var(--accent-color);
    font-weight: 500;
    animation: status-pulse 1.4s infinite;
    opacity: 0.9;
}

@keyframes status-pulse {
    0%, 80%, 100% { opacity: 0.7; }
    40% { opacity: 1; }
}

@keyframes thinking-dots {
    0%, 80%, 100% { opacity: 0.4; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.0); }
}

/* Markdown Formatting Styles inside messages */
.message-text p {
    margin-bottom: 0.75rem; /* Spacing between paragraphs */
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.3;
}

.message-text h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 0.8rem;
    margin-bottom: 0.4rem;
}

.message-text ul,
.message-text ol {
    margin-left: 1.2rem;
    margin-bottom: 0.6rem;
}

.message-text li {
    margin-bottom: 0.2rem;
}

.message-text strong,
.message-text b {
    font-weight: 600; /* Make bold stand out more */
}

.message-text code {
    background-color: var(--primary-color);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.85em;
}

.message-text pre {
    background-color: var(--primary-color);
    padding: 0.6rem;
    border-radius: 4px;
    margin-bottom: 0.6rem;
    overflow-x: auto; /* Allow scrolling for long code blocks */
}

.message-text pre code {
    background-color: transparent;
    padding: 0;
}

.source-controls {
    display: none; /* Hidden by default, shown only in expanded mode */
}

.source-panel.expanded .source-controls {
    display: flex;
}

.source-sources h4 {
    margin: 0.5rem 0 1rem;
    font-size: 1.1rem;
    color: var(--text-color);
}

#expanded-source-pills {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    z-index: 1000 !important; /* High z-index to ensure tooltips can be positioned correctly */
}

#expanded-source-pills .source-pill {
    margin: 0;
    width: fit-content; /* Change from 100% to fit-content */
    max-width: 95%; /* Prevent overflow */
}

.zoom-controls {
    display: none; /* Hide by default */
    gap: 0.5rem;
    align-items: center;
}

/* Only show zoom controls in source panel */
.source-panel .zoom-controls {
    display: flex;
}

.zoom-controls button {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.2s ease;
}

.zoom-controls button:hover {
    background: var(--primary-color);
    color: var(--accent-color);
    transform: scale(1.1);
}

.source-detail-header {
    background: var(--primary-color);
    padding: 1rem;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-color);
}

.source-detail-header h4 {
    font-family: 'EB Garamond', serif;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.source-metadata {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #a0a0a0;
}

.relevance-score {
    color: var(--accent-color);
    font-weight: 500;
}

/* Updated message styling */
.message-text {
    font-size: 0.95rem;
    line-height: 1.4;
}

.message-text p {
    margin-bottom: 0.6rem; /* Spacing between paragraphs */
}

.message-text h1,
.message-text h2 {
    font-family: 'EB Garamond', serif;
    margin-top: 0.8rem;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: #ffffff;
}

.message-text h1 {
    font-size: 1.5rem;
}

.message-text h2 {
    font-size: 1.3rem;
}

.message-text h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Image zoom controls as an overlay */
.image-zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    padding: 8px;
    display: flex;
    gap: 8px;
    transition: opacity 0.3s ease;
    opacity: 0.7;
}

.image-zoom-controls:hover {
    opacity: 1;
}

.image-zoom-controls button {
    background: var(--input-bg);
    border: none;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.2s ease;
}

.image-zoom-controls button:hover {
    background: var(--accent-color);
    color: white;
}

/*
========================================
  UTILITY & MISC
========================================
*/

/* --- Scrollbar Styles --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--primary-color);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* --- Focus States --- */
textarea:focus, button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* --- Expand/Close Buttons --- */
.expand-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    margin-right: 0.5rem;
}

.expand-button:hover {
    color: var(--accent-color);
}

/* --- Loading Indicators --- */
.source-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(228, 7, 18, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--accent-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Floating Action Button (FAB) --- */
.fab-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 999;
    display: none; /* Initially hidden, shown via JS/Media Query */
}

.mobile-only-fab {
    display: none; /* Always hidden by default */
}

.fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(228, 7, 18, 0.4);
    cursor: pointer;
    border: none;
    font-size: 1.5rem;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
                box-shadow 0.3s ease;
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(228, 7, 18, 0.5);
}

/*
========================================
  MEDIA QUERIES
========================================
*/
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
}

@media (max-width: 768px) {
    /* Body setup */
    body {
        position: fixed; /* This prevents iOS safari from bouncing */
    }
    
    /* Main layout */
    .layout-container {
        flex-direction: column;
    }
    
    /* Sidebar header */
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
    }
    
    .sidebar-header {
        margin-bottom: 0;
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: space-between;
    }
    
    /* Hide ASKDND text, only show logo */
    .sidebar-header h1 span.text-logo {
        display: none;
    }
    
    .sidebar-header h1 {
        font-size: 1.5rem;
        display: flex;
        align-items: center;
    }
    
    .sidebar-header p {
        display: none;
    }
    
    /* Hide settings on mobile */
    .vector-store-container {
        display: none;
    }
    
    .sidebar-footer {
        padding-top: 0;
        border-top: none;
        text-align: right;
    }
    
    /* Main content area */
    .main-wrapper {
        height: calc(100vh - 60px);
    }
    
    /* Chat container */
    .chat-container {
        position: relative;
        padding-bottom: 70px; /* Space for fixed input container */
    }
    
    /* Chat messages */
    .chat-messages {
        height: 100%;
        padding-bottom: 10px;
    }
    
    /* Fixed input container */
    .input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 8px;
        background: var(--secondary-color);
        z-index: 100;
        box-shadow: 0 -2px 10px var(--shadow-color);
        border-top: 1px solid var(--border-color);
        height: auto;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    /* For iOS Safari - address safe area at bottom */
    @supports (-webkit-touch-callout: none) {
        .input-container {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
    }
    
    /* Mobile input sizing */
    #user-input {
        min-height: 36px;
        max-height: 54px;
        padding: 5px 8px;
        font-size: 0.95rem;
        line-height: 1.4;
    }
    
    /* Mobile button sizing */
    #send-button {
        padding: 0.25rem 0.6rem;
        font-size: 0.9rem;
        min-width: auto;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Hide the word "Ask" in the send button on mobile */
    #send-button span {
        display: none;
    }
    
    /* Ensure the icon is still visible */
    #send-button i {
        margin: 0;
    }
    
    /* Mobile Source Panel Animations */
    .source-panel.open {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 1000;
        animation: mobileSlideIn 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    }
    
    @keyframes mobileSlideIn {
        0% {
            transform: translateY(20px);
            opacity: 0;
        }
        100% {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    /* Mobile closing animation */
    .source-panel.closing {
        width: 100%;
        animation: mobileSlideOut 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    }
    
    @keyframes mobileSlideOut {
        0% {
            transform: translateY(0);
            opacity: 1;
        }
        100% {
            transform: translateY(20px);
            opacity: 0;
        }
    }

    /* Show FAB on smaller screens but position in the header */
    .fab-container {
        display: none; /* Hide default FAB */
    }
    
    /* Hide mobile-only FAB as we're using the header toggle instead */
    .mobile-only-fab {
        display: none;
    }
    
    /* Create a new mobile source button in the header */
    .mobile-header-source-toggle {
        display: flex;
        background: none;
        border: none;
        color: var(--text-color);
        font-size: 1.5rem;
        padding: 0.5rem;
        cursor: pointer;
        margin-left: auto;
    }
    
    .mobile-header-source-toggle:hover {
        color: var(--accent-color);
    }

    /* Hide the expand button on mobile since panel is already full-screen */
    .expand-button {
        display: none;
    }

    /* Adjust message styling for mobile */
    .message {
        max-width: 90%;
        padding: 0.7rem; /* Smaller padding */
        margin-bottom: 0.8rem; /* Reduced spacing between messages */
    }
    
    .message-text {
        font-size: 0.9rem; /* Slightly smaller font */
        line-height: 1.4;
    }
    
    .message-text p {
        margin-bottom: 0.5rem; /* Reduced paragraph spacing */
    }
    
    .message.system {
        max-width: 95%;
        padding: 0.7rem;
    }
    
    /* Adjust source pills for mobile */
    .source-pill {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
        margin: 0.25rem;
        /* Make sure width behavior is consistent */
        width: fit-content;
        max-width: 95%;
    }

    /* Ensure centering works for welcome message */
    .chat-messages:only-child,
    .chat-messages:has(.message.system:only-child) {
        display: flex;
        justify-content: center;
        align-items: center;
    }
}

/* Expanded source panel styles */
.source-panel.expanded .source-panel-header {
    position: sticky;
    top: 0;
    z-index: 10;
}

.source-panel.expanded .source-content-wrapper {
    display: flex;
    width: 100%;
    height: calc(100vh - 60px); /* Full height minus header */
    overflow: hidden;
}

/* Container for pills in expanded view */
.source-sources {
    display: none; /* Hidden by default */
    width: 30%; /* Percentage width for responsive behavior */
    min-width: 350px;
    background: var(--primary-color);
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    height: 100%;
    overflow-y: auto; /* Main scrolling happens at this level */
    flex-shrink: 0; /* Don't allow width to shrink */
    position: relative;
    z-index: 5; /* Ensure this container has a stacking context */
}

.source-panel.expanded .source-sources {
    display: block; /* Show in expanded mode */
}

/* Section for message content */
.expanded-message-container {
    margin-bottom: 1.5rem;
}

.expanded-message-content {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    padding: 0.9rem;
    overflow-y: auto;
    max-height: none;
    min-height: 300px;
    font-size: 0.95rem;
    line-height: 1.4;
    /* Less aggressive preservation of whitespace */
    white-space: normal;
}

/* Apply proper indentation for lists in expanded view */
.expanded-message-content ul,
.expanded-message-content ol {
    padding-left: 1.5rem;
    margin-bottom: 0.6rem;
}

/* Match paragraph spacing with chat view */
.expanded-message-content p {
    margin-bottom: 0.6rem;
}

/* For code blocks, preserve formatting */
.expanded-message-content pre,
.expanded-message-content code {
    white-space: pre;
}

/* Sources separator */
.expanded-sources-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 1.5rem 0;
    width: 100%;
}

/* Sources section */
.expanded-sources-section h3 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.expanded-source-pills-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    position: relative;
    z-index: 10 !important;
}

.expanded-source-pills-container .source-pill {
    width: fit-content; /* Match the width from #expanded-source-pills .source-pill */
    max-width: 95%; /* Prevent overflow */
    text-align: left;
}

/* Main content area */
.source-panel.expanded .source-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.source-panel.expanded #source-image-container {
    flex: 1;
    overflow: auto;
}

/* When sidebar content exceeds viewport height */
@media (max-height: 700px) {
    .expanded-message-content {
        max-height: 40vh; /* Cap height on small screens */
    }
}

/* Responsive behavior */
@media (max-width: 900px) {
    .source-sources {
        width: 40%;
    }
}

/* Create a new mobile source button in the header */
.mobile-header-source-toggle {
    display: none; /* Hidden by default on desktop */
}

/* Source Panel Content Styling */
.source-image-container {
    position: relative;
    width: 100%;
    height: calc(100% - 110px); /* Account for header and navigation */
    background-color: var(--primary-color);
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1;
}

/* Placeholder to maintain size while loading */
.image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    z-index: 1;
}

.source-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
    transform-origin: center center;
    padding: 10px;
    z-index: 2;
}

/* Loading indicator centered */
.image-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    color: var(--text-color);
    font-style: italic;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 4px;
}

/* Error message styling */
.error-source {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ff5252;
    font-style: italic;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 4px;
    z-index: 3;
}

/* Zoom controls */
.source-panel-header .zoom-controls {
    display: none;
}

.zoom-controls button {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.2s ease;
}

.zoom-controls button:hover {
    background: var(--primary-color);
    color: var(--accent-color);
}

/* Admin UI Styles */
.desktop-only {
    display: none;
}

@media (min-width: 769px) {
    .desktop-only {
        display: block;
    }
}

.admin-settings-button {
    background: linear-gradient(135deg, #4a5568, #2d3748);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    width: 100%;
}

.admin-settings-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.admin-settings-button i {
    font-size: 1.1rem;
}

/* Admin Modal */
.admin-modal {
    display: none; /* Display is controlled by JS - MODAL MUST BE HIDDEN INITIALLY */
    position: fixed;
    z-index: 1000; 
    
    /* Horizontal Centering only */
    left: 50%;
    transform: translateX(-50%); 
    top: 30px; /* Add some margin from the top */
    margin-bottom: 30px; /* Ensure space at bottom if content overflows */
    
    /* Sizing (moved from admin-modal-content) */
    width: 90%; 
    max-width: 1200px; /* Default max-width */
    max-height: calc(100vh - 60px); /* Max height considering top/bottom margin */
}

.admin-modal-content {
    background-color: #2a2a2e;
    color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 8px 20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Content overflow will be handled by modal-body */
    border: 1px solid #383838;
    height: 100%; /* Make content fill the modal height */
    max-height: inherit; /* Inherit max-height from parent */
}

/* Specific overrides for log and status modals */
#log-modal,
#live-status-modal {
    /* Re-apply vertical centering */
    top: 50%;
    transform: translate(-50%, -50%);
    /* Adjust max-height to avoid conflict with top/transform */
    max-height: 85vh; 
}

#log-modal {
    max-width: 80%; 
    width: 900px; 
    height: 80vh; 
}

#live-status-modal {
    max-width: 70%; 
    width: 800px; 
    height: 70vh; 
}

.admin-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: #1b1b1b;
    color: white;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom: 1px solid #383838;
}

.admin-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    color: #ffffff;
}

.admin-modal-header h2 i {
    margin-right: 10px;
    color: #e40712;
}

.admin-close-button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.admin-close-button:hover {
    color: #e40712;
}

.admin-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    color: #ffffff;
}

/* Admin Login Section */
#admin-login-section {
    max-width: 400px;
    margin: 40px auto;
    padding: 30px;
    background-color: #242527;
    border-radius: 8px;
    border: 1px solid #383838;
    text-align: center;
}

#admin-login-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.4rem;
    color: #ffffff;
}

#admin-login-section .admin-form-group {
    margin-bottom: 25px;
    text-align: left;
}

#admin-login-section label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: #ffffff;
}

#admin-login-section input[type="password"] {
    display: block;
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #1b1b1b;
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#admin-login-section input[type="password"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(228, 7, 18, 0.2);
}

#admin-login-section .admin-button {
    margin-top: 5px;
    padding: 12px 30px;
    font-size: 1rem;
    width: 100%;
}

#admin-login-error {
    margin-top: 15px;
    color: #ff6b6b;
    font-size: 0.9rem;
}

/* General Admin Form Styles */
.admin-form-group {
    margin-bottom: 15px;
}

.admin-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #ffffff;
}

.admin-form-group input[type="text"],
.admin-form-group input[type="password"],
.admin-form-group textarea,
.admin-form-group select {
    display: block;
    width: fit-content;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-top: 0.25rem;
}

.admin-form-group input[type="text"]:focus,
.admin-form-group input[type="password"]:focus,
.admin-form-group textarea:focus,
.admin-form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(228, 7, 18, 0.2);
}

.admin-form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.admin-checkbox-group,
.admin-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.admin-checkbox-group label,
.admin-radio-group label {
    display: flex;
    align-items: center;
    font-weight: normal;
    margin-bottom: 0;
    cursor: pointer;
    color: #ffffff;
}

.admin-checkbox-group input,
.admin-radio-group input {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: #e40712;
}

.admin-checkbox-group input:checked,
.admin-radio-group input:checked {
    background-color: #e40712;
    border-color: #e40712;
}

button.admin-button {
    background-color: #e40712;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    width: auto;
    height: auto;
    display: inline-block;
}

button.admin-button:hover {
    background-color: #ff3b3b;
    transform: none;
}

.admin-error {
    color: #ff6b6b;
    margin-top: 10px;
    font-size: 14px;
}

.admin-status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 4px;
    font-size: 14px;
}

.admin-status.success {
    background-color: rgba(40, 167, 69, 0.2);
    color: #7adb96;
    border: 1px solid rgba(40, 167, 69, 0.3);
}

.admin-status.error {
    background-color: rgba(220, 53, 69, 0.2);
    color: #ff6b6b;
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.admin-status.info {
    background-color: rgba(23, 162, 184, 0.2);
    color: #5dceec;
    border: 1px solid rgba(23, 162, 184, 0.3);
}

.admin-status.warning {
    background-color: rgba(255, 165, 0, 0.1);
    color: #ffa500;
    border-left: 4px solid #ffa500;
}

/* Admin Content Tabs */
.admin-content {
    margin-top: 20px;
}

.admin-tabs {
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid #383838;
    margin-bottom: 20px;
    background-color: #1b1b1b;
}

.admin-tab-button {
    background: none;
    border: none;
    padding: 12px 18px;
    cursor: pointer;
    font-size: 14px;
    color: #a0a0a0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.admin-tab-button:hover {
    color: #ffffff;
}

.admin-tab-button.active {
    color: #e40712;
    border-bottom-color: #e40712;
    font-weight: 500;
    background-color: rgba(228, 7, 18, 0.1);
}

.admin-tab-pane {
    display: none;
}

.admin-tab-pane.active {
    display: block;
}

.admin-section {
    background-color: #242527;
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #383838;
}

.admin-section h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.2rem;
    color: #ffffff;
}

.admin-section h4 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1rem;
    color: #ffffff;
}

/* Admin Tables */
.admin-table-container {
    margin-top: 15px;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    color: #ffffff;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    text-align: left;
    border: 1px solid #383838;
}

.admin-table th {
    background-color: #1b1b1b;
    font-weight: 600;
    color: #ffffff;
}

.admin-table tr:nth-child(even) {
    background-color: #2c2c30;
}

.admin-table tr:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

/* Admin Links Grid */
.admin-links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.admin-external-link {
    display: flex;
    align-items: center;
    padding: 15px;
    border-radius: 6px;
    background-color: #2c2c30;
    border: 1px solid #383838;
    text-decoration: none;
    color: #ffffff;
    transition: all 0.2s;
    min-height: 90px;
}

.admin-external-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border-color: #e40712;
    background-color: #3a3a3e;
}

.admin-link-icon {
    min-width: 48px;
    width: 48px;
    height: 48px;
    background-color: #1b1b1b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    font-size: 20px;
    color: #e40712;
    flex-shrink: 0;
    padding: 0; /* Remove padding to give more space for icons */
}

/* Specific icon adjustments */
.admin-link-icon .fab.fa-github,
.admin-link-icon .fab.fa-aws {
    font-size: 26px; /* Increased from 24px */
    transform: scale(1); /* Ensure proper scaling */
}

.admin-link-text {
    flex: 1;
    overflow: hidden;
}

.admin-link-text h4 {
    margin: 0 0 5px 0;
    font-size: 16px;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-link-text p {
    margin: 0;
    font-size: 12px;
    color: #a0a0a0;
}

/* Override for the rounded corner gear button */
.admin-button-container .admin-button {
    background-color: #1b1b1b;
    border: 1px solid #383838;
}

.admin-button-container .admin-button:hover {
    background-color: #e40712;
}

/* Admin Responsive Styles */
@media (max-width: 768px) {
    .admin-tabs {
        flex-wrap: wrap;
    }
    
    .admin-tab-button {
        flex: 1 0 auto;
        text-align: center;
        padding: 10px;
    }
    
    .admin-checkbox-group,
    .admin-radio-group {
        flex-direction: column;
        gap: 12px;
    }
    
    .admin-links-grid {
        grid-template-columns: 1fr;
    }
    
    .admin-modal-content {
        margin: 10px;
        width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
    }
    
    .admin-section {
        padding: 15px;
    }
}

/* Fix potential conflicts with site-wide buttons */
.admin-modal button:not(.admin-close-button):not(.admin-tab-button) {
    border-radius: 4px;
    width: auto;
    height: auto;
    display: inline-block;
}

/* Override for pre elements within admin sections */
.admin-section pre {
    background-color: #1b1b1b;
    padding: 10px;
    border-radius: 4px;
    color: #ffffff;
    overflow-x: auto;
    margin-top: 5px;
    font-size: 13px;
    border: 1px solid #383838;
}

#prompt-status {
    margin-top: 0.75rem;
}

/* Add specific styles for the system prompt textarea */
#system-prompt {
    overflow-y: auto; /* Only show scrollbars when needed */
    height: auto;
    min-height: 180px; /* Increased from 100px */
    width: 100%;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical; /* Allow users to resize vertically if they want */
    max-height: 400px; /* Cap the max height */
}

/* Drag and Drop Styles */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    background-color: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.drop-zone.dragover {
    border-color: var(--accent-color);
    background-color: rgba(228, 7, 18, 0.1);
}

.drop-zone p {
    color: #a0a0a0;
    margin: 0;
}

.drop-zone a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
}

.drop-zone a:hover {
    text-decoration: underline;
}

.file-list {
    margin-top: 1rem;
}

.file-list-item {
    background-color: var(--input-bg);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-list-item span {
    font-size: 0.9rem;
}

.remove-file-btn {
    background: none;
    border: none;
    color: #a0a0a0;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
}

.remove-file-btn:hover {
    color: var(--accent-color);
}

.admin-content {
    display: none;
}

/* Styling for log modal */
#log-modal pre {
    background-color: var(--primary-color); /* Slightly darker background for contrast */
    color: #ccc; /* Lighter text for readability */
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    line-height: 1.4;
}

/* Dynamic link styles for category-colored links */
.dynamic-link {
    text-decoration: underline;
    transition: all 0.2s ease;
    font-weight: 500;
}

.dynamic-link:hover {
    filter: brightness(1.3);
}

/* Internal links have a subtle background on hover */
.dynamic-link[data-link-type="internal"]:hover {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 2px;
    text-decoration: none !important;
}

/* External links get an icon */
.dynamic-link[data-link-type="external"]::after {
    content: " \f08e";
    font-family: "Font Awesome 5 Free";
    font-size: 0.7em;
    font-weight: 900;
    position: relative;
    top: -0.5em;
    margin-left: 0.2em;
    opacity: 0.7;
}

/* Improve link visibility against dark backgrounds */
.message.assistant .dynamic-link {
    font-weight: 600; /* Make links bolder in assistant messages */
    text-shadow: 0 0 1px rgba(0, 0, 0, 0.5); /* Add subtle text shadow for better contrast */
}

/* Link color legend */
.link-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    margin-top: 12px;
    background-color: rgba(20, 20, 20, 0.5);
    border-radius: 4px;
    font-size: 0.8rem;
    max-width: 100%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.link-legend-item {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 3px;
    background-color: rgba(0, 0, 0, 0.25);
}

.link-legend-color {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-right: 5px;
}

/* Color boxes for each category */
.link-legend-color.monster { background-color: #a70000; }
.link-legend-color.spell { background-color: #704cd9; }
.link-legend-color.skill { background-color: #036634; }
.link-legend-color.item { background-color: #623a1e; }
.link-legend-color.magic-item { background-color: #0f5cbc; }
.link-legend-color.rule { background-color: #6a5009; }
.link-legend-color.sense { background-color: #a41b96; }
.link-legend-color.condition { background-color: #364d00; }
.link-legend-color.lore { background-color: #a83e3e; }

/* Link legend toggle button */
.toggle-legend-btn {
    font-size: 0.85rem;
    color: #aaa;
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    margin-top: 6px;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}

.toggle-legend-btn:hover {
    color: white;
}

.toggle-legend-btn i {
    margin-right: 4px;
    font-size: 0.8rem;
}

/* Admin Container */
.admin-container {
    padding: 0.5rem;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Responsive styles */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    .sidebar-bottom-content {
        display: none !important;
    }
}

#expanded-source-pills .source-pill[data-tooltip]::after {
    --tooltip-left: 100%;
    --tooltip-top: 0;
    --tooltip-transform: translateX(10px);
    width: 250px;
    z-index: 999999 !important;
    position: fixed !important;
    /* Adjust the positioning to ensure the tooltip is visible */
    left: auto !important; /* Override calculated position */
    right: auto !important;
    transform: none !important; /* Override transform to control position directly */
}

#expanded-source-pills .source-pill[data-tooltip]::before {
    --tooltip-arrow-left: 0;
    --tooltip-arrow-top: 50%;
    --tooltip-arrow-border-color: transparent rgba(20, 20, 20, 0.95) transparent transparent;
    z-index: 999999 !important;
    position: fixed !important;
    /* Adjust the positioning to ensure the arrow is visible */
    left: auto !important; /* Override calculated position */
    right: auto !important;
    transform: none !important; /* Override transform to control position directly */
}

/* Specifically target expanded source pills */
#expanded-source-pills .source-pill {
    position: relative;
    z-index: 100 !important;
}

/* Override positioning for expanded view tooltips */
#expanded-source-pills .source-pill[data-tooltip]:hover::after {
    margin-left: 10px;
    top: 0 !important;
    left: 100% !important;
}

#expanded-source-pills .source-pill[data-tooltip]:hover::before {
    margin-left: 0;
    top: 50% !important;
    left: 100% !important;
    margin-top: -5px !important;
    border-color: transparent rgba(20, 20, 20, 0.95) transparent transparent !important;
}

/* Source content panel styles */
.source-content-wrapper {
    position: relative;
    z-index: 1;
}

/* Ensure tooltips in expanded view are always on top and positioned correctly */
#expanded-source-pills .source-pill[data-tooltip]::after {
    display: block;
    position: absolute; /* Not fixed, to allow for scrolling */
    top: 0 !important;
    left: 100% !important;
    margin-left: 10px !important;
    transform: none !important;
    z-index: 9999999 !important; /* Ultra high z-index */
    pointer-events: none;
}

#expanded-source-pills .source-pill[data-tooltip]::before {
    display: block;
    position: absolute; /* Not fixed, to allow for scrolling */
    top: 50% !important;
    left: 100% !important;
    margin-top: -5px !important;
    transform: none !important;
    z-index: 9999999 !important; /* Ultra high z-index */
    border-color: transparent rgba(20, 20, 20, 0.95) transparent transparent !important;
}

/* Make sure source-content has a lower z-index than tooltips */
.source-content {
    z-index: 5;
    position: relative;
}

/* Custom styling for the source content header */
#source-panel-header-text {
    padding: 15px 20px;
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--primary-color);
    text-align: center;
}

/* GitHub Repo Button - Match About Project style */
button#github-repo-button.about-project-button {
    width: 100%;
    padding: 10px 12px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(228, 7, 18, 0.2);
}

button#github-repo-button.about-project-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(228, 7, 18, 0.3);
}

button#github-repo-button.about-project-button i {
    font-size: 1.1rem;
}

/* Override FAB styles if they affect the GitHub button */
#github-repo-button {
    width: 100% !important;
    height: auto !important;
    border-radius: 6px !important;
    transform: none;
    display: flex !important;
    box-shadow: 0 2px 5px rgba(228, 7, 18, 0.2) !important;
}

/* General link styling within messages */
.message-text a {
    /* Let inline styles (from category coloring) or specific classes override */
    color: inherit; 
    text-decoration: underline; /* Base underline, overridden by .internal-link */
    font-weight: 600; /* Set base weight to match strong tags */
    transition: color 0.2s ease;
}

.message-text a:hover {
    /* Define a general hover effect, can be overridden */
    color: var(--accent-color); 
}

/* Specific styles for internal/external links generated by the utility */
.message-text a.internal-link {
    text-decoration: none; /* NOT underlined */
}

.message-text a.internal-link:hover {
    font-weight: 700; /* Increase weight on hover */
    /* text-decoration: none; Inherited from base rule */
}

.external-link {
    /* REMOVED: font-style: italic; */
    /* Inherits base link styles (which include underline) */
    /* REMOVED: padding-right: 2px; */
    text-decoration: underline; /* Explicitly underlined */
    /* It will inherit text-decoration-color from inline style if category coloring applied */
}

.external-link:hover {
    font-weight: 700; /* Increase weight on hover */
}

/* Optional: Ensure focus is visible for keyboard navigation */
.external-link:focus,
.message-text a.internal-link:focus { /* Update focus selector */
   outline: 1px dotted currentcolor; /* Or your preferred focus style */
}

/* --- REMOVE OLD/REDUNDANT STYLES --- */