/* ===================================================================
   1. CORE LAYOUT & GRID SYSTEM
   Defines the main structure for both mobile and desktop.
=================================================================== */
.main-content.has-mobile-nav {
    height: 100vh;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-content.has-mobile-nav .card {
    flex: 1;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.desktop-chat-layout {
    display: grid;
    grid-template-columns: 1fr;
    height: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chat-column {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* ===================================================================
   2. MOBILE HEADER
   Styles for the fixed header on small screens.
=================================================================== */
.mobile-header {
    display: none;
    /* Hidden by default, shown in media query */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--surface-light);
    z-index: 1000;
    border-bottom: 1px solid var(--neutral-200);
    padding: 0 8px;
    align-items: center;
    justify-content: space-between;
}

.mobile-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-grow: 1;
}

.mobile-header .hamburger {
    position: static;
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    flex-shrink: 0;
}

.mobile-header-channel {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    margin-left: 10%;
}

.mobile-channel-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.mobile-channel-text-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}

.mobile-channel-title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-channel-subscribers {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.header-actions {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.kebab-menu-button {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color 0.2s ease;
    color: var(--text-secondary);
}

.kebab-menu-button:hover {
    background-color: var(--surface-medium);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface-light);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 1000;
    display: none;
    overflow: hidden;
    padding: var(--spacing-sm) 0;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.dropdown-menu a:hover {
    background-color: var(--surface-medium);
}

.dropdown-menu hr {
    margin: 4px 0;
    border: none;
    border-top: 1px solid var(--neutral-200);
}


/* ===================================================================
   3. CHAT CONTAINER & BUBBLES
   Styles for the main conversation area.
=================================================================== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    scroll-behavior: smooth;
}

.example-questions-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 4rem 2rem;
    text-align: center;
}

.example-question {
    padding: 10px 16px;
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.example-question:hover {
    background-color: var(--surface-medium);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.qna-pair {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
    animation: slideInUp 0.4s ease-out;
}

.question-box {
    align-self: flex-end;
    max-width: 85%;
    background: linear-gradient(135deg, #fff3e6, #ffe8d0);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: 18px 18px 4px 18px;
    font-size: 1rem;
    font-weight: 450;
    line-height: 1.6;
    letter-spacing: 0.01em;
    border: 1px solid #ffddb8;
}

.question-content {
    font-family: 'Poppins', sans-serif;
}

html[data-theme='dark'] .question-box {
    background: linear-gradient(135deg, #3a2f24, #4a3828);
    color: #E0E0E0;
    border-color: #5a4832;
}

.answer-box {
    align-self: flex-start;
    max-width: 95%;
    background: var(--surface-light);
    border: 1px solid var(--neutral-200);
    border-radius: 18px 18px 18px 4px;
    padding: var(--spacing-md) calc(var(--spacing-md) + 4px);
}

.answer-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.answer-avatar-container {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.answer-avatar,
.answer-avatar-placeholder {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    flex-shrink: 0;
}

.answer-avatar {
    object-fit: cover;
}

.answer-avatar-placeholder {
    background-color: var(--surface-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.ai-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: linear-gradient(135deg, #282828, #282828);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--surface-light);
}

.answer-label {
    font-family: 'Poppins', sans-serif;
    font-weight: 650;
    font-size: 0.875rem;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.copy-answer-btn {
    position: relative;
    background: none;
    border: none;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-answer-btn:hover {
    background-color: var(--surface-medium);
    color: var(--text-primary);
}

.copy-answer-btn .icon-copy-check {
    display: none;
    color: var(--accent-success);
}

.copy-answer-btn .icon-copy-default {
    display: inline-block;
}

/* Success state when copied */
.copy-answer-btn.copied {
    background-color: #d4edda;
    color: #155724;
    transform: scale(1.05);
}

html[data-theme='dark'] .copy-answer-btn.copied {
    background-color: #1e4620;
    color: #7dcea0;
}


/* --- Markdown Content --- */
.answer-content {
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.answer-content p,
.answer-content ul,
.answer-content ol {
    margin-bottom: 0.75em;
}

.answer-content>*:last-child {
    margin-bottom: 0;
}

.answer-content ul,
.answer-content ol {
    padding-left: 24px;
}

.answer-content li {
    margin-bottom: 0.35em;
}

.answer-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.answer-content blockquote {
    margin-left: 0;
    padding-left: var(--spacing-md);
    border-left: 3px solid var(--accent-primary);
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.875rem;
}

/* --- Sources & Regenerate --- */
.sources-section {
    border-top: 1px solid var(--neutral-200);
    padding-top: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

.source-buttons {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.toggle-sources-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.toggle-sources-btn:hover {
    background: var(--surface-medium);
    color: var(--text-primary);
}

.sources-list {
    margin-top: var(--spacing-sm);
    border-left: 2px solid var(--neutral-200);
    padding-left: var(--spacing-sm);
}

.source-item {
    margin-bottom: var(--spacing-xs);
}

.source-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-size: 0.905rem;
    display: block;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background-color 0.2s ease;
}

.source-link:hover {
    background: var(--surface-medium);
    text-decoration: underline;
}

.source-snippet {
    font-size: 0.82rem;
    color: var(--text-muted);
    background-color: var(--surface-light);
    border-left: 2px solid var(--accent-primary);
    padding: 6px 10px;
    margin-top: 4px;
    margin-bottom: 8px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    line-height: 1.4;
    font-style: italic;
    opacity: 0.85;
}

/* --- Typing Indicator --- */
.typing-container {
    display: none;
    margin: 8px 0;
}

.typing-container.active {
    display: block;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}


/* ===================================================================
   4. QUESTION INPUT FORM
   Styles for the textarea and submit button.
=================================================================== */
.question-form {
    flex-shrink: 0;
    padding: var(--spacing-sm);
    background-color: transparent;
    z-index: 10;
    position: relative;
    bottom: 0;
    width: 100%;
}

.textarea-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--surface-light);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
    transition: border-color 0.2s ease;
}

.textarea-wrapper:focus-within {
    border-color: var(--accent-primary);
}

.question-textarea {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    line-height: 1.5;
    padding: 8px 12px;
    min-height: 24px;
    max-height: 120px;
    color: var(--text-primary);
}

.textarea-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--neutral-200);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.submit-btn:not(:disabled):hover,
.submit-btn.active {
    background: var(--accent-primary);
    color: white;
}

.submit-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}


/* ===================================================================
   5. RIGHT SIDEBAR (DESKTOP)
   Styles for the channel profile card on large screens.
=================================================================== */
.chat-sidebar-right {
    display: none;
    /* Hidden by default, shown in media query */
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    background-color: var(--surface-light);
    border-left: 1px solid var(--neutral-200);
    padding: var(--spacing-lg);
}

.channel-profile-card {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

.profile-header {
    text-align: center;
}

.profile-avatar {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto var(--spacing-md);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--surface-light);
    box-shadow: var(--shadow-md);
}

.profile-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--spacing-xs);
}

