/* ============================================================
   SEO landing header — visible to crawlers/screen readers,
   visually hidden to sighted users (the chat UI is the real UX).
   This is intentionally NOT display:none so search engines index it.
   ============================================================ */
.seo-skip-link {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}
.seo-skip-link:focus {
    left: 8px;
    top: 8px;
    width: auto;
    height: auto;
    background: #1f2937;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    z-index: 10000;
    text-decoration: none;
}

.seo-landing {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
}
.seo-landing-title,
.seo-landing-tagline,
.seo-landing-links,
.seo-landing-brand {
    margin: 0;
}

.login-section {
    margin-bottom: 15px;
}

.login-section input {
    width: 100%;
    padding: 6px;
    margin-bottom: 5px;
}

.login-section button {
    width: 100%;
    padding: 6px;
    background: #2563eb;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 4px;
}

.user-info {
    margin-top: 5px;
    font-size: 12px;
    color: #ccc;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #fff;
}

/* Softer taps, consistent micro-interactions */
button,
a,
input,
textarea,
select,
.sidebar-toggle,
[role="button"] {
    -webkit-tap-highlight-color: transparent;
}

.layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    max-height: 100vh;
    max-height: 100dvh;
}

.sidebar {
    width: 260px;
    max-width: 100%;
    background: #1f2937;
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: none;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
    box-sizing: border-box;
}

.sidebar h2 {
    margin-bottom: 15px;
}

.sidebar button {
    padding: 10px 14px;
    margin-bottom: 10px;
    border: none;
    background: #2563eb;
    color: white;
    cursor: pointer;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.22s ease, transform 0.12s ease, box-shadow 0.22s ease;
}

.sidebar button:active {
    transform: scale(0.98);
}

/* Help + blog links under profile (before DocuMind title) */
.sidebar-top-links {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin: 14px 0 10px;
}

.sidebar-top-links .sidebar-how-link {
    margin: 0;
}

.sidebar-how-link {
    display: block;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: #9ca3af;
    text-decoration: none;
    margin: 14px 0 14px;
    transition: color 0.15s ease;
}

.sidebar-how-link:hover {
    color: #e5e7eb;
    text-decoration: underline;
}

.section {
    margin-top: 15px;
}

.section h4 {
    margin-bottom: 5px;
    font-size: 14px;
}

.section ul {
    list-style: none;
    padding: 0;
    font-size: 13px;
}

.section li {
    background: #374151;
    padding: 5px;
    margin-bottom: 5px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section li button {
    font-size: 10px;
    padding: 2px 5px;
}

/* Chat list item: name + 3-dot menu (visible on hover) */
.chat-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    cursor: pointer;
    border-radius: 6px;
    transition: box-shadow 0.2s ease, background 0.2s ease;
}

