/* Import Modern Fonts */
/* FONT LOADING WAS MOVED TO HTML FOR PERFORMANCE. The @import rule was removed. */

/* CSS Variables for Minimalist Theme */
:root {
    --primary-bg: #fdf8f3;
    --secondary-bg: #ffffff;
    --surface-light: #FFFFFF;
    --surface-medium: #fef7f0;
    --surface-dark: #f4ede4;
    --neutral-50: #fdf8f3;
    --neutral-100: #f8f1e8;
    --neutral-200: #f0e6d6;
    --neutral-300: #e6d5c1;
    --neutral-400: #c4a882;
    --neutral-500: #a08660;
    --neutral-600: #7d6847;
    --neutral-700: #5a4a32;
    --neutral-800: #3d3024;
    --neutral-900: #2a1f16;
    --accent-primary: #ff9a56;
    --accent-secondary: #ff8c42;
    --accent-purple: #9333ea;
    --accent-purple-light: #a855f7;
    --accent-success: #4caf50;
    --accent-error: #e57373;
    --accent-info: #42a5f5;
    --text-primary: #2a1f16;
    --text-secondary: #5a4a32;
    --text-muted: #7d6847;
    --text-white: #ffffff;
    --shadow-xs: 0 1px 3px 0 rgba(160, 134, 96, 0.08);
    --shadow-sm: 0 2px 6px 0 rgba(160, 134, 96, 0.12);
    --shadow-md: 0 4px 12px 0 rgba(160, 134, 96, 0.15);
    --shadow-lg: 0 8px 20px 0 rgba(160, 134, 96, 0.18);
    --shadow-xl: 0 12px 28px 0 rgba(160, 134, 96, 0.20);
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --sidebar-width: 290px;
}

/* =================================================================
   DARK MODE THEME
================================================================== */
html[data-theme='dark'] {
    --primary-bg: #121212;
    --secondary-bg: #1e1e1e;
    --surface-light: #2c2c2c;
    --surface-medium: #3a3a3a;
    --surface-dark: #484848;
    --neutral-200: #484848;
    --neutral-300: #6c6c6c;
    --text-primary: #e0e0e0;
    --text-secondary: #b3b3b3;
    --text-muted: #8e8e8e;
    --shadow-xs: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 6px 0 rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.4);
}

html[data-theme='dark'] .question-box {
    background: #36425E;
    color: #E0E0E0;
}

/* =================================================================
   BASE & LAYOUT
================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    overflow-x: hidden;
}

body {
    font-family: 'Poppins', sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--primary-bg);
    min-height: 100vh;
}

h1,
h2,
h3,
h4,
.page-title,
.profile-name,
.sidebar-logo-link,
.login-popup-title {
    font-family: 'Poppins', sans-serif;
}

.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: var(--spacing-sm);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card {
    background: var(--surface-light);
    border-radius: var(--radius-xl);
}

/* =================================================================
   LEFT SIDEBAR
================================================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface-light);
    border-right: 1px solid var(--neutral-200);
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 1002;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: var(--spacing-md);
    background: var(--surface-light);
    border-bottom: 1px solid var(--neutral-200);
}

.sidebar-content {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

.sidebar-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--neutral-200);
}

/* --- START: Improved Sidebar Channel List --- */
.channel-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0.02em;
    margin-bottom: var(--spacing-sm);
    padding: 0 var(--spacing-sm);
}

.add-channel-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background: transparent;
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.875rem;
}

.add-channel-btn:hover {
    background: var(--surface-medium);
    color: var(--text-primary);
    border-color: var(--neutral-300);
}

.channel-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.channel-item-wrapper {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    background: transparent;
    border-radius: var(--radius-md);
    transition: background-color 0.2s ease;
    border: 1px solid transparent;
}

.channel-item-wrapper:hover {
    background: var(--surface-medium);
}

.channel-item-wrapper.active {
    background: var(--surface-medium);
    color: var(--text-primary);
}

.channel-item-wrapper.active .channel-name {
    font-weight: 600;
}

