/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&display=swap');

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --font-serif: 'Source Serif 4', Georgia, serif;
    --primary-color: #7A5C3E;
    --primary-hover: #2A2520;
    --secondary-color: #6B6259;
    --background: #F7F2EA;
    --surface: #FDFAF5;
    --text-primary: #2E2E2E;
    --text-secondary: #8C8279;
    --border-color: #D5C9B8;
    --user-message-bg: #7A5C3E;
    --assistant-message-bg: #F1E8D9;
    --success-color: #5B8C7A;
    --error-color: #A3423A;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --border-radius: 0.75rem;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* App Container - Sidebar + Main Content Layout */
.app-container {
    display: flex;
    height: 100vh;
    background: var(--background);
    overflow: hidden;
}

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100vh;
    background: var(--surface);
    overflow: hidden;
    padding-bottom: 2.5rem; /* Space for fixed app footer */
}

/* Legacy container class for compatibility */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--surface);
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.header-left {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.welcome-logo {
    width: 140px;
    height: auto;
}

.title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tenant-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: var(--assistant-message-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    font-size: 0.8125rem;
    line-height: 1.2;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
}

.tenant-badge-name {
    font-weight: 600;
    color: var(--primary-color);
    overflow: hidden;
    text-overflow: ellipsis;
}

.tenant-badge-role {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: capitalize;
}

.user-email {
    font-size: 0.875rem;
    color: var(--primary-color);
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kb-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
}

.stat-item {
    display: flex;
    gap: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--background);
    color: var(--text-primary);
    border-color: var(--primary-color);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    background: var(--background);
}

.messages {
    max-width: 900px;
    margin: 0 auto;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary-color, #7A5C3E);
}

.welcome-message h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.welcome-message p {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.welcome-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    animation: messageSlideIn 0.3s ease-out;
}

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

.message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--primary-color);
    color: white;
}

.assistant-message .message-avatar {
    background: var(--assistant-message-bg);
    color: var(--text-primary);
}

.message-content {
    flex: 1;
    max-width: 75%;
}

.message-bubble {
    padding: 0.875rem 1.125rem;
    border-radius: var(--border-radius);
    line-height: 1.6;
}

.user-message .message-bubble {
    background: var(--user-message-bg);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.assistant-message .message-bubble {
    background: var(--assistant-message-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 0.25rem;
}

/* Markdown formatting within assistant messages */
.assistant-message .message-bubble p {
    margin: 0.5em 0;
}

.assistant-message .message-bubble p:first-child {
    margin-top: 0;
}

.assistant-message .message-bubble p:last-child {
    margin-bottom: 0;
}

.assistant-message .message-bubble strong,
.assistant-message .message-bubble b {
    font-weight: 600;
    color: var(--text-primary);
}

.assistant-message .message-bubble em,
.assistant-message .message-bubble i {
    font-style: italic;
}

.assistant-message .message-bubble code {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 0.875em;
    color: #A67B5B;
}

.assistant-message .message-bubble pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
    border-radius: 0.375rem;
    overflow-x: auto;
    margin: 0.75em 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.assistant-message .message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.assistant-message .message-bubble ul,
.assistant-message .message-bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5rem;
}

.assistant-message .message-bubble li {
    margin: 0.25em 0;
}

.assistant-message .message-bubble a {
    color: var(--primary-color);
    text-decoration: underline;
}

.assistant-message .message-bubble a:hover {
    color: var(--primary-hover);
}

.assistant-message .message-bubble blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1rem;
    margin: 0.75em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.assistant-message .message-bubble h1,
.assistant-message .message-bubble h2,
.assistant-message .message-bubble h3,
.assistant-message .message-bubble h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
}

.assistant-message .message-bubble h1:first-child,
.assistant-message .message-bubble h2:first-child,
.assistant-message .message-bubble h3:first-child,
.assistant-message .message-bubble h4:first-child {
    margin-top: 0;
}

.assistant-message .message-bubble h1 { font-size: 1.5em; }
.assistant-message .message-bubble h2 { font-size: 1.3em; }
.assistant-message .message-bubble h3 { font-size: 1.15em; }
.assistant-message .message-bubble h4 { font-size: 1.05em; }

.assistant-message .message-bubble hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1em 0;
}

.assistant-message .message-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75em 0;
}

.assistant-message .message-bubble th,
.assistant-message .message-bubble td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    text-align: left;
}

.assistant-message .message-bubble th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    opacity: 0.7;
}