.section li.chat-list-item-active,
.chat-list-item.chat-list-item-active {
    background: rgba(37, 99, 235, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.chat-name-wrap {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-name-text {
    cursor: pointer;
}

.chat-item-actions {
    flex-shrink: 0;
    position: relative;
}

.chat-menu-btn {
    opacity: 0;
    padding: 2px 6px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.chat-list-item:hover .chat-menu-btn {
    opacity: 1;
}

.chat-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.chat-menu-dropdown {
    display: block;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 2px;
    min-width: 100px;
    padding: 4px 0;
    background: #1f2937;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.chat-menu-dropdown.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.chat-menu-rename {
    display: block;
    width: 100%;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: white;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.chat-menu-rename:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-name-edit {
    width: 100%;
    padding: 2px 4px;
    font-size: inherit;
    color: #1f2937;
    background: #fff;
    border: 1px solid #2563eb;
    border-radius: 4px;
    outline: none;
}

/* Document list items: name + remove cross (below upload) */
.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.doc-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-remove-btn {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: rgba(220, 38, 38, 0.2);
    color: #fca5a5;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.doc-remove-btn:hover {
    background: #dc2626;
    color: #fff;
}

.sidebar .doc-remove-btn {
    background: rgba(220, 38, 38, 0.25);
    color: #fca5a5;
}

.sidebar .doc-remove-btn:hover {
    background: #dc2626;
    color: #fff;
}

/* Documents uploaded N - single toggle, expand to show list */
.documents-block {
    margin-top: 8px;
}

.company-doc-hint {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
    margin: 8px 0 0;
    line-height: 1.4;
}

.company-show-count-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
}

.company-show-count-wrap input[type="checkbox"] {
    cursor: pointer;
}

.company-doc-count-employee {
    font-weight: 500;
    color: rgba(255, 255, 255, 0.95);
}

.documents-toggle {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 8px 10px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.documents-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.documents-toggle:active {
    transform: scale(0.98);
}

.chat-docs-panel .documents-toggle {
    background: #fff;
    color: #334155;
    border-color: #e2e8f0;
}

.chat-docs-panel .documents-toggle:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.doc-list {
    list-style: none;
    padding: 0;
    margin: 4px 0 0 0;
    font-size: 13px;
    max-height: 180px;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    opacity: 1;
    transition: max-height 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease, margin-top 0.32s ease;
}

.doc-list-collapsed {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.doc-link {
    cursor: pointer;
    text-decoration: none;
    color: #93c5fd;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-link:hover {
    text-decoration: underline;
    color: #bfdbfe;
}

.chat-docs-list .doc-link {
    color: #2563eb;
}

.chat-docs-list .doc-link:hover {
    color: #1d4ed8;
}

.footer {
    margin-top: auto;
    font-size: 12px;
    padding-top: 10px;
    border-top: 1px solid #444;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ----- Mobile: sidebar overlay and toggle ----- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-mobile-top {
    display: block;
}

.sidebar-mobile-auth {
    display: block;
}

.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 1.5rem;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.sidebar-close:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0 8px 0 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.12s ease;
}

.sidebar-toggle:hover {
    background: rgba(0, 0, 0, 0.04);
}

.sidebar-toggle:active {
    transform: scale(0.96);
}

.sidebar-toggle-icon {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 5px;
    width: 22px;
    height: 18px;
}

.sidebar-toggle-line {
    display: block;
    width: 18px;
    height: 2px;
    background: #64748b;
    border-radius: 1px;
}

.sidebar-toggle-dot {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    background: #2563eb;
    border-radius: 50%;
}

/* Shown only on mobile; desktop keeps two lines + dot (toggle hidden ≥769px). */
.sidebar-toggle-line--third {
    display: none;
}

.sidebar-toggle:hover .sidebar-toggle-line {
    background: #475569;
}

@media (max-width: 768px) {
    html {
        height: 100%;
        height: 100dvh;
        height: -webkit-fill-available;
        overflow-x: hidden;
        width: 100%;
        max-width: 100%;
    }

    body {
        margin: 0;
        min-height: 100%;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
        overflow: hidden;
        overflow-x: hidden;
        overscroll-behavior: none;
        width: 100%;
        max-width: 100%;
    }

    .layout {
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        min-height: 0;
        overflow: hidden;
        overflow-x: hidden;
        max-width: 100%;
        width: 100%;
    }

    .main {
        min-width: 0;
        min-height: 0;
        flex: 1;
        overflow-x: hidden;
        overflow-y: hidden;
        display: flex;
        flex-direction: column;
    }

    #mainChatPanel {
        min-width: 0;
        min-height: 0;
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .chat-container {
        min-width: 0;
        min-height: 0;
        flex: 1;
        overflow: hidden;
    }

    .chat-container-inner {
        min-height: 0;
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .chat-container:not(.has-messages) .chat-area {
        flex: 1 1 0;
        min-height: 0;
        overflow: hidden;
    }

    .chat-container:not(.has-messages) .start-prompt {
        margin: auto 0 6px 0 !important;
        font-size: 0.875rem;
        line-height: 1.35;
        max-width: none;
        padding: 0 4px;
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .layout.sidebar-open .sidebar-overlay {
        pointer-events: auto;
        opacity: 1;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        max-width: 85vw;
        z-index: 101;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        box-sizing: border-box;
        overflow-x: hidden;
        overscroll-behavior-x: none;
        touch-action: pan-y;
    }

    .layout.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
    }

    .sidebar .section,
    .sidebar #documentSection {
        min-width: 0;
        max-width: 100%;
    }

    .sidebar .company-show-count-wrap {
        flex-wrap: wrap;
    }

    .sidebar .company-doc-hint,
    .sidebar .company-show-count-wrap span {
        overflow-wrap: anywhere;
    }

    .chat-name-edit {
        font-size: 16px;
    }

    .sidebar-toggle {
        display: flex !important;
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
        margin: 0 4px 0 0;
    }

    .sidebar-toggle-icon {
        width: 26px;
        height: 22px;
        gap: 6px;
    }

    .sidebar-toggle-line {
        width: 24px;
        height: 3px;
        border-radius: 2px;
    }

    .sidebar-toggle-dot {
        display: none !important;
    }

    .sidebar-toggle-line--third {
        display: block !important;
        position: static;
        transform: none;
        width: 24px;
        height: 3px;
        border-radius: 2px;
    }

    .sidebar-mobile-top {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .sidebar-mobile-auth {
        flex: 1;
        min-width: 0;
    }

    .profile-section .login-btn {
        width: auto;
        max-width: 110px;
        padding: 8px 12px;
        min-height: 38px;
        font-size: 13px;
    }

    /* --- Compact profile trigger on mobile (matches close × button visually) --- */
    .profile-section .profile-box {
        display: inline-block;
    }

    .profile-section .profile-trigger {
        width: auto;
        max-width: 100%;
        gap: 8px;
        padding: 4px 10px 4px 4px;
        min-height: 36px;
        border-radius: 999px;
    }

    .profile-section .profile-img {
        width: 28px;
        height: 28px;
        border-width: 1.5px;
    }

    .profile-section .profile-name {
        font-size: 12px;
        max-width: 110px;
    }

    .profile-section .profile-chevron {
        font-size: 9px;
    }

    .sidebar-close {
        display: flex !important;
        flex-shrink: 0;
    }

    .layout.sidebar-open .sidebar-close {
        display: flex !important;
    }

    /* Mobile: always show 3-dot menu (hover doesn't work on touch) */
    .chat-list-item .chat-menu-btn {
        opacity: 1;
    }

    /* Mobile: chatbox pinned in viewport; safe area for home indicator */
    .chat-container:not(.has-messages) .input-box {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        align-self: stretch !important;
        max-width: none !important;
        flex-shrink: 0;
    }

    /* Mobile: chatbox responsive – no overflow, Send button always visible */
    .chat-container .input-box {
        padding: 12px 10px max(12px, env(safe-area-inset-bottom));
        gap: 8px;
        min-width: 0;
        width: 100%;
        box-sizing: border-box;
        flex-shrink: 0;
    }

    .chat-container .input-box input {
        min-width: 0;
        flex: 1;
        font-size: 16px;
        line-height: 1.25;
    }

    .chat-container:not(.has-messages) .input-box input {
        font-size: 16px;
    }

    .chat-container .input-box button {
        flex-shrink: 0;
        padding: 12px 14px;
        white-space: nowrap;
    }

    /* iOS: avoid automatic zoom when focusing inputs (needs ≥16px) */
    .login-popup-input,
    #newAdminEmail,
    .db-search-input {
        font-size: 16px !important;
    }

    .api-keys-input {
        font-size: 16px;
    }

    .chat-container.has-messages .input-box {
        padding: 12px 10px max(12px, env(safe-area-inset-bottom));
    }

    .chat-container .chat-header {
        padding: max(8px, env(safe-area-inset-top)) 10px 10px;
        gap: 8px;
        min-width: 0;
        align-items: center;
        flex-wrap: nowrap;
        justify-content: flex-start;
    }

    /* Mobile header: menu (left) + doc / API actions (right); no chat title */
    .chat-container .chat-header .sidebar-toggle {
        align-self: center;
        flex-shrink: 0;
        background: transparent !important;
        border-radius: 8px;
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        margin: 0 2px 0 0;
        padding: 0;
    }

    .chat-container .chat-header .sidebar-toggle:hover,
    .chat-container .chat-header .sidebar-toggle:active,
    .chat-container .chat-header .sidebar-toggle:focus-visible {
        background: transparent !important;
    }

    .chat-container .chat-header .sidebar-toggle .sidebar-toggle-icon {
        width: 18px;
        height: 14px;
        gap: 3px;
    }

    .chat-container .chat-header .sidebar-toggle .sidebar-toggle-line,
    .chat-container .chat-header .sidebar-toggle .sidebar-toggle-line--third {
        width: 18px;
        height: 2px;
        border-radius: 1px;
    }

    .chat-container .chat-header .chat-header-brand {
        display: none !important;
    }

    .chat-container .chat-header .chat-docs-panel {
        align-self: center;
        margin-left: auto;
        margin-right: 0;
        flex: 0 0 auto;
        width: auto !important;
        min-width: 0 !important;
        max-width: calc(100% - 48px);
    }

    .chat-docs-panel {
        position: relative;
        width: auto !important;
        min-width: 0 !important;
        max-width: none;
        flex-shrink: 0;
        flex-grow: 0;
        padding: 0 !important;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }

    .chat-docs-panel-inner {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        flex-wrap: nowrap;
        gap: 8px;
        width: auto;
        max-width: 100%;
    }

    .chat-api-key-toolbar {
        display: flex;
        align-items: center;
        flex-shrink: 0;
    }

    .chat-docs-main {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        flex: 0 0 auto;
        min-width: 0;
    }

    .chat-docs-upload-toolbar-inner {
        position: relative;
        z-index: 64;
        display: flex;
        align-items: center;
    }

    .chat-api-key-toolbar-inner {
        position: relative;
        z-index: 65;
        display: flex;
        align-items: center;
    }

    /* Header actions: hide desktop SVG + long labels; show mobile icon + short copy */
    .chat-header-btn-icon-desktop,
    .chat-header-label-desktop {
        display: none !important;
    }

    .chat-header-label-mobile,
    .chat-header-api-emoji-mobile {
        display: inline !important;
    }

    .chat-header-btn-icon--mobile {
        display: block !important;
        width: 16px;
        height: 16px;
        flex-shrink: 0;
        color: #047857;
    }

    .chat-header-api-emoji-mobile {
        font-size: 13px;
        line-height: 1;
        vertical-align: -1px;
    }

    /*
     * Mobile header chips — readable, balanced touch targets, soft pill style.
     * (Large desktop styles are scoped to min-width 769px so these always apply on phones.)
     */
    .chat-docs-upload-trigger,
    .chat-api-key-trigger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        margin: 0;
        padding: 8px 14px;
        min-height: 36px;
        min-width: 0;
        box-sizing: border-box;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: -0.015em;
        line-height: 1.2;
        border-radius: 999px;
        border-style: solid;
        border-width: 1px;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
        transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
        gap: 6px;
    }

    .chat-docs-upload-trigger:active,
    .chat-api-key-trigger:active {
        transform: scale(0.98);
        box-shadow: 0 0 0 rgba(15, 23, 42, 0);
    }

    .chat-docs-upload-trigger {
        color: #047857;
        background: #ecfdf5;
        border-color: #6ee7b7;
    }

    .chat-docs-upload-trigger:hover {
        background: #d1fae5;
        border-color: #34d399;
    }

    .chat-api-key-trigger {
        color: #1d4ed8;
        background: #eff6ff;
        border-color: #93c5fd;
    }

    .chat-api-key-trigger:hover {
        background: #dbeafe;
        border-color: #60a5fa;
    }

    .chat-docs-upload-trigger:focus-visible,
    .chat-api-key-trigger:focus-visible {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
    }

    .chat-docs-panel .chat-docs-list li {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* Same full-width layout at start and after 1st message */
#mainChatPanel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 0;
    padding: 0;
}

.chat-container {
    width: 100%;
    max-width: 100%;
    flex: 1;
    align-self: stretch;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
    overflow: hidden;
    transition: max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1), max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-container-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 28px 24px;
    transition: padding 0.35s ease;
}

/* Start view: header at top, empty area, input at bottom (same width as after message) */
.chat-container:not(.has-messages) .chat-header {
    flex-shrink: 0;
}

.chat-container:not(.has-messages) .chat-area {
    flex: 1;
    min-height: 0;
}

.chat-container:not(.has-messages) .start-spacer {
    display: none;
}

.chat-container.has-messages .start-spacer {
    display: none;
}

/* Hint text above chatbox: show only before first message (before + after login) */
.start-prompt {
    display: none;
    margin: 0 0 -30px 0;
    font: apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    text-align: center;
    font-size: 18px;
    color: #060707;
    max-width: 420px;
    align-self: center;
}

.chat-container:not(.has-messages) .start-prompt {
    display: block;
}

.chat-container.has-messages .start-prompt {
    display: none;
}

.chat-container-inner {
    padding: 0;
    justify-content: flex-start;
}

@media (max-width: 768px) {
    .chat-container-inner {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* Start branding hidden so start screen matches chat layout (header + empty area + input) */
.start-branding {
    display: none;
}

.start-branding-title {
    margin: 0 0 8px 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.02em;
}

.start-branding-tagline {
    margin: 0;
    font-size: 0.9375rem;
    color: #64748b;
    line-height: 1.4;
}

/* Crawlable intro copy for search engines (visible, not keyword-hidden) */
.site-seo-footer {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex-shrink: 0;
    padding: 12px 20px 20px;
    max-width: 52rem;
    margin: 0 auto;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.site-seo-footer-copy {
    flex: 1;
    min-width: 0;
}

.site-seo-footer-text {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: #64748b;
}

.site-seo-footer-text--mobile {
    display: none;
}

.site-seo-footer-text--mobile .site-seo-footer-mobile-line1 {
    display: block;
}

.site-seo-footer-text--mobile .site-seo-footer-mobile-line2 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.15rem 0.5rem;
    margin-top: 0.2em;
}

.site-seo-footer-mobile-line2-lead {
    flex: 1 1 auto;
    min-width: 0;
}

.site-seo-footer-mobile-line2-links {
    flex: 0 0 auto;
    margin-left: auto;
    text-align: right;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .site-seo-footer {
        padding: 8px 12px 12px;
        gap: 6px;
    }

    .site-seo-footer-text--desktop {
        display: none;
    }

    .site-seo-footer-text--mobile {
        display: block;
        font-size: 0.75rem;
        line-height: 1.35;
    }

    .site-seo-footer-close {
        margin-top: -2px;
    }
}

.site-seo-footer-close {
    flex-shrink: 0;
    margin: -4px -6px 0 0;
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 1.35rem;
    line-height: 1.1;
    cursor: pointer;
    border-radius: 8px;
}

.site-seo-footer-close:hover {
    color: #475569;
    background: rgba(15, 23, 42, 0.06);
}

.site-seo-footer-close:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.site-seo-footer a {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.site-seo-footer a:hover {
    color: #1d4ed8;
}

/* Header: same at start and after — chat name left, Chat Documents right (like 2nd SS) */
.chat-container .chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

/* Start view: input bar centered in mid screen with small width */
.chat-container:not(.has-messages) .chat-area {
    border: none;
    border-top: none;
}

.chat-container:not(.has-messages) .input-box {
    padding: 16px 20px;
    background: #fff;
    border-top: none;
    max-width: 680px;
    width: 100%;
    align-self: center;
    margin-top: 60px;
    margin-bottom: 220px;
    transition: max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1), margin 0.35s ease, align-self 0.35s ease;
}

.chat-container:not(.has-messages) .input-box input {
    padding: 12px 16px;
    font-size: 0.9375rem;
    border-radius: 12px;
}

.chat-container:not(.has-messages) .input-box button {
    padding: 12px 20px;
    font-size: inherit;
    border-radius: 12px;
}

/* Input: same bar in both states, sits at bottom when has messages */
.input-box {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0 0 0;
    background: transparent;
    border: none;
    border-top: none;
    transition: padding 0.35s ease, border 0.35s ease, background 0.35s ease;
}

.chat-container .input-box input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-size: 0.9375rem;
    background: #fff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-container .input-box input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.chat-container .input-box input::placeholder {
    color: #94a3b8;
}

.chat-container .input-box button {
    padding: 12px 20px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-container .input-box button:hover {
    background: #1d4ed8;
}

.chat-container.has-messages .input-box {
    padding: 16px 20px;
    background: #fff;
    border-top: 1px solid #eee;
    max-width: none;
    align-self: stretch;
    margin-top: 0;
    margin-bottom: 0;
}

/* Chat area: no height at start, grows when has messages */
.chat-container .chat-area {
    flex: 0 0 0;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    transition: flex 0.35s ease, padding 0.35s ease;
}

.chat-container.has-messages .chat-area {
    flex: 1;
    min-height: 0;
    padding: 20px;
    overflow-y: auto;
}

.chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 15px;
    background: white;
    border-bottom: 1px solid #ddd;
}

.chat-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.chat-header-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.chat-header h3 {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat Documents panel - upper right, plain (no box lines); wide layout desktop only */
.chat-docs-panel {
    flex-shrink: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.chat-docs-panel-inner {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
}

.chat-docs-main {
    flex: 0 0 auto;
    min-width: 0;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: flex-start;
}

.chat-docs-upload-toolbar-inner {
    position: relative;
}

/* Chat header actions — large ghost buttons (desktop/tablet only; mobile uses compact rules in @media max-width 768px) */
@media (min-width: 769px) {

    .chat-docs-upload-trigger,
    .chat-api-key-trigger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 10px 14px;
        min-height: 40px;
        box-sizing: border-box;
        font-size: 13px;
        font-weight: 600;
        font-family: inherit;
        line-height: 1.2;
        border-radius: 10px;
        cursor: pointer;
        white-space: nowrap;
        transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.14s ease, box-shadow 0.18s ease;
    }

    .chat-docs-upload-trigger:hover,
    .chat-api-key-trigger:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    }

    .chat-docs-upload-trigger:active,
    .chat-api-key-trigger:active {
        transform: translateY(0) scale(0.97);
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
        transition-duration: 0.05s;
    }

    .chat-docs-upload-trigger.chat-docs-upload-trigger--armed,
    .chat-api-key-trigger.chat-api-key-trigger--armed {
        transform: scale(0.97);
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    }

    .chat-header-btn-icon {
        flex-shrink: 0;
        width: 18px;
        height: 18px;
        display: block;
    }

    .chat-docs-upload-trigger {
        color: #15803d;
        background: rgba(240, 253, 244, 0.92);
        border: 1px solid #4ade80;
    }

    .chat-docs-upload-trigger:hover {
        background: #dcfce7;
        border-color: #22c55e;
        color: #14532d;
    }

    .chat-docs-upload-trigger .chat-header-btn-icon--doc {
        color: #15803d;
    }

    .chat-docs-upload-trigger:hover .chat-header-btn-icon--doc {
        color: #14532d;
    }

    .chat-api-key-trigger {
        color: #1d4ed8;
        background: rgba(239, 246, 255, 0.95);
        border: 1px solid #60a5fa;
    }

    .chat-api-key-trigger:hover {
        background: #dbeafe;
        border-color: #3b82f6;
        color: #1e3a8a;
    }

    .chat-api-key-trigger .chat-header-btn-icon--key {
        color: #1d4ed8;
    }

    .chat-api-key-trigger:hover .chat-header-btn-icon--key {
        color: #1e3a8a;
    }
}

.chat-docs-upload-popover {
    display: block;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: auto;
    min-width: min(280px, calc(100vw - 32px));
    max-width: min(320px, calc(100vw - 32px));
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    z-index: 80;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.97);
    transform-origin: top right;
    transition:
        opacity 0.22s ease,
        transform 0.26s cubic-bezier(0.34, 1.15, 0.64, 1),
        visibility 0.22s linear;
}

.chat-docs-upload-popover.chat-docs-upload-popover--open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.chat-docs-upload-popover .chat-docs-upload {
    width: 100%;
    max-width: 100%;
}

/* Chat header: Upload document + Create API key (grouped, end-aligned) */
.chat-api-key-toolbar {
    flex-shrink: 0;
}

.chat-api-key-toolbar-inner {
    position: relative;
}

.chat-docs-upload-label,
.chat-api-key-label {
    display: inline;
}

/* Mobile-only labels + upload SVG; hidden on desktop */
.chat-header-label-mobile,
.chat-header-btn-icon--mobile,
.chat-header-api-emoji-mobile {
    display: none;
}

.chat-api-key-popover {
    display: block;
    position: absolute;
    top: calc(100% + 6px);
    left: auto;
    right: 0;
    min-width: min(280px, calc(100vw - 32px));
    max-width: min(320px, calc(100vw - 32px));
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
    z-index: 80;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.97);
    transform-origin: top right;
    transition:
        opacity 0.22s ease,
        transform 0.26s cubic-bezier(0.34, 1.15, 0.64, 1),
        visibility 0.22s linear;
}

.chat-api-key-popover.chat-api-key-popover--open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.chat-api-key-popover .api-keys-input {
    max-width: 100%;
}

/*
 * Mobile: header popovers were clipped (left side cut off) because .chat-container uses overflow:hidden
 * and the panel was position:absolute with a wide min-width. Fixed + horizontal center keeps the sheet on-screen.
 */
@media (max-width: 768px) {

    .chat-docs-upload-popover,
    .chat-api-key-popover {
        position: fixed;
        left: 50%;
        right: auto;
        top: max(52px, calc(env(safe-area-inset-top, 0px) + 44px));
        bottom: auto;
        transform: translate(-50%, -8px) scale(0.97);
        transform-origin: top center;
        width: min(320px, calc(100vw - 24px));
        min-width: 0;
        max-width: calc(100vw - 24px);
        max-height: min(480px, 72vh);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 200;
        margin: 0;
    }

    .chat-docs-upload-popover.chat-docs-upload-popover--open,
    .chat-api-key-popover.chat-api-key-popover--open {
        transform: translate(-50%, 0) scale(1);
    }
}

@media (min-width: 769px) {
    .chat-docs-panel {
        width: 340px;
        padding: 12px;
    }
}

.chat-docs-panel-title {
    margin: 0 0 6px 0;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
}

.chat-docs-upload {
    width: 100%;
    font-size: 12px;
    margin-bottom: 8px;
}

.chat-docs-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 12px;
    max-height: 120px;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    transition: max-height 0.2s ease-out;
}

.chat-docs-list.doc-list-collapsed {
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.chat-docs-list li {
    padding: 4px 8px;
    margin-bottom: 4px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.chat-docs-list .doc-remove-btn {
    background: #fee2e2;
    color: #dc2626;
}

.chat-docs-list .doc-remove-btn:hover {
    background: #dc2626;
    color: #fff;
}

.chat-area {
    flex: 1;
    min-height: 0;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message-row {
    animation: messageRowIn 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Space between assistant avatar and reply bubble */
.message-row--assistant {
    gap: 12px;
}

@keyframes messageRowIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* DocuMind logo (transparent PNG) next to assistant replies */
.message-avatar--bot {
    border-radius: 8px;
    object-fit: contain;
    background: transparent;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.message {
    max-width: 60%;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 8px;
}

.user {
    background: #dbeafe;
    align-self: flex-end;
}

.bot {
    background: white;
    border: 1px solid #ccc;
}

.message.typing-indicator {
    font-style: italic;
    color: #6b7280;
}

.input-box {
    display: flex;
    padding: 15px;
    background: white;
    border-top: 1px solid #ddd;
}

.input-box input {
    flex: 1;
    padding: 10px;
}

.input-box button {
    padding: 10px;
    background: #2563eb;
    color: white;
    border: none;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
}

.login-btn {
    padding: 8px;
    background: #2563eb;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 5px;
    width: 100%;
}

.popup {
    position: fixed;
    inset: 0;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.28s;
}

.popup.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.popup .popup-box {
    transform: scale(0.94) translateY(16px);
    opacity: 0;
    transition: transform 0.32s cubic-bezier(0.34, 1.15, 0.64, 1), opacity 0.28s ease;
}

.popup.is-open .popup-box {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.popup-box {
    position: relative;
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 320px;
    text-align: left;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

/* Login modal — simple professional layout */
.login-popup-box {
    padding: 0;
    max-width: 320px;
}

.login-popup-icon-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease;
}

.login-popup-icon-close:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #0f172a;
}

.login-popup-icon-close:active {
    transform: scale(0.96);
}

.login-popup-hero {
    padding: 20px 20px 16px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    text-align: center;
}

.login-popup-logo-img {
    display: block;
    width: 40px;
    height: 40px;
    margin: 0 auto 10px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.login-popup-brand-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: #212529;
}

.login-popup-brand-line {
    margin: 4px 0 0;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: #6c757d;
}

.login-popup-body {
    padding: 16px 20px 20px;
}

.login-popup-step-label {
    margin: 0 0 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
}

.login-popup-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-choice-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.login-choice-card:hover {
    border-color: #2563eb;
    background: #f8f9fa;
}

.login-choice-card:active {
    background: #e9ecef;
}

.login-choice-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: #2563eb;
    background: #e7f3ff;
}

.login-choice-icon--company {
    color: #0d9488;
    background: #e6fffa;
}

.login-choice-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.login-choice-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #212529;
}

.login-choice-desc {
    font-size: 0.75rem;
    line-height: 1.3;
    color: #6c757d;
}

.login-choice-chevron {
    flex-shrink: 0;
    font-size: 1.25rem;
    font-weight: 300;
    color: #94a3b8;
    line-height: 1;
}

.login-step2-heading {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: #212529;
}

.login-step2-hint {
    margin: 0 0 16px;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: #6c757d;
}

.login-field-label {
    display: block;
    margin: 0 0 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
}

#loginStep1,
#loginStep2 {
    animation: loginStepFade 0.28s ease;
}

@keyframes loginStepFade {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

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

.popup-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 0 16px;
    padding: 6px 10px 6px 4px;
    font-size: 0.875rem;
    font-weight: 500;
    background: transparent;
    color: #64748b;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.popup-back-icon {
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.85;
}

.popup-back-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.login-popup-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 0.875rem;
    color: #212529;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    transition: border-color 0.2s ease;
}

.login-popup-input::placeholder {
    color: #adb5bd;
}

.login-popup-input:hover {
    border-color: #ced4da;
}

.login-popup-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.login-popup-input--otp {
    letter-spacing: 0.35em;
    font-weight: 600;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.popup-email-login-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s ease;
}

.popup-email-login-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.popup-email-login-btn:active:not(:disabled) {
    background: #0d4ed8;
}

.popup-email-login-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    box-shadow: none;
}

.login-popup-or {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0 12px;
}

.login-popup-or-line {
    flex: 1;
    height: 1px;
    background: #dee2e6;
}

.login-popup-or-text {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
}

.popup-google-btn,
.profile-section .google-login-btn {
    pointer-events: none;
    opacity: 0.6;
    cursor: not-allowed;
}

.popup-google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    background: #fff;
    color: #495057;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.popup-google-btn:hover {
    background: #f8f9fa;
    border-color: #ced4da;
}

.popup-google-btn:active {
    background: #e9ecef;
}

.popup-google-icon {
    display: inline-flex;
    flex-shrink: 0;
}

.popup-google-icon svg {
    display: block;
}

.login-otp-section {
    margin-top: 16px;
    padding: 14px;
    border-radius: 6px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
}

.login-otp-msg {
    margin: 0 0 12px;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: #495057;
}

.login-otp-section .login-field-label {
    margin-top: 4px;
}

.login-otp-section .login-popup-input {
    margin-bottom: 12px;
    background: #fff;
}

@media (max-width: 420px) {
    .login-popup-hero {
        padding: 24px 44px 20px 20px;
    }

    .login-popup-body {
        padding: 18px 16px 22px;
    }

    .login-choice-card {
        padding: 12px 14px;
    }

    .login-choice-icon {
        width: 40px;
        height: 40px;
    }
}

.user-info {
    font-size: 12px;
    margin-top: 5px;
    color: #ccc;
}

/* ---------- PROFILE SECTION ---------- */
.profile-section {
    position: relative;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Login button: same slot and style as profile trigger (after login) */
.profile-section .login-btn {
    width: 100%;
    padding: 10px 14px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-section .login-btn:hover {
    background: #1d4ed8;
}

.profile-section .login-btn:active {
    transform: scale(0.98);
}

.profile-section .google-login-btn {
    margin-top: 8px;
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

.profile-section .google-login-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.profile-box {
    position: relative;
    display: block;
}

.profile-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    cursor: pointer;
    color: inherit;
    font: inherit;
    text-align: left;
    transition: background 0.2s, border-color 0.2s;
}

.profile-trigger:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
}

.profile-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.profile-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.profile-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #e5e7eb;
}

.profile-chevron {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
    transition: transform 0.2s;
}

.profile-box.open .profile-chevron {
    transform: rotate(180deg);
}

.profile-dropdown {
    display: block;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    color: #111827;
    padding: 6px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    border: 1px solid #e5e7eb;
    z-index: 100;
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.profile-box.open .profile-dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.profile-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 4px;
    background: transparent;
    color: #374151;
}

.profile-dropdown-item:last-child {
    margin-bottom: 0;
}

.profile-dropdown-item:hover {
    background: #f3f4f6;
}

.upload-label {
    cursor: pointer;
    font-weight: 500;
    box-sizing: border-box;
}

.upload-label input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
}

.profile-logout {
    color: #dc2626;
    font-weight: 500;
}

.profile-logout:hover {
    background: #fef2f2;
    color: #b91c1c;
}

.profile-user-id-line {
    padding: 8px 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12px;
    color: #374151;
}

.profile-user-id-label {
    margin-right: 6px;
    color: #6b7280;
}

.profile-user-id-value {
    font-weight: 600;
    font-family: monospace;
}

/* ---------- ADMIN DATABASE VIEW ---------- */
.admin-db-btn {
    width: 100%;
    padding: 8px;
    margin-bottom: 5px;
    background: #374151;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.12s ease;
}

.admin-db-btn:hover {
    background: #4b5563;
}

.admin-db-btn:active {
    transform: scale(0.98);
}

.database-view {
    flex: 1;
    min-height: 0;
    padding: 20px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: databaseViewIn 0.32s ease;
}

@keyframes databaseViewIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

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

.database-view-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.database-view-header h3 {
    margin: 0;
}

.back-to-chat-btn {
    padding: 8px 14px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.12s ease;
}

.back-to-chat-btn:hover {
    background: #1d4ed8;
}

.back-to-chat-btn:active {
    transform: scale(0.98);
}

.admin-add-admin {
    flex-shrink: 0;
    margin-bottom: 20px;
    padding: 15px;
    background: #f3f4f6;
    border-radius: 8px;
}

.admin-add-admin h4 {
    margin-top: 0;
    margin-bottom: 10px;
}

.admin-add-admin input {
    padding: 6px 10px;
    margin-right: 8px;
    width: 220px;
}

.admin-add-admin button {
    padding: 6px 12px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.admin-list-label {
    margin: 10px 0 0;
    font-size: 13px;
    color: #4b5563;
}

.admin-list-toggle {
    display: block;
    width: 10%;
    margin-top: 10px;
    padding: 8px 10px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    background: #e5e7eb;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.admin-list-toggle:hover {
    background: #d1d5db;
    border-color: #9ca3af;
}

.admin-list-with-remove .admin-list-ul.admin-list-dropdown {
    list-style: none;
    padding: 8px 0 0;
    margin: 4px 0 0;
}

.admin-list-with-remove .admin-list-ul.admin-list-dropdown .admin-list-li {
    margin-bottom: 8px;
}

.admin-list-empty {
    color: #6b7280;
    font-size: 13px;
}

.admin-list-li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.admin-remove-btn {
    padding: 4px 10px;
    font-size: 12px;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.admin-remove-btn:hover {
    background: #b91c1c;
}

.db-search-wrap {
    flex-shrink: 0;
    margin-bottom: 10px;
}

.db-search-input {
    width: 100%;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
}

.database-tables {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.db-tabs {
    flex-shrink: 0;
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.db-tab {
    padding: 8px 14px;
    background: #e5e7eb;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s ease, transform 0.1s ease;
}

.db-tab:hover {
    background: #d1d5db;
}

.db-tab:active {
    transform: scale(0.98);
}

.db-tab.active {
    background: #2563eb;
    color: white;
}

.db-table-content {
    overflow: auto;
    flex: 1;
    min-height: 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.db-doc-link {
    color: #2563eb;
    text-decoration: none;
}

.db-doc-link:hover {
    text-decoration: underline;
}

.db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.db-table th,
.db-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.db-table th {
    background: #f3f4f6;
    font-weight: 600;
}

.db-empty {
    padding: 20px;
    color: #6b7280;
}


/* Chat list loader */
.chat-list-loading {
    display: flex;
    gap: 6px;
    padding: 12px 8px;
    align-items: center;
    justify-content: center;
    list-style: none;
}

/* Chat area loader */
.chat-area-loading {
    display: flex;
    gap: 8px;
    padding: 40px;
    align-items: center;
    justify-content: center;
}

/* Loader dots */
.chat-loader-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4f8ef7;
    display: inline-block;
    animation: chatLoaderBounce 1.2s infinite ease-in-out;
}

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

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

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

@keyframes chatLoaderBounce {

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

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

/* ---------- In-app toasts (replaces browser alert) ---------- */
.toast-container {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translateX(-50%);
    z-index: 10050;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: min(340px, calc(100vw - 32px));
    pointer-events: none;
    box-sizing: border-box;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 12px 12px;
    box-sizing: border-box;
    border-radius: 12px;
    background: #fff;
    color: #0f172a;
    font-size: 0.875rem;
    line-height: 1.4;
    box-shadow:
        0 10px 40px rgba(15, 23, 42, 0.12),
        0 0 0 1px rgba(15, 23, 42, 0.06);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.toast--visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.toast--out {
    opacity: 0;
    transform: translateY(-6px);
}

.toast-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-icon svg {
    display: block;
    width: 22px;
    height: 22px;
}

.toast-message {
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.toast-dismiss {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin: -4px -6px -4px 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #94a3b8;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.toast-dismiss:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #475569;
}

.toast--success {
    border-left: 4px solid #10b981;
}

.toast--success .toast-icon {
    color: #059669;
}

.toast--error {
    border-left: 4px solid #ef4444;
}

.toast--error .toast-icon {
    color: #dc2626;
}

.toast--warning {
    border-left: 4px solid #f59e0b;
}

.toast--warning .toast-icon {
    color: #d97706;
}

.toast--info {
    border-left: 4px solid #3b82f6;
}

.toast--info .toast-icon {
    color: #2563eb;
}

.toast--loading {
    border-left: 4px solid #3b82f6;
}

.toast--loading .toast-icon {
    color: #2563eb;
}

.toast-icon--spinner {
    margin-top: 0;
}

.toast-icon--spinner .toast-spinner {
    display: block;
    width: 20px;
    height: 20px;
    animation: toastSpinnerRotate 0.75s linear infinite;
}

.toast-icon--spinner .toast-spinner circle {
    transform-origin: center;
}

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

/* ---------- Custom confirm (replaces browser confirm) ---------- */
.confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 10040;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    box-sizing: border-box;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.22s ease, visibility 0.22s linear;
}

.confirm-dialog.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.confirm-dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: opacity 0.22s ease;
}

.confirm-dialog-box {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 24px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.06);
    opacity: 1;
    transform: translateY(0) scale(1);
    transition:
        opacity 0.24s ease,
        transform 0.28s cubic-bezier(0.34, 1.15, 0.64, 1);
}

.confirm-dialog.hidden .confirm-dialog-box {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
}

.confirm-dialog-message {
    margin: 0 0 20px;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: #334155;
}

.confirm-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.confirm-dialog-btn {
    padding: 10px 18px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s, transform 0.12s;
}

.confirm-dialog-btn:active {
    transform: scale(0.98);
}

.confirm-dialog-cancel {
    background: #f1f5f9;
    color: #475569;
    border-color: #e2e8f0;
}

.confirm-dialog-cancel:hover {
    background: #e2e8f0;
}

.confirm-dialog-btn--primary {
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.confirm-dialog-btn--primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
}

.confirm-dialog-btn--danger {
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
    color: #fff;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.35);
}

.confirm-dialog-btn--danger:hover:not(:disabled) {
    background: linear-gradient(180deg, #dc2626 0%, #b91c1c 100%);
}

/* --- User API keys (embed / external chat) --- */
.api-keys-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(148, 163, 184, 0.35);
}

.api-keys-section--inline {
    margin-top: 0.75rem;
    padding: 0.65rem 0.75rem;
    background: rgba(241, 245, 249, 0.65);
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.api-keys-title {
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0 0 0.35rem 0;
    color: #1e293b;
}

.api-keys-desc {
    font-size: 0.72rem;
    color: #64748b;
    margin: 0 0 0.5rem 0;
    line-height: 1.35;
}

.api-keys-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 0.35rem;
}

.api-keys-contact-wrap {
    text-align: center;
    margin: 10px 0 4px;
}

.api-keys-contact-wrap .sidebar-how-link {
    margin: 0;
    display: inline-block;
}

.api-keys-input {
    flex: 1;
    min-width: 0;
    width: 0;
    max-width: none;
    padding: 0.28rem 0.45rem;
    font-size: 0.72rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    line-height: 1.25;
}

.api-keys-actions .api-keys-btn {
    flex-shrink: 0;
    margin: 0; /* override .sidebar button margin so row aligns with input */
    padding: 0.28rem 0.55rem;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;
    border-radius: 8px;
    border: none;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
    align-self: stretch;
    min-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.api-keys-actions .api-keys-btn:hover {
    background: #1d4ed8;
}

.api-keys-actions .api-keys-btn--ghost {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.api-keys-actions .api-keys-btn--ghost:hover {
    background: #e2e8f0;
}

.api-keys-reveal {
    font-size: 0.72rem;
    word-break: break-all;
    padding: 0.5rem;
    background: #fef3c7;
    border-radius: 6px;
    color: #92400e;
    margin: 0.35rem 0;
}

.api-keys-list {
    list-style: none;
    margin: 0.25rem 0 0 0;
    padding: 0;
    font-size: 0.72rem;
}

.api-keys-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
}

.api-keys-list li:last-child {
    border-bottom: none;
}

.api-keys-revoke {
    font-size: 0.7rem;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    border: 1px solid #fca5a5;
    background: #fff;
    color: #b91c1c;
    cursor: pointer;
}

.api-keys-revoke:hover {
    background: #fef2f2;
}

@media (max-width: 480px) {
    .toast-container {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: min(200px, calc(100vw - max(32px, env(safe-area-inset-left) + env(safe-area-inset-right))));
        align-items: center;
        width: max-content;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .chat-area,
    .sidebar,
    .doc-list,
    .chat-docs-list,
    .db-table-content {
        scroll-behavior: auto;
    }

    .message-row {
        animation: none;
    }

    #loginStep1,
    #loginStep2 {
        animation: none;
    }

    .database-view {
        animation: none;
    }

    .popup {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .popup,
    .popup .popup-box {
        transition: none;
    }

    .profile-dropdown,
    .chat-menu-dropdown {
        transition: none;
    }

    .chat-docs-upload-popover,
    .chat-api-key-popover {
        transition: none;
    }

    .toast {
        transition: none;
    }

    .toast.toast--visible,
    .toast.toast--out {
        transform: none;
    }

    .toast-icon--spinner .toast-spinner {
        animation: none;
    }

    .confirm-dialog-backdrop {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

/* ============================================================
   Profile modal
   ============================================================ */
.profile-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.profile-modal.is-open {
    display: flex;
    animation: profileModalIn 0.2s ease-out;
}
@keyframes profileModalIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.profile-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
.profile-modal-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.25), 0 8px 24px rgba(15, 23, 42, 0.12);
    padding: 28px 24px 24px;
    color: #0f172a;
    animation: profileModalCardIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes profileModalCardIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.profile-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.profile-modal-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.profile-modal-title {
    margin: 0 0 18px;
    font-size: 19px;
    font-weight: 600;
    text-align: center;
    color: #0f172a;
}
.profile-modal-photo-wrap {
    position: relative;
    width: 112px;
    height: 112px;
    margin: 0 auto 22px;
}
.profile-modal-photo {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #ffffff;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.22), 0 0 0 3px rgba(99, 102, 241, 0.18);
    background: #e2e8f0;
}
.profile-modal-photo-edit {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(145deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
    transition: transform 0.15s ease, filter 0.15s ease;
}
.profile-modal-photo-edit:hover {
    transform: scale(1.06);
    filter: brightness(1.06);
}
.profile-modal-photo-edit:active {
    transform: scale(0.94);
}
.profile-modal-field {
    margin-bottom: 16px;
}
.profile-modal-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.profile-modal-readonly {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: #94a3b8;
}
.profile-modal-input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 14px;
    box-sizing: border-box;
    cursor: not-allowed;
}
.profile-modal-input:focus {
    outline: none;
}
.profile-modal-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
}
.profile-modal-name-display {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: #f8fafc;
    font-size: 14px;
    color: #0f172a;
    font-weight: 500;
    line-height: 1.2;
    min-height: 18px;
    word-break: break-word;
}
.profile-modal-name-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    font-size: 14px;
    color: #0f172a;
    background: #fff;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.profile-modal-name-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.profile-modal-pencil {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #4f46e5;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.profile-modal-pencil:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}
.profile-modal-pencil:active {
    transform: scale(0.95);
}
.profile-modal-namesave,
.profile-modal-namecancel {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: filter 0.15s ease, background 0.15s ease;
}
.profile-modal-namesave {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
}
.profile-modal-namesave:hover { filter: brightness(1.07); }
.profile-modal-namecancel {
    background: #f1f5f9;
    color: #475569;
}
.profile-modal-namecancel:hover { background: #e2e8f0; }
.profile-modal-namesave:disabled,
.profile-modal-namecancel:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .profile-modal { padding: 14px; }
    .profile-modal-card { padding: 22px 18px 18px; max-width: 380px; }
    .profile-modal-photo,
    .profile-modal-photo-wrap { width: 96px; height: 96px; }
}

.profile-open-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    color: #374151;
}
.profile-open-btn:hover {
    background: #f3f4f6;
    color: #374151;
}
.profile-open-btn svg {
    flex-shrink: 0;
    color: inherit;
    opacity: 0.85;
}

/* ============================================================
   Chat history loading skeleton
   ============================================================ */
.chat-loading {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px 20px 20px;
    width: 100%;
    box-sizing: border-box;
    animation: chatLoadingFadeIn 0.18s ease-out;
}
@keyframes chatLoadingFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0);   }
}
.chat-loading-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.chat-loading-row--user {
    justify-content: flex-end;
}
.chat-loading-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(90deg, #eef2ff 0%, #e0e7ff 50%, #eef2ff 100%);
    background-size: 200% 100%;
    animation: chatLoadingShimmer 1.4s linear infinite;
}
.chat-loading-bubble {
    border-radius: 14px;
    padding: 12px 14px;
    background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%);
    background-size: 200% 100%;
    animation: chatLoadingShimmer 1.4s linear infinite;
    min-height: 18px;
    max-width: 70%;
}
.chat-loading-row--user .chat-loading-bubble {
    background: linear-gradient(90deg, #dbeafe 0%, #bfdbfe 50%, #dbeafe 100%);
    background-size: 200% 100%;
    animation: chatLoadingShimmer 1.4s linear infinite;
}
.chat-loading-bubble--short { width: 38%; }
.chat-loading-bubble--med   { width: 56%; }
.chat-loading-bubble--long  { width: 70%; }
.chat-loading-row--user .chat-loading-bubble--short { width: 30%; }
.chat-loading-row--user .chat-loading-bubble--med   { width: 48%; }

.chat-loading-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 4px 0;
    color: #6366f1;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.2px;
}
.chat-loading-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(99, 102, 241, 0.25);
    border-top-color: #6366f1;
    animation: chatLoadingSpin 0.85s linear infinite;
}
@keyframes chatLoadingSpin {
    to { transform: rotate(360deg); }
}
@keyframes chatLoadingShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
    .chat-loading,
    .chat-loading-avatar,
    .chat-loading-bubble,
    .chat-loading-spinner {
        animation: none !important;
    }
}

