* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-body: #000;
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1e1e1e;
    --bg-widget: #1a1a1a;
    --border: #151515;
    --border-hover: #3a3a3a;
    --text: #e5e5e5;
    --text-dim: #777;
    --text-muted: #555;
    --accent: #007aff;
    --accent-light: #409cff;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f59e0b;
    --radius: 12px;
    --widget-radius: 18px;
    --chat-h: 78px;
    --dashboard-header-h: 144px;
    --hover-overlay: rgba(255, 255, 255, 0.06);
    --hover-overlay-strong: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-heavy: rgba(0, 0, 0, 0.5);
    --backdrop-color: rgba(0, 0, 0, 0.55);
    --icon-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    /* profile + tabs floating zone */
}

[data-theme="light"] {
    --bg-body: #f2f2f7;
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
    --bg-widget: #ffffff;
    --border: #eae4e4;
    --border-hover: #c0c0c0;
    --text: #1c1c1e;
    --text-dim: #8e8e93;
    --text-muted: #aeaeb2;
    --accent: #007aff;
    --accent-light: #409cff;
    --green: #34c759;
    --red: #ff3b30;
    --orange: #ff9500;
    --hover-overlay: rgba(0, 0, 0, 0.04);
    --hover-overlay-strong: rgba(0, 0, 0, 0.08);
    --shadow-color: rgba(0, 0, 0, 0.08);
    --shadow-heavy: rgba(0, 0, 0, 0.15);
    --backdrop-color: rgba(0, 0, 0, 0.3);
    --icon-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto,
        sans-serif;
    background: var(--bg-body);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ── Loading Screen ── */
.loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

/* ── Typing Logo ── */
.typing-logo {
    display: flex;
    flex-direction: column;
    min-width: 280px;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    padding-left: 42px;
    color: var(--text);
    user-select: none;
    position: relative;
}

.typing-line1 {
    display: flex;
    align-items: center;
    font-size: 70px;
    font-weight: 700;
    letter-spacing: 4px;
}

.typing-cursor {
    display: inline-block;
    width: 32px;
    height: 58px;
    background: #007aff;
    margin-left: 4px;
    vertical-align: middle;
    animation: cursor-blink 0.7s step-end infinite;
}

@keyframes cursor-blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* ── Auth Screen ── */
.auth-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 24px;
}

.auth-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Pixel Logo ── */
.px-row {
    display: flex;
    justify-content: center;
}

.px {
    flex-shrink: 0;
    border-radius: 1px;
}

.px.on {
    animation: px-shimmer 6s ease-in-out infinite;
}

.px-gap {
    flex-shrink: 0;
}

@keyframes px-shimmer {

    0%,
    100% {
        background: #e06070;
    }

    16% {
        background: #e0a050;
    }

    33% {
        background: #60c060;
    }

    50% {
        background: #40b0b0;
    }

    66% {
        background: #5080d0;
    }

    83% {
        background: #9060c0;
    }
}

.auth-logo .px {
    margin: 1px;
    border-radius: 2px;
    width: 8px;
    height: 8px;
}

.auth-logo .px-gap {
    width: 5px;
}

.chat-logo .px {
    margin: 1px;
    border-radius: 2px;
    width: 3px;
    height: 3px;
}

.chat-logo .px-gap {
    width: 2px;
}

/* Logo panel — positioned outside chat-header so backdrop-filter works */
.logo-panel {
    position: absolute;
    top: 16px;
    left: 20px;
    z-index: 2100;
    display: none;
}

.logo-panel-header {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.logo-panel-header:active .key-logo {
    transform: scale(0.88);
    box-shadow:
        0 1px 0 #1a1a1c,
        0 1px 2px rgba(0, 0, 0, 0.3);
}

.logo-panel-body {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 48px;
    max-height: 48px;
    overflow: hidden;
    border-radius: 10px;
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: -1;
}

.logo-panel.open .logo-panel-body {
    width: 190px;
    max-height: 220px;
    background: rgba(30, 30, 34, 0.97);
    border-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
}

.logo-panel-items {
    opacity: 0;
    transition: opacity 0.15s ease 0s;
    padding: 44px 4px 4px;
}

.logo-panel.open .logo-panel-items {
    opacity: 1;
    transition: opacity 0.15s ease 0.1s;
}

.logo-panel-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border: none;
    background: none;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    text-align: left;
    white-space: nowrap;
}

.logo-panel-item:hover {
    background: rgba(255, 255, 255, 0.07);
}

.logo-panel-item.danger {
    color: #f87171;
}

.logo-panel-item.danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

/* Logo menu backdrop */
.logo-menu-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2099;
}

.logo-menu-backdrop.open {
    display: block;
}

/* Keyboard key logo */
.key-logo {
    width: 36px;
    height: 35px;
    background: #2a2a2e;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow:
        0 2px 0 #1a1a1c,
        0 3px 4px rgba(0, 0, 0, 0.3);
    transition:
        transform 0.1s ease,
        box-shadow 0.1s ease;
}

.key-logo-f {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 20px;
    font-weight: 700;
    color: #f0f0f0;
    line-height: 1;
}

.key-logo-cursor {
    width: 9px;
    height: 15px;
    background: var(--accent);
    margin-left: 2px;
}

[data-theme="light"] .key-logo {
    background: #e8e8e8;
    box-shadow:
        0 2px 0 #c0c0c0,
        0 3px 4px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .key-logo-f {
    color: #1a1a1a;
}

.auth-sub {
    color: var(--text-dim);
    font-size: 15px;
    margin: 0;
    width: 300px;
}

#g_id_onload,
.g_id_signin {
    margin-top: 8px;
}

/* ── Auth Divider ── */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 260px;
    color: var(--text-muted);
    font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Email Auth ── */
.email-auth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 240px;
}

.email-auth-step {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.email-input-wrap {
    position: relative;
    width: 100%;
}

.email-send-icon {
    position: absolute;
    right: -48px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.15s;
    opacity: 0;
}

.email-send-icon.visible {
    transform: translateY(-50%) scale(1);
    opacity: 1;
}

.email-send-icon:hover {
    background: var(--accent-light);
}

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

.email-auth-input {
    width: 100%;
    padding: 12px 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.email-auth-input:focus {
    border-color: var(--border-hover);
}

.email-auth-input::placeholder {
    color: var(--text-muted);
}

.email-auth-input.code-input {
    text-align: center;
    font-size: 24px;
    letter-spacing: 8px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    padding: 10px 24px;
}

.email-auth-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.email-auth-btn:hover {
    background: var(--accent-light);
}

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

.email-auth-sent {
    font-size: 13px;
    color: var(--text-dim);
    text-align: center;
}

.email-auth-back {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px;
    transition: color 0.15s;
}

.email-auth-back:hover {
    color: var(--text);
}

.email-auth-error {
    font-size: 13px;
    color: var(--red);
    text-align: center;
    min-height: 0;
}

.auth-footer {
    position: absolute;
    bottom: 24px;
    text-align: center;
    color: #555;
    font-size: 11px;
    line-height: 1.5;
}

.auth-footer-company {
    font-weight: 600;
    color: #666;
}

/* ── Main Layout ── */
.app {
    display: none;
}

.app.visible {
    display: block;
}

/* ── Desktop Surface ── */
.desktop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: transparent;
    display: flex;
    flex-direction: column;
}

/* Gradient that icons scroll under — top (covers floating header zone) */
.desktop::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--dashboard-header-h) + 28px);
    background: linear-gradient(to bottom,
            rgba(0, 0, 0, 0.35) 40%,
            transparent 100%);
    z-index: 5;
    pointer-events: none;
}

/* Gradient that icons scroll under — bottom (covers chat input zone) */
.desktop::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--chat-h) + 24px);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.4) 40%, transparent 100%);
    z-index: 5;
    pointer-events: none;
}

.desktop.app-fullscreen::before,
.desktop.app-fullscreen::after {
    display: none;
}

#bgCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    display: block;
    background: var(--bg-body);
    transition: opacity 0.4s ease;
}

/* Tab switcher — centered glass pill */
.desktop-tabs {
    display: flex;
    gap: 0;
    flex-shrink: 0;
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    margin: 12px auto 0;
    padding: 3px;
    position: relative;
    z-index: 10;
    overflow-x: auto;
    scrollbar-width: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    width: fit-content;
}

.desktop-tabs::-webkit-scrollbar {
    display: none;
}

.desktop-tab {
    flex: 0 0 auto;
    padding: 7px 16px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.55);
    font:
        13px/1 -apple-system,
        system-ui,
        sans-serif;
    font-weight: 500;
    border-radius: 17px;
    cursor: pointer;
    transition:
        color 0.2s,
        background 0.2s;
    position: relative;
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

/* Sliding indicator behind active tab */
.desktop-tabs-indicator {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 0;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 17px;
    transition:
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    pointer-events: none;
}

.desktop-tab.active {
    color: #fff;
}

/* App tabs */
.desktop-tab.app-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 160px;
    padding: 5px 6px 5px 12px;
}

.app-tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tab-close {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition:
        background 0.15s,
        color 0.15s;
    padding: 0;
}

.app-tab-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text);
}

/* Panels container — fills full desktop area, panels scroll independently */
.desktop-panels {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
}

.desktop-panel {
    display: none;
}

.desktop-panel-title {
    display: none;
}

.desktop-panel.active {
    display: block;
    position: absolute;
    inset: 0;
    overflow-y: auto;
}

.desktop-panel.app-panel.active {
    display: flex;
    flex-direction: column;
    position: absolute;
    inset: 0;
    overflow: hidden;
}

/* Icons grid — grid-template-columns is set dynamically by fitIconGridColumns() */
.desktop-icons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* fallback before JS runs */
    gap: 8px;
    padding: 100px 24px 16px;
    padding-bottom: calc(var(--chat-h) + 24px);
    align-content: start;
}

/* When an app tab is active, hide profile and tabs — app fills the whole column */
.desktop.app-fullscreen>.public-profile,
.desktop.app-fullscreen>.desktop-tabs,
.desktop.app-fullscreen>.profile-inline-panel {
    display: none;
}

/* App takes priority over profile — make panels and profile buttons visible */
.desktop.app-fullscreen .desktop-panels {
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
}

.desktop.app-fullscreen .profile-back-btn,
.desktop.app-fullscreen .profile-edit-float-btn,
.desktop.app-fullscreen #profileOpenHeader {
    display: none !important;
}

/* Floating glass toolbar over app */
.app-tab-toolbar {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    pointer-events: none;
}

.app-tab-toolbar>* {
    pointer-events: auto;
}