.channel-item-wrapper.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background-color: var(--accent-primary);
    border-radius: 0 4px 4px 0;
}

.channel-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    flex-grow: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    flex-shrink: 0;
}

.channel-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-btn {
    background-color: transparent;
    color: #474747;
    opacity: 0;
    transform: scale(0.9);
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease-in-out;
}

.channel-item-wrapper:hover .delete-btn {
    opacity: 1;
    transform: scale(1);
}

.delete-btn:hover {
    background-color: var(--accent-error);
    color: var(--text-white);
}

/* --- Mobile & Responsive --- */
.hamburger {
    display: none;
    position: fixed;
    top: var(--spacing-lg);
    left: var(--spacing-lg);
    z-index: 1003;
    width: 44px;
    height: 44px;
    background: var(--surface-light);
    border-radius: var(--radius-md);
    border: 1px solid var(--neutral-200);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}

.hamburger span {
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(42, 31, 22, 0.4);
    backdrop-filter: blur(4px);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

.clear-chat-btn {
    position: static;
    bottom: auto;
    right: auto;
    background: none;
    color: var(--accent-primary);
    border: none;
    border-radius: var(--radius-full);
    padding: var(--spacing-xs);
    font-size: 0.875rem;
    box-shadow: none;
    z-index: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.clear-chat-btn .reset-icon {
    font-size: 1.85rem;
    transform: rotate(0deg);
    transition: transform 0.3s ease;
}

.clear-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
    background: var(--surface-medium);
}

.clear-chat-btn:hover .reset-icon {
    transform: rotate(180deg);
}

.clear-chat-btn:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .sidebar-logo-img {
        margin-left: 22%;
        padding-top: 3%;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .hamburger {
        display: flex;
        position: fixed;
        top: var(--spacing-sm);
        left: var(--spacing-sm);
        z-index: 1003;
        background: var(--surface-light);
    }

    .channel-info-content,
    .qa-header-content {
        flex-grow: 0;
        display: flex;
        align-items: center;
        gap: 100px;
        min-width: 0;
        justify-content: flex-end;
    }

    .channel-header,
    .qa-header-main {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        flex-grow: 0;
        min-width: 0;
        flex-shrink: 1;
    }

    .main-content {
        margin-left: 0;
        padding: 0;
    }

    .main-content.has-mobile-nav .card {
        padding: 0;
        border-radius: 0;
        box-shadow: none;
        border: none;
        background: transparent;
        height: calc(100vh - (var(--spacing-xl) * 2));
        display: flex;
        flex-direction: column;
    }

    .main-content.has-mobile-nav .chat-wrapper {
        flex-grow: 1;
        min-height: 0;
    }

    .channel-avatar {
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
        flex-shrink: 0;
        border: none;
        background: var(--surface-medium);
    }

    .qa-title {
        font-size: 1.0rem;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 1;
    }

    .qa-description {
        font-size: 0.75rem;
        display: none;
    }

    .clear-chat-btn {
        position: static;
        bottom: auto;
        right: auto;
        background: none;
        color: var(--accent-primary);
        border: none;
        border-radius: var(--radius-full);
        padding: var(--spacing-xs);
        font-size: 0.875rem;
        box-shadow: none;
        z-index: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 60px;
        height: 60px;
        flex-shrink: 0;
    }

    .clear-chat-btn .reset-icon {
        font-size: 2.8rem;
        transform: rotate(0deg);
        transition: transform 0.3s ease;
    }

    .clear-chat-btn:hover .reset-icon {
        transform: rotate(180deg);
    }

    .chat-wrapper {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
    }

    .question-form {
        flex-shrink: 0;
        padding: var(--spacing-md);
        background-color: var(--surface-light);
        border-top: 1px solid var(--neutral-200);
    }

    .form-card {
        padding: var(--spacing-lg) var(--spacing-md);
        box-shadow: var(--shadow-sm);
        border: 1px solid var(--neutral-200);
        background: var(--surface-medium);
        margin-top: 0;
    }

    .channel-form .form-group {
        margin-bottom: var(--spacing-lg);
    }

    .input-with-icon input {
        padding-right: 40px;
        height: 48px;
    }

    .input-icon {
        right: var(--spacing-sm);
        width: 20px;
        height: 20px;
    }

    .btn.btn-primary {
        width: 100%;
        font-size: 1rem;
        padding: var(--spacing-md) var(--spacing-lg);
        height: 50px;
    }

    .saved-channels-section {
        margin-top: var(--spacing-xl);
        padding: var(--spacing-lg) var(--spacing-md);
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--neutral-200);
        border-radius: var(--radius-lg);
    }

    .section-title {
        font-size: 1.5rem;
        justify-content: center;
        text-align: center;
        margin-bottom: var(--spacing-md);
    }

    .section-title svg {
        width: 28px;
        height: 28px;
    }

    .section-description {
        font-size: 0.85rem;
        text-align: center;
        padding: 0;
        margin-bottom: var(--spacing-xl);
    }

    .channel-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .channel-card {
        flex-direction: row;
        padding: var(--spacing-md);
        box-shadow: var(--shadow-xs);
        border: 1px solid var(--neutral-200);
    }

    .channel-card-avatar,
    .channel-card-avatar-placeholder {
        width: 40px;
        height: 40px;
        margin-right: var(--spacing-sm);
    }

    .channel-card-title {
        font-size: 0.95rem;
    }

    .channel-card-stats {
        font-size: 0.75rem;
    }

    .delete-channel-btn {
        margin-left: var(--spacing-sm);
    }

    .delete-channel-btn svg {
        width: 18px;
        height: 18px;
    }

    .question-box,
    .answer-box {
        margin-left: 0%;
        margin-right: 0%;
    }
}