/* While history is loading, dim the chat list active state to indicate "switching" */
.chat-list-item.is-loading {
    opacity: 0.65;
}

/* Slim top progress bar (used for "new chat" / lightweight transitions) */
.top-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: transparent;
    pointer-events: none;
    z-index: 10001;
    overflow: hidden;
    display: none;
}
.top-progress-bar.is-active {
    display: block;
}
.top-progress-bar::before {
    content: "";
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, #6366f1 30%, #a855f7 70%, transparent 100%);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.55);
    animation: topProgressSlide 1.1s ease-in-out infinite;
}
@keyframes topProgressSlide {
    0%   { left: -40%; }
    100% { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    .top-progress-bar::before { animation: none; }
}

/* Voice-turn message bubbles: persisted user/bot turns spoken in voice mode.
   Backend wraps these in « … » and adds .message--voice client-side. */
.message.message--voice {
    font-style: italic;
    position: relative;
    padding-left: 30px;
}
.message.message--voice::before {
    content: "";
    position: absolute;
    left: 10px;
    top: 50%;
    width: 14px;
    height: 14px;
    transform: translateY(-50%);
    background-color: currentColor;
    opacity: 0.55;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V20h2v-2.08A7 7 0 0 0 19 11h-2z'/></svg>") center/contain no-repeat;
            mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V20h2v-2.08A7 7 0 0 0 19 11h-2z'/></svg>") center/contain no-repeat;
}

/* ============================================================
   Voice mode (ChatGPT-style fullscreen voice chat)
   Must beat `.chat-container .input-box button` (solid blue Send styling).
   ============================================================ */
.voice-mode-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: linear-gradient(145deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.45);
    font-weight: normal;
    white-space: normal;
}
.voice-mode-btn:hover {
    transform: translateY(-1px) scale(1.04);
    filter: brightness(1.06);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
    background: linear-gradient(145deg, #4f46e5 0%, #7c3aed 55%, #9333ea 100%);
}
.voice-mode-btn:active {
    transform: scale(0.96);
}
.voice-mode-btn__icon {
    display: block;
    pointer-events: none;
}
.chat-container .input-box button.voice-mode-btn,
.chat-container:not(.has-messages) .input-box button.voice-mode-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0 !important;
    border-radius: 50% !important;
    background: linear-gradient(145deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%) !important;
    color: #fff !important;
    font-weight: normal !important;
    white-space: normal !important;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.45);
}
.chat-container .input-box button.voice-mode-btn:hover,
.chat-container:not(.has-messages) .input-box button.voice-mode-btn:hover {
    background: linear-gradient(145deg, #4f46e5 0%, #7c3aed 55%, #9333ea 100%) !important;
}
@media (max-width: 768px) {
    .chat-container .input-box button.voice-mode-btn,
    .chat-container:not(.has-messages) .input-box button.voice-mode-btn {
        padding: 0 !important;
        min-width: 44px;
    }
}

.voice-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 40%, #1e1b4b 0%, #0a0a1a 70%, #050510 100%);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #fff;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: voiceOverlayIn 0.32s ease-out;
}
.voice-overlay.is-open {
    display: flex;
}
@keyframes voiceOverlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.voice-overlay-close {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.voice-overlay-close:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: scale(1.05);
}