/* Back button — large round glass */
.app-toolbar-back {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background 0.15s,
        transform 0.15s;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

@media (hover: hover) {
    .app-toolbar-back:hover {
        background: rgba(220, 40, 40, 0.7);
        transform: scale(1.05);
    }
}

.app-toolbar-back:active {
    transform: scale(0.95);
}

/* Right action group */
.app-toolbar-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-toolbar-action {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background 0.15s,
        color 0.15s;
    padding: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.app-toolbar-action:hover {
    background: rgba(50, 50, 50, 0.7);
    color: #fff;
}

.app-toolbar-action.flash {
    color: var(--green, #34d399);
}

/* Dropdown menu */
.app-toolbar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 140px;
    background: rgba(30, 30, 30, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 20;
}

.app-toolbar-dropdown.open {
    display: block;
}

.app-toolbar-drop-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.12s;
    white-space: nowrap;
}

.app-toolbar-drop-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Standalone blue CTA button (Add to dashboard / Fork) */
.app-toolbar-cta {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #6366f1;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background 0.15s,
        transform 0.15s;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4);
}

.app-toolbar-cta:hover {
    background: #818cf8;
    transform: scale(1.08);
}

.app-toolbar-cta:active {
    transform: scale(0.95);
}

.app-toolbar-cta:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

/* ── Custom tooltip ── */
.custom-tooltip {
    position: fixed;
    z-index: 99999;
    background: rgba(20, 20, 20, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    padding: 6px 10px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.custom-tooltip.visible {
    opacity: 1;
}

.app-tab-iframe {
    flex: 1;
    border: none;
    width: 100%;
    background: #fff;
}

.app-tab-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg, #0a0a0a);
    z-index: 10;
}

.app-tab-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Chat area inside chat ── */
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    overflow: hidden;
    min-height: 0;
    padding-bottom: 0px;
    scrollbar-width: none;
    opacity: 0;
}

.chat-body::-webkit-scrollbar {
    display: none;
}

/* ── Chat panel ── */
.chat {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    height: 100vh;
    background: transparent;
    display: none;
    flex-direction: column;
    z-index: 999;
    overflow: hidden;
}

/* Wide: sidebar chat (always open) + content panels to the right */
@media (min-width: 800px) {

    /* ── Chat sidebar: always visible on the left ── */
    .chat {
        display: flex;
        left: 0;
        right: auto;
        top: 0;
        bottom: 0;
        width: var(--chat-w, 600px);
        height: 100vh !important;
        border-right: 1px solid var(--border);
        background: rgba(10, 10, 10, 0.55);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Chat area always scrollable, glassmorphism */
    .chat-body {
        overflow-y: auto;
        overflow-x: hidden;
        justify-content: flex-start;
        opacity: 1;
        transition: opacity 0.15s;
        background: rgba(18, 18, 24, 0.55);
        backdrop-filter: blur(24px) saturate(1.4);
        -webkit-backdrop-filter: blur(24px) saturate(1.4);
        overscroll-behavior: contain;
    }

    .chat-body::before {
        content: '';
        flex: 1 0 0px;
    }

    .messages {
        overflow: visible;
    }

    /* Neutralise body.chat-open transitions */
    body.chat-open .chat {
        height: 100vh !important;
    }

    /* Frosted glass input */
    .chat-input,
    .chat-input-row,
    body.chat-open .chat-input-row {
        flex: 1 !important;
    }

    .chat-input-row,
    body.chat-open .chat-input-row {
        min-height: 52px !important;
    }

    body.chat-open .chat-send {
        width: 38px !important;
        height: 38px !important;
    }

    /* Desktop occupies the area to the right of the sidebar */
    .desktop {
        left: var(--chat-w, 600px);
        bottom: 0;
        transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* No bottom chat bar in wide mode — remove bottom gradient and padding */
    .desktop::after {
        display: none;
    }

    .desktop-icons {
        padding-bottom: 24px;
    }

    .desktop-empty {
        padding-bottom: 0;
    }

    /* Hide mobile-only overlay elements */
    .chat-backdrop {
        display: none !important;
    }

    .chat-close {
        display: none !important;
    }

    /* Chat resize handle */
    .chat-resize-handle {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 6px;
        left: calc(var(--chat-w, 600px) - 3px);
        cursor: col-resize;
        z-index: 1000;
        background: transparent;
        transition:
            background 0.15s,
            left 0.25s cubic-bezier(0.4, 0, 0.2, 1),
            width 0.25s;
    }

    .chat-resize-handle:hover,
    .chat-resize-handle.dragging {
        background: rgba(255, 255, 255, 0.15);
    }

    /* Collapse/expand button centered on handle — hidden until hover */
    .chat-collapse-btn {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 14px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.03);
        border: none;
        border-radius: 5px;
        cursor: pointer;
        color: rgba(255, 255, 255, 0.25);
        backdrop-filter: blur(12px) saturate(1.3);
        -webkit-backdrop-filter: blur(12px) saturate(1.3);
        transition:
            color 0.15s,
            background 0.15s,
            border-color 0.15s,
            opacity 0.15s;
        z-index: 1;
        opacity: 0;
        pointer-events: none;
    }

    .chat-resize-handle:hover .chat-collapse-btn {
        opacity: 1;
        pointer-events: auto;
    }

    .chat-collapse-btn:hover {
        color: rgba(255, 255, 255, 0.55);
        background: rgba(255, 255, 255, 0.08);
    }

    .chat-collapse-btn svg {
        transition: transform 0.2s;
    }

    /* When chat is collapsed */
    body.chat-collapsed .chat {
        transform: translateX(-100%);
    }

    body.chat-collapsed .chat-bar {
        transform: translateX(-100%);
    }

    body.chat-collapsed .desktop {
        left: 0 !important;
    }

    body.chat-collapsed .chat-resize-handle {
        left: 0 !important;
        width: 20px;
        background: none !important;
        cursor: pointer;
        transition: background 0.2s, width 0.2s;
    }

    body.chat-collapsed .chat-resize-handle:hover {
        width: 28px;
        background: rgba(255, 255, 255, 0.06) !important;
    }

    body.chat-collapsed .chat-collapse-btn {
        left: 8px;
        border-radius: 0 6px 6px 0;
        opacity: 1;
        pointer-events: auto;
    }

    body.chat-collapsed .chat-collapse-btn svg {
        transform: rotate(180deg);
    }

    body.chat-collapsed .profile-overlay {
        left: 0;
    }

    /* Floating compose button on desktop when chat collapsed AND app is open */
    body.chat-collapsed.app-active .mobile-compose-btn {
        display: flex;
        position: fixed;
        top: 10px;
        right: 58px;
        left: auto;
    }

    body:has(.desktop.profile-open) .mobile-compose-btn {
        display: none !important;
    }

    /* Disable transitions during drag resize */
    body.chat-resizing .chat,
    body.chat-resizing .chat-bar,
    body.chat-resizing .desktop,
    body.chat-resizing .chat-resize-handle {
        transition: none !important;
    }
}

/* Hide resize handle on mobile */
@media (max-width: 799px) {
    .chat-resize-handle {
        display: none;
    }
}

/* ── Public apps grid (4 columns, same as dashboard) ── */
.profile-apps-strip {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 2px 16px 10px 16px;
    margin-bottom: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.profile-apps-strip::-webkit-scrollbar {
    display: none;
}

.profile-app-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 6px;
    border-radius: 14px;
    transition: background 0.15s;
    width: 88px;
    min-width: 88px;
    flex-shrink: 0;
}

.profile-app-icon:hover {
    background: rgba(255, 255, 255, 0.06);
}

.profile-app-icon:active .profile-app-icon-box {
    transform: scale(0.94);
}

.profile-app-icon-box {
    width: 68px;
    height: 68px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition:
        transform 0.15s,
        box-shadow 0.15s;
    flex-shrink: 0;
}

.profile-app-icon:hover .profile-app-icon-box {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.profile-app-icon-label {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

@media (min-width: 800px) {
    .profile-inline-content {
        margin: 0;
    }

    .profile-apps-strip {
        padding-left: 32px;
        padding-right: 32px;
        gap: 8px;
    }

    .profile-overlay-content {
        padding: 12px 24px 0;
    }
}

@media (min-width: 1200px) {

    .profile-overlay-content {
        padding: 12px 40px 0;
    }
}

.people-search {
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
}

.people-search:focus {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
}

.desktop-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    transition:
        background 0.15s,
        transform 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.desktop-icon:hover {
    background: rgba(255, 255, 255, 0.06);
}

.desktop-icon .icon-box {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: box-shadow 0.15s;
}

.desktop-icon:hover .icon-box {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ── Building state (app is being created) ── */
.icon-box.icon-building-box {
    position: relative;
    overflow: hidden;
    background: transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border-radius: 15px;
}

.icon-building-inner {
    position: absolute;
    inset: 0;
    border-radius: 15px;
    overflow: hidden;
}

.icon-building-overlay {
    position: absolute;
    inset: 0;
    border-radius: 15px;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1;
    pointer-events: none;
}

.icon-arc-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.icon-arc-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.2);
    stroke-width: 3;
    stroke-linecap: round;
}

.icon-arc-fill {
    fill: none;
    stroke: #fff;
    stroke-width: 3;
    stroke-linecap: round;
    /* JS-driven animation — no CSS transition */
}

.icon-building-pct {
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    z-index: 3;
    pointer-events: none;
    letter-spacing: -0.5px;
    line-height: 1;
}

.desktop-icon .icon-box.icon-logo {
    object-fit: cover;
    border-radius: 15px;
    font-size: 0;
}

.desktop-icon .icon-label {
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;
    line-height: 1.2;
}

.desktop-icon {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.desktop-icon .icon-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    border: 2px solid var(--bg-primary);
    font-size: 11px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
}

.desktop-icon:hover .icon-delete {
    opacity: 1;
}

@media (max-width: 799px) {
    .desktop-icon .icon-delete {
        display: none !important;
    }
}

/* ── Large desktop: bigger icons ── */
@media (min-width: 1200px) {
    .desktop-icon .icon-box {
        width: 88px;
        height: 88px;
        border-radius: 20px;
        font-size: 32px;
    }

    .desktop-icon .icon-box.icon-logo img {
        border-radius: 20px;
    }

    .icon-box.icon-building-box,
    .icon-building-inner,
    .icon-building-overlay {
        border-radius: 20px;
    }

    .icon-building-pct {
        font-size: 22px;
    }

    .desktop-icon .icon-label {
        font-size: 12px;
    }
}

/* ── Icon context menu (mobile long-press) ── */
.icon-context-menu {
    background: rgba(30, 30, 36, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    min-width: 140px;
}

.icon-context-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    color: var(--text);
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.icon-context-item.danger {
    color: #ef4444;
}

/* ── Drag & Drop Reordering ── */

.desktop-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: var(--text-muted);
    user-select: none;
}

.desktop-empty .empty-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.desktop-empty .empty-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dim);
}

.desktop-empty .empty-sub {
    font-size: 14px;
    margin-top: 6px;
}

/* ── Chat Backdrop ── */
.chat-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: -1;
    pointer-events: none;
}

.chat-backdrop.open {
    pointer-events: auto;
}

body.chat-open .chat-backdrop {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
}

body.chat-open .chat {
    display: flex;
    background: rgba(0, 0, 0, 0.45);
}

body.chat-open .chat-body {
    overflow-y: auto;
    overflow-x: hidden;
    justify-content: flex-start;
    opacity: 1;
    overscroll-behavior: contain;
}

body.chat-open .chat-body::before {
    content: '';
    flex: 1 0 0px;
}

body.chat-open .messages {
    overflow: visible;
    padding-bottom: 4px;
}

/* ── Chat header (logo, wide screens only) ── */
.chat-header {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: var(--chat-w, 600px);
    flex-shrink: 0;
    padding: 16px 20px 16px;
    background: rgba(10, 10, 10, 0.75);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--border);
}

.chat-header::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -20px;
    height: 20px;
    background: linear-gradient(to bottom, rgba(10, 10, 10, 0.3), transparent);
    pointer-events: none;
}

.chat-context {
    position: absolute;
    left: 50%;
    top: 18px;
    transform: translateX(-50%);
    z-index: 101;
    display: none;
}

