/* Lexo.nu - Modern Chat Styles (Based on V3 Design) */

:root {
    /* Premium Design System - Original Flavor Restoration (v7 - Rich Navy) */
    --background: hsl(225, 22%, 10%);
    --bg-surface: hsl(225, 25%, 12%);
    --bg-canvas: hsl(225, 18%, 14%);
    --foreground: hsl(0, 0%, 98%);
    --card: hsla(225, 20%, 18%, 0.45);
    --card-foreground: hsl(0, 0%, 98%);
    --glass: hsla(255, 255%, 255%, 0.03);

    /* Primary - Original Azure Blue */
    --primary: hsl(217, 91%, 60%);
    --primary-foreground: hsl(0, 0%, 100%);
    --primary-dim: hsl(217, 85%, 52%);
    --primary-glow: hsla(217, 91%, 60%, 0.3);

    --secondary: hsl(225, 15%, 12%);
    --secondary-foreground: hsl(225, 10%, 70%);

    /* Legacy Flavor & Contrast Helpers */
    --text-primary: var(--foreground);
    --text-secondary: hsl(225, 10%, 85%);
    --text-muted: hsla(0, 0%, 98%, 0.4);
    --bg-hover: hsla(225, 30%, 50%, 0.08);

    --muted: hsl(225, 15%, 15%);
    --muted-foreground: hsl(225, 10%, 55%);

    --accent: hsl(217, 91%, 70%);
    --success: hsl(152, 69%, 45%);
    --danger: hsl(0, 72%, 51%);

    --border: transparent;
    /* Absolute Borderless */
    --shadow-luxe: 0 10px 30px rgba(0, 0, 0, 0.5);

    /* Typography */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Outfit', 'Inter', sans-serif;

    /* Chat Specific - Sync with Prototype */
    --bubble-user: linear-gradient(135deg, var(--primary) 0%, var(--primary-dim) 100%);
}

[data-theme='light'] {
    --background: hsl(225, 15%, 97%);
    --bg-surface: hsl(225, 20%, 95%);
    --bg-canvas: hsl(225, 15%, 97%);
    --foreground: hsl(225, 25%, 12%);
    --card: hsl(0, 0%, 100%);
    --card-foreground: hsl(225, 25%, 12%);
    --glass: hsl(0, 0%, 100%);

    --primary: hsl(217, 91%, 55%);
    --primary-dim: hsl(217, 85%, 50%);
    --primary-glow: hsla(217, 91%, 55%, 0.15);

    --secondary: hsl(225, 15%, 93%);
    --secondary-foreground: hsl(225, 20%, 30%);

    /* Legacy Flavor - Light */
    --text-primary: hsl(225, 25%, 12%);
    --text-secondary: hsl(225, 15%, 35%);
    --text-muted: hsl(225, 10%, 50%);
    --bg-hover: hsla(225, 30%, 50%, 0.06);

    --muted: hsl(225, 15%, 93%);
    --muted-foreground: hsl(225, 12%, 45%);

    --border: hsl(225, 15%, 88%);
    --shadow-luxe: 0 4px 20px hsla(225, 30%, 20%, 0.08);
}

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

body {
    font-family: var(--font-main);
    background: var(--background);
    color: var(--foreground);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar (Matches Settings Sidebar) */
.chat-sidebar {
    width: 280px;
    background: var(--bg-surface);
    border-right: none;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease, margin-left 0.3s ease;
}

/* Desktop Hiding Logic */
@media(min-width: 769px) {
    .chat-sidebar.collapsed {
        margin-left: -280px;
    }
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: none;
}

.new-chat-btn {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--accent-glow);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.new-chat-btn:hover {
    transform: translateY(-2px);
}

[data-theme='light'] .new-chat-btn {
    color: var(--foreground);
}

.history-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.history-select-btn,
.history-toggle-all-btn,
.history-delete-selected-btn {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--glass);
    color: var(--text-secondary);
    border-radius: 9px;
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.history-select-btn:hover,
.history-toggle-all-btn:hover:not(:disabled),
.history-delete-selected-btn:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--accent);
}

.history-toggle-all-btn {
    display: none;
}

.history-delete-selected-btn {
    display: none;
}

.history-toggle-all-btn:disabled,
.history-delete-selected-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* History List */
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-item.active {
    background: var(--primary-glow);
    color: var(--primary);
    border: none;
}

.history-item.selected {
    background: var(--bg-hover);
    border: 1px solid var(--accent);
}

.history-content {
    flex: 1;
    overflow: hidden;
}

.history-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
}

.history-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: var(--danger);
    background: hsla(0, 72%, 51%, 0.1);
}

.history-checkbox {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.history-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
}

.history-checkbox span {
    font-size: 12px;
    line-height: 1;
}