.voice-lang-bar {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    backdrop-filter: blur(10px) saturate(140%);
    color: rgba(255, 255, 255, 0.86);
    font-size: 13px;
    line-height: 1;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
    z-index: 5;
}
.voice-lang-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    color: rgba(255, 255, 255, 0.7);
    margin-right: 2px;
}
.voice-lang-btn {
    appearance: none;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.2px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
    font-family: inherit;
}
.voice-lang-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
.voice-lang-btn.is-active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    color: #fff;
    box-shadow:
        0 4px 14px rgba(139, 92, 246, 0.45),
        inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}
.voice-lang-btn.is-active:hover {
    filter: brightness(1.05);
}
.voice-lang-btn:focus-visible {
    outline: 2px solid rgba(167, 139, 250, 0.85);
    outline-offset: 2px;
}
@media (max-width: 480px) {
    .voice-lang-bar {
        top: 14px;
        font-size: 12px;
        padding: 5px 6px 5px 10px;
    }
    .voice-lang-btn {
        padding: 6px 11px;
        font-size: 12px;
    }
}

.voice-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    text-align: center;
    max-width: 520px;
    width: 100%;
}

.voice-orb {
    position: relative;
    width: 260px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.voice-orb-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(139, 92, 246, 0.45);
    opacity: 0;
}
.voice-orb-glow {
    position: absolute;
    inset: -30px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.45) 0%, rgba(99, 102, 241, 0.18) 45%, transparent 70%);
    filter: blur(8px);
    animation: voiceGlowPulse 3.5s ease-in-out infinite;
}
@keyframes voiceGlowPulse {
    0%, 100% { transform: scale(1);   opacity: 0.85; }
    50%      { transform: scale(1.1); opacity: 1; }
}