@media (min-width: 800px) {
    .chat-header {
        display: flex;
        align-items: center;
        width: var(--chat-w, 600px);
        z-index: 100;
    }

    .chat-header .chat-logo {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .logo-panel {
        display: block;
    }

    .chat-context {
        display: block;
    }
}

@media (max-width: 799px) {
    body.chat-open .chat-header {
        display: flex;
        position: fixed;
        top: 20px;
        left: 0;
        right: 0;
        width: 100% !important;
        justify-content: center;
        align-items: center;
        padding: 14px 16px;
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border-bottom: none;
        z-index: 1002;
    }

    body.chat-open .logo-panel {
        display: none;
    }

    body.chat-open .chat-header::after {
        display: none;
    }

    .chat-context-btn {
        background: rgba(30, 30, 30, 0.55);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 12px;
        padding: 7px 14px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
        color: rgba(255, 255, 255, 0.85);
    }

    body.chat-open .chat-menu {
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
    }

    body.chat-open .chat-menu-btn {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.18);
        color: #fff;
    }

    body.chat-open .chat-body {
        padding-top: 56px;
    }

}

/* Mobile: kill all chat animations for instant open/close */
@media (max-width: 799px) {
    .chat {
        transition: none !important;
    }

    .chat-input-row {
        transition: border-color 0.15s !important;
    }

    .chat-close-inline {
        transition:
            width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            background 0.15s !important;
    }

    .chat-backdrop {
        transition: none !important;
    }

    .chat-body {
        transition: none !important;
        display: none;
    }

    body.chat-open .chat-body {
        display: flex;
    }
}

/* ── Chat three-dots menu ── */
.chat-menu {
    margin-left: auto;
    position: relative;
    flex-shrink: 0;
}

.chat-menu-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background 0.15s,
        color 0.15s;
}

.chat-menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.chat-menu-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: rgba(18, 18, 22, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 2100;
    padding: 4px;
    overflow: hidden;
}

.chat-menu-dropdown.open {
    display: block;
}

.chat-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    background: none;
    border-radius: 7px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    color: var(--text);
    transition: background 0.1s;
    text-align: left;
}

.chat-menu-item:hover {
    background: rgba(255, 255, 255, 0.07);
}

.chat-menu-item.danger {
    color: #f87171;
}

.chat-menu-item.danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

@media (max-width: 799px) {
    .chat-menu {
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        margin-left: 0;
    }

    body:not(.chat-open) .chat-menu {
        display: none;
    }

    .chat-menu-dropdown {
        right: 0;
    }
}

/* ── Confirm modal ── */
.confirm-modal {
    display: none;
    position: fixed;
    z-index: 10011;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-hover);
    border-radius: 16px;
    padding: 24px;
    width: 300px;
    max-width: calc(100vw - 48px);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.confirm-modal.open {
    display: block;
}

.confirm-modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.confirm-modal-desc {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-modal-actions {
    display: flex;
    gap: 8px;
}

.confirm-modal-btn {
    flex: 1;
    padding: 9px;
    border-radius: 10px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}

.confirm-modal-btn:hover {
    opacity: 0.85;
}

.confirm-modal-btn.danger {
    background: #ef4444;
    color: #fff;
}

.confirm-modal-btn.cancel {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.chat-context-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    min-width: 200px;
    max-width: 280px;
    justify-content: center;
    transition: background 0.15s;
}

.chat-context-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.chat-context-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-context-btn svg {
    flex-shrink: 0;
    opacity: 0.6;
    transition: transform 0.15s;
}

.chat-context-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    width: 280px;
    background: rgba(18, 18, 22, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    overflow: hidden;
}

.chat-context-dropdown.open {
    display: block;
}

.chat-context-search-wrap {
    padding: 8px 8px 4px;
}

.chat-context-search {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.chat-context-search::placeholder {
    color: var(--text-dim);
}

.chat-context-search:focus {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
}

.chat-context-list {
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-context-item {
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition:
        background 0.1s,
        color 0.1s;
}

.chat-context-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.chat-context-item.active {
    color: #fff;
    background: var(--accent);
}

.chat-ctx-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}

.chat-ctx-icon-img {
    object-fit: cover;
    border-radius: 6px;
}

.chat-ctx-icon-globe {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-dim);
}

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

.chat-ctx-del {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    margin-left: auto;
    margin-right: -4px;
    color: var(--text-dim);
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.chat-context-item:hover .chat-ctx-del {
    opacity: 1;
}

.chat-context-item.active .chat-ctx-del {
    opacity: 1;
    color: rgba(255, 255, 255, 0.7);
}

.chat-context-item.active .chat-ctx-del:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
}

.chat-ctx-del:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* ── Universal iframe loader ── */
.iframe-loader-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.iframe-loader-dot {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: iframe-spin 0.7s linear infinite;
}

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

[data-theme="light"] .iframe-loader-dot {
    border-color: rgba(0, 0, 0, 0.08);
    border-top-color: var(--accent);
}

/* ── New chat button ── */
.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.chat-new-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

[data-theme="light"] .chat-new-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
}