/* Desktop specific adjustments for header elements */
@media (min-width: 769px) {

    .channel-info-banner,
    .general-qa-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #feedd900;
        padding: var(--spacing-lg);
        margin-bottom: var(--spacing-xl);
    }

    .channel-info-content,
    .qa-header-content {
        flex-grow: 1;
        display: flex;
        align-items: center;
        gap: 100px;
    }

    .clear-chat-btn {
        position: static;
        background: var(--surface-medium);
        color: var(--accent-primary);
        box-shadow: none;
        border: 1px solid var(--neutral-300);
        padding: var(--spacing-sm);
        font-size: 0.875rem;
        z-index: auto;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .clear-chat-btn .reset-icon {
        font-size: 2.5rem;
        transform: rotate(0deg);
        transition: transform 0.3s ease;
    }

    .clear-chat-btn:hover .reset-icon {
        transform: rotate(180deg);
    }
}

/* --- General Components --- */
h2 {
    font-size: 1.75rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
}

p.text-muted {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.form-group {
    margin-bottom: 0;
}

label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    font-size: 0.875rem;
}

input,
select,
textarea {
    width: 100%;
    padding: var(--spacing-md);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface-light);
    color: var(--text-primary);
}

button,
.btn {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    color: #ffffff;
    padding: var(--spacing-md) var(--spacing-xl);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* --- Page: ask.html --- */
.general-qa-header {
    background: var(--surface-light);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.qa-header-main {
    flex-grow: 1;
}

.qa-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

.qa-description {
    color: var(--text-secondary);
    margin: 0;
}

.channel-info-banner {
    background: var(--surface-light);
    padding: var(--spacing-lg);
}

.channel-info-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-2xl+20px);
}

.channel-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.channel-actions {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
}

.clear-chat-btn:hover {
    background: var(--accent-error);
    color: var(--text-white);
    border-color: var(--accent-error);
}

.reset-icon {
    transition: transform 0.2s ease;
}

.clear-chat-btn:hover .reset-icon {
    transform: scale(1.1);
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.char-count.near-limit {
    color: var(--accent-warning);
}

.submit-btn {
    position: static;
    transform: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--neutral-300);
    cursor: not-allowed;
    transition: all 0.2s ease-in-out;
    flex-shrink: 0;
}

