/* Chat page — mobile-first ChatGPT/Claude style with smooth animations */

body.page-chat {
    background: #fff;
    margin: 0;
    padding: 0;
}

body.page-chat .mobile-top-bar,
body.page-chat .mobile-bottom-nav,
body.page-chat footer,
body.page-chat header.nav-desktop {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.chat-layout {
    display: flex;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    background: #f9fafb;
}

/* Sidebar */
.chat-sidebar {
    width: 260px;
    background-color: #f9fafb;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.35s cubic-bezier(.22,1,.36,1), opacity 0.25s ease;
    z-index: 40;
}

.chat-sidebar-header {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.chat-new-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #fff;
    border: 1px solid #d1d5db;
    padding: 8px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.34,1.56,.64,1);
}
.chat-new-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
.chat-new-btn:active { transform: scale(0.96); }

.chat-back-btn, .chat-sidebar-close, .chat-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #6b7280;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}
.chat-back-btn:hover, .chat-sidebar-close:hover, .chat-sidebar-toggle:hover { background: #e5e7eb; color: #111827; }
.chat-back-btn:active, .chat-sidebar-close:active, .chat-sidebar-toggle:active { transform: scale(0.9); }

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-history-loading {
    padding: 12px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

.chat-session-item {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    color: #374151;
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.22,1,.36,1);
    transform-origin: left center;
}
.chat-session-item:hover {
    background: #e5e7eb;
    transform: translateX(4px);
}
.chat-session-item:active {
    transform: scale(0.97) translateX(4px);
}
.chat-session-item.active {
    background: #e5e7eb;
    font-weight: 500;
    color: #111827;
}

/* Main Content */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
    position: relative;
}

.chat-app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    z-index: 10;
}

.chat-app-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-app-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.chat-app-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-model-select {
    padding: 6px 28px 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background-color: #fff;
    color: #374151;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.chat-model-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    scroll-behavior: smooth;
}

.chat-messages-inner {
    max-width: 48rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Empty State */
.chat-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    text-align: center;
    animation: chat-empty-enter 0.6s cubic-bezier(.22,1,.36,1) both;
}
.chat-empty-icon {
    font-size: 40px;
    margin-bottom: 16px;
    color: #10a37f;
    animation: chat-icon-float 3s ease-in-out infinite;
    display: inline-block;
}
.chat-empty-title {
    font-size: 20px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 8px;
    animation: chat-slide-up 0.5s cubic-bezier(.22,1,.36,1) 0.1s both;
}
.chat-empty-hint {
    font-size: 14px;
    animation: chat-slide-up 0.5s cubic-bezier(.22,1,.36,1) 0.2s both;
}

@keyframes chat-empty-enter {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes chat-icon-float {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-8px) rotate(2deg); }
}
@keyframes chat-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Message Bubbles */
.chat-msg {
    display: flex;
    gap: 16px;
    max-width: 100%;
    animation: chat-msg-enter 0.4s cubic-bezier(.22,1,.36,1) both;
}
.chat-msg.user { flex-direction: row-reverse; }

@keyframes chat-msg-enter {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
}
.chat-msg.assistant .chat-avatar { background: #10a37f; color: #fff; }
.chat-msg.user .chat-avatar { background: #3b82f6; color: #fff; }

.chat-bubble {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
    font-size: 15px;
    line-height: 1.6;
    color: #111827;
    overflow-wrap: break-word;
    transition: all 0.2s ease;
}
.chat-msg.user .chat-bubble {
    background: #eff6ff;
    border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
    background: transparent;
    padding: 4px 0;
    max-width: 100%;
    width: 100%;
}

.chat-bubble img { max-width: 100%; border-radius: 8px; margin-top: 8px; }
.chat-bubble pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: 14px 16px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 12px 0;
    font-size: 13px;
    line-height: 1.5;
}
.chat-bubble code {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Cascadia Code', monospace;
    background: #e5e7eb;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}
.chat-bubble pre code { background: none; padding: 0; }
.chat-bubble a, .chat-md-link {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 4px;
    font-weight: 500;
    word-break: break-all;
    transition: color 0.2s;
}
.chat-bubble a:hover, .chat-md-link:hover {
    color: #1d4ed8;
}

/* Thinking / Typing indicator */
.chat-thinking {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}
.chat-thinking-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: chat-think-bounce 1.4s ease-in-out infinite;
}
.chat-thinking-dot:nth-child(1) { animation-delay: 0s; }
.chat-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-think-bounce {
    0%, 80%, 100% { transform: translateY(0) scale(0.8); opacity: 0.4; }
    40% { transform: translateY(-8px) scale(1); opacity: 1; }
}

/* Typing status in composer */
.chat-status {
    font-size: 12px;
    color: #6b7280;
    text-align: center;
    margin-top: 8px;
    min-height: 18px;
    transition: opacity 0.3s ease;
}

/* Composer */
.chat-composer-wrap {
    padding: 16px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    position: relative;
}
.chat-composer {
    max-width: 48rem;
    margin: 0 auto;
    position: relative;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 8px;
    transition: all 0.25s cubic-bezier(.22,1,.36,1);
}
.chat-composer:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2), 0 2px 8px rgba(59,130,246,0.08);
    background: #fff;
}

.chat-attachments {
    padding: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    animation: chat-slide-up 0.25s cubic-bezier(.22,1,.36,1) both;
}
.chat-attach-preview {
    position: relative;
    width: 60px;
    height: 60px;
    animation: chat-scale-in 0.25s cubic-bezier(.34,1.56,.64,1) both;
}
.chat-attach-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.chat-attach-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
}
.chat-attach-preview:hover .chat-attach-remove { opacity: 1; }