/* ── Chat segmented control (iOS style) ── */
.chat-seg {
    display: flex;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 9px;
    padding: 3px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.chat-seg-slider {
    position: absolute;
    top: 3px;
    bottom: 3px;
    background: var(--accent);
    border-radius: 7px;
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.chat-seg-btn {
    flex: 1;
    padding: 6px 20px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s;
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.chat-seg-btn.active {
    color: #fff;
}

.chat-seg-btn:not(.active):hover {
    color: var(--text-secondary);
}

.chat-seg-btn:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background: rgba(255, 255, 255, 0.12);
    transition: opacity 0.2s;
}

.chat-seg-btn.active::after,
.chat-seg-btn:has(+ .chat-seg-btn.active)::after {
    opacity: 0;
}

[data-theme="light"] .chat-seg-btn:not(:last-child)::after {
    background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .chat-seg {
    background: rgba(0, 0, 0, 0.06);
}

@media (max-width: 799px) {
    body.chat-open .chat-seg {
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    [data-theme="light"] body.chat-open .chat-seg {
        background: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
}

/* ── App Picker Popup (Add to App from general chat) ── */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.app-picker-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.app-picker-popup {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 280px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.app-picker-title {
    padding: 14px 16px 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.app-picker-list {
    overflow-y: auto;
    padding: 0 6px 6px;
    max-height: 340px;
}

.app-picker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}

.app-picker-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.app-picker-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
}

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

[data-theme="light"] .app-picker-popup {
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .app-picker-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ── Description panel (iframe) ── */
.chat-desc-panel {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.chat-desc-panel.visible {
    display: block;
}

.chat-media-panel {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
}

.chat-media-panel.visible {
    display: block;
}

.chat-close {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 10001;
}

body.chat-open .chat-close {
    display: flex;
}

.chat-open .chat-context {
    display: block;
}

@media (max-width: 799px) {
    body.chat-open .chat-context {
        position: fixed;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1003;
        box-shadow: 0 2px 52px rgba(0, 0, 0, 0.2);
        border-radius: 12px;
    }
}

@media (max-width: 799px) {
    body.chat-open .chat-close {
        display: none;
    }
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text);
}

/* ── Inline close button (mobile only, inside chat-bar) ── */
.chat-close-inline {
    width: 0;
    height: 44px;
    min-width: 0;
    opacity: 0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    pointer-events: none;
    transition:
        width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.15s;
    padding: 0;
}

.chat-close-inline:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

@media (max-width: 799px) {
    body.chat-open .chat-close-inline {
        width: 44px;
        opacity: 1;
        pointer-events: auto;
    }
}

@media (min-width: 800px) {
    .chat-close-inline {
        display: none;
    }
}

/* ── Input bar (independent from chat panel) ── */
.chat-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-end;
    padding: 16px 16px 10px;
    gap: 12px;
    background: transparent;
    z-index: 10001;
}

/* Gradient shadow fading into the input */
.chat-bar::before {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(to bottom, transparent, var(--bg-primary));
    pointer-events: none;
}

/* Desktop: input bar sits at the bottom of the sidebar area */
@media (min-width: 800px) {
    .chat-bar {
        right: auto;
        width: var(--chat-w, 600px);
        padding-bottom: 20px;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* Mobile: hide chat-bar when an app is active (until chat is opened) */
@media (max-width: 799px) {
    body.app-active .chat-bar {
        display: none;
    }

    body.app-active.chat-open .chat-bar {
        display: flex;
    }
}

/* Taskbar window buttons */
.chat-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-family: inherit;
    padding: 0;
}

.chat-btn:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

.chat-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.chat-btn.minimized {
    opacity: 0.5;
}

/* ── Taskbar Input ── */
.chat-input {
    flex: 0 1 800px;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ── Media attachment preview (Telegram-style reply) ── */
.media-attach-preview {
    display: none;
    min-width: 0;
}

.media-attach-preview.has-media {
    display: block;
    margin-bottom: 6px;
}

.media-attach-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: rgba(20, 20, 20, 0.55);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
}

.media-attach-accent {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 3px 0 0 3px;
}

.media-attach-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.media-attach-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.media-attach-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

.media-attach-prompt {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-attach-close {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    border-radius: 50%;
    transition: all 0.15s;
}

.media-attach-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
}

.chat-input .photo-preview {
    display: none;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-x: auto;
    scrollbar-width: none;
    margin-bottom: 6px;
}

.chat-input .photo-preview::-webkit-scrollbar {
    display: none;
}

.chat-input .photo-preview.has-photos,
.chat-input .photo-preview.has-attachments {
    display: flex;
}

.chat-input-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid rgb(22 22 22);
    border-radius: 14px;
    padding: 6px 6px;
    min-height: 52px;
    cursor: text;
    transition:
        background 0.2s,
        border-color 0.15s,
        border-radius 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    background: rgb(22 22 22);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

.chat-input-top {
    display: flex;
    align-items: flex-end;
    gap: 0;
    width: 100%;
}

.chat-input-bottom {
    display: flex;
    align-items: center;
    padding: 2px 2px 2px 2px;
}

.model-selector {
    position: relative;
}

.model-selected {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    padding: 2px 20px 2px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.model-selected::after {
    content: '';
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-bottom: 4px solid currentColor;
    opacity: 0.5;
}

.model-selected:hover,
.model-selector.open .model-selected {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.model-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    min-width: 120px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.model-selector.open .model-dropdown {
    display: flex;
    flex-direction: column;
}

.model-option {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-family: inherit;
    padding: 7px 12px;
    border-radius: 7px;
    cursor: pointer;
    text-align: left;
    transition: all 0.12s;
}

.model-option:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.model-option+.model-option {
    margin-top: 2px;
}

.model-option.active {
    color: #fff;
    background: var(--accent);
}

.chat-input-row:focus-within {
    background: rgba(20, 20, 20, 0.55);
    border-color: var(--accent);
}

.chat-attach {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s;
    margin-bottom: 5px;
}

.chat-attach:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.chat-input-row textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    min-width: 0;
    padding: 8px 4px 8px 4px;
    text-overflow: ellipsis;
    resize: none;
    overflow-y: hidden;
    max-height: 150px;
    height: 36px;
}

.chat-input-row textarea::placeholder {
    color: var(--text-muted);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.chat-mic {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s;
}

.chat-mic:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.chat-mic.recording {
    color: #ef4444;
    animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ── Voice Recording Overlay ── */
.voice-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--bg);
    border-radius: inherit;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
    z-index: 10;
}

.voice-overlay.active {
    display: flex;
}

.chat-input-row:has(.voice-overlay.active)> :not(.voice-overlay) {
    opacity: 0;
    pointer-events: none;
}

.voice-overlay-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.voice-rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: mic-pulse 1s ease-in-out infinite;
}

.voice-timer {
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 32px;
}

.voice-waveform-canvas {
    flex: 1;
    height: 36px;
    min-width: 60px;
    display: block;
}

.voice-stop-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ef4444;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.voice-stop-btn:hover {
    background: #dc2626;
}

/* ── Voice Player Widget ── */
.voice-msg {
    max-width: 320px;
}

.voice-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.voice-play-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.voice-play-btn:hover {
    background: var(--accent-light);
}

.voice-bars {
    display: flex;
    align-items: center;
    gap: 1.5px;
    flex: 1;
    height: 32px;
    min-width: 0;
}

.voice-bar {
    width: 3px;
    min-height: 3px;
    border-radius: 1.5px;
    background: rgba(255, 255, 255, 0.25);
    transition: background 0.15s ease;
}

.voice-bar.played {
    background: var(--accent);
}

.voice-duration {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.voice-transcript {
    font-size: 13px;
    color: inherit;
    opacity: 0.8;
    padding-top: 2px;
    line-height: 1.4;
    min-height: 0;
}

.voice-transcript:empty {
    display: none;
}

.voice-transcript.transcribing::after {
    content: "";
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    margin-left: 4px;
    animation: mic-pulse 1s ease-in-out infinite;
}

.voice-bar {
    flex-shrink: 0;
}

.msg.user .voice-bar {
    background: rgba(255, 255, 255, 0.35);
}

.msg.user .voice-bar.played {
    background: #fff;
}

.msg.user .voice-duration {
    color: rgba(255, 255, 255, 0.7);
}

.msg.user .voice-play-btn {
    background: rgba(255, 255, 255, 0.25);
}

.msg.user .voice-play-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.chat-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-send:hover:not(:disabled) {
    background: var(--accent-light);
}

.chat-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ── Window Manager ── */
.wm-window {
    position: fixed;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    min-width: 320px;
    min-height: 200px;
}

.wm-window.wm-active {
    border-color: var(--border-hover);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.wm-title-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.6;
    margin-left: 6px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.wm-window.wm-maximized {
    border-radius: 0;
}

.wm-titlebar {
    height: 36px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: rgba(30, 30, 30, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: grab;
    flex-shrink: 0;
    gap: 8px;
    user-select: none;
    transition:
        background 0.2s,
        backdrop-filter 0.2s;
}

.wm-active .wm-titlebar {
    background: var(--bg-tertiary);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: 1px solid var(--border);
}

.wm-titlebar:active {
    cursor: grabbing;
}

.wm-title-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.wm-title-text {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wm-title-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    margin-right: 8px;
}

.wm-action-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.wm-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.wm-title-buttons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.wm-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.15s;
}

.wm-btn:hover {
    opacity: 0.8;
}

.wm-btn-close {
    background: #ff5f57;
}

.wm-btn-minimize {
    background: #ffbd2e;
}

.wm-btn-maximize {
    background: #28c840;
}

.wm-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}


/* Resize handles */
.wm-resize-handle {
    position: absolute;
    z-index: 2;
}

.wm-resize-n {
    top: -3px;
    left: 10px;
    right: 10px;
    height: 6px;
    cursor: n-resize;
}

.wm-resize-s {
    bottom: -3px;
    left: 10px;
    right: 10px;
    height: 6px;
    cursor: s-resize;
}

.wm-resize-e {
    top: 10px;
    right: -3px;
    bottom: 10px;
    width: 6px;
    cursor: e-resize;
}

.wm-resize-w {
    top: 10px;
    left: -3px;
    bottom: 10px;
    width: 6px;
    cursor: w-resize;
}

.wm-resize-ne {
    top: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    cursor: ne-resize;
}

.wm-resize-nw {
    top: -3px;
    left: -3px;
    width: 14px;
    height: 14px;
    cursor: nw-resize;
}

.wm-resize-se {
    bottom: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    cursor: se-resize;
}

.wm-resize-sw {
    bottom: -3px;
    left: -3px;
    width: 14px;
    height: 14px;
    cursor: sw-resize;
}

.desktop.wm-dragging iframe,
.wm-dragging .wm-content iframe,
body.wm-dragging iframe {
    pointer-events: none;
}

/* ── Mobile: backdrop behind bottom-sheet windows ── */
#wm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1099;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#wm-backdrop.wm-backdrop-visible {
    opacity: 1;
    pointer-events: auto;
}

/* ── Mobile: windows become iOS-style bottom sheets ── */
@media (max-width: 799px) {
    .wm-window {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: 88dvh !important;
        min-width: unset !important;
        min-height: unset !important;
        border-radius: 18px 18px 0 0 !important;
        box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.5) !important;
        transform: translateY(100%);
        transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .wm-window.wm-sheet-open {
        transform: translateY(0);
    }

    .wm-resize-handle {
        display: none !important;
    }

    .wm-btn-minimize,
    .wm-btn-maximize {
        display: none !important;
    }

    /* Titlebar: transparent, no border, no blur */
    .wm-titlebar,
    .wm-active .wm-titlebar {
        cursor: default !important;
        height: 52px !important;
        padding: 0 12px !important;
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-bottom: none !important;
        position: relative;
    }

    /* Hide emoji icon, center title via absolute positioning */
    .wm-title-icon {
        display: none !important;
    }

    .wm-title-text {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        max-width: calc(100% - 96px);
        text-align: center;
        font-size: 14px;
        font-weight: 600;
        color: var(--text);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Move close button group to the right */
    .wm-title-buttons {
        order: 10;
        margin-left: auto;
    }

    /* Large circular close button with ✕ */
    .wm-btn-close {
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        background: rgba(255, 255, 255, 0.1) !important;
        position: relative;
    }

    .wm-btn-close::before,
    .wm-btn-close::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 14px;
        height: 2px;
        background: rgba(255, 255, 255, 0.75);
        border-radius: 1px;
    }

    .wm-btn-close::before {
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .wm-btn-close::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }
}

/* ── App Window ── */
.app-window-iframe {
    flex: 1;
    border: none;
    background: #fff;
    width: 100%;
}

/* ── Common UI ── */

.btn-sm {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-sm:hover {
    border-color: var(--border-hover);
    color: var(--text);
}

/* ── Messages ── */
.messages {
    min-height: min-content;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 20px 16px 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 800px;
}

.messages::-webkit-scrollbar {
    display: none;
}

@media (min-width: 800px) {
    .messages {
        padding-top: 80px;
    }
}

.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg.user {
    background: var(--accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Media reply preview inside user bubble */
.msg-media-reply {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    margin: -4px -4px 6px -4px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.msg-media-reply-accent {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px 0 0 3px;
}

.msg-media-reply-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.msg-media-reply-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
}

.msg-photos {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
    max-width: 100%;
}

.msg-photos-standalone {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-self: flex-end;
    max-width: 85%;
    justify-content: flex-end;
}

.msg-image-standalone {
    align-self: flex-start;
    max-width: 85%;
}

.media-block {
    display: inline-flex;
    flex-direction: column;
}

.msg-photo {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
}

.msg-photo:hover {
    opacity: 0.85;
}

.msg.assistant {
    background: none;
    max-width: 100%;
    padding: 5px 0px 10px;
    font-size: 15px;
    align-self: flex-start;
    white-space: normal;
}

.msg.assistant.msg-error {
    background: rgba(220, 38, 38, 0.15);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #fca5a5;
}

/* Markdown */
.msg.assistant p {
    margin: 0 0 8px 0;
}

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

.msg.assistant code {
    background: rgba(255, 255, 255, 0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9em;
}

.msg.assistant pre {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
}

.msg.assistant pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
}

.msg.assistant ul,
.msg.assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}

.msg.assistant li {
    margin: 2px 0;
}

.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3,
.msg.assistant h4 {
    margin: 10px 0 6px 0;
    line-height: 1.3;
}

.msg.assistant h1 {
    font-size: 1.3em;
}

.msg.assistant h2 {
    font-size: 1.15em;
}

.msg.assistant h3 {
    font-size: 1.05em;
}

.msg.assistant blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--text-dim);
}

.msg.assistant a {
    color: var(--accent-light);
    text-decoration: none;
}

.msg.assistant a:hover {
    text-decoration: underline;
}

.msg.assistant hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 0;
}

.msg.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.msg.assistant th,
.msg.assistant td {
    border: 1px solid var(--border);
    padding: 4px 8px;
    font-size: 13px;
}

.msg.assistant th {
    background: rgba(255, 255, 255, 0.04);
}

.msg.assistant strong {
    font-weight: 600;
}

.msg.system {
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    align-self: center;
    max-width: 100%;
}

.chat-invite-prompt {
    text-align: center;
    padding: 24px 16px;
    margin: 16px;
    background: var(--bg-tertiary);
    border-radius: 14px;
    border: 1px solid var(--border);
}

.chat-invite-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.chat-invite-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.chat-invite-form {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.chat-invite-input {
    width: 140px;
    padding: 10px 12px;
    text-align: center;
    font-size: 18px;
    letter-spacing: 4px;
    text-transform: uppercase;
    font-family: monospace;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text);
    outline: none;
}

.chat-invite-input:focus {
    border-color: var(--accent);
}

.chat-invite-btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
}

.chat-invite-error {
    color: #f87171;
    font-size: 12px;
    margin-top: 8px;
    min-height: 16px;
}

.chat-invite-or {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 12px;
}

.chat-invite-sub-btn {
    margin-top: 8px;
    padding: 8px 20px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-invite-sub-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    opacity: 0.5;
}

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex: 1;
    padding: 32px 24px 48px;
    text-align: center;
}

.back-to-general {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    margin: 8px auto 4px;
    color: var(--secondary-text);
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    transition: color 0.15s;
    width: fit-content;
}

.back-to-general:hover {
    color: var(--accent);
}

.back-to-general .back-arrow {
    font-size: 15px;
}

.chat-empty-img {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    opacity: 0.88;
    pointer-events: none;
    user-select: none;
}

.chat-empty-sub {
    font-size: 13px;
    color: var(--text-muted);
}

.msg.context-switch {
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    align-self: stretch;
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    margin: 4px 0;
}

.msg.context-switch::before,
.msg.context-switch::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.msg.no-tokens {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--red);
    align-self: stretch;
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
}

.no-tokens-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.no-tokens-text {
    flex: 1;
}

/* Success state after top-up */
.msg.no-tokens-success {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    align-self: stretch;
    max-width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
}

.no-tokens-received {
    flex-shrink: 0;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #60a5fa;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.no-tokens-received:hover {
    background: rgba(59, 130, 246, 0.25);
}

.no-tokens-fulfill {
    flex-shrink: 0;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #60a5fa;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.no-tokens-fulfill:hover {
    background: rgba(59, 130, 246, 0.25);
}

/* Top-up modal */
.topup-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.topup-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px 24px;
    max-width: 340px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.topup-modal-icon {
    font-size: 36px;
    margin-bottom: 4px;
}

.topup-modal-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.topup-modal-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 6px;
}

.topup-modal-btn {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.topup-modal-btn:hover {
    opacity: 0.88;
}

.topup-modal-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.topup-modal-cancel {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
}

.topup-modal-cancel:hover {
    color: var(--text);
}

/* Generated images */
.generated-img-wrap {
    position: relative;
    display: inline-block;
    max-width: min(300px, 100%);
    margin: 6px 0;
    line-height: 0;
    flex-shrink: 0;
}

.generated-img-wrap.generating {
    flex-shrink: 0;
    border-radius: 12px;
    overflow: hidden;
    background: #111;
}

.video-failed-card {
    padding: 12px 14px;
    text-align: left;
    line-height: normal;
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: fit-content;
}

.video-failed-title {
    font-size: 14px;
    font-weight: 600;
    color: #fca5a5;
    margin-bottom: 3px;
}

.video-failed-msg {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.4;
}

.video-failed-code {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

.video-failed-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
}

.video-failed-copy:active {
    color: var(--text);
}

/* Generated video player */
.video-player-wrap {
    position: relative;
    cursor: pointer;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
}

.generated-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.video-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        opacity 0.2s,
        transform 0.15s;
    z-index: 2;
    padding-left: 3px;
}

.video-play-btn:active {
    transform: translate(-50%, -50%) scale(0.9);
}

.video-player-wrap.playing .video-play-btn {
    opacity: 0;
    pointer-events: none;
}

.video-player-wrap.playing:hover .video-play-btn {
    opacity: 1;
    pointer-events: auto;
}

.video-fs-btn {
    position: absolute;
    top: 8px;
    right: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 8px;
    border: none;
    color: #fff;
    cursor: pointer;
    z-index: 3;
}

/* Video app integration button — top-left */
/* "Add to App" button — below media, matches media width */
.media-insert-app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
    margin-top: 6px;
    padding: 7px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.45);
    font: 500 12px/1 -apple-system, system-ui, sans-serif;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.media-insert-app-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border-color: rgba(255, 255, 255, 0.15);
}