.submit-btn.active {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.submit-btn.loading {
    animation: spin 1s linear infinite;
}

.submit-btn:hover:not(:disabled) {
    transform: scale(1.05);
}

.submit-icon {
    width: 20px;
    height: 20px;
    color: var(--text-white);
}

.qna-pair {
    margin-bottom: var(--spacing-xl);
    animation: fadeIn 0.3s ease;
}

.question-box,
.answer-box {
    background: var(--surface-light);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--neutral-200);
    transition: all 0.3s ease;
}

.question-box:hover,
.answer-box:hover {
    box-shadow: var(--shadow-md);
}

.question-box {
    border-left: 4px solid var(--accent-tertiary);
    margin-bottom: var(--spacing-md);
}

.answer-box {
    border-left: 4px solid var(--accent-primary);
}

.question-header,
.answer-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
}

.question-label,
.answer-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.question-content,
.answer-content {
    font-size: 1rem;
    line-height: 1.7;
    word-wrap: break-word;
}

.question-content {
    font-style: italic;
}

.sources-section {
    margin-top: var(--spacing-lg);
    border-top: 1px solid var(--neutral-200);
    padding-top: var(--spacing-lg);
}

.toggle-sources-btn {
    background: var(--surface-medium);
    border: 1px solid var(--neutral-300);
    color: var(--text-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all 0.2s ease;
}

.toggle-sources-btn:hover {
    background: var(--neutral-100);
    border-color: var(--neutral-400);
}

.sources-icon {
    transition: transform 0.2s ease;
}

.toggle-sources-btn:hover .sources-icon {
    transform: scale(1.1);
}

.toggle-indicator {
    transition: transform 0.3s ease;
}

.toggle-sources-btn.expanded .toggle-indicator {
    transform: rotate(180deg);
}

.sources-list {
    margin-top: var(--spacing-md);
    background: var(--surface-medium);
    border-radius: var(--radius-md);
    border: 1px solid var(--neutral-200);
    overflow: hidden;
    transition: all 0.3s ease;
}

.source-item {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--neutral-200);
    transition: background-color 0.2s ease;
}

.source-item:hover {
    background-color: var(--neutral-100);
}

.source-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
    transition: color 0.2s ease;
}

.source-link:hover {
    color: var(--accent-secondary);
}

.source-title {
    flex-grow: 1;
}

.source-duration {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--neutral-100);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.source-excerpt {
    margin-top: var(--spacing-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-style: italic;
    background: rgba(255, 154, 86, 0.05);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-primary);
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-start;
}

.quote-icon {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--accent-primary);
}

.typing-indicator {
    display: flex;
    padding: 10px 0;
}

/* Error message styling */
.error-message {
    color: var(--accent-error);
    background: rgba(229, 115, 115, 0.1);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-error);
    margin: var(--spacing-md) 0;
}

/* Custom confirm dialog */
.confirm-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(42, 31, 22, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2100;
    animation: fadeIn 0.2s ease;
}

.confirm-content {
    background: var(--surface-light);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease;
}

.confirm-content h3 {
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.confirm-content p {
    margin-bottom: var(--spacing-lg);
    color: var(--text-secondary);
}

.confirm-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
}

.confirm-actions button {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all 0.2s ease;
}

.confirm-actions .cancel-btn {
    background: var(--surface-medium);
    color: var(--text-primary);
    border: 1px solid var(--neutral-300);
}

.confirm-actions .cancel-btn:hover {
    background: var(--neutral-100);
    border-color: var(--neutral-400);
}

.confirm-actions .confirm-btn {
    background: var(--accent-error);
    color: var(--text-white);
}