/* Sources */
.message-sources {
    margin-top: 1rem;
    padding: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.sources-header {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sources-header::before {
    content: "▶";
    display: inline-block;
    transition: transform 0.2s;
    font-size: 0.75rem;
}

.sources-header.expanded::before {
    transform: rotate(90deg);
}

.sources-list {
    display: none;
    margin-top: 0.5rem;
    padding-left: 0.5rem;
}

.sources-list.expanded {
    display: block;
}

.source-item {
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    border-left: 2px solid var(--primary-color);
    padding-left: 0.75rem;
}

.source-filename {
    font-weight: 500;
    color: var(--text-primary);
}

.source-relevance {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* Attachments */
.message-attachments {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: var(--transition);
}

/* Feedback Section */
.message-feedback {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.feedback-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.feedback-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.375rem 0.625rem;
    font-size: 1.125rem;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.feedback-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.feedback-thumbs-up:hover:not(:disabled) {
    background: #E0EEEA;
    border-color: #5B8C7A;
}

.feedback-thumbs-down:hover:not(:disabled) {
    background: #F5E0DC;
    border-color: #A3423A;
}

.message-actions {
    margin-top: 0.5rem;
    display: flex;
    justify-content: flex-end;
}

.feedback-regenerate {
    margin-left: auto;
    font-size: 1.25rem;
}

.feedback-regenerate:hover:not(:disabled) {
    background: #E0E6EE;
    border-color: #5B6E8C;
}

.feedback-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.feedback-thanks {
    font-size: 0.875rem;
    color: var(--success-color);
    font-weight: 500;
}

.attachment-chip:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.attachment-icon {
    display: inline-flex;
    align-items: center;
    margin-right: 0.5rem;
    font-size: 0.875rem;
}

/* Input Area */
.input-container {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    box-shadow: var(--shadow-sm);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

.query-input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    transition: var(--transition);
    line-height: 1.5;
}

.query-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(122, 92, 62, 0.1);
}

.send-btn {
    padding: 0.875rem;
    background: var(--primary-color);
    border: none;
    border-radius: 0.5rem;
    color: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.input-hint kbd {
    padding: 0.125rem 0.375rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-family: monospace;
    font-size: 0.75rem;
}

/* Typing Indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    padding: 1rem 1.5rem !important;
}

.typing-dots {
    display: flex;
    gap: 0.375rem;
    align-items: center;
}

.typing-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    opacity: 0.6;
    animation: typing-bounce 1.4s infinite;
}

.typing-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Hide loading overlay (no longer used) */
.loading-overlay {
    display: none !important;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--text-primary);
    color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    gap: 0.75rem;
    animation: toastSlideIn 0.3s ease-out;
    z-index: 1001;
    max-width: 400px;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.show {
    display: flex;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

/* Error Message */
.error-message {
    padding: 1rem;
    background: #F5E0DC;
    border: 1px solid var(--error-color);
    border-radius: 0.5rem;
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* ====================================
   RESPONSIVE DESIGN - MOBILE FIRST
   ==================================== */

/* Tablets and Small Desktops (1024px and below) */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .messages {
        max-width: 100%;
    }
}

/* Tablets (768px and below) */
@media (max-width: 768px) {
    /* Header Adjustments */
    .header {
        padding: 0.875rem 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-left {
        width: 100%;
    }

    .title {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 0.8125rem;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .kb-stats {
        flex: 1;
        gap: 1rem;
    }

    .stat-item {
        font-size: 0.75rem;
    }

    .header-actions {
        gap: 0.5rem;
    }

    /* Messages Area */
    .messages-container {
        padding: 1rem;
    }

    .message-content {
        max-width: 90%;
    }

    .message-bubble {
        padding: 0.75rem 1rem;
        font-size: 0.9375rem;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8125rem;
    }

    .header-logo {
        width: 32px;
        height: 32px;
    }

    /* Welcome Message */
    .welcome-message {
        padding: 2rem 1rem;
    }

    .welcome-icon {
        font-size: 2.5rem;
    }

    .welcome-logo {
        width: 72px;
    }

    .welcome-message h2 {
        font-size: 1.25rem;
    }

    .welcome-message p {
        font-size: 0.9375rem;
    }

    /* Input Area */
    .input-container {
        padding: 0.875rem 1rem;
        padding-bottom: max(0.875rem, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        gap: 0.5rem;
    }

    .query-input {
        padding: 0.75rem 0.875rem;
        font-size: 0.9375rem;
    }

    .send-btn {
        padding: 0.75rem;
        min-width: 44px;
        min-height: 44px;
    }

    .input-hint {
        font-size: 0.6875rem;
    }

    /* Touch Targets - Ensure minimum 44x44px */
    .btn-icon {
        min-width: 40px;
        min-height: 40px;
        padding: 0.5rem;
    }

    /* Toast Notifications */
    .toast {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
        max-width: none;
    }

    /* Sources */
    .message-sources {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }

    /* Example Questions */
    .example-questions {
        gap: 0.625rem;
    }

    .example-question-chip {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
}

/* Large Phones (640px and below) */
@media (max-width: 640px) {
    /* Header - More Compact */
    .header {
        padding: 0.75rem 0.875rem;
    }

    .title {
        font-size: 1.125rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .organization {
        font-size: 0.75rem !important;
    }

    /* Hide KB stats on smaller screens to save space */
    .kb-stats {
        display: none;
    }

    /* User email - shorter */
    .user-email {
        max-width: 120px;
        font-size: 0.8125rem;
    }

    /* Messages - Wider bubbles on small screens */
    .message-content {
        max-width: 95%;
    }

    .message-bubble {
        padding: 0.625rem 0.875rem;
    }

    /* Conversation items more compact */
    .conversation-item {
        padding: 0.75rem;
    }

    .conversation-title {
        font-size: 0.8125rem;
    }

    .conversation-preview {
        font-size: 0.75rem;
        -webkit-line-clamp: 1;
    }

    /* Input more compact */
    .input-container {
        padding: 0.75rem 0.875rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .query-input {
        padding: 0.625rem 0.75rem;
    }

    /* Welcome message more compact */
    .welcome-message {
        padding: 1.5rem 0.875rem;
    }

    .welcome-icon {
        font-size: 2rem;
    }

    .welcome-message h2 {
        font-size: 1.125rem;
    }
}

/* Small Phones (480px and below) */
@media (max-width: 480px) {
    /* Very compact header */
    .header {
        padding: 0.625rem 0.75rem;
    }

    .header-logo {
        width: 28px;
        height: 28px;
    }

    .title {
        font-size: 1rem;
    }

    .subtitle {
        font-size: 0.6875rem;
    }

    /* Hide organization on very small screens */
    .organization {
        display: none !important;
    }

    /* Stack header actions vertically if needed */
    .header-actions {
        gap: 0.375rem;
    }

    .btn-icon {
        min-width: 36px;
        min-height: 36px;
        padding: 0.375rem;
    }

    .btn-icon svg {
        width: 18px;
        height: 18px;
    }

    /* Messages very compact */
    .messages-container {
        padding: 0.75rem 0.5rem;
    }

    .message {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .message-bubble {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Input very compact but still usable */
    .input-container {
        padding: 0.625rem;
        padding-bottom: max(0.625rem, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        gap: 0.375rem;
    }

    .query-input {
        padding: 0.5rem 0.625rem;
        font-size: 0.875rem;
    }

    .send-btn {
        padding: 0.625rem;
        min-width: 40px;
        min-height: 40px;
    }

    .send-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Welcome message very compact */
    .welcome-message {
        padding: 1rem 0.625rem;
    }

    .welcome-icon {
        font-size: 1.75rem;
    }

    .welcome-message h2 {
        font-size: 1rem;
    }

    .welcome-message p {
        font-size: 0.875rem;
    }

    .welcome-hint {
        font-size: 0.75rem;
    }

    /* Sidebar narrower on very small screens when open */
    .sidebar {
        width: 280px;
    }

    .sidebar-header {
        padding: 0.875rem 1rem;
    }

    .sidebar-header h3 {
        font-size: 1rem;
    }

    /* Example questions more compact */
    .example-question-chip {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
    }

    /* Toast full width on very small screens */
    .toast {
        bottom: 0.75rem;
        right: 0.75rem;
        left: 0.75rem;
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }
}

/* Landscape Mode Optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical padding in landscape */
    .header {
        padding: 0.5rem 1rem;
    }

    .messages-container {
        padding: 0.75rem 1rem;
    }

    .input-container {
        padding: 0.5rem 1rem;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    .welcome-message {
        padding: 1rem;
    }

    .message {
        margin-bottom: 1rem;
    }
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--background);
}

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

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* ====================================
   Sidebar & Conversations
   ==================================== */

.sidebar {
    width: 320px;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
}

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

.sidebar-header h3 {
    font-family: var(--font-serif);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.search-container {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    background: var(--background);
    color: var(--text-primary);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--surface);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.conversation-item {
    padding: 0.875rem;
    border-radius: 0.5rem;
    cursor: pointer;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    transition: var(--transition);
    position: relative;
}

.conversation-item:hover {
    background: var(--background);
    border-color: var(--primary-color);
    transform: translateX(2px);
}

.conversation-item.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.conversation-item.active * {
    color: white !important;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.conversation-channel {
    display: inline-flex;
    align-items: center;
    margin-right: 0.5rem;
    font-size: 1rem;
    color: var(--text-secondary, #8C8279);
}

.conversation-title {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.conversation-preview {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
}

.conversation-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.conversation-count {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.conversation-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    z-index: 2;
    transition: var(--transition);
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
}

.delete-conversation-btn {
    padding: 0.25rem;
    background: var(--error-color);
    border: none;
    border-radius: 0.375rem;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.delete-conversation-btn:hover {
    background: #8A3630;
}

.delete-conversation-btn svg {
    width: 16px;
    height: 16px;
}

.loading-conversations,
.empty-conversations {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
}

.loading-conversations p,
.empty-conversations p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 1rem;
}

.spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Sidebar Toggle Button (Mobile) */
.sidebar-toggle {
    display: none;
}

/* Conversation List Scrollbar */
.conversations-list::-webkit-scrollbar {
    width: 6px;
}

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

.conversations-list::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -320px;
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        width: 100%;
        padding-bottom: 2.25rem; /* Space for fixed app footer on mobile */
    }

    /* Overlay when sidebar is open */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }
}

/* ====================================
   Document Descriptions
   ==================================== */

.document-description {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.description-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.description-toggle:hover {
    color: var(--primary-hover);
}

.toggle-icon {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.description-content {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--background);
    border-left: 3px solid var(--primary-color);
    border-radius: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-primary);
}

/* Example Questions */
.example-questions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 600px;
    margin: 0 auto;
}

.example-question-chip {
    padding: 0.875rem 1.25rem;
    background: var(--surface);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.example-question-chip:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.example-question-chip:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* ====================================
   TENANT SELECTOR MODAL
   ==================================== */

.tenant-select-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.tenant-select-dialog {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 2rem;
    max-width: 460px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.tenant-select-dialog h2 {
    font-family: var(--font-serif);
    font-size: 1.375rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.tenant-select-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.tenant-select-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tenant-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--background);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.tenant-card:hover {
    border-color: var(--primary-color);
    background: var(--assistant-message-bg);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.tenant-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.tenant-card-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.tenant-card-role {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.tenant-card-arrow {
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: var(--transition);
}

.tenant-card:hover .tenant-card-arrow {
    color: var(--primary-color);
    transform: translateX(2px);
}

/* Make tenant badge clickable when switchable */
.tenant-badge[data-switchable] {
    cursor: pointer;
    transition: var(--transition);
}

.tenant-badge[data-switchable]:hover {
    border-color: var(--primary-color);
    background: var(--background);
}

/* ====================================
   PLAN BANNER (trial/expired)
   ==================================== */

.plan-banner {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.plan-banner.banner-warning {
    background: #FEF3CD;
    color: #856404;
    border-bottom: 1px solid #FFE69C;
}

.plan-banner.banner-danger {
    background: #F8D7DA;
    color: #842029;
    border-bottom: 1px solid #F5C2C7;
}

.plan-banner.banner-info {
    background: #D1ECF1;
    color: #0C5460;
    border-bottom: 1px solid #BEE5EB;
}

.plan-banner a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

/* ====================================
   APP FOOTER
   ==================================== */

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary, #F7F2EA);
    border-top: 1px solid var(--border, #D5C9B8);
    padding: 0.5rem 1rem;
    z-index: 100;
    font-size: 0.75rem;
    color: var(--text-secondary, #8C8279);
}

.footer-content {
    text-align: center;
    line-height: 1.5;
}

.footer-content a {
    color: var(--primary, #7A5C3E);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-content a:hover {
    color: var(--primary-dark, #5E4730);
    text-decoration: underline;
}

/* Adjust body padding to prevent content from being hidden behind footer */
body {
    padding-bottom: 0;
}

/* For admin page, adjust the container padding */
.admin-container {
    padding-bottom: 4rem;
}

/* Mobile responsive footer */
@media (max-width: 640px) {
    .app-footer {
        font-size: 0.7rem;
        padding: 0.4rem 0.75rem;
    }

    .admin-container {
        padding-bottom: 3.5rem;
    }
}