.voice-orb-core {
    position: relative;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    box-shadow:
        0 0 60px rgba(139, 92, 246, 0.55),
        0 0 120px rgba(99, 102, 241, 0.35),
        inset 0 0 40px rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    animation: voiceCoreFloat 6s ease-in-out infinite;
}
@keyframes voiceCoreFloat {
    0%, 100% { transform: translateY(0)    rotate(0deg);  }
    50%      { transform: translateY(-8px) rotate(2deg);   }
}
.voice-orb-core::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, rgba(255,255,255,0.0), rgba(255,255,255,0.35), rgba(255,255,255,0.0) 60%, rgba(255,255,255,0.0));
    animation: voiceCoreSpin 8s linear infinite;
    mix-blend-mode: overlay;
}
@keyframes voiceCoreSpin {
    to { transform: rotate(360deg); }
}

.voice-orb-logo {
    position: relative;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
    z-index: 2;
    animation: voiceLogoBob 3s ease-in-out infinite;
}
@keyframes voiceLogoBob {
    0%, 100% { transform: translateY(0)    scale(1);    }
    50%      { transform: translateY(-4px) scale(1.04); }
}

.voice-orb-bars {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 5px;
    height: 28px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 3;
}
.voice-orb-bars span {
    display: block;
    width: 4px;
    height: 8px;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.85);
}