.media-insert-app-btn:active {
    transform: scale(0.98);
}

.media-insert-app-btn svg {
    flex-shrink: 0;
}

/* Video edit (pencil) button — top-left corner (legacy) */
.video-edit-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 8px;
    border: none;
    color: #fff;
    cursor: pointer;
    z-index: 3;
}

/* Video edit popup */
.video-edit-popup {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 240px;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.08);
    z-index: 100;
    overflow: hidden;
}

.vep-viewport {
    position: relative;
    overflow: hidden;
}

.vep-slider {
    display: flex;
    transition: transform 0.25s ease;
    will-change: transform;
}

.vep-screen {
    min-width: 100%;
    flex-shrink: 0;
    overflow-y: auto;
    scrollbar-width: thin;
}

.vep-screen::-webkit-scrollbar {
    width: 3px;
}

.vep-screen::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.vep-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.vep-back {
    cursor: pointer;
    display: flex;
    align-items: center;
    color: var(--text-dim);
    transition: color 0.15s;
}

.vep-back:hover {
    color: var(--text);
}

.vep-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0 12px 4px;
}

.vep-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: background 0.15s;
}

.vep-option:hover {
    background: rgba(255, 255, 255, 0.05);
}

.vep-value {
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}

.vep-value svg {
    opacity: 0.5;
}

.vep-choice {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}

.vep-choice:hover {
    background: rgba(255, 255, 255, 0.05);
}

.vep-choice.selected {
    color: var(--accent);
}

.vep-choice .vep-check {
    opacity: 0;
    transition: opacity 0.15s;
}

.vep-choice.selected .vep-check {
    opacity: 1;
}

.vep-submit-wrap {
    padding: 8px 12px 12px;
}

.vep-submit {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

.vep-submit:hover {
    opacity: 0.9;
}

.vep-submit:active {
    transform: scale(0.97);
}

.vep-submit:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.vep-submit.hidden {
    display: none;
}

.vep-error {
    font-size: 12px;
    color: #f87171;
    padding: 0 0 8px;
    line-height: 1.4;
    max-width: 216px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Video version group */
.video-version-group {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: flex-start;
}

/* Version column: thumbs + arrows side by side */
.video-version-col {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 4px;
}

.vv-arrow-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 2px;
}

.vv-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    border-radius: 50%;
    transition: opacity 0.2s, background 0.15s, color 0.15s;
    padding: 0;
    flex-shrink: 0;
}

.vv-arrow:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* Version switching: crossfade + resize via a sizing wrapper */
.video-version-stage {
    position: relative;
    transition: width 0.4s ease, height 0.4s ease;
    overflow: hidden;
    border-radius: 12px;
    max-width: 100%;
}

.video-version-main {
    transition: opacity 0.35s ease;
}

.video-version-main.vv-hidden {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
}

/* 3D carousel container */
.video-version-thumbs {
    position: relative;
    perspective: 200px;
    min-width: 48px;
    transition: height 0.4s ease;
    overflow: hidden;
}

.video-version-thumb {
    position: absolute;
    left: 2px;
    top: 0;
    width: 44px;
    height: 34px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.12);
    background: #111;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease, border-color 0.3s, box-shadow 0.3s;
    transform-style: preserve-3d;
    transform-origin: top center;
}

.video-version-thumb:hover {
    border-color: rgba(255, 255, 255, 0.35);
}

.video-version-thumb.active {
    border-color: #fff;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3), 0 2px 12px rgba(0, 0, 0, 0.5);
}

.video-version-thumb .vvt-video,
.video-version-thumb .vvt-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    display: block;
}

.video-version-badge {
    position: absolute;
    bottom: 1px;
    left: 1px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 8px;
    padding: 0 3px;
    border-radius: 3px;
    font-weight: 700;
    line-height: 14px;
}

.video-version-thumb .vvt-loader {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1025, #0d1a2a);
}

.video-version-thumb .vvt-loader::after {
    content: '';
    width: 10px;
    height: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: vvt-spin 0.8s linear infinite;
}

/* Overflow "+N" indicator */
.vv-overflow {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
    cursor: pointer;
}

.vv-overflow-text {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
}

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

/* Placeholder while video is in lightbox */
.video-lb-placeholder {
    border-radius: 12px;
    background: #111;
    margin: 6px 0;
}

/* Video lightbox */
.video-lightbox-video {
    max-width: 95vw;
    max-height: 85vh;
    border-radius: 10px;
    object-fit: contain;
    display: block;
}

.video-lightbox-play {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding-left: 4px;
    z-index: 10000;
    transition:
        opacity 0.2s,
        transform 0.15s;
}

.video-lightbox-play:active {
    transform: translate(-50%, -50%) scale(0.9);
}

/* When playing: hide all controls, show on hover */
.video-lightbox.playing .video-lightbox-play,
.video-lightbox.playing .lightbox-close,
.video-lightbox.playing .lightbox-download {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.video-lightbox.playing:hover .video-lightbox-play,
.video-lightbox.playing:hover .lightbox-close,
.video-lightbox.playing:hover .lightbox-download {
    opacity: 1;
    pointer-events: auto;
}

/* Loader overlay — sits on top of content, fades out when loaded */
.media-loader-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: 12px;
    overflow: hidden;
}

/* Dreamy gradient blur loader for video generation */
.video-dream-loader {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    filter: blur(40px);
    background: #0a0a12;
}

.video-dream-blob {
    position: absolute;
    border-radius: 50%;
    mix-blend-mode: screen;
}

.video-dream-blob-1 {
    width: 70%;
    height: 70%;
    top: -10%;
    left: -10%;
    background: radial-gradient(circle,
            rgba(90, 50, 200, 0.8) 0%,
            transparent 70%);
    animation: dreamDrift1 8s ease-in-out infinite;
}

.video-dream-blob-2 {
    width: 60%;
    height: 60%;
    bottom: -10%;
    right: -10%;
    background: radial-gradient(circle,
            rgba(20, 140, 190, 0.7) 0%,
            transparent 70%);
    animation: dreamDrift2 10s ease-in-out infinite;
}

.video-dream-blob-3 {
    width: 50%;
    height: 50%;
    top: 30%;
    left: 30%;
    background: radial-gradient(circle,
            rgba(200, 60, 120, 0.7) 0%,
            transparent 70%);
    animation: dreamDrift3 12s ease-in-out infinite;
}

@keyframes dreamDrift1 {

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

    33% {
        transform: translate(40%, 20%) scale(1.2);
    }

    66% {
        transform: translate(10%, 50%) scale(0.9);
    }
}

@keyframes dreamDrift2 {

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

    33% {
        transform: translate(-30%, -20%) scale(1.1);
    }

    66% {
        transform: translate(-50%, 10%) scale(1.3);
    }
}

@keyframes dreamDrift3 {

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

    33% {
        transform: translate(20%, -40%) scale(1.2);
    }

    66% {
        transform: translate(-30%, 20%) scale(0.8);
    }
}

/* Crossfade overlay: image loads invisibly on top of placeholder, then fades in */
.generated-img-reveal {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    opacity: 0;
    transition: opacity 0.38s ease;
    display: block;
}

.generated-img-reveal.loaded {
    opacity: 1;
}

.generated-img-placeholder {
    width: 100%;
    height: 100%;
    display: block;
}

/* ── Lightbox ─────────────────────────────────────────────────────────── */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
    cursor: zoom-out;
}

.lightbox-overlay.visible {
    opacity: 1;
}

.lightbox-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    border-radius: 10px;
    object-fit: contain;
    display: block;
    pointer-events: none;
    user-select: none;
}

.lightbox-close {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    z-index: 10000;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.lightbox-download {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background 0.15s;
    z-index: 10000;
}

.lightbox-download:hover {
    background: rgba(255, 255, 255, 0.22);
}

.generated-img {
    cursor: zoom-in;
}

.generated-img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    object-fit: contain;
    display: block;
}

.img-download-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
}

.img-edit-btn {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px 7px 11px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.55), rgba(59, 130, 246, 0.55), rgba(6, 182, 212, 0.55));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    color: #fff;
    font: 600 13px/1 -apple-system, system-ui, sans-serif;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    z-index: 2;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.25);
    letter-spacing: 0.2px;
}

.img-edit-btn:hover {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.75), rgba(59, 130, 246, 0.75), rgba(6, 182, 212, 0.75));
    box-shadow: 0 3px 14px rgba(59, 130, 246, 0.35);
}

.img-edit-btn:active {
    transform: scale(0.95);
}

.img-edit-btn svg {
    flex-shrink: 0;
}

.msg-meta {
    display: none;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
    gap: 4px;
}

.msg.meta-visible .msg-meta {
    display: flex;
}

.msg-meta .tag {
    display: inline-block;
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: "SF Mono", Monaco, monospace;
}

.msg-files {
    margin-top: 4px;
    font-size: 11px;
    color: var(--green);
}

.msg-files span {
    display: inline-block;
    margin-right: 6px;
}

/* ── Photo thumbnails ── */
.photo-thumb {
    position: relative;
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attach-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-remove:hover {
    background: var(--red);
}

.photo-thumb.uploading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    border-radius: inherit;
}

.photo-thumb.uploading::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    z-index: 1;
}

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

/* ── Description block attachments ── */
.desc-block-chip {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.desc-block-chip .attach-remove {
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    width: 16px;
    height: 16px;
    font-size: 10px;
}

.desc-block-chip .attach-remove:hover {
    background: #fff;
}

/* ── Element Picker Button ── */
.pick-element-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: all 0.15s;
}

/* ── Annotate Screenshot Overlay ── */
.annotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: var(--bg-body, #000);
    display: flex;
    flex-direction: column;
}