.profile-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.profile-actions-new {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.action-btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.secondary-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.action-btn-secondary {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
    background: var(--surface-medium);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn-secondary:hover {
    background: var(--neutral-200);
    color: var(--text-primary);
}

.action-btn-secondary::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%;
    background-color: var(--text-primary);
    color: var(--surface-light);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
}

.action-btn-secondary:hover::before {
    opacity: 1;
    visibility: visible;
}

.profile-topics {
    border-top: 1px solid var(--neutral-200);
    padding-top: var(--spacing-xl);
}

.topics-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-md);
}

.topics-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.tag {
    background-color: var(--surface-medium);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tag:hover {
    transform: translateY(-2px);
    background-color: var(--accent-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.admin-channel-settings {
    border-top: 1px solid var(--neutral-200);
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-xl);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-md);
}

.setting-label label {
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    margin-bottom: var(--spacing-xs);
}

.setting-label p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

/* ===================================================================
   6. SHARE MODAL
=================================================================== */
#shareModal .login-popup-content {
    max-width: 500px;
}

.link-copy-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--surface-medium);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    padding-left: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.link-copy-wrapper:hover {
    border-color: var(--accent-primary);
}

.link-copy-wrapper input {
    flex-grow: 1;
    border: none;
    background: transparent;
    padding: 0.75rem 0;
    font-size: 0.9rem;
    font-family: monospace;
    cursor: pointer;
    outline: none;
    color: var(--text-primary);
}