.confirm-actions .confirm-btn:hover {
    background: var(--accent-error);
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Mobile optimizations */
@media (max-width: 768px) {

    .general-qa-header {
        margin-bottom: var(--spacing-md);
    }

    .question-box,
    .answer-box {
        padding: var(--spacing-md);
    }

    .sources-list {
        margin: var(--spacing-sm) 0;
    }

    .source-item {
        padding: var(--spacing-sm);
    }

    .source-link {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }

    .source-duration {
        align-self: flex-start;
    }

    .confirm-content {
        width: 95%;
        padding: var(--spacing-lg);
    }

    .confirm-actions {
        flex-direction: column;
    }

    .confirm-actions button {
        width: 100%;
    }

    .textarea-actions {
        position: absolute;
        right: 6px;
        bottom: 6px;
    }

    .char-count {
        background: #fef7f000;
        padding: 2px 6px;
        border-radius: var(--radius-sm);
    }
}

/* --- Channel Page Specific Styles --- */
.page-header {
    text-align: center;
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-2xl);
    padding: 0 var(--spacing-lg);
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.page-title svg {
    color: var(--accent-primary);
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.page-description {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-2xl);
    line-height: 1.8;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.form-card {
    background: var(--surface-medium);
    border-radius: var(--radius-lg);
    padding: var(--spacing-2xl);
    border: 1px solid var(--neutral-200);
    box-shadow: var(--shadow-sm);
    margin-top: 0;
    margin-bottom: var(--spacing-2xl);
}

.channel-form .form-group {
    margin-bottom: var(--spacing-xl);
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon input {
    padding: var(--spacing-md) var(--spacing-lg);
    padding-right: 48px;
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--surface-light);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-with-icon input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(255, 154, 86, 0.15);
}

.input-icon {
    position: absolute;
    right: var(--spacing-md);
    color: var(--neutral-400);
    pointer-events: none;
    width: 20px;
    height: 20px;
}

.btn.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-2xl);
    font-size: 1.05rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    height: 50px;
}

.btn.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Saved Channels Section */
.saved-channels-section {
    background: var(--surface-light);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-lg);
    padding: var(--spacing-2xl);
    margin-top: var(--spacing-2xl);
    box-shadow: var(--shadow-lg);
}

.section-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.section-title svg {
    color: var(--accent-primary);
    flex-shrink: 0;
    width: 32px;
    height: 32px;
}

.section-description {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
    line-height: 1.7;
}

.channel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-lg);
}

.channel-card {
    background: var(--surface-medium);
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.channel-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.channel-card-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    text-decoration: none;
    color: inherit;
    flex-grow: 1;
    min-width: 0;
}

.channel-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--accent-primary);
}

.channel-card-avatar-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--neutral-300);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    flex-shrink: 0;
}

.channel-card-details {
    flex-grow: 1;
    min-width: 0;
}