@keyframes chat-scale-in {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

/* File Preview */
.chat-file-preview {
    padding: 8px 8px 4px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
    animation: chat-slide-up 0.3s cubic-bezier(.22,1,.36,1) both;
}
.chat-file-preview-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 13px;
    color: #374151;
}
.chat-file-preview-name {
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-file-preview-chars {
    color: #6b7280;
    font-size: 11px;
    white-space: nowrap;
}
.chat-file-preview-status {
    color: #6b7280;
    font-size: 12px;
    animation: chat-pulse 1.5s ease-in-out infinite;
}
.chat-file-preview-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #9ca3af;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.chat-file-preview-remove:hover { background: #e5e7eb; color: #ef4444; }
.chat-file-preview-body {
    max-height: 120px;
    overflow-y: auto;
    margin-top: 4px;
    padding: 6px 8px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}
.chat-file-preview-text {
    font-size: 11px;
    line-height: 1.4;
    color: #6b7280;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
    margin: 0;
}
.chat-extracting-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: chat-spin 0.6s cubic-bezier(.6,.2,.4,.8) infinite;
    margin: 8px auto;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }
@keyframes chat-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Extract Actions */
.chat-extract-actions {
    display: flex;
    gap: 6px;
    padding: 4px 8px 0;
    animation: chat-slide-up 0.25s cubic-bezier(.22,1,.36,1) both;
}
.chat-extract-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(.22,1,.36,1);
}
.chat-extract-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    transform: translateY(-1px);
}
.chat-extract-btn:active {
    transform: scale(0.96) translateY(0);
}
.chat-extract-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.chat-generate-note-btn {
    background: #f0fdf4;
    border-color: #86efac;
    color: #166534;
}
.chat-generate-note-btn:hover { background: #dcfce7; border-color: #4ade80; }

.chat-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #6b7280;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(.34,1.56,.64,1);
}
.chat-icon-btn:hover { background: #e5e7eb; color: #111827; }
.chat-icon-btn:active { transform: scale(0.88); }
.chat-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.chat-input-wrap { flex: 1; }
.chat-input {
    width: 100%;
    min-height: 24px;
    max-height: 200px;
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    padding: 6px 0;
    font-size: 15px;
    line-height: 1.5;
    color: #111827;
}
.chat-input::placeholder {
    color: #9ca3af;
    transition: color 0.3s ease;
}
.chat-input:focus::placeholder {
    color: #d1d5db;
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111827;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(.34,1.56,.64,1);
}
.chat-send-btn:hover:not(:disabled) {
    background: #374151;
    transform: scale(1.05);
}
.chat-send-btn:active:not(:disabled) {
    transform: scale(0.92);
}
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile */
@media (max-width: 1023px) {
    .chat-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        opacity: 0;
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
        transition: transform 0.35s cubic-bezier(.22,1,.36,1), opacity 0.25s ease;
    }
    .chat-sidebar.open {
        transform: translateX(0);
        opacity: 1;
    }
}
@media (min-width: 1024px) {
    .chat-sidebar-close, .chat-sidebar-toggle { display: none !important; }
}

/* Drag and Drop */
.chat-composer-wrap.chat-dragover .chat-composer {
    border-color: #3b82f6;
    background: #eff6ff;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.25);
    transform: scale(1.01);
}
.chat-composer-wrap.chat-dragover::after {
    content: 'Drop file here';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #3b82f6;
    background: rgba(239,246,255,0.92);
    border-radius: 16px;
    pointer-events: none;
    animation: chat-fade-in 0.2s ease both;
}

@keyframes chat-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Streaming cursor */
.chat-streaming .chat-content-wrap::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #111827;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: chat-blink 0.8s step-end infinite;
}
.chat-streaming .chat-thinking {
    display: none !important;
}

@keyframes chat-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Streaming pulse animation for the assistant message */
.chat-msg.assistant.streaming .chat-bubble {
    animation: chat-stream-pulse 2s ease-in-out infinite;
}
@keyframes chat-stream-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Smooth text reveal */
.chat-content-wrap {
    transition: opacity 0.1s ease;
}

/* Copy button */
.chat-copy-btn {
    opacity: 0;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 8px;
    right: 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-bubble:hover .chat-copy-btn {
    opacity: 1;
}
.chat-copy-btn:hover {
    background: #e5e7eb;
    color: #111827;
}
.chat-copy-btn.copied {
    background: #d1fae5;
    color: #059669;
    border-color: #6ee7b7;
}

/* File ready indicator */
.chat-file-ready {
    font-size: 12px;
    color: #059669;
    text-align: center;
    padding: 6px;
    font-weight: 500;
    animation: chat-slide-up 0.3s cubic-bezier(.22,1,.36,1) both;
}

/* Smooth scrolling for message container */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
    transition: background 0.2s ease;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Markdown tables in messages */
.chat-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 14px;
}
.chat-bubble th {
    border: 1px solid #d1d5db;
    background: #f3f4f6;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: #111827;
}
.chat-bubble td {
    border: 1px solid #d1d5db;
    padding: 6px 12px;
    color: #374151;
}
.chat-bubble tr:nth-child(even) td {
    background: #f9fafb;
}

/* Blockquote */
.chat-bubble blockquote {
    border-left: 3px solid #3b82f6;
    margin: 12px 0;
    padding: 8px 16px;
    background: #f9fafb;
    border-radius: 0 8px 8px 0;
    color: #6b7280;
    font-style: italic;
}

/* Lists */
.chat-bubble ul, .chat-bubble ol {
    padding-left: 24px;
    margin: 8px 0;
}
.chat-bubble li {
    margin: 4px 0;
}