.voice-orb[data-state="listening"] .voice-orb-ring--1 { animation: voiceRingPulse 1.6s ease-out infinite;        opacity: 1; }
.voice-orb[data-state="listening"] .voice-orb-ring--2 { animation: voiceRingPulse 1.6s ease-out 0.4s infinite;    opacity: 1; }
.voice-orb[data-state="listening"] .voice-orb-ring--3 { animation: voiceRingPulse 1.6s ease-out 0.8s infinite;    opacity: 1; }
.voice-orb[data-state="listening"] .voice-orb-bars    { opacity: 1; }
.voice-orb[data-state="listening"] .voice-orb-bars span { animation: voiceBars 0.9s ease-in-out infinite; }
.voice-orb[data-state="listening"] .voice-orb-bars span:nth-child(2) { animation-delay: 0.1s; }
.voice-orb[data-state="listening"] .voice-orb-bars span:nth-child(3) { animation-delay: 0.2s; }
.voice-orb[data-state="listening"] .voice-orb-bars span:nth-child(4) { animation-delay: 0.3s; }
.voice-orb[data-state="listening"] .voice-orb-bars span:nth-child(5) { animation-delay: 0.4s; }
@keyframes voiceRingPulse {
    0%   { transform: scale(0.85); opacity: 0.65; }
    100% { transform: scale(1.4);  opacity: 0;    }
}
@keyframes voiceBars {
    0%, 100% { height: 6px;  }
    50%      { height: 26px; }
}