.channel-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.channel-card-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.delete-channel-btn {
    background: none;
    border: none;
    color: var(--accent-error);
    cursor: pointer;
    padding: var(--spacing-xs);
    border-radius: var(--radius-sm);
    opacity: 0.7;
    transition: opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.delete-channel-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.delete-channel-btn svg {
    width: 20px;
    height: 20px;
}

.qna-pair {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.question-box,
.answer-box {
    max-width: 95%;
    border-radius: var(--radius-xl);
    margin: 8px;
}

.question-box {
    align-self: flex-end;
    background: #E3EFFB;
    color: #0B3C6F;
    border-bottom-right-radius: var(--radius-sm);
}

.answer-box {
    align-self: flex-start;
    background: var(--surface-light);
    border-bottom-left-radius: var(--radius-sm);
}

.question-box .question-header {
    display: none;
}

.question-box .question-content {
    font-style: normal;
    color: inherit;
}

.answer-box .answer-header {
    margin-bottom: var(--spacing-sm);
}

.header-actions {
    position: relative;
}

.kebab-menu-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kebab-menu-button:hover {
    background-color: var(--surface-medium);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 110%;
    right: 0;
    background-color: var(--surface-light);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--neutral-200);
    z-index: var(--z-dropdown);
    min-width: 200px;
    overflow: hidden;
    padding: var(--spacing-sm) 0;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

.dropdown-menu a:hover {
    background-color: var(--surface-medium);
    color: var(--accent-primary);
}

.dropdown-menu hr {
    border: none;
    border-top: 1px solid var(--neutral-200);
    margin: var(--spacing-sm) 0;
}

.button-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.kebab-menu-button .icon-success,
.kebab-menu-button .icon-failure,
.kebab-menu-button.state-loading .icon-default {
    display: none;
}

.kebab-menu-button.state-success .icon-success,
.kebab-menu-button.state-failure .icon-failure {
    display: block;
}

.kebab-menu-button .icon-success {
    color: var(--accent-success);
}

.kebab-menu-button .icon-failure {
    color: var(--accent-error);
}

.empty-state-container {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-xl);
    margin-top: var(--spacing-2xl);
    background: var(--surface-medium);
    border: 2px dashed var(--neutral-300);
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.empty-state-icon svg {
    color: var(--neutral-400);
    margin-bottom: var(--spacing-md);
}

.empty-state-title {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0;
}

.empty-state-text {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    max-width: 450px;
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--spacing-md);
}

.channel-card.is-processing {
    background-color: var(--surface-medium);
    border-style: dashed;
    opacity: 0.7;
    pointer-events: none;
}

.channel-card.is-processing .channel-card-details {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.channel-card.is-failed {
    border-color: var(--accent-error);
    background-color: rgba(229, 115, 115, 0.05);
}

.channel-card.is-failed .channel-card-title {
    color: var(--accent-error);
    font-weight: 600;
}

.channel-card-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--neutral-300);
    border-left-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

/* === Login Popup Modal Styles === */
.login-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.login-popup-content {
    background: var(--surface-light);
    padding: var(--spacing-2xl);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    text-align: center;
    position: relative;
    animation: slideUp 0.4s ease;
}

.login-popup-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.login-popup-icon {
    margin-bottom: var(--spacing-lg);
}

.login-popup-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.login-popup-subtitle {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.login-popup-google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    width: 100%;
    padding: var(--spacing-md);
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--neutral-300);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.login-popup-google-btn:hover {
    background: var(--surface-medium);
    border-color: var(--neutral-400);
}

.login-popup-terms {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--spacing-lg);
}

@media (max-width: 768px) {
    .login-popup-overlay {
        align-items: flex-end;
    }

    .login-popup-content {
        max-width: 100%;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        animation: slideUpFromBottom 0.4s ease;
    }

    @keyframes slideUpFromBottom {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }
}

.progress-bar-inner {
    height: 100%;
    background-color: var(--accent-primary);
    border-radius: var(--radius-full);
    transition: width 0.5s ease-in-out;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-card.is-processing .channel-card-details {
    justify-content: center;
}

.sidebar-logo-img {
    height: 70px;
    margin: -20px;

    width: auto;
}

@media (max-width: 768px) {
    .sidebar-logo-img {
        margin-left: 22%;
    }

    .page-header {
        margin-top: var(--spacing-lg);
        margin-bottom: var(--spacing-xl);
        padding-left: var(--spacing-md);
        padding-right: var(--spacing-md);
    }

    .page-title {
        font-size: 1.8rem;
        justify-content: center;
        text-align: center;
        margin-bottom: var(--spacing-sm);
    }

    .page-title svg {
        width: 28px;
        height: 28px;
    }

    .page-description {
        font-size: 0.95rem;
        text-align: center;
        padding: 0;
        margin-bottom: var(--spacing-lg);
    }

    .form-card {
        padding: var(--spacing-xl) var(--spacing-md);
        box-shadow: var(--shadow-sm);
        border: 1px solid var(--neutral-200);
        background: var(--surface-medium);
        margin-top: 0;
    }

    .channel-form .form-group {
        margin-bottom: var(--spacing-lg);
    }

    .input-with-icon input {
        padding-right: 40px;
        height: 48px;
    }

    .input-icon {
        right: var(--spacing-sm);
        width: 20px;
        height: 20px;
    }

    .btn.btn-primary {
        width: 100%;
        font-size: 1rem;
        padding: var(--spacing-md) var(--spacing-lg);
        height: 50px;
    }

    .saved-channels-section {
        margin-top: var(--spacing-xl);
        padding: var(--spacing-xl) var(--spacing-md);
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--neutral-200);
        border-radius: var(--radius-lg);
    }

    .section-title {
        font-size: 1.6rem;
        justify-content: center;
        text-align: center;
        margin-bottom: var(--spacing-md);
    }

    .section-title svg {
        width: 28px;
        height: 28px;
    }

    .section-description {
        font-size: 0.85rem;
        text-align: center;
        padding: 0;
        margin-bottom: var(--spacing-xl);
    }

    .channel-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .channel-card {
        flex-direction: row;
        padding: var(--spacing-md);
        box-shadow: var(--shadow-xs);
        border: 1px solid var(--neutral-200);
    }

    .channel-card-avatar,
    .channel-card-avatar-placeholder {
        width: 40px;
        height: 40px;
        margin-right: var(--spacing-sm);
    }

    .channel-card-title {
        font-size: 0.95rem;
    }

    .channel-card-stats {
        font-size: 0.75rem;
    }

    .delete-channel-btn {
        margin-left: auto;
        width: 30px;
        height: 30px;
        padding: var(--spacing-xs);
    }

    .delete-channel-btn svg {
        width: 16px;
        height: 16px;
    }

    .question-box,
    .answer-box {
        margin-left: 0%;
        margin-right: 0%;
    }
}