/* User Profile in Sidebar */
.user-profile {
    padding: 1rem 1.25rem;
    border-top: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--sidebar-bg);
    margin-bottom: env(safe-area-inset-bottom, 0);
    /* Handle notches/bars */
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
}

/* PDF Upload Modal Buttons */
.modal-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-cancel {
    flex: 1;
    padding: 0.875rem 1.5rem;
    background: hsla(230, 15%, 20%, 0.4);
    color: var(--text-secondary);
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-cancel:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.btn-confirm {
    flex: 1;
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-confirm:active {
    transform: translateY(0);
}

/* Mobile adjustments for modal buttons */
@media (max-width: 480px) {
    .modal-buttons {
        flex-direction: column;
    }

    .btn-cancel,
    .btn-confirm {
        width: 100%;
    }
}

/* Light theme modal buttons */
[data-theme='light'] .btn-cancel {
    background: hsl(230, 15%, 92%);
    color: hsl(230, 15%, 35%);
}

[data-theme='light'] .btn-cancel:hover {
    background: hsl(230, 15%, 85%);
    color: var(--accent);
}

[data-theme='light'] .modal-content h3,
[data-theme='light'] .modal-content p {
    color: hsl(230, 25%, 15%);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* Background Glow Effects */
.chat-main::before {
    content: '';
    position: absolute;
    top: -10%;
    left: 20%;
    transform: translateX(-50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, hsla(217, 91%, 60%, 0.12) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
    filter: blur(60px);
}

.chat-main::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(hsla(217, 91%, 60%, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, hsla(217, 91%, 60%, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.8;
}

/* Light theme chat canvas */
[data-theme='light'] .chat-main {
    background: linear-gradient(135deg,
            hsl(240, 20%, 97%) 0%,
            hsl(245, 20%, 95%) 50%,
            hsl(240, 20%, 97%) 100%);
}

/* Header (Mobile mostly, or Top Bar) */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    height: 60px;
    border-bottom: 1px solid var(--border);
    background: var(--glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
}

[data-theme='light'] .header {
    background: hsla(0, 0%, 100%, 0.8);
    border-bottom: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.header-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Premium Language Selector Dropdown */
.language-dropdown {
    position: relative;
    z-index: 1100;
}

.lang-current {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(12px);
}

.lang-current:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dropdown-arrow {
    transition: transform 0.3s ease;
    opacity: 0.6;
}

.lang-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 160px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 0.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(24px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.lang-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-item {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.lang-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.lang-item.active {
    color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

/* Light theme adjustments */
[data-theme='light'] .lang-current {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.05);
}

[data-theme='light'] .lang-current:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme='light'] .lang-menu {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.05);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

[data-theme='light'] .lang-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme='light'] .lang-item.active {
    background: rgba(99, 102, 241, 0.05);
}

@media(max-width: 768px) {
    .header-actions {
        gap: 8px;
    }

    .user-profile {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .user-info {
        max-width: calc(100% - 100px);
        /* Leave room for buttons */
    }

    .logout-btn,
    .theme-toggle,
    .settings-btn {
        flex-shrink: 0;
    }

    /* .header is already display: flex globally */

    .logo-text {
        font-size: 1rem;
    }
}

.hamburger-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
}

.hamburger-btn:hover {
    background: var(--bg-hover);
}

.logo-text {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

/* Messages Area */
/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: hsla(230, 15%, 30%, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: hsla(230, 15%, 40%, 0.5);
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    scroll-behavior: smooth;
    width: 100%;
}

/* Gemini-style centered content area */
.chat-container>* {
    max-width: 800px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 900px) {
    .chat-container {
        padding: 1rem;
        gap: 1.5rem;
    }

    .chat-container>* {
        max-width: 100%;
    }
}

.message,
.welcome {
    width: 100%;
}

.welcome {
    text-align: center;
    margin-top: 4rem;
    animation: fadeIn 0.5s ease-out;
}

.welcome h1 {
    font-family: var(--font-display);
    font-size: 2.75rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #a5b4fc 0%, #c4b5fd 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

/* Lexo branding in welcome */
.welcome h1 .logo-lex {
    background: linear-gradient(135deg, #ffffff 0%, #e0e7ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome h1 .logo-o {
    background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Light theme Lexo branding */
[data-theme='light'] .welcome h1 .logo-lex {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme='light'] .welcome h1 .logo-o {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome p {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto 2rem;
    position: relative;
    z-index: 1;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.suggestion {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.suggestion:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 100%;
    animation: messageEntry 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageEntry {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-role-label {
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 2px;
}

.message.user .message-role-label {
    color: var(--foreground);
    opacity: 0.7;
    align-self: flex-end;
    margin-right: 8px;
}

.message.user {
    align-items: flex-end;
}

.message-content {
    font-size: 1rem;
    line-height: 1.6;
    max-width: fit-content;
    position: relative;
    font-family: var(--font-main);
}

.message.assistant .message-content {
    color: var(--foreground);
    background: transparent;
    padding: 0;
    border: none;
    max-width: 100%;
}

.message.user .message-content {
    background: var(--bubble-user);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 18px 18px 2px 18px;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.2);
    font-weight: 500;
}

.message-avatar {
    display: none;
}

/* Streaming cursor indicator */
.message-content.is-streaming::after {
    content: '▊';
    animation: blink 1s step-end infinite;
    color: var(--accent);
    margin-left: 2px;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Copy button - only visible on hover for clean UI */
.message-actions {
    position: absolute;
    top: 0;
    right: 0;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 8px;
    z-index: 10;
}

.message-body {
    position: relative;
}

.message-body:hover .message-actions {
    opacity: 1;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* User text links/markdown should be white */
.message.user .message-content a {
    color: white;
    text-decoration: underline;
}

/* Markdown Styles in Assistant - Gemini-like typography */
.message-content h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.message-content h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

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

.message-content p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

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

.message-content ul,
.message-content ol {
    margin-left: 1.25rem;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.message-content li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

/* Strong/Bold */
.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

/* Links */
.message-content a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.message-content a:hover {
    border-bottom-color: var(--accent);
}

.message-content code {
    background: rgba(99, 102, 241, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
    color: var(--accent);
}

.message-content pre {
    background: hsl(230, 20%, 12%);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    word-wrap: break-word;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--border);
    max-width: 100%;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: var(--text-primary);
}

/* Gemini-style blockquotes */
.message-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.05);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}

/* Premium Citation Cards */
.citation-container {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.citation-header {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.citation-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.citation-card {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    max-width: 100%;
}

.citation-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.citation-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Typing Indicator */
.typing {
    display: flex;
    gap: 0.3rem;
    padding: 0.5rem 0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Input Area - Seamless design */
.input-container {
    padding: 1rem 2rem;
    background: transparent;
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

[data-theme='light'] .input-container {
    background: transparent;
}

.mode-tabs-container {
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    width: 100%;
}

.input-wrapper {
    width: 100%;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-end;
    box-shadow: var(--shadow-luxe);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.input-wrapper:focus-within {
    background: var(--bg-surface);
    border-color: var(--primary);
    box-shadow: 0 8px 30px hsla(217, 91%, 60%, 0.15);
}

.btn-attach {
    background: none;
    border: none;
    padding: 10px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

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

/* Upload Menu Dropdown */
.attach-container {
    position: relative;
}

.upload-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    min-width: 260px;
    background: hsl(225, 22%, 14%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 6px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: all 0.2s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

[data-theme='light'] .upload-menu {
    background: hsl(0, 0%, 100%);
    border: 1px solid hsl(230, 15%, 90%);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.upload-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.upload-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.upload-menu-item:hover {
    background: var(--bg-hover);
}

.upload-menu-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.upload-menu-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.upload-menu-label {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-menu-formats {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.upload-menu-divider {
    height: 1px;
    background: var(--bg-hover);
    margin: 4px 12px;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    padding: 10px;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: inherit;
    max-height: 200px;
    outline: none;
}

textarea::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--bubble-user);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-send:hover {
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 8px 24px var(--primary-glow);
}

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

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* Light theme input styling */
[data-theme='light'] .input-wrapper {
    background: hsla(230, 20%, 96%, 0.9);
    border: 1px solid var(--border);
}

[data-theme='light'] .input-wrapper:focus-within {
    background: hsla(0, 0%, 100%, 0.95);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px hsla(239, 84%, 67%, 0.1);
}

/* Citations */
.citation-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: none;
}

.citation-header {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.citation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.8rem;
}

.citation-card {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    padding: 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.citation-card:hover {
    background: rgba(0, 0, 0, 0.3);
}

.citation-type {
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 2px;
}

.citation-title {
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive Sidebar */
@media(max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 80%;
        max-width: 300px;
    }

    .chat-sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 45;
        /* Lower than sidebar (50) */
    }

    .sidebar-overlay.active {
        display: block;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: hsl(230, 20%, 14%);
    border: 1px solid hsla(230, 20%, 30%, 0.3);
    border-radius: 24px;
    padding: 2rem;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h3 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

[data-theme='light'] .modal-content {
    background: hsl(0, 0%, 100%);
    border: 1px solid hsla(230, 15%, 85%, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: none;
    padding-bottom: 1rem;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.settings-section {
    margin-bottom: 1.5rem;
}

.settings-section label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.settings-value {
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--background);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.settings-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Upgrade Modal Specifics */
.upgrade-modal {
    text-align: center;
}

.upgrade-modal .modal-icon {
    font-size: 48px;
    margin-bottom: 20px;
    display: inline-block;
    animation: bounce 2s infinite;
}

.upgrade-modal h2 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.upgrade-modal p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Upgrade Modal Buttons */
.upgrade-btn {
    width: 100%;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px var(--accent-glow);
    margin-bottom: 0.75rem;
}

.upgrade-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.dismiss-btn {
    width: 100%;
    padding: 1rem 2rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.dismiss-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

/* Disclaimer Toast */
.disclaimer-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 450px;
    background: hsl(230, 20%, 14%);
    border: 1px solid hsla(230, 20%, 30%, 0.3);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: none;
}

[data-theme='light'] .disclaimer-toast {
    background: hsl(0, 0%, 100%);
    border: 1px solid hsl(230, 15%, 88%);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

.disclaimer-content {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem;
    position: relative;
}

.disclaimer-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.disclaimer-text-container {
    flex: 1;
}

.disclaimer-title {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.disclaimer-body {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.disclaimer-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.disclaimer-close:hover {
    color: var(--text-primary);
}

@keyframes slideInUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}


[data-theme='light'] {
    --background: hsl(225, 15%, 97%);
    --foreground: hsl(225, 25%, 12%);
    --card-bg: hsl(0, 0%, 100%);
    --text-primary: hsl(225, 25%, 12%);
    --text-secondary: hsl(225, 15%, 35%);
    --text-muted: hsl(225, 10%, 50%);
    --accent: hsl(239, 84%, 62%);
    --accent-dark: hsl(243, 75%, 50%);
    --border: hsl(225, 15%, 88%);
    --input-bg: hsl(225, 15%, 94%);
    /* Specific to chat */
    --msg-user-bg: hsl(239, 84%, 62%);
    --msg-user-text: white;
    --msg-ai-bg: hsl(0, 0%, 100%);
}

/* Message Actions (BELOW Content) */
.message-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: flex-end;
    /* Align right to stay out of the way */
    gap: 0.5rem;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

/* Enable pointer events on the button itself */
.action-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

/* Mobile: Always show */
@media (max-width: 768px) {
    .message-actions {
        opacity: 1;
    }
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.copy-btn svg {
    opacity: 0.8;
}

.copy-btn:hover svg {
    opacity: 1;
}

/* Tooltip Styles */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    padding: 14px 20px;
    /* 50% mer padding */
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    /* Litet större border-radius */
    font-size: 0.9rem;
    /* Lite större text också */

    white-space: normal;
    max-width: 420px;
    /* 50% mer än 280px */
    min-width: 200px;
    /* 50% mer än 150px */
    text-align: center;
    word-wrap: break-word;
    line-height: 1.4;
    /* Lite mer radavstånd */

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1000;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    /* Djupare skugga */
}

[data-tooltip]::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(2px);
    border: 6px solid transparent;
    border-bottom-color: var(--border-color);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 999;
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(4px);
}

/* Mobile: Disable tooltips */
@media (max-width: 768px) {

    [data-tooltip]::before,
    [data-tooltip]::after {
        display: none;
    }
}

/* ========================================
   FILE UPLOAD CARDS - Premium Style
   ======================================== */

#file-status {
    margin-top: 12px;
    margin-bottom: 12px;
}

.upload-cards-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideIn 0.3s ease-out;
}

.upload-card {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    background: hsl(230, 20%, 14%);
    border: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    animation: cardSlideIn 0.3s ease-out;
}

/* Success - subtle accent tint */
.upload-card.success {
    background: hsl(230, 20%, 14%);
}

.upload-card.error {
    background: hsl(230, 20%, 14%);
}

.upload-card.uploading {
    background: hsl(230, 20%, 14%);
}

.upload-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 14px;
}

/* Success icon - accent/purple instead of green */
.upload-icon.success {
    background: hsla(239, 84%, 67%, 0.15);
    color: var(--accent);
    animation: checkmarkPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.upload-icon.error {
    background: hsla(38, 92%, 50%, 0.15);
    color: hsl(38, 92%, 50%);
    animation: shake 0.4s ease;
}

.upload-icon.uploading {
    background: hsla(239, 84%, 67%, 0.15);
    color: var(--accent);
}

.upload-details {
    flex: 1;
    min-width: 0;
}

.upload-filename {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.upload-file-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.25rem;
}

.upload-file-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.upload-file-icon {
    flex-shrink: 0;
    font-size: 0.75rem;
    line-height: 1;
}

.upload-file-name {
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-message {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.upload-message.error {
    color: hsl(38, 80%, 55%);
}

.upload-message.success {
    color: var(--text-secondary);
}

/* Spinner for uploading state */
.upload-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Personal error message styling */
.upload-error-note {
    margin-top: 12px;
    padding: 12px 16px;
    background: hsl(230, 20%, 14%);
    border-left: 3px solid hsl(38, 92%, 50%);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.upload-error-note strong {
    color: hsl(38, 80%, 55%);
    font-weight: 600;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes checkmarkPop {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

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

/* Upload Privacy Notice & Action Buttons - Seamless */
.upload-privacy-notice {
    margin: 0.5rem 0;
    padding: 0.5rem 0;
    background: transparent;
    border: none;
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.upload-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.doc-action-btn {
    padding: 0.6rem 0.75rem;
    background: hsla(230, 20%, 16%, 0.5);
    border: none;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-family: inherit;
}

.doc-action-btn:hover {
    background: hsla(239, 84%, 67%, 0.12);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.doc-action-btn:active {
    transform: translateY(0);
}

/* Light theme adjustments */
[data-theme='light'] .upload-privacy-notice {
    background: rgba(99, 102, 241, 0.05);
    border-color: rgba(99, 102, 241, 0.15);
}

[data-theme='light'] .doc-action-btn {
    background: hsla(230, 20%, 92%, 0.8);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

[data-theme='light'] .doc-action-btn:hover {
    background: hsla(239, 84%, 67%, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}

/* Light theme adjustments for upload cards */
[data-theme='light'] .upload-card.success {
    background: hsl(0, 0%, 97%);
    border: none;
}

[data-theme='light'] .upload-card.error {
    background: hsl(0, 0%, 97%);
    border: none;
}

[data-theme='light'] .upload-card {
    background: hsl(0, 0%, 97%);
}

[data-theme='light'] .upload-error-note {
    background: hsl(0, 0%, 97%);
    color: hsl(230, 15%, 35%);
}

[data-theme='light'] .upload-icon.success {
    background: hsla(239, 84%, 67%, 0.12);
}

[data-theme='light'] .upload-icon.error {
    background: hsla(38, 92%, 50%, 0.12);
}

[data-theme='light'] .btn-confirm {
    background: transparent;
    color: var(--foreground);
    box-shadow: none;
}

/* RTL support for Arabic */
.rtl .upload-actions {
    direction: rtl;
}

.rtl .doc-action-btn {
    text-align: right;
}

/* Mobile: stack buttons vertically */
@media (max-width: 480px) {
    .upload-actions {
        grid-template-columns: 1fr;
        width: 100%;
        overflow: visible;
    }

    .doc-action-btn {
        width: 100%;
        overflow: visible;
        white-space: normal;
        word-break: break-word;
    }
}

/* Ensure upload containers don't clip on mobile */
@media (max-width: 768px) {
    .upload-cards-container {
        width: 100%;
        overflow: visible;
    }

    .upload-card {
        align-items: flex-start;
    }

    .upload-file-name {
        max-width: 100%;
    }

    .upload-actions {
        width: 100%;
        overflow: visible;
    }
}

/* ========================================
   DOCUMENT-STYLE FORMATTING FRAMEWORK
   ======================================== */

/* Message formatting */
.message.assistant {
    padding-bottom: 2rem;
    border: none;
}

.message.assistant:last-of-type {
    padding-bottom: 1rem;
}

/* ========================================
   BLOCKQUOTES & LEGAL CITATIONS
   ======================================== */

.message-content blockquote {
    background: hsla(239, 60%, 55%, 0.06);
    border-left: 3px solid var(--accent);
    padding: 1rem 1.5rem;
    margin: 1.25rem 0;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--text-secondary);
}

.message-content blockquote cite {
    display: block;
    margin-top: 0.5rem;
    font-style: normal;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
}

/* Legal citation styling */
.legal-cite {
    background: hsla(152, 69%, 45%, 0.06);
    border-left: 3px solid var(--success);
    padding: 1rem 1.5rem;
    margin: 1.25rem 0;
    border-radius: 0 8px 8px 0;
}

.legal-cite .case-number {
    font-weight: 600;
    color: var(--success);
    font-size: 0.9rem;
}

.legal-cite .excerpt {
    font-style: italic;
    margin-top: 0.5rem;
}

/* ========================================
   ALERTS & CALLOUTS
   ======================================== */

.alert {
    padding: 1rem 1.25rem;
    border-radius: 10px;
    margin: 1.25rem 0;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: 0.9rem;
}

.alert .icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.alert.info {
    background: hsla(199, 89%, 48%, 0.08);
    border: none;
}

.alert.tip {
    background: hsla(280, 70%, 60%, 0.08);
    border: none;
}

.alert.warning {
    background: hsla(38, 92%, 50%, 0.08);
    border: none;
}

.alert.success {
    background: hsla(152, 69%, 45%, 0.08);
    border: none;
}

.alert.danger {
    background: hsla(0, 72%, 51%, 0.08);
    border: none;
}

/* ========================================
   TABLES
   ======================================== */

.message-content .table-wrapper {
    margin: 1.25rem 0;
    border-radius: 10px;
    overflow: hidden;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
}

.message-content th {
    background: hsla(230, 20%, 15%, 0.8);
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--foreground);
    font-size: 0.85rem;
}

.message-content td {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.message-content tr:hover td {
    background: hsla(239, 60%, 55%, 0.03);
}

/* ========================================
   ACTION BUTTONS (Copy, Like, Dislike)
   ======================================== */

.ai-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 1.5rem;
    padding-top: 1rem;
}

.ai-actions .action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ai-actions .action-btn:hover {
    background: hsla(230, 20%, 20%, 0.6);
    color: var(--text-primary);
}

.ai-actions .action-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.ai-actions .action-btn.liked {
    color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
}

.ai-actions .action-btn.disliked {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* ========================================
   TIMELINE
   ======================================== */

.timeline {
    margin: 1.5rem 0;
    padding-left: 1.5rem;
    border-left: 2px solid var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.6rem;
    top: 0.3rem;
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
}

.timeline-item.done::before {
    background: var(--success);
}

.timeline-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ========================================
   COMPARISON (Side by side)
   ======================================== */

.comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 1.25rem 0;
}

.comparison-item {
    background: hsla(230, 20%, 12%, 0.3);
    border-radius: 10px;
    padding: 1rem;
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.comparison-item.good {
    background: hsla(152, 69%, 45%, 0.08);
}

.comparison-item.bad {
    background: hsla(0, 72%, 51%, 0.08);
}

@media (max-width: 600px) {
    .comparison {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   COLLAPSIBLE / FAQ
   ======================================== */

.message-content details {
    margin: 1rem 0;
    background: hsla(230, 20%, 12%, 0.3);
    border: none;
    border-radius: 8px;
}

.message-content summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--foreground);
}

.message-content summary:hover {
    background: hsla(239, 60%, 55%, 0.05);
}

.message-content details[open] summary {
    border-bottom: 1px solid var(--border);
}

.message-content details>div {
    padding: 1rem;
}

/* ========================================
   STEP LIST (Numbered circles)
   ======================================== */

.steps {
    counter-reset: step;
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.steps li {
    counter-increment: step;
    display: flex;
    gap: 12px;
    margin-bottom: 1rem;
    align-items: flex-start;
}

.steps li::before {
    content: counter(step);
    min-width: 26px;
    height: 26px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

/* ========================================
   KEYBOARD SHORTCUTS
   ======================================== */

.message-content kbd {
    background: hsla(230, 20%, 18%, 0.8);
    border: none;
    border-radius: 4px;
    padding: 0.15em 0.4em;
    font-family: 'SF Mono', monospace;
    font-size: 0.8em;
}

/* ========================================
   FORMULA / MATH
   ======================================== */

.formula {
    background: hsla(230, 20%, 12%, 0.5);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin: 1.25rem 0;
    font-family: 'Times New Roman', serif;
    font-size: 1.1rem;
    text-align: center;
    color: var(--foreground);
}

/* ========================================
   HORIZONTAL RULE
   ======================================== */

.message-content hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 2rem 0;
}

/* ===========================================
   RTL (Right-to-Left) Support for Arabic
   Text direction only - layout stays LTR
   =========================================== */

body.rtl .message-content,
body.rtl .assistant-message .message-content {
    text-align: right;
    direction: rtl;
}

/* User messages - keep bubble on right */
body.rtl .user-message .message-content {
    text-align: right;
    direction: rtl;
}

/* Welcome text */
body.rtl .welcome-title,
body.rtl .welcome-subtitle {
    text-align: right;
    direction: rtl;
}

/* Input field */
body.rtl #userInput,
body.rtl .chat-textarea {
    text-align: right;
    direction: rtl;
}

/* Suggestion cards text */
body.rtl .suggestion-text {
    text-align: right;
    direction: rtl;
}

/* Sidebar content */
body.rtl .sidebar-content h3,
body.rtl .sidebar-content p {
    text-align: right;
    direction: rtl;
}

/* History items */
body.rtl .history-item-title,
body.rtl .history-item-preview {
    text-align: right;
    direction: rtl;
}

/* Light theme - darker gradient for readability */
[data-theme='light'] .welcome h1 {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme='light'] .welcome p {
    color: #4b5563;
}

[data-theme='light'] .suggestion {
    background: rgba(79, 70, 229, 0.08);
    border: none;
    color: #1e1b4b;
}

[data-theme='light'] .suggestion:hover {
    background: rgba(79, 70, 229, 0.12);
}

/* Light mode - stronger text colors */
[data-theme='light'] .chat-input,
[data-theme='light'] textarea {
    color: #1e1b4b;
}

[data-theme='light'] .chat-input::placeholder,
[data-theme='light'] textarea::placeholder {
    color: #6b7280;
}

[data-theme='light'] .history-item-title {
    color: #1e1b4b;
}

[data-theme='light'] .history-item-preview {
    color: #4b5563;
}

[data-theme='light'] .sidebar-content h3,
[data-theme='light'] .sidebar h3 {
    color: #1e1b4b;
}

[data-theme='light'] .sidebar-content p {
    color: #4b5563;
}

[data-theme='light'] .input-wrapper {
    background: rgba(255, 255, 255, 0.8);
    border: none;
}

[data-theme='light'] .input-actions button,
[data-theme='light'] .send-btn {
    color: #4f46e5;
}

[data-theme='light'] .quota-display,
[data-theme='light'] .usage-stats {
    color: #4b5563;
}

/* ===================================
   Input Container - Gemini Edge-to-Edge Design
   =================================== */
.input-container {
    padding: 1rem 0;
    background: transparent;
    border-top: none;
    position: relative;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    min-height: 60px;
}

.input-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    padding: 4px 0;
    min-height: 32px;
    max-height: 200px;
    font-family: inherit;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.btn-attach {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-attach:hover {
    color: var(--accent);
    background: var(--bg-hover);
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.5rem 0 1rem;
    background: transparent;
    border: none;
}

/* Canvas Panel (Split View - Phase 3) */
.canvas-panel {
    width: 0;
    min-width: 0;
    max-width: 0;
    flex: 0 0 0;
    background: var(--bg-canvas);
    border-left: 1px solid rgba(255, 255, 255, 0.03);
    /* Subtle separator */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        min-width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        max-width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        flex 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.3s ease,
        visibility 0s 0.5s;
    position: relative;
    z-index: 60;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.3);
    /* Stronger shadow for depth */
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

.canvas-panel.active {
    width: 45%;
    max-width: 900px;
    min-width: 450px;
    flex: 0 0 45%;
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transition-delay: 0s;
}

.canvas-panel.fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    max-width: 100vw !important;
    min-width: 100vw !important;
    height: 100vh !important;
    z-index: 1000;
    background: var(--background);
    flex: none;
}

.canvas-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem 0 2.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(15, 23, 42, 0.3);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.canvas-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.canvas-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--glass);
    color: var(--text-primary);
}

.canvas-action-btn:hover {
    background: var(--bg-surface);
    transform: translateY(-1px);
}

.canvas-action-btn.premium-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.canvas-action-btn.premium-btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.canvas-close-luxe {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 8px;
}

.canvas-close-luxe:hover {
    background: hsla(0, 0%, 100%, 0.1);
    color: var(--foreground);
    transform: rotate(90deg);
}

/* Mobile Canvas Overhaul - Full Overlay */
@media (max-width: 900px) {
    .hide-mobile {
        display: none !important;
    }

    .lexo-document {
        padding: 2.5rem 1.5rem !important;
    }

    .canvas-panel.active {
        position: fixed;
        inset: 0;
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 100vw !important;
        height: 100vh !important;
        z-index: 2000;
        background: var(--background);
        border: none;
    }

    .canvas-header {
        height: 80px;
        padding: 0 1.5rem;
    }
}


/* Dynamic Canvas Components */
.canvas-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--bg-canvas);
    scrollbar-gutter: stable;
    position: relative;
}

.canvas-content::before {
    content: '';
    position: fixed;
    top: 50%;
    right: 0;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle at center, hsla(239, 84%, 67%, 0.05) 0%, transparent 70%);
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 0;
}

/* Premium Document Formatting (Lexo Standard) */
.lexo-document {
    padding: 3.5rem 4.5rem;
    max-width: 850px;
    margin: 0 auto;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.7;
    color: var(--text-primary);
    background: transparent;
    word-wrap: break-word;
    position: relative;
    z-index: 1;
}

.canvas-empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2.5rem;
    color: var(--text-muted);
}

.canvas-empty-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 2rem;
    color: var(--primary);
    opacity: 0.5;
    filter: drop-shadow(0 0 15px var(--primary-glow));
    animation: floatIcon 4s ease-in-out infinite;
}

.canvas-empty-state p {
    font-size: 1.1rem;
    font-weight: 500;
    max-width: 300px;
    line-height: 1.6;
    font-family: 'Inter', sans-serif;
}

.lexo-document h1 {
    font-family: var(--font-display);
    font-size: 2.2rem;
    text-align: center;
    color: var(--primary);
    margin: 1rem 0 3rem 0;
    font-weight: 800;
    border-bottom: 2px solid var(--primary-glow);
    padding-bottom: 1.5rem;
}

.lexo-document h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--foreground);
    margin: 2.5rem 0 1rem 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-left: 4px solid var(--primary);
    padding-left: 1rem;
}

.lexo-document h3 {
    font-size: 1.1rem;
    color: var(--primary);
    margin: 1.5rem 0 0.5rem 0;
    font-weight: 600;
}

.lexo-document p {
    margin-bottom: 1.2rem;
    font-size: 1rem;
    opacity: 0.95;
    letter-spacing: -0.01em;
}

/* Legal Lists and Indentation */
.lexo-document ul,
.lexo-document ol {
    margin: 1.25rem 0;
    padding-left: 2rem;
}

.lexo-document li {
    margin-bottom: 0.6rem;
    padding-left: 0.5rem;
}

.lexo-document b,
.lexo-document strong {
    color: var(--foreground);
    font-weight: 600;
}

.lexo-document hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--glass), transparent);
    margin: 3rem 0;
}

/* Fix for form fields and underscore spacing */
.lexo-document p:contains("____") {
    letter-spacing: -1px !important;
}

.lexo-document blockquote {
    border-left: 4px solid var(--primary-glow);
    padding: 1.2rem 2rem;
    background: var(--glass);
    border-radius: 8px;
    margin: 2rem 0;
    font-style: italic;
    color: var(--text-secondary);
}

@keyframes skeleton-shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.canvas-badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--primary-glow);
    color: var(--primary);
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.canvas-excerpt {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--foreground);
    margin-bottom: 2rem;
    white-space: pre-wrap;
}

.canvas-actions {
    display: flex;
    gap: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.canvas-btn {
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.canvas-btn.outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

.canvas-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

/* Artifact Cards (Phase 6: Visual Trigger) */
.artifact-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem;
    background: hsla(225, 20%, 20%, 0.3);
    border: none !important;
    border-radius: 16px;
    pointer-events: auto !important;
    margin: 1rem 0;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    /* No transforms to prevent flicker */
    position: relative;
    overflow: hidden;
    max-width: 440px;
    flex-shrink: 0;
    -webkit-transform: translateZ(0);
    /* Force GPU */
    transform: translateZ(0);
    backface-visibility: hidden;
    flex-shrink: 0;
}

.artifact-card:hover {
    background: hsla(225, 20%, 25%, 0.6);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* Removed ::before light effect to prevent flicker as requested */

.artifact-icon {
    width: 48px;
    height: 48px;
    background: var(--primary-glow);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.artifact-info {
    flex: 1;
    min-width: 0;
}

.artifact-title {
    font-weight: 600;
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artifact-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.pulse-dot {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0% {
        transform: scale(0.95);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.5;
    }
}

.pulse-dot.streaming {
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary-glow);
    animation: pulse-dot-streaming 0.8s infinite alternate;
}

@keyframes pulse-dot-streaming {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1);
    }

    100% {
        transform: scale(1.4);
        opacity: 0.7;
        filter: brightness(1.5);
    }
}

.artifact-preview-btn {
    padding: 6px 12px;
    background: var(--glass);
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    border: none;
    margin-top: 8px;
    display: inline-flex;
}

[data-theme='light'] .artifact-card {
    background: #f0f4f8;
    border: none;
}

[data-theme='light'] .artifact-card .artifact-title {
    color: var(--foreground);
}

/* ===================================
   Frame Flatten Override
   Keep chat surface visually continuous
   =================================== */
.chat-main {
    max-width: none !important;
    margin: 0 !important;
}

.header {
    background: transparent !important;
    border-bottom: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

.input-container {
    background: transparent !important;
    border-top: none !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.75rem !important;
}

.input-wrapper {
    background: rgba(255, 255, 255, 0.04) !important;
    border: none !important;
    border-radius: 14px !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18) !important;
    padding: 10px 12px !important;
}

.input-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.06) !important;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25), 0 8px 22px rgba(0, 0, 0, 0.22) !important;
    border-color: transparent !important;
}

.input-wrapper textarea::placeholder {
    color: rgba(226, 232, 240, 0.65) !important;
}

[data-theme='light'] .input-wrapper {
    background: rgba(255, 255, 255, 0.9) !important;
    border: none !important;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08) !important;
}

[data-theme='light'] .input-wrapper:focus-within {
    background: #ffffff !important;
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2), 0 8px 20px rgba(15, 23, 42, 0.12) !important;
    border-color: transparent !important;
}

[data-theme='light'] .input-wrapper textarea::placeholder {
    color: rgba(51, 65, 85, 0.55) !important;
}