.annotate-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-primary, #111);
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text, #fff);
}

.annotate-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.annotate-tools-seg {
    display: flex;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 2px;
    position: relative;
}

.annotate-tool-btn {
    padding: 5px 10px;
    border-radius: 6px;
    border: none;
    background: none;
    color: var(--text-muted, #999);
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    transition: color 0.15s;
}

.annotate-tool-btn.active {
    color: #fff;
}

.annotate-seg-indicator {
    position: absolute;
    top: 2px;
    height: calc(100% - 4px);
    background: var(--accent, #007aff);
    border-radius: 6px;
    transition: left 0.2s cubic-bezier(.4, 0, .2, 1), width 0.2s cubic-bezier(.4, 0, .2, 1);
    z-index: 0;
}

.annotate-separator {
    width: 1px;
    height: 20px;
    background: var(--border, rgba(255, 255, 255, 0.1));
    margin: 0 4px;
}

.annotate-color-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: border-color 0.1s;
}

.annotate-color-btn[data-color="#ffffff"] {
    border-color: rgba(255, 255, 255, 0.25);
}

.annotate-color-btn.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--accent, #007aff);
}

.annotate-color-btn:hover {
    border-color: rgba(255, 255, 255, 0.5);
}

.annotate-icon-btn {
    background: none;
    border: none;
    color: var(--text-muted, #999);
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.annotate-icon-btn:hover {
    color: var(--text, #fff);
    background: rgba(255, 255, 255, 0.08);
}

.annotate-action-btn {
    padding: 5px 12px;
    border-radius: 6px;
    border: none;
    background: var(--accent, #007aff);
    color: #fff;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}

.annotate-action-btn:hover {
    opacity: 0.85;
}

.annotate-close {
    background: none;
    border: none;
    color: var(--text-muted, #999);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
}

.annotate-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#annotateCanvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    cursor: crosshair;
}

.annotate-footer {
    padding: 12px 16px;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.1));
}

.annotate-attach-btn {
    padding: 10px 32px;
    border-radius: 10px;
    border: none;
    background: var(--accent, #007aff);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.annotate-attach-btn:hover {
    opacity: 0.85;
}

.picker-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    top: 0;
    right: 0;
    left: var(--chat-w, 600px);
    z-index: 900;
    padding: 6px 16px;
    background: #ef4444;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.picker-banner span {
    flex: 1;
}

.picker-banner button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.picker-banner button:hover {
    color: #fff;
}

@media (max-width: 799px) {
    .picker-banner {
        left: 0;
    }
}

body.chat-collapsed .picker-banner {
    left: 0;
}

body.app-active .pick-element-btn {
    display: flex;
}

.pick-element-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
}

.pick-element-btn.active {
    color: var(--accent);
    background: rgba(0, 122, 255, 0.15);
}

[data-theme="light"] .pick-element-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .pick-element-btn.active {
    background: rgba(0, 122, 255, 0.1);
}

.element-attach-chip {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 44px;
    padding: 0 28px 0 10px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
}

.element-attach-label {
    font-size: 12px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* UI Element card in messages */
.ui-element-card {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 12px;
    line-height: 1.4;
}

.ui-el-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    font-family: 'SF Mono', Monaco, Menlo, monospace;
    margin-bottom: 6px;
}

.ui-el-path {
    color: rgba(255, 255, 255, 0.55);
    font-size: 11px;
    font-family: 'SF Mono', Monaco, Menlo, monospace;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ui-el-text {
    color: rgba(255, 255, 255, 0.85);
    font-size: 12px;
}

[data-theme="light"] .ui-element-card {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .ui-el-tag {
    background: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.7);
}

[data-theme="light"] .ui-el-path {
    color: rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .ui-el-text {
    color: rgba(0, 0, 0, 0.6);
}

/* UI Element card inside user bubble (blue) — white text */
.msg.user .ui-element-card {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.25);
}

.msg.user .ui-el-tag {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.msg.user .ui-el-path {
    color: rgba(255, 255, 255, 0.6);
}

.msg.user .ui-el-text {
    color: rgba(255, 255, 255, 0.9);
}

.element-attach-chip .attach-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    width: 16px;
    height: 16px;
    font-size: 10px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Log Button ── */
.log-btn {
    display: none;
    margin-top: 6px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.msg.meta-visible .log-btn {
    display: inline-block;
}

.log-btn:hover {
    color: var(--accent-light);
    border-color: var(--accent);
}

.btn-logs {
    color: var(--accent-light);
    border-color: var(--accent);
}

.btn-logs:hover {
    background: var(--accent);
    color: #fff;
}

/* ── Thinking ── */
/* ── Thinking cursor indicator ── */
.msg.thinking {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background: transparent;
    align-self: flex-start;
    padding: 8px 4px;
}

@keyframes cursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.fork-cursor {
    display: inline-block;
    width: 8px;
    height: 1.15em;
    background: var(--accent);
    vertical-align: text-bottom;
    animation: cursorBlink 0.6s step-end infinite;
}

/* Dot-to-bubble entrance — disabled, cursor transitions to text directly */
.msg.assistant.from-dot {}

.searching-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    padding: 4px 0;
    animation: searchPulse 1.4s ease-in-out infinite;
}

.msg.assistant.bubble-loading .msg-content {
    color: var(--text);
    min-height: 1.4em;
}

@keyframes typingDots {
    0% {
        content: "";
    }

    25% {
        content: ".";
    }

    50% {
        content: "..";
    }

    75% {
        content: "...";
    }
}

.searching-status span {
    animation: searchPulse 1.4s ease-in-out infinite;
}

@keyframes searchPulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* ── Progress ── */
.msg.progress-msg {
    background: var(--bg-tertiary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    max-width: 90%;
    min-width: 220px;
    border: 1px solid transparent;
    cursor: pointer;
}

.msg.progress-done {
    cursor: pointer;
}

.progress-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.progress-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar-row .progress-bar-track {
    flex: 1;
}

.progress-cancel-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-dim);
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.progress-cancel-btn:hover {
    background: rgba(255, 80, 80, 0.2);
    color: #ff5050;
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    /* JS-driven animation — no CSS transition */
}

.progress-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.progress-text {
    font-size: 13px;
    color: var(--text-dim);
    background: linear-gradient(90deg,
            var(--text-dim),
            var(--accent-light),
            var(--text-dim));
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: thinking-shimmer 2s ease-in-out infinite;
}

.progress-percent {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
}

.progress-done .progress-text {
    animation: none;
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    color: var(--accent-light);
}

.progress-done .progress-percent {
    color: var(--accent-light);
}

.app-done-simple {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--success, #34c759);
    cursor: pointer;
}

.app-done-simple:hover {
    opacity: 0.7;
}

/* ── App Done Card ── */
.app-done-card {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-done-icon-wrap {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    overflow: hidden;
}

.app-done-icon-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-done-icon-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    border-radius: 12px;
}

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

.app-done-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-done-subtitle {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.app-done-arrow {
    flex-shrink: 0;
    color: var(--text-dim);
    display: flex;
    align-items: center;
}

/* ── Task Steps ── */
.msg.task-list {
    background: var(--bg-tertiary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    max-width: 90%;
}

.task-list-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.task-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    line-height: 1.4;
    transition: opacity 0.2s;
}

.task-step-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 10px;
}

.task-step.pending .task-step-icon {
    border: 2px solid var(--text-muted);
    color: transparent;
}

.task-step.in_progress .task-step-icon {
    border: 2px solid var(--accent);
    color: transparent;
    animation: pulse-border 1.2s ease-in-out infinite;
}

.task-step.completed .task-step-icon {
    background: var(--green);
    color: #fff;
    border: none;
}

.task-step.error .task-step-icon {
    background: var(--red);
    color: #fff;
    border: none;
}

.task-step.completed .task-step-text {
    color: var(--text-dim);
}

.task-step.pending .task-step-text {
    color: var(--text-muted);
}

.task-step.in_progress .task-step-text {
    color: var(--text);
}

.task-step.error .task-step-text {
    color: var(--red);
}

@keyframes pulse-border {

    0%,
    100% {
        border-color: var(--accent);
    }

    50% {
        border-color: var(--accent-light);
    }
}

/* ── Responsive: narrow screens ── */
@media (max-width: 600px) {
    .chat-input {
        flex: 1 1 0;
        min-width: 0;
    }

    .public-profile-stats {
        gap: 4px;
    }

    .public-profile-stat {
        padding: 4px 6px;
    }

    .public-profile-stat-num {
        font-size: 14px;
    }

    .public-profile-stat-label {
        font-size: 7px;
    }
}

/* ──────────────────────────────────────────────
   Direct Chat Overlay
────────────────────────────────────────────── */
.dc-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dc-backdrop.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.dc-overlay {
    display: none;
    position: fixed;
    z-index: 1101;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    flex-direction: column;
    overflow: hidden;
}

.dc-overlay.open {
    display: flex;
}

/* Desktop: centered modal */
@media (min-width: 800px) {
    .dc-overlay {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 480px;
        height: 600px;
        border-radius: 18px;
        box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    }
}

/* Mobile: bottom sheet */
@media (max-width: 799px) {
    .dc-backdrop {
        display: block;
        opacity: 0;
        pointer-events: none;
    }

    .dc-backdrop.open {
        pointer-events: auto;
        opacity: 1;
    }

    .dc-overlay {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 85dvh;
        border-radius: 20px 20px 0 0;
    }

    .dc-overlay::before {
        content: "";
        display: block;
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: var(--border-hover);
        border-radius: 2px;
    }
}

/* Header */
.dc-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

@media (max-width: 799px) {
    .dc-header {
        padding-top: 24px;
    }
}

.dc-back {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-radius: 6px;
    transition:
        color 0.15s,
        background 0.15s;
}

.dc-back:hover {
    color: var(--text);
    background: var(--bg-tertiary);
}

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

.dc-avatar-placeholder {
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    border-radius: 50%;
    width: 34px;
    height: 34px;
}

.dc-partner-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Messages area */
.dc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.dc-loading {
    color: var(--text-dim);
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

.dc-msg {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.dc-msg.mine {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.dc-msg.theirs {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.dc-msg-photo {
    max-width: 200px;
    border-radius: 10px;
    display: block;
    margin-top: 4px;
}

.dc-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 2px;
    text-align: right;
}

.dc-msg.theirs .dc-msg-time {
    text-align: left;
}

.dc-date-divider {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    margin: 6px 0;
}

/* Input bar */
.dc-bar {
    flex-shrink: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.dc-input-wrap {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 22px;
    overflow: hidden;
}

.dc-input-row {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    gap: 6px;
}

.dc-attach {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: color 0.15s;
}

.dc-attach:hover {
    color: var(--text);
}

.dc-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    min-width: 0;
    padding: 2px 0;
}

.dc-input::placeholder {
    color: var(--text-dim);
}

.dc-send {
    background: var(--accent);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    flex-shrink: 0;
    transition:
        opacity 0.15s,
        transform 0.15s;
}

.dc-send:disabled {
    opacity: 0.3;
    cursor: default;
}

.dc-send:not(:disabled):hover {
    opacity: 0.85;
}

.dc-photo-preview {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 8px 0;
}

.dc-photo-thumb-wrap {
    position: relative;
    display: inline-block;
}

.dc-photo-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
}

.dc-photo-thumb-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    background: rgba(0, 0, 0, 0.65);
    border: none;
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ── Chat header bell button (desktop only) ── */
.chat-bell-btn {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    padding: 0;
    margin-left: auto;
    transition:
        background 0.15s,
        color 0.15s;
}

@media (min-width: 800px) {
    .chat-bell-btn {
        display: flex;
    }
}

.chat-bell-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.chat-bell-btn.has-unread {
    color: #ef4444;
}

.chat-bell-badge {
    display: none;
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.chat-bell-btn.has-unread .chat-bell-badge {
    display: block;
}

/* ── Desktop notification overlay (covers chat body + bar) ── */
.desktop-notif-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    background: rgba(14, 14, 18, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    flex-direction: column;
    overflow: hidden;
}

.desktop-notif-overlay.open {
    display: flex;
}

.desktop-notif-list {
    flex: 1;
    overflow-y: auto;
    padding-top: 70px;
}

/* ── Chat header transforms when notifs open ── */

/* "Notifications" title — hidden by default, shown in notifs-open state */
.chat-header::before {
    content: var(--notif-title, "Notifications");
    display: none;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin-right: auto;
}

.chat.notifs-open .chat-header::before {
    display: block;
}

/* Hide logo, context selector, and menu when notifs are open */
.chat.notifs-open .logo-panel,
.chat.notifs-open .chat-logo,
.chat.notifs-open .chat-context,
.chat.notifs-open .chat-menu {
    display: none;
}

/* Bell becomes a close (X) icon */
.chat.notifs-open .chat-bell-btn svg {
    display: none;
}

.chat-bell-btn::after {
    content: "";
    display: none;
}

.chat.notifs-open .chat-bell-btn::after {
    content: "✕";
    display: block;
    font-size: 18px;
    line-height: 1;
    color: var(--text-dim);
}

.chat.notifs-open .chat-bell-btn {
    color: var(--text-dim);
}

.chat.notifs-open .chat-bell-btn .chat-bell-badge {
    display: none;
}

.notif-item {
    padding: 12px 16px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 12px;
    line-height: 1.4;
}

.notif-item.unread {
    color: #fff;
}

.notif-clickable {
    cursor: pointer;
}

.notif-item.notif-clickable:hover {
    background: rgba(255, 255, 255, 0.04);
}

.notif-item .notif-time {
    display: none;
    /* replaced by inline notif-time-inline */
}

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

.notif-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

.notif-body {
    flex: 1;
    min-width: 0;
}

.notif-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    display: inline;
}

.notif-username {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
    display: inline;
}

.notif-desc {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    display: inline;
}

.notif-time-inline {
    color: rgba(255, 255, 255, 0.35);
    font-size: 14px;
}

.notif-follow {
    padding: 12px 16px;
}

.notif-follow-btn {
    flex-shrink: 0;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    background: var(--accent, #007aff);
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s;
}

.notif-follow-btn:hover {
    opacity: 0.85;
}

.notif-publish {
    padding: 12px 16px;
}

.notif-app-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    object-fit: cover;
}

.notif-app-icon-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
}

/* ── Mobile compose (pencil) button — fixed top-right ── */
.mobile-compose-btn {
    display: none;
    position: fixed;
    top: 10px;
    right: 58px;
    z-index: 998;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

@media (max-width: 799px) {

    /* Compose button only when app is open and chat is closed */
    body.app-active .mobile-compose-btn {
        display: flex;
    }

    /* When app is open: hide entire chat panel */
    body.app-active .chat {
        display: none !important;
    }

    /* When chat is open: restore chat panel */
    body.app-active.chat-open .chat {
        display: flex !important;
    }

    /* Hide compose button when chat is open or profile is open */
    body.chat-open .mobile-compose-btn,
    body:has(.desktop.profile-open) .mobile-compose-btn {
        display: none !important;
    }
}

/* ── Mobile app notif button (outside chatPanel, fixed bottom-left) ── */
.mobile-app-notif-btn {
    display: none;
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: 998;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(20, 20, 20, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #999;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.mobile-app-notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    display: none;
}

.mobile-app-notif-btn.has-unread .mobile-app-notif-badge {
    display: block;
}

/* mobile-app-notif-btn removed — notifications accessible via chat header */

/* ── Mobile notification bell button ── */
.mobile-notif-btn {
    display: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    padding: 0;
    box-shadow: 0 2px 52px rgba(0, 0, 0, 0.2);
}

.mobile-notif-btn.has-unread {
    color: #ef4444;
}

@media (max-width: 799px) {
    .mobile-notif-btn {
        display: flex;
    }
}

.mobile-notif-badge {
    display: none;
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.mobile-notif-btn.has-unread .mobile-notif-badge {
    display: block;
}

/* ── Mobile notification modal ── */
.mobile-notif-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2000;
}

.mobile-notif-backdrop.open {
    display: block;
}

.mobile-notif-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2001;
    background: var(--bg-body, #000);
    flex-direction: column;
    overflow: hidden;
}

.mobile-notif-modal.open {
    display: flex;
}

.mobile-notif-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 20px;
    font-size: 17px;
    font-weight: 700;
    color: var(--text, #fff);
    flex-shrink: 0;
    position: relative;
}

.mobile-notif-close {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted, #999);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.mobile-notif-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 env(safe-area-inset-bottom);
}

.notif-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text, #fff);
    padding: 16px 16px 8px;
}

.notif-section-title:first-child {
    padding-top: 8px;
}

.notif-follow-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.notif-follow-btn.following {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
}

/* ── Error Card ── */
.error-msg {
    padding: 0 !important;
}

.error-card {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 12px;
    padding: 12px 16px;
    max-width: 420px;
}

.error-summary {
    color: #f87171;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    word-break: break-word;
}

.error-location {
    color: var(--text-muted);
    font-size: 12px;
    font-family: ui-monospace, "SF Mono", monospace;
    margin-top: 4px;
}

.error-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.error-details-btn {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.error-details-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.error-fix-btn {
    background: #ef4444;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.error-fix-btn:hover {
    opacity: 0.85;
}

.error-fix-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* App edit suggestions tooltip */
.app-edit-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: rgba(30, 30, 30, 0.92);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 4px;
    z-index: 100;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.app-edit-suggestion-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.app-edit-suggestion-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.app-edit-magic:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

/* Navigate widget */
.msg.navigate-widget-msg {
    align-self: flex-start;
    background: none;
    padding: 4px 0;
}

.navigate-btn {
    background: var(--accent, #6366f1);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.navigate-btn:hover {
    filter: brightness(1.1);
}

.navigate-btn:active {
    filter: brightness(0.9);
}

/* ══════════════════════════════════════════════
   Light Theme Overrides
═══════════════════════════════════════════════ */

/* Glass surfaces: tabs, chat bar, header */
[data-theme="light"] .desktop-tabs {
    background: rgba(255, 255, 255, 0.7);
    border-color: var(--border);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .desktop-tabs-indicator {
    background: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .desktop-tab {
    color: var(--text-dim);
}

[data-theme="light"] .desktop-tab.active {
    color: var(--text);
}

/* Desktop icon hover */
[data-theme="light"] .desktop-icon:hover {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .desktop-icon .icon-box {
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .desktop-icon:hover .icon-box {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

[data-theme="light"] .desktop-icon .icon-label {
    color: var(--text);
}

/* Chat / taskbar */
[data-theme="light"] .chat-collapse-btn {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-muted);
}

[data-theme="light"] .chat-collapse-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text);
    border-color: var(--border);
}

[data-theme="light"] .chat-header {
    background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .chat-header::after {
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), transparent);
}

[data-theme="light"] .chat-header::before {
    color: var(--text);
}

[data-theme="light"] body.chat-open .chat {
    background: #fff;
}

[data-theme="light"] body.chat-open .chat-backdrop {
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
}

/* Desktop chat sidebar */
@media (min-width: 800px) {
    [data-theme="light"] .chat {
        background: #fff !important;
        border-right-color: var(--border);
    }

    [data-theme="light"] .chat-body {
        background: rgba(255, 255, 255, 0.5) !important;
        backdrop-filter: blur(24px) saturate(1.2) !important;
        -webkit-backdrop-filter: blur(24px) saturate(1.2) !important;
    }
}

[data-theme="light"] .chat-bar {
    background: transparent;
}

[data-theme="light"] .chat-bar::before {
    background: linear-gradient(to bottom,
            transparent,
            rgba(255, 255, 255, 0.85));
}

[data-theme="light"] .chat-input-row {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-color: var(--border) !important;
}

[data-theme="light"] .chat-input-row:focus-within {
    border-color: var(--accent) !important;
}

[data-theme="light"] .model-selected:hover,
[data-theme="light"] .model-selector.open .model-selected {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .model-dropdown {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .model-option:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .model-option.active {
    color: #fff;
    background: var(--accent);
}

[data-theme="light"] .media-attach-bar {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--border);
}

[data-theme="light"] .chat-send {
    color: #fff;
}

[data-theme="light"] .voice-bar {
    background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .voice-overlay {
    background: var(--bg);
}

/* Public profile header */
[data-theme="light"] .public-profile {
    background: rgba(255, 255, 255, 0.7);
    border-color: var(--border);
}

/* Profile open — white background in light theme */
#bgCanvas.profile-fade {
    opacity: 0;
}

[data-theme="light"] body.profile-bg-white {
    background: #fff;
}

[data-theme="light"] .desktop.profile-open .public-profile {
    background: transparent;
    border-color: transparent;
}

[data-theme="light"] .desktop.profile-open .profile-inline-panel {
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Desktop gradients */
[data-theme="light"] .desktop::before {
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0.3) 40%,
            transparent 100%);
}

[data-theme="light"] .desktop::after {
    background: linear-gradient(to top,
            rgba(255, 255, 255, 0.3) 40%,
            transparent 100%);
}

/* Profile pill / dropdown */
[data-theme="light"] .profile-dropdown {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .profile-dropdown-item:hover {
    background: var(--hover-overlay);
}

[data-theme="light"] .profile-dropdown-item.danger:hover {
    background: rgba(255, 59, 48, 0.08);
}

/* Profile panel */
[data-theme="light"] .public-profile-name {
    color: var(--text);
}

[data-theme="light"] .public-profile-username {
    color: var(--text-dim);
}

/* Window manager windows */
[data-theme="light"] .wm-window {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .wm-titlebar {
    background: var(--bg-primary);
    border-color: var(--border);
}

[data-theme="light"] .wm-titlebar-title {
    color: var(--text);
}

/* Messages */
[data-theme="light"] .msg.assistant {
    color: var(--text);
}

[data-theme="light"] .msg.user {
    color: #fff;
}

/* Hide modals whose full styles are in lazy-loaded CSS modules.
   Without this, elements render unstyled until the module CSS arrives. */
.fork-modal-backdrop,
.fork-modal,
.share-modal,
.integrations-modal,
.trash-modal,
.settings-modal,
.asset-modal,
.sub-modal {
    display: none;
}

/* Backdrop base — must be in app.css so confirm/clear-chat modals work
   even before lazy modules load. Module CSS can override with richer styles. */
.fork-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.fork-modal-backdrop.open {
    display: block;
}

/* Modals */
[data-theme="light"] .fork-modal-backdrop {
    background: rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .fork-modal,
[data-theme="light"] .confirm-modal,
[data-theme="light"] .share-modal,
[data-theme="light"] .trash-modal,
[data-theme="light"] .settings-modal,
[data-theme="light"] .asset-modal,
[data-theme="light"] .sub-modal {
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .chat-close-inline {
    background: rgba(255, 255, 255, 0.85);
    border-color: var(--border);
    color: var(--text-muted);
    box-shadow: 0 2px 52px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .chat-close-inline:hover {
    background: #fff;
    color: var(--text);
}

/* Chat context selector */
[data-theme="light"] .chat-context-btn {
    color: var(--text-dim);
}

[data-theme="light"] .chat-context-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
}

@media (max-width: 799px) {
    [data-theme="light"] body.chat-open .chat-context-btn {
        background: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    [data-theme="light"] body.chat-open .chat-menu-btn {
        background: rgba(0, 0, 0, 0.05);
        border-color: var(--border);
        color: var(--text);
    }
}

[data-theme="light"] .chat-context-dropdown {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .chat-context-search {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="light"] .chat-context-search:focus {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

[data-theme="light"] .chat-context-item {
    color: var(--text-dim);
}

[data-theme="light"] .chat-context-item:hover {
    background: var(--hover-overlay);
    color: var(--text);
}

[data-theme="light"] .chat-context-item.active {
    color: #fff;
    background: var(--accent);
}

/* Chat three-dots menu */
[data-theme="light"] .chat-menu-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .logo-panel.open .logo-panel-body {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .logo-panel-item:hover {
    background: var(--hover-overlay);
}

[data-theme="light"] .logo-panel-item.danger {
    color: #dc2626;
}

[data-theme="light"] .logo-panel-item.danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

[data-theme="light"] .chat-menu-dropdown {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .chat-menu-item {
    color: var(--text);
}

[data-theme="light"] .chat-menu-item:hover {
    background: var(--hover-overlay);
}

[data-theme="light"] .chat-menu-item.danger {
    color: #dc2626;
}

[data-theme="light"] .chat-menu-item.danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

/* Input fields */
[data-theme="light"] .edit-profile-input {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--text);
}

/* Buttons with white text on dark bg — keep them visible */
[data-theme="light"] .notif-follow-btn {
    background: var(--text);
    color: var(--bg-primary);
}

[data-theme="light"] .notif-follow-btn.following {
    background: var(--bg-tertiary);
    color: var(--text-dim);
}

/* Notification items */
[data-theme="light"] .notif-item {
    color: var(--text-dim);
    border-bottom-color: var(--border);
}

[data-theme="light"] .notif-item.unread {
    color: var(--text);
}

[data-theme="light"] .notif-name {
    color: var(--text);
}

[data-theme="light"] .notif-username {
    color: var(--text-muted);
}

[data-theme="light"] .notif-desc {
    color: var(--text-dim);
}

/* Mobile buttons */
[data-theme="light"] .mobile-notif-btn {
    background: rgba(255, 255, 255, 0.85);
    border-color: var(--border);
    color: var(--text-dim);
}

[data-theme="light"] .mobile-app-notif-btn {
    background: rgba(255, 255, 255, 0.85);
    border-color: var(--border);
    color: var(--text-dim);
}

[data-theme="light"] .mobile-compose-btn {
    background: rgba(30, 30, 30, 0.55);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.75);
}

/* Mobile notification modal */
[data-theme="light"] .mobile-notif-modal {
    background: #fff;
}

[data-theme="light"] .mobile-notif-header {
    color: var(--text);
}

[data-theme="light"] .mobile-notif-close {
    color: var(--text-dim);
}

[data-theme="light"] .notif-section-title {
    color: var(--text);
}

/* Direct chat overlay */
[data-theme="light"] .dc-backdrop {
    background: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .dc-overlay {
    background: var(--bg-primary);
    border-color: var(--border);
}

/* Desktop notification overlay */
[data-theme="light"] .desktop-notif-overlay {
    background: rgba(255, 255, 255, 0.97);
}

/* Error card */
[data-theme="light"] .error-details-btn {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

[data-theme="light"] .error-details-btn:hover {
    background: var(--hover-overlay-strong);
}

/* Icon delete button */
[data-theme="light"] .icon-delete {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}

/* Scrollbar */
[data-theme="light"] .chat-body {
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* Context menu */
[data-theme="light"] .icon-context-menu {
    background: var(--bg-primary);
    border-color: var(--border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .icon-context-item:hover {
    background: var(--hover-overlay);
}

/* Settings theme toggle */
.settings-theme-toggle {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 3px;
    flex-shrink: 0;
}

.settings-theme-btn {
    padding: 5px 12px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition:
        background 0.2s,
        color 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.settings-theme-btn.active {
    background: var(--bg-secondary);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .settings-theme-btn.active {
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.settings-lang-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 28px 6px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.settings-lang-select:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-sub-btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    transition: opacity 0.15s;
}

.settings-sub-btn:hover {
    opacity: 0.85;
}

.settings-sub-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

/* Profile back circle button */
.profile-back-circle {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 101;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(30, 30, 30, 0.55);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .profile-back-circle {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Profile page header (Followers/Following title) */
.profile-page-header {
    padding: 16px 0 12px;
}

.profile-page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

/* Profile user list */
.profile-user-list {
    display: flex;
    flex-direction: column;
}

.profile-user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px;
    border-radius: 10px;
    transition: background 0.15s;
}

.profile-user-item.clickable {
    cursor: pointer;
}

.profile-user-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .profile-user-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

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

.profile-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 16px;
}

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

.profile-user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-user-username {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Follow button in user lists */
.follow-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
    color: #000;
}

.follow-btn:hover {
    opacity: 0.85;
}

.follow-btn.following {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="light"] .follow-btn {
    background: var(--text);
    color: var(--bg-primary);
}

[data-theme="light"] .follow-btn.following {
    background: var(--bg-tertiary);
    color: var(--text-dim);
}

/* Profile loading spinner */
.profile-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 58px - var(--chat-h) - 32px);
}

.wm-content .profile-spinner {
    height: 200px;
}

.profile-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 14px;
}

.profile-spinner::after {
    content: "";
    width: 28px;
    height: 28px;
    border: 2.5px solid rgba(128, 128, 128, 0.25);
    border-top-color: rgba(128, 128, 128, 0.7);
    border-radius: 50%;
    animation: profile-spin 0.7s linear infinite;
}

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

/* App proposal widget */
.msg.app-proposal-msg {
    align-self: stretch;
    padding: 0;
    background: none;
    border: none;
    max-width: 100%;
}

.app-proposal-card {
    background: #fdfdfd;
    border: 1px solid #ebebeb;
    border-radius: 16px;
    overflow: hidden;
}

.app-proposal-header {
    padding: 16px 20px 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
}

.app-proposal-title {
    font-size: 18px;
    font-weight: 700;
    color: #111;
    padding: 8px 20px 0;
}

.app-proposal-slug {
    font-size: 12px;
    color: #999;
    padding: 2px 20px 0;
    font-family: 'SF Mono', Monaco, Menlo, monospace;
}

.app-proposal-desc {
    font-size: 14px;
    color: #000;
    line-height: 1.5;
    padding: 6px 20px 16px;
}

.app-proposal-features {
    list-style: none;
    padding: 0 20px 16px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-proposal-features li {
    font-size: 14px;
    color: #000;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.4;
}

.app-proposal-features li:last-child {
    border-bottom: none;
}

.app-proposal-features li.fade-in {
    animation: proposalFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

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

.app-proposal-features li::before {
    content: "";
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #ccc;
    flex-shrink: 0;
    margin-top: 1px;
    box-sizing: border-box;
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.app-proposal-features li.done::before {
    content: "\2713";
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-proposal-features li.done {
    color: var(--text-dim, #888);
}

.app-proposal-buttons {
    display: flex;
    gap: 10px;
    padding: 0 20px 20px;
}

.app-proposal-create-btn {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.app-proposal-create-btn:hover {
    opacity: 0.85;
}

.app-proposal-create-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.app-proposal-cancel-btn {
    padding: 12px 20px;
    border-radius: 12px;
    border: 1px solid #ddd;
    background: #fff;
    color: #666;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
}

.app-proposal-cancel-btn:hover {
    background: #f0f0f0;
    color: #333;
}

/* Progress inside proposal card */
.app-proposal-progress-wrap {
    padding: 0 20px 20px;
    transition: opacity 0.3s ease;
}

.app-proposal-progress .progress-bar-track {
    background: rgba(0, 0, 0, 0.06);
}

.app-proposal-progress .progress-text {
    color: #888;
    background: linear-gradient(90deg, #888, var(--accent-light, var(--accent)), #888);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: thinking-shimmer 2s ease-in-out infinite;
}

.app-proposal-progress .progress-percent {
    color: #333;
}

.app-proposal-status {
    color: var(--green, #22c55e);
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    padding: 12px 20px;
}

.app-proposal-status.cancelled {
    color: #999;
}

.app-proposal-done-card {
    padding: 8px 20px 20px;
    margin: 0 -4px;
    border-radius: 12px;
    cursor: pointer;
}

.app-proposal-done-card:active {
    opacity: 0.7;
}

/* Clarify widget */
.msg.clarify-widget-msg {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    padding: 14px 16px;
}

.clarify-widget-question {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 10px;
    line-height: 1.4;
}

/* Options widget */
.msg.options-widget-msg {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    max-width: 90%;
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    min-width: 260px;
}

.options-widget-prompt {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 10px;
    letter-spacing: 0.02em;
}

.options-widget-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.options-widget-btn {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.options-widget-btn:hover {
    background: rgba(0, 122, 255, 0.15);
    border-color: rgba(0, 122, 255, 0.4);
    color: #409cff;
    box-shadow: 0 0 20px rgba(0, 122, 255, 0.1);
}

.options-widget-btn:active {
    transform: scale(0.98);
}

.options-widget-btn.selected {
    background: rgba(0, 122, 255, 0.2);
    border-color: rgba(0, 122, 255, 0.5);
    color: #409cff;
    cursor: default;
}

.options-widget-btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.options-custom-row {
    display: flex;
    gap: 6px;
}

.options-custom-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.options-custom-input::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

.options-custom-input:focus {
    border-color: rgba(56, 189, 248, 0.4);
    border-style: solid;
}

.options-custom-submit {
    width: 46px;
    min-width: 46px;
    padding: 0;
    text-align: center;
    font-size: 18px;
}

/* Light theme: options widget */
[data-theme="light"] .msg.options-widget-msg {
    background: #f5f5fa;
    border-color: #e0e0ea;
    backdrop-filter: none;
}

[data-theme="light"] .options-widget-prompt {
    color: #555;
}

[data-theme="light"] .options-widget-btn {
    background: #fff;
    border-color: #d8d8e4;
    color: #222;
}

[data-theme="light"] .options-widget-btn:hover {
    background: rgba(79, 110, 247, 0.08);
    border-color: rgba(79, 110, 247, 0.4);
    color: #4f6ef7;
    box-shadow: 0 0 12px rgba(79, 110, 247, 0.08);
}

[data-theme="light"] .options-widget-btn.selected {
    background: rgba(79, 110, 247, 0.1);
    border-color: rgba(79, 110, 247, 0.4);
    color: #4f6ef7;
}

[data-theme="light"] .options-custom-input {
    background: #fff;
    border-color: #d8d8e4;
    color: #222;
}

[data-theme="light"] .options-custom-input::placeholder {
    color: #aaa;
}

[data-theme="light"] .options-custom-input:focus {
    border-color: rgba(79, 110, 247, 0.5);
}

}