/* --- Desktop Two-Column Chat Layout --- */
@media (min-width: 769px) {
    .main-content.has-mobile-nav {
        height: 100vh;
        padding: 0;
    }

    .main-content.has-mobile-nav .card {
        height: 100%;
        border-radius: 0;
        box-shadow: none;
        border: none;
        background: transparent;
        padding: 0px;
    }

    .desktop-chat-layout {
        display: grid;
        grid-template-columns: 1fr 360px;
        gap: 0px;
        height: 100%;
    }

    .chat-column {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
    }

    .chat-column .chat-wrapper {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        border-radius: 0;
        background: transparent;
    }

    .question-form {
        flex-shrink: 0;
    }

    .chat-sidebar-right {
        position: sticky;
        top: var(--spacing-sm);
        max-height: calc(100vh - (var(--spacing-sm) * 2));
        overflow-y: auto;
    }

    .chat-sidebar-right .channel-info-banner,
    .chat-sidebar-right .general-qa-header {
        margin-bottom: 0;
        box-shadow: none;
        border: none;
        padding: 0;
        border-radius: 0;
        background: transparent;
    }
}

/* --- Mobile Only Rule --- */
@media (max-width: 768px) {
    .chat-sidebar-right {
        display: none;
    }

    .channel-info-banner,
    .general-qa-header {
        top: 0;
        left: 0;
        width: 100%;
        height: 64px;
        margin-left: 20px;
        background: #0b3b6f00;
        z-index: 998;
        border-bottom: 1px solid var(--neutral-200);
        display: flex;
        align-items: center;
        padding: var(--spacing-sm) var(--spacing-md) var(--spacing-sm) calc(var(--spacing-md) + 70px);
    }
}

.channel-list>* {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    background-color: var(--surface-medium);
    border: 1px solid var(--neutral-200);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
}

.channel-list>*:hover {
    background-color: var(--neutral-100);
    border-color: var(--neutral-300);
    color: var(--text-primary);
}

.question-header,
.answer-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
}

.question-label,
.answer-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

body {
    font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--primary-bg);
    min-height: 100vh;
}

.btn-primary {
    background: var(--accent-primary-gradient);
}

@media (max-width: 768px) {
    .channel-item-wrapper .delete-btn {
        opacity: 1 !important;
        transform: scale(1) !important;
        width: 36px;
        height: 36px;
    }

    .channel-item-wrapper .delete-btn:hover {
        background-color: var(--accent-error);
        color: var(--text-white);
    }

    /* Adjust channel item padding to accommodate the visible delete button */
    .channel-item-wrapper {
        padding: var(--spacing-sm) var(--spacing-sm);
    }

    /* Make sure the channel name doesn't get hidden by the delete button */
    .channel-name {
        max-width: calc(100% - 50px);
    }
}