.copy-action {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-left: 1px solid var(--neutral-200);
    color: var(--accent-primary);
    font-weight: 500;
}

.copy-action .icon-copy-check {
    display: none;
    color: var(--accent-success);
}

.modal-divider {
    border: none;
    height: 1px;
    background-color: var(--neutral-200);
    margin: 1.5rem 0;
}


/* ===================================================================
   CALL TO ACTION BANNER NOTICE
=================================================================== */
.c-banner-notice {
    /* A soft yellow for better highlighting */
    background-color: #FFF3CD;
    color: #664D03;
    padding: var(--spacing-sm) var(--spacing-md);
    margin: 0 var(--spacing-md) var(--spacing-sm);
    border-radius: var(--radius-md);
    display: none;
    /* Hidden by default */
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
    /* A matching border color */
    border: 1px solid #FFECB5;
}

.notice-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.c-banner-notice p {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
}

.c-banner-notice p strong {
    font-weight: 700;
}

.btn-upgrade {
    background-color: var(--accent-primary);
    color: white;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.btn-upgrade:hover {
    opacity: 0.85;
    box-shadow: var(--shadow-sm);
}

.notice-close-btn {
    background: none;
    border: none;
    /* Match the new text color */
    color: #664D03;
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 var(--spacing-xs);
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.notice-close-btn:hover {
    opacity: 1;
}

/* ===================================================================
   7. UTILITIES & ANIMATIONS
=================================================================== */
.skeleton {
    opacity: 0.7;
    animation: skeleton-loading 1s linear infinite alternate;
}

.skeleton-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--neutral-200);
}

.skeleton-line {
    height: 1em;
    border-radius: var(--radius-sm);
    background-color: var(--neutral-200);
}

@keyframes skeleton-loading {
    from {
        background-color: var(--neutral-200);
    }

    to {
        background-color: var(--neutral-300);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes typingAnimation {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}


/* ===================================================================
   8. RESPONSIVE LAYOUT (MEDIA QUERIES)
=================================================================== */
@media (max-width: 768px) {
    .main-content.has-mobile-nav {
        padding-top: 64px;
        /* Match the new header height */
    }

    .chat-sidebar-right {
        display: none;
    }

    .mobile-header {
        display: flex;
    }

    .chat-container {
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }
}

@media (min-width: 769px) {

    /* body has zoom:0.8 applied globally on desktop.
       100vh only covers 80% of the visual viewport, so we use 125vh (= 100/0.8)
       to fill the full screen with no dead space below. */
    html,
    body {
        height: 111.11vh;
        overflow: hidden;
    }

    .app-layout {
        height: 111.11vh;
        min-height: unset;
        overflow: hidden;
    }

    .main-content.has-mobile-nav {
        height: 111.11vh;
    }

    .desktop-chat-layout {
        grid-template-columns: 1fr 320px;
    }

    .chat-sidebar-right {
        display: flex;
        position: sticky;
        top: 0;
        max-height: 100%;
    }
}

@media (min-width: 1200px) {
    .desktop-chat-layout {
        grid-template-columns: 1fr 360px;
    }
}

.chat-container {
    /* For Firefox */
    scrollbar-width: thin;
    scrollbar-color: var(--neutral-300) transparent;
}

/* For Chrome, Safari, and other WebKit browsers */
.chat-container::-webkit-scrollbar {
    width: 6px;
    /* Makes the scrollbar narrow */
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
    /* Makes the track invisible */
}

.chat-container::-webkit-scrollbar-thumb {
    background-color: var(--neutral-300);
    /* Sets the color of the scrollbar handle */
    border-radius: 3px;
    /* Rounds the corners of the handle */
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--neutral-400);
    /* Changes color on hover */

}