.voice-orb[data-state="speaking"] .voice-orb-core {
    animation: voiceCoreFloat 6s ease-in-out infinite, voiceCoreSpeak 0.6s ease-in-out infinite;
}
.voice-orb[data-state="speaking"] .voice-orb-glow {
    animation: voiceGlowPulse 1.4s ease-in-out infinite;
}
@keyframes voiceCoreSpeak {
    0%, 100% { box-shadow: 0 0 60px rgba(139, 92, 246, 0.55), 0 0 120px rgba(99, 102, 241, 0.35), inset 0 0 40px rgba(255,255,255,0.18); }
    50%      { box-shadow: 0 0 90px rgba(236, 72, 153, 0.7),  0 0 160px rgba(139, 92, 246, 0.55), inset 0 0 60px rgba(255,255,255,0.32); }
}

.voice-orb[data-state="thinking"] .voice-orb-core {
    animation: voiceCoreFloat 6s ease-in-out infinite, voiceCoreThink 1.6s ease-in-out infinite;
}
@keyframes voiceCoreThink {
    0%, 100% { filter: brightness(1);    }
    50%      { filter: brightness(1.25); }
}

.voice-orb[data-state="muted"] .voice-orb-core {
    filter: grayscale(0.4) brightness(0.85);
}

.voice-status-title {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.4px;
    color: #fff;
    text-shadow: 0 2px 14px rgba(99, 102, 241, 0.55);
}

.voice-status-text {
    margin: 0;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.78);
    min-height: 22px;
    transition: opacity 0.2s ease;
}

.voice-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 22px;
    margin-top: 8px;
}
.voice-action-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.voice-action-btn:active {
    transform: scale(0.94);
}
.voice-action-btn--mute {
    background: rgba(255, 255, 255, 0.1);
}
.voice-action-btn--mute:hover {
    background: rgba(255, 255, 255, 0.2);
}
.voice-action-btn--mute.is-muted {
    background: rgba(239, 68, 68, 0.85);
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.4);
}
.voice-action-btn--end {
    background: #ef4444;
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.45);
}
.voice-action-btn--end:hover {
    background: #dc2626;
    transform: scale(1.05);
}

@media (max-width: 480px) {
    .voice-orb       { width: 220px; height: 220px; }
    .voice-orb-core  { width: 150px; height: 150px; }
    .voice-orb-logo  { width: 92px;  height: 92px;  padding: 10px; }
    .voice-status-title { font-size: 19px; }
    .voice-status-text  { font-size: 14px; }
    .voice-action-btn   { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
    .voice-orb-core,
    .voice-orb-logo,
    .voice-orb-glow,
    .voice-orb-core::before,
    .voice-orb-ring,
    .voice-orb-bars span {
        animation: none !important;
    }
}