        :root {
            /* Chrome Dark Theme - Unified */
            --bg-primary: #202124;
            --bg-secondary: #202124;
            --bg-tertiary: #292a2d;
            --bg-elevated: #252629;
            --bg-hover: #3c4043;
            --text-primary: #FFFFFF;
            --text-secondary: #A0A0A0;
            --text-muted: #666666;
            --border: rgba(255,255,255,0.06);
            --border-hover: rgba(255,255,255,0.12);
            --accent: #FFFFFF;
            --shadow: 0 0 0 1px rgba(255,255,255,0.05);
            /* iOS safe-area insets */
            --safe-top: env(safe-area-inset-top, 0px);
            --safe-bottom: env(safe-area-inset-bottom, 0px);
            --safe-left: env(safe-area-inset-left, 0px);
            --safe-right: env(safe-area-inset-right, 0px);
        }

        html.light {
            --bg-primary: #FFFFFF;
            --bg-secondary: #FFFFFF;
            --bg-tertiary: #F5F5F5;
            --bg-elevated: #FAFAFA;
            --bg-hover: #EEEEEE;
            --text-primary: #000000;
            --text-secondary: #666666;
            --text-muted: #999999;
            --border: rgba(0,0,0,0.06);
            --border-hover: rgba(0,0,0,0.12);
            --accent: #000000;
            --shadow: 0 0 0 1px rgba(0,0,0,0.05);
        }

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

        *::before, *::after {
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background: var(--bg-primary);
            color: var(--text-primary);
            overflow: hidden;
            overscroll-behavior: none;
            transition: background 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                        color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }

        /* Scrollbar - minimal */
        ::-webkit-scrollbar {
            width: 4px;
            height: 4px;
        }

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

        ::-webkit-scrollbar-thumb {
            background: var(--border);
            border-radius: 2px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--text-muted);
        }

        /* App Layout */
        .app {
            display: flex;
            height: 100vh;
            height: 100dvh;
            overflow: hidden;
        }

        /* Sidebar */
        .sidebar {
            width: 260px;
            background: var(--bg-secondary);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
            padding-left: env(safe-area-inset-left);
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .sidebar-header {
            padding: 20px;
            border-bottom: 1px solid var(--border);
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 16px;
        }

        .logo-mark {
            width: 32px;
            height: 32px;
            position: relative;
        }

        .logo-mark::before,
        .logo-mark::after {
            content: '';
            position: absolute;
            border-radius: 50%;
            background: var(--text-primary);
        }

        .logo-mark::before {
            width: 8px;
            height: 8px;
            top: 4px;
            left: 4px;
            animation: nodePulse 2s ease-in-out infinite;
        }

        .logo-mark::after {
            width: 6px;
            height: 6px;
            top: 4px;
            right: 4px;
            animation: nodePulse 2s ease-in-out infinite 0.3s;
        }

        .logo-mark-inner {
            position: absolute;
            width: 5px;
            height: 5px;
            background: var(--text-primary);
            border-radius: 50%;
            bottom: 4px;
            left: 50%;
            margin-left: -2.5px;
            animation: nodePulse 2s ease-in-out infinite 0.6s;
        }

        .logo-mark-line {
            position: absolute;
            height: 1.5px;
            background: var(--text-primary);
            transform-origin: left center;
        }

        .logo-mark-line:first-of-type {
            width: 16px;
            top: 7px;
            left: 8px;
        }

        .logo-mark-line:last-of-type {
            width: 14px;
            top: 12px;
            left: 10px;
            transform: rotate(60deg);
        }

        @keyframes nodePulse {
            0%, 100% { transform: scale(1); opacity: 1; }
            50% { transform: scale(1.2); opacity: 1; }
        }

        .logo-text {
            font-size: 16px;
            font-weight: 300;
            letter-spacing: 4px;
            color: var(--text-primary);
            text-transform: uppercase;
        }

        .new-chat-btn {
            width: 100%;
            padding: 10px 14px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 13px;
            font-weight: 450;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            transition: all 0.2s ease;
        }

        .new-chat-btn:hover {
            border-color: var(--text-secondary);
            background: var(--bg-tertiary);
        }

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

        .sidebar-search {
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
        }

        .search-input {
            width: 100%;
            padding: 8px 12px;
            background: var(--bg-tertiary);
            border: 1px solid transparent;
            border-radius: 6px;
            color: var(--text-primary);
            font-size: 13px;
            outline: none;
            transition: all 0.2s ease;
        }

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

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

        .sidebar-content {
            flex: 1;
            overflow-y: auto;
            padding: 0 8px 8px;
        }

        .section-title {
            padding: 16px 12px 8px;
            font-size: 11px;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-muted);
        }

        .chat-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 8px 10px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            margin-bottom: 2px;
            position: relative;
            animation: slideIn 0.3s ease-out;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateX(-8px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        .chat-item:hover {
            background: var(--bg-tertiary);
        }

        .chat-item.active {
            background: var(--bg-elevated);
        }

        .chat-item.pinned {
            position: relative;
        }

        .chat-item.pinned::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 2px;
            height: 12px;
            background: var(--text-primary);
            border-radius: 0 1px 1px 0;
        }

        .chat-icon {
            width: 14px;
            height: 14px;
            color: var(--text-muted);
            flex-shrink: 0;
            opacity: 0.5;
        }

        .chat-title,
        .chat-item-name {
            flex: 1;
            min-width: 0;
            max-width: 180px;
            font-size: 13px;
            color: var(--text-secondary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            transition: color 0.15s ease;
        }

        .chat-item:hover .chat-title,
        .chat-item.active .chat-title {
            color: var(--text-primary);
        }

        .chat-actions {
            display: flex;
            gap: 2px;
            opacity: 0;
            transition: opacity 0.15s ease;
        }

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

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

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

        .chat-menu-btn {
            width: 22px;
            height: 22px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            border-radius: 4px;
            transition: all 0.15s ease;
            opacity: 0;
        }

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

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

        .chat-menu-dropdown {
            position: absolute;
            right: 8px;
            top: 100%;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 4px;
            min-width: 140px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.4);
            opacity: 0;
            visibility: hidden;
            transform: translateY(-8px);
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 100;
        }

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

        .chat-menu-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            font-size: 13px;
            color: var(--text-secondary);
        }

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

        .chat-menu-item svg {
            width: 14px;
            height: 14px;
        }

        /* Floating project context menu (right-click / long-press on a tab). */
        .project-menu {
            position: fixed;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 4px;
            min-width: 160px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.4);
            z-index: 10000;
            display: none;
        }
        .project-menu.open { display: block; }
        .project-menu .chat-menu-item { color: var(--text-primary); }

        .sidebar-footer {
            padding: 12px 16px;
            border-top: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .footer-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 10px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            font-size: 13px;
            cursor: pointer;
            border-radius: 6px;
            transition: all 0.15s ease;
        }

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

        .theme-toggle {
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid var(--border);
            background: transparent;
            color: var(--text-muted);
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .theme-toggle:hover {
            border-color: var(--text-secondary);
            color: var(--text-primary);
        }

        /* Main Content */
        .main {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-width: 0;
            background: var(--bg-primary);
        }

        .main-header {
            height: calc(56px + env(safe-area-inset-top));
            padding: env(safe-area-inset-top) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: var(--bg-secondary);
            border-bottom: 1px solid var(--border);
        }

        .header-nav {
            display: flex;
            gap: 4px;
            flex: 1 1 auto;
            min-width: 0;
            overflow-x: auto;
            overflow-y: hidden;
            scrollbar-width: thin;
            -ms-overflow-style: auto;
            -webkit-overflow-scrolling: touch;
            white-space: nowrap;
            align-items: center;
            max-width: calc(100vw - 350px);
            scroll-snap-type: x proximity;
        }
        .header-nav::-webkit-scrollbar {
            height: 4px;
        }
        .header-nav::-webkit-scrollbar-thumb {
            background: var(--border-hover);
            border-radius: 2px;
        }
        .header-nav::-webkit-scrollbar-track {
            background: transparent;
        }
        .header-nav .nav-item {
            scroll-snap-align: start;
        }

        .nav-item {
            padding: 6px 14px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            font-size: 13px;
            font-weight: 450;
            cursor: pointer;
            border-radius: 6px;
            transition: all 0.15s ease;
            position: relative;
            flex-shrink: 0;
            white-space: nowrap;
        }

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

        .nav-item.active {
            color: var(--text-primary);
            background: transparent;
        }

        .nav-item.active::after {
            content: '';
            position: absolute;
            left: 12px;
            right: 12px;
            bottom: -6px;
            height: 2px;
            background: var(--text-primary);
            border-radius: 2px;
        }

        .nav-item-add {
            width: 28px;
            height: 28px;
            padding: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: var(--text-muted);
            border-radius: 6px;
            flex-shrink: 0;
            border: 1px dashed var(--border);
        }

        .nav-item-add:hover {
            color: var(--text-primary);
            border-color: var(--border-hover);
            background: var(--bg-tertiary);
        }

        .nav-item-add svg {
            width: 14px;
            height: 14px;
            stroke: currentColor;
            fill: none;
            stroke-width: 2;
        }

        .nav-item-dot {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 6px;
            vertical-align: middle;
            background: #555;
        }

        /* Right Sidebar - Tools */
        .right-sidebar {
            width: 280px;
            background: var(--bg-secondary);
            border-left: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            transition: all 0.3s ease;
            overflow: hidden;
        }

        .right-sidebar.hidden {
            width: 0;
            border-left: none;
            opacity: 0;
            visibility: hidden;
        }

        /* Overlay behind the tools panel on mobile (click to close). */
        .right-sidebar-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 999;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        /* Mobile: slide in from the right as an overlay drawer. */
        @media (max-width: 768px) {
            .right-sidebar {
                position: fixed;
                top: 0;
                right: 0;
                height: 100vh;
                width: 280px;
                max-width: 85vw;
                background: var(--bg-primary);
                border-left: 1px solid var(--border);
                z-index: 1000;
                transform: translateX(0);
                transition: transform 0.3s ease;
                opacity: 1;
                visibility: visible;
                overflow-y: auto;
            }
            .right-sidebar.hidden {
                /* Keep visible in layout so transition animates out. */
                width: 280px;
                max-width: 85vw;
                transform: translateX(100%);
                opacity: 1;
                visibility: visible;
                border-left: 1px solid var(--border);
                pointer-events: none;
            }
            .right-sidebar-overlay.active {
                display: block;
                opacity: 1;
            }
        }

        /* Notepad sidebar — per-project markdown scratchpad.
           Inherits .right-sidebar visuals; only layout differences below. */
        .notepad-sidebar {
            width: 360px;
        }
        @media (max-width: 768px) {
            .notepad-sidebar {
                width: 360px;
                max-width: 90vw;
            }
            .notepad-sidebar.hidden {
                width: 360px;
                max-width: 90vw;
            }
        }
        .notepad-header {
            flex-direction: column;
            align-items: stretch;
            gap: 8px;
        }
        .notepad-project-select {
            width: 100%;
            padding: 6px 8px;
            background: var(--bg-primary);
            color: var(--text-primary);
            border: 1px solid var(--border);
            border-radius: 6px;
            font-size: 13px;
            font-family: inherit;
            cursor: pointer;
        }
        .notepad-project-select:focus {
            outline: none;
            border-color: var(--accent, #666);
        }
        .notepad-body {
            flex: 1;
            display: flex;
            min-height: 0;
        }
        .notepad-textarea {
            flex: 1;
            width: 100%;
            min-height: 0;
            padding: 14px 16px;
            background: transparent;
            color: var(--text-primary);
            border: none;
            outline: none;
            resize: none;
            font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
            font-size: 13px;
            line-height: 1.55;
            letter-spacing: 0.1px;
        }
        .notepad-textarea::placeholder {
            color: var(--text-tertiary, #6a6a6a);
        }
        .notepad-footer {
            padding: 8px 14px;
            border-top: 1px solid var(--border);
            display: flex;
            justify-content: flex-end;
            min-height: 32px;
        }
        .notepad-status {
            font-size: 11px;
            color: var(--text-tertiary, #6a6a6a);
            letter-spacing: 0.2px;
        }
        .notepad-status.saving {
            color: var(--text-secondary, #9a9a9a);
        }
        .notepad-sidebar-overlay {
            /* Same base rules as .right-sidebar-overlay, set via the shared
               .right-sidebar-overlay class in HTML. */
        }

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

        .right-sidebar-title {
            font-size: 13px;
            font-weight: 500;
            color: var(--text-primary);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .right-sidebar-toggle {
            width: 28px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            border-radius: 6px;
            transition: all 0.15s ease;
        }

        .right-sidebar-toggle:hover {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .tools-section {
            padding: 12px 0;
            border-bottom: 1px solid var(--border);
        }

        .tools-section-title {
            padding: 0 16px 8px;
            font-size: 11px;
            font-weight: 500;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .tool-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 16px;
            cursor: pointer;
            transition: all 0.15s ease;
            color: var(--text-secondary);
            font-size: 13px;
        }

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

        .tool-item.active {
            background: var(--bg-tertiary);
            color: var(--text-primary);
            border-left: 2px solid var(--text-primary);
        }

        .tool-icon {
            width: 18px;
            height: 18px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* SSH panel */
        .ssh-section .tools-section-title {
            padding-bottom: 10px;
        }

        .ssh-list {
            display: flex;
            flex-direction: column;
            gap: 2px;
            padding: 0 8px;
        }

        .ssh-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 10px;
            border-radius: 8px;
            cursor: default;
            transition: background 0.15s ease;
        }

        .ssh-item:hover {
            background: var(--bg-tertiary);
        }

        .ssh-status {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #555;
            flex-shrink: 0;
        }

        .ssh-status.active {
            background: #22c55e;
            box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
        }

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

        .ssh-name {
            font-size: 13px;
            color: var(--text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            line-height: 1.3;
        }

        .ssh-host {
            font-size: 11px;
            color: var(--text-muted);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .ssh-remove,
        .ssh-edit {
            width: 24px;
            height: 24px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            border-radius: 5px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            opacity: 0;
            transition: all 0.15s ease;
        }
        .ssh-item:hover .ssh-edit { opacity: 1; }
        .ssh-edit:hover { background: var(--bg-tertiary); color: var(--text-primary); }
        .ssh-edit svg { width: 14px; height: 14px; }

        .ssh-item:hover .ssh-remove {
            opacity: 1;
        }

        .ssh-remove:hover {
            background: rgba(220, 38, 38, 0.15);
            color: #f87171;
        }

        .ssh-remove svg {
            width: 14px;
            height: 14px;
            stroke: currentColor;
            fill: none;
            stroke-width: 2;
        }

        .ssh-empty {
            padding: 12px 10px;
            color: var(--text-muted);
            font-size: 12px;
        }

        .ssh-add-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            width: calc(100% - 16px);
            margin: 10px 8px 0;
            padding: 9px 12px;
            background: transparent;
            border: 1px dashed var(--border);
            border-radius: 8px;
            color: var(--text-secondary);
            font-size: 12px;
            cursor: pointer;
            font-family: inherit;
            transition: all 0.15s ease;
        }

        .ssh-add-btn:hover {
            border-color: var(--border-hover);
            color: var(--text-primary);
            background: var(--bg-tertiary);
        }

        .ssh-add-btn svg {
            width: 14px;
            height: 14px;
        }

        /* SSH modal buttons row */
        .ssh-modal-actions {
            display: flex;
            gap: 10px;
            margin-top: 16px;
        }

        .ssh-modal-actions .auth-btn {
            margin-top: 0;
        }

        .ssh-modal-actions .auth-btn.secondary {
            background: transparent;
            color: var(--text-primary);
            border: 1px solid var(--border);
        }

        .ssh-modal-actions .auth-btn.secondary:hover {
            background: var(--bg-tertiary);
            opacity: 1;
        }

        .ssh-modal-label {
            display: block;
            font-size: 11px;
            letter-spacing: 0.5px;
            color: var(--text-muted);
            margin: 4px 0 6px;
            text-transform: uppercase;
        }

        .move-to-list {
            display: flex;
            flex-direction: column;
            gap: 2px;
            max-height: 320px;
            overflow-y: auto;
            margin: 4px 0 0;
        }

        .move-to-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px;
            border-radius: 8px;
            cursor: pointer;
            color: var(--text-primary);
            font-size: 14px;
            background: var(--bg-tertiary);
            border: 1px solid transparent;
            transition: border-color 0.15s ease;
        }

        .move-to-item:hover {
            border-color: var(--border-hover);
        }

        .move-to-item.current {
            opacity: 0.55;
            cursor: default;
        }

        .move-to-item.current:hover {
            border-color: transparent;
        }

        .move-to-item .dot {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .move-to-item .badge {
            margin-left: auto;
            font-size: 11px;
            color: var(--text-muted);
        }

        /* Storage Page */
        .storage-toolbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            padding: 16px 0;
            flex-wrap: wrap;
        }

        .storage-filter-group {
            display: inline-flex;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 3px;
            gap: 2px;
        }

        .storage-filter-btn {
            background: transparent;
            border: none;
            color: var(--text-muted);
            padding: 6px 14px;
            font-size: 12px;
            letter-spacing: 0.5px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            font-family: inherit;
        }

        .storage-filter-btn:hover {
            color: var(--text-primary);
        }

        .storage-filter-btn.active {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .storage-toolbar-right {
            display: inline-flex;
            align-items: center;
            gap: 10px;
        }

        .storage-sort-select {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            padding: 7px 30px 7px 12px;
            font-size: 12px;
            cursor: pointer;
            font-family: inherit;
            appearance: none;
            -webkit-appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 10px center;
        }

        .storage-sort-select:hover {
            border-color: var(--border-hover);
        }

        .storage-view-toggle {
            display: inline-flex;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 3px;
            gap: 2px;
        }

        .storage-view-btn {
            background: transparent;
            border: none;
            width: 28px;
            height: 28px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: var(--text-muted);
            cursor: pointer;
            border-radius: 5px;
            transition: all 0.15s ease;
        }

        .storage-view-btn:hover {
            color: var(--text-primary);
        }

        .storage-view-btn.active {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .storage-view-btn svg {
            width: 14px;
            height: 14px;
            stroke: currentColor;
            fill: none;
            stroke-width: 2;
        }

        /* Windows Explorer style storage grid */
        .storage-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(120px, 130px));
            gap: 8px;
            padding: 8px 0 20px;
            justify-content: start;
        }

        @media (max-width: 768px) {
            .storage-grid {
                grid-template-columns: repeat(auto-fill, minmax(100px, 110px));
                gap: 6px;
            }
        }

        .storage-grid.list-view {
            grid-template-columns: 1fr;
            gap: 0;
        }

        .storage-item {
            position: relative;
            width: auto;
            height: 140px;
            background: transparent;
            border: 1px solid transparent;
            border-radius: 6px;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 6px 4px;
            gap: 4px;
            transition: background 0.12s ease, border-color 0.12s ease;
            overflow: hidden;
        }

        .storage-item:hover {
            background: var(--bg-tertiary);
            border-color: var(--border);
        }

        /* Thumbnail box — 100x100 centered, applies to both image and doc */
        .storage-item .storage-thumb-box {
            width: 100px;
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
            background: var(--bg-secondary);
            overflow: hidden;
            flex-shrink: 0;
        }

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

        /* Doc icon inside thumb-box */
        .storage-icon {
            width: 64px;
            height: 64px;
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            flex-shrink: 0;
        }

        .storage-icon svg {
            width: 28px;
            height: 28px;
        }

        .storage-icon.type-pdf { background: #dc2626; }
        .storage-icon.type-docx { background: #2563eb; }
        .storage-icon.type-xlsx { background: #16a34a; }
        .storage-icon.type-code { background: #7c3aed; }
        .storage-icon.type-archive { background: #d97706; }
        .storage-icon.type-default { background: var(--bg-tertiary); color: var(--text-secondary); }

        .storage-item .storage-info {
            width: 100%;
            min-width: 0;
            text-align: center;
        }

        .storage-name {
            font-size: 11px;
            line-height: 1.25;
            color: var(--text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 108px;
            margin: 0 auto;
        }

        .storage-meta {
            display: none;
        }

        /* Hover action buttons */
        .storage-actions {
            position: absolute;
            top: 4px;
            right: 4px;
            display: flex;
            gap: 2px;
            opacity: 0;
            transition: opacity 0.12s ease;
            z-index: 2;
        }

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

        .storage-action-btn {
            width: 24px;
            height: 24px;
            border-radius: 4px;
            background: rgba(0, 0, 0, 0.65);
            border: 1px solid rgba(255, 255, 255, 0.12);
            color: #fff;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            transition: background 0.12s ease;
            padding: 0;
        }

        .storage-action-btn:hover {
            background: rgba(0, 0, 0, 0.9);
        }

        .storage-action-btn.danger:hover {
            background: #dc2626;
        }

        .storage-action-btn svg {
            width: 12px;
            height: 12px;
            stroke: currentColor;
            fill: none;
            stroke-width: 2;
        }

        /* On touch devices without hover, always show the actions row so
           the menu button and delete/download are reachable. */
        @media (hover: none) {
            .storage-actions { opacity: 1; }
        }

        /* Storage item right-click / long-press / ⋯ context menu */
        .storage-item-context-menu {
            position: fixed;
            background: rgba(30, 30, 35, 0.98);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            padding: 6px;
            min-width: 180px;
            z-index: 10000;
            box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
            color: var(--text-primary, #fff);
        }
        .storage-item-context-menu .menu-item {
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 8px;
            user-select: none;
        }
        .storage-item-context-menu .menu-item:hover {
            background: rgba(255, 255, 255, 0.08);
        }
        .storage-item-context-menu .menu-item.danger {
            color: #ef4444;
        }
        .storage-item-context-menu .menu-item.danger:hover {
            background: rgba(239, 68, 68, 0.1);
        }
        .storage-item-context-menu .menu-item svg {
            flex-shrink: 0;
            stroke: currentColor;
            fill: none;
        }

        /* List view — Windows details style, 36px rows */
        .storage-grid.list-view .storage-item {
            width: auto;
            height: 40px;
            flex-direction: row;
            align-items: center;
            padding: 0 12px;
            gap: 10px;
            border-radius: 0;
            border-top: none;
            border-left: none;
            border-right: none;
            border-bottom: 1px solid transparent;
        }

        .storage-grid.list-view .storage-item:hover {
            background: var(--bg-tertiary);
            border-bottom-color: var(--border);
        }

        .storage-grid.list-view .storage-item .storage-thumb-box {
            width: 32px;
            height: 32px;
            border-radius: 4px;
        }

        .storage-grid.list-view .storage-item .storage-icon {
            width: 32px;
            height: 32px;
            border-radius: 4px;
        }

        .storage-grid.list-view .storage-item .storage-icon svg {
            width: 16px;
            height: 16px;
        }

        .storage-grid.list-view .storage-item .storage-info {
            flex: 1;
            min-width: 0;
            text-align: left;
            display: flex;
            align-items: center;
            gap: 12px;
            overflow: hidden;
        }

        .storage-grid.list-view .storage-item .storage-name {
            flex: 1;
            font-size: 12px;
            max-width: none;
            text-align: left;
            margin: 0;
        }

        .storage-grid.list-view .storage-item .storage-meta {
            display: block;
            color: var(--text-muted);
            font-size: 11px;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .storage-grid.list-view .storage-actions {
            position: static;
            opacity: 1;
            margin-left: 4px;
        }

        .storage-grid.list-view .storage-action-btn {
            background: transparent;
            border-color: transparent;
            color: var(--text-muted);
            width: 24px;
            height: 24px;
        }

        .storage-grid.list-view .storage-action-btn:hover {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .storage-grid.list-view .storage-action-btn.danger:hover {
            background: #dc2626;
            color: #fff;
        }

        .storage-empty {
            color: var(--text-muted);
            font-size: 13px;
            padding: 24px 0;
            text-align: center;
        }

        .lightbox-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.85);
            z-index: 10000;
            display: none;
            align-items: center;
            justify-content: center;
            cursor: zoom-out;
            padding: 20px;
        }

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

        .lightbox-img {
            max-width: 90vw;
            max-height: 90vh;
            border-radius: 8px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
            cursor: default;
            object-fit: contain;
        }

        .lightbox-close {
            position: fixed;
            top: 20px;
            right: 20px;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 22px;
            line-height: 1;
            z-index: 10001;
            transition: background 0.15s;
            padding: 0;
        }

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

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

        .model-selector {
            position: relative;
        }

        .model-selector-inline {
            position: relative;
            display: flex;
            align-items: center;
            flex-shrink: 0;
        }

        .model-btn-inline {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 6px 10px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 6px;
            color: var(--text-secondary);
            font-size: 12px;
            font-weight: 450;
            cursor: pointer;
            transition: all 0.15s ease;
            white-space: nowrap;
        }

        .model-btn-inline:hover {
            border-color: var(--border-hover);
            color: var(--text-primary);
            background: var(--bg-tertiary);
        }

        .model-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 6px 12px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 6px;
            color: var(--text-primary);
            font-size: 13px;
            font-weight: 450;
            cursor: pointer;
            transition: all 0.15s ease;
        }

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

        .model-btn.active {
            background: var(--text-primary);
            color: var(--bg-primary);
            border-color: var(--text-primary);
        }

        .model-dropdown {
            position: absolute;
            bottom: calc(100% + 6px);
            right: 0;
            width: 220px;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 6px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.3);
            opacity: 0;
            visibility: hidden;
            transform: translateY(8px);
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 100;
        }

        .model-dropdown.open {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .model-option {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .model-option:hover {
            background: var(--bg-tertiary);
        }

        .model-dropdown-separator {
            height: 1px;
            background: var(--border);
            margin: 6px 2px;
        }

        .model-search-toggle {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            color: var(--text-primary);
            transition: background 0.15s ease;
        }

        .model-search-toggle:hover {
            background: var(--bg-tertiary);
        }

        .model-search-toggle input[type="checkbox"] {
            width: 14px;
            height: 14px;
            accent-color: var(--text-primary);
            cursor: pointer;
            margin: 0;
            flex-shrink: 0;
        }

        .model-option.selected .model-radio {
            border-color: var(--text-primary);
            background: var(--text-primary);
        }

        .model-radio {
            width: 14px;
            height: 14px;
            border: 1.5px solid var(--border-hover);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            transition: all 0.15s ease;
        }

        .model-radio::after {
            content: '';
            width: 5px;
            height: 5px;
            background: var(--bg-primary);
            border-radius: 50%;
            opacity: 0;
            transition: opacity 0.15s ease;
        }

        .model-option.selected .model-radio::after {
            opacity: 1;
        }

        .model-info {
            flex: 1;
        }

        .model-name {
            font-size: 13px;
            font-weight: 450;
            color: var(--text-primary);
        }

        .model-desc {
            font-size: 11px;
            color: var(--text-muted);
            margin-top: 1px;
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--text-primary);
            font-weight: 500;
            font-size: 12px;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .user-avatar:hover {
            border-color: var(--border-hover);
        }

        /* Chat Area */
        .chat-area {
            flex: 1;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }

        .scroll-to-bottom {
            position: absolute;
            right: calc(24px + env(safe-area-inset-right));
            bottom: calc(96px + env(safe-area-inset-bottom));
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(40, 40, 44, 0.9);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            padding: 0;
            z-index: 5;
            opacity: 0;
            transform: translateY(8px);
            pointer-events: none;
            transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
        }

        .scroll-to-bottom.visible {
            opacity: 1;
            transform: translateY(0);
            pointer-events: auto;
        }

        .scroll-to-bottom:hover {
            background: rgba(50, 50, 55, 0.95);
            transform: translateY(0) scale(1.05);
        }

        .scroll-to-bottom svg {
            width: 16px;
            height: 16px;
            stroke: #fff;
            stroke-width: 2;
            fill: none;
            stroke-linecap: round;
            stroke-linejoin: round;
        }

        @media (max-width: 640px) {
            .scroll-to-bottom {
                right: calc(16px + env(safe-area-inset-right));
                bottom: calc(84px + env(safe-area-inset-bottom));
                width: 36px;
                height: 36px;
            }
        }

        /* Welcome Screen */
        .welcome-screen {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 40px;
            overflow-y: auto;
        }

        .welcome-logo {
            width: 64px;
            height: 64px;
            position: relative;
            margin-bottom: 24px;
        }

        .welcome-logo-node {
            position: absolute;
            border-radius: 50%;
            background: var(--text-primary);
            animation: nodePulse 2.5s ease-in-out infinite;
        }

        .welcome-logo-node:nth-child(1) {
            width: 16px;
            height: 16px;
            top: 8px;
            left: 8px;
        }

        .welcome-logo-node:nth-child(2) {
            width: 12px;
            height: 12px;
            top: 8px;
            right: 8px;
            animation-delay: 0.4s;
        }

        .welcome-logo-node:nth-child(3) {
            width: 10px;
            height: 10px;
            bottom: 8px;
            left: 50%;
            margin-left: -5px;
            animation-delay: 0.8s;
        }

        .welcome-logo-line {
            position: absolute;
            height: 2px;
            background: var(--text-primary);
            transform-origin: left center;
        }

        .welcome-logo-line:nth-child(4) {
            width: 34.06px;
            top: 15px;
            left: 16px;
            transform: rotate(0deg);
            animation: lineGlow 2.5s ease-in-out infinite;
        }

        .welcome-logo-line:nth-child(5) {
            width: 34px;
            top: 15px;
            left: 16px;
            transform: rotate(65deg);
            animation: lineGlow 2.5s ease-in-out infinite 0.4s;
        }

        .welcome-logo-line:nth-child(6) { display: none;
            width: 24px;
            top: 22px;
            left: 14px;
            transform: rotate(-60deg);
            animation: lineGlow 2.5s ease-in-out infinite 0.8s;
        }

        @keyframes lineGlow {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        .welcome-title {
            font-size: 28px;
            font-weight: 300;
            letter-spacing: 8px;
            margin-bottom: 8px;
            color: var(--text-primary);
            text-transform: uppercase;
            opacity: 0;
            animation: fadeUp 0.6s ease-out 0.2s forwards;
        }

        .welcome-subtitle {
            font-size: 14px;
            color: var(--text-muted);
            margin-bottom: 48px;
            opacity: 0;
            animation: fadeUp 0.6s ease-out 0.3s forwards;
        }

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

        .quick-actions {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
            max-width: 640px;
            width: 100%;
        }

        .quick-action {
            padding: 16px;
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            text-align: left;
            opacity: 0;
            animation: fadeUp 0.5s ease-out forwards;
        }

        .quick-action:nth-child(1) { animation-delay: 0.4s; }
        .quick-action:nth-child(2) { animation-delay: 0.45s; }
        .quick-action:nth-child(3) { animation-delay: 0.5s; }
        .quick-action:nth-child(4) { animation-delay: 0.55s; }
        .quick-action:nth-child(5) { animation-delay: 0.6s; }
        .quick-action:nth-child(6) { animation-delay: 0.65s; }

        .quick-action:hover {
            border-color: var(--border-hover);
            background: var(--bg-tertiary);
            transform: translateY(-2px);
        }

        .quick-action-icon {
            width: 32px;
            height: 32px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 12px;
            color: var(--text-secondary);
            transition: all 0.2s ease;
        }

        .quick-action:hover .quick-action-icon {
            border-color: var(--text-muted);
            color: var(--text-primary);
        }

        .quick-action-title {
            font-size: 13px;
            font-weight: 500;
            color: var(--text-primary);
            margin-bottom: 3px;
        }

        .quick-action-desc {
            font-size: 12px;
            color: var(--text-muted);
            line-height: 1.4;
        }

        /* Messages */
        .messages-container {
            flex: 1;
            overflow-y: auto;
            padding: 24px;
            /* position:relative makes this the offsetParent for descendants,
               so element.offsetTop returns container-relative coordinates.
               Required for the focus-thread-view scroll pin
               (container.scrollTop = stage.offsetTop) to land at the right
               spot. Without this, offsetTop walks up to body and the scroll
               write lands in the wrong place. See vault feature note. */
            position: relative;
            /* No scroll-behavior: smooth — it animates every scrollTop
               write, which fights with the streaming auto-scroll and
               makes the question-pin scroll laggy/wrong. */
        }



        .messages {
            max-width: 720px;
            margin: 0 auto;
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 0;
        }

        .message {
            display: flex;
            gap: 14px;
            animation: messageAppear 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            padding: 20px 0;
            border-bottom: 1px solid var(--border);
        }

        .message:last-child {
            border-bottom: none;
        }

        /* Message Truncation - Perplexity-style */
        .message.truncated {
            display: none !important;
        }

        .message.truncated.revealed {
            display: flex !important;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-8px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .truncation-banner {
            text-align: center;
            padding: 12px;
            margin-bottom: 16px;
            cursor: pointer;
            border-radius: 8px;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            color: var(--text-muted);
            font-size: 13px;
            transition: all 0.2s ease;
            user-select: none;
            letter-spacing: 0.5px;
        }

        .truncation-banner:hover {
            background: var(--bg-tertiary);
            color: var(--text-secondary);
            border-color: var(--border-hover);
        }

        .truncation-banner .count {
            color: var(--text-secondary);
            font-weight: 500;
        }

        /* Loading Skeletons */
        .skeleton {
            background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
            background-size: 200% 100%;
            animation: shimmer 1.5s infinite;
            border-radius: 4px;
        }

        .skeleton-text {
            height: 16px;
            margin-bottom: 8px;
            border-radius: 4px;
        }

        .skeleton-text.short { width: 60%; }
        .skeleton-text.medium { width: 80%; }
        .skeleton-title {
            height: 20px;
            width: 40%;
            margin-bottom: 12px;
        }

        @keyframes shimmer {
            0% { background-position: 200% 0; }
            100% { background-position: -200% 0; }
        }

        .skeleton-chat-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 10px 12px;
            opacity: 0.6;
        }

        .skeleton-icon {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .skeleton-line {
            height: 14px;
            border-radius: 4px;
            flex: 1;
        }







        .message.user {
            justify-content: flex-end;
            align-items: flex-start;
            gap: 6px;
        }

        .message.assistant {
            justify-content: flex-start;
        }

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

        .message-avatar {
            display: none;
        }

        .message-sender {
            font-size: 10px;
            font-weight: 300;
            color: var(--text-muted);
            letter-spacing: 3px;
            margin-bottom: 6px;
            text-transform: uppercase;
        }

        .degraded-banner {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 9px 12px;
            margin: 0 0 10px 0;
            background: rgba(255, 200, 0, 0.08);
            border: 1px solid rgba(255, 200, 0, 0.2);
            border-radius: 8px;
            font-size: 13px;
            font-weight: 300;
            line-height: 1.4;
            color: var(--text-primary);
        }

        .degraded-banner-icon {
            flex-shrink: 0;
            width: 18px;
            height: 18px;
            color: rgb(255, 200, 0);
            stroke: currentColor;
            fill: none;
            stroke-width: 2;
            stroke-linecap: round;
            stroke-linejoin: round;
        }

        .degraded-banner-text {
            flex: 1;
            min-width: 0;
        }

        .degraded-banner-cta {
            flex-shrink: 0;
            background: rgba(255, 200, 0, 0.14);
            border: 1px solid rgba(255, 200, 0, 0.35);
            color: var(--text-primary);
            padding: 5px 12px;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 400;
            cursor: pointer;
            transition: background 0.15s ease, border-color 0.15s ease;
        }

        .degraded-banner-cta:hover {
            background: rgba(255, 200, 0, 0.22);
            border-color: rgba(255, 200, 0, 0.5);
        }

        @media (max-width: 640px) {
            .degraded-banner {
                flex-wrap: wrap;
                font-size: 12px;
                padding: 8px 10px;
            }
            .degraded-banner-cta {
                font-size: 11px;
                padding: 4px 10px;
            }
        }

        .message-content {
            font-size: 14px;
            line-height: 1.7;
            max-width: 85%;
            font-weight: 300;
        }

        .message-content img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
            margin: 8px 0;
        }

        .message-content.user {
            color: var(--text-primary);
            text-align: left;
            max-width: min(70%, 640px);
            margin-right: 16px;
            padding: 10px 14px;
            background: rgba(255, 255, 255, 0.06);
            border-radius: 14px;
            align-self: flex-end;
            word-wrap: break-word;
            overflow-wrap: break-word;
        }

        @media (max-width: 640px) {
            .message-content.user {
                max-width: 85%;
                margin-right: 8px;
            }
        }

        .message-content.assistant {
            color: var(--text-primary);
        }

        .message-actions {
            display: none;
        }

        /* DNA Helix Thinking Indicator - Horizontal */
        .dna-helix {
            width: 44px;
            height: 14px;
            position: relative;
            display: inline-block;
            animation-play-state: running;
        }

        /* DNA stops spinning when response is complete */
        .message.assistant:not(.current-response) .dna-helix,
        .dna-helix.paused {
            animation-play-state: paused;
        }
        .dna-helix .pair {
            position: absolute;
            width: 2px;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            animation: dnaRotate 1.6s ease-in-out infinite;
        }
        .dna-helix .pair::before,
        .dna-helix .pair::after {
            content: '';
            width: 3px;
            height: 3px;
            border-radius: 50%;
            background: var(--text-secondary);
            flex-shrink: 0;
        }
        .dna-helix .pair .bridge {
            width: 1.5px;
            flex: 1;
            background: var(--border-hover);
            margin: 1px 0;
        }
        .dna-helix .pair:nth-child(1) { left: 0px; animation-delay: 0s; }
        .dna-helix .pair:nth-child(2) { left: 6px; animation-delay: -0.2s; }
        .dna-helix .pair:nth-child(3) { left: 12px; animation-delay: -0.4s; }
        .dna-helix .pair:nth-child(4) { left: 18px; animation-delay: -0.6s; }
        .dna-helix .pair:nth-child(5) { left: 24px; animation-delay: -0.8s; }
        .dna-helix .pair:nth-child(6) { left: 30px; animation-delay: -1.0s; }
        .dna-helix .pair:nth-child(7) { left: 36px; animation-delay: -1.2s; }
        .dna-helix .pair:nth-child(8) { left: 42px; animation-delay: -1.4s; }

        @keyframes dnaRotate {
            0%, 100% { transform: rotateX(0deg); opacity: 1; }
            50% { transform: rotateX(180deg); opacity: 0.5; }
        }

        .thinking-indicator {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-top: 8px;
        }

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

        /* Input Area */
        .input-area {
            padding: 16px max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
            background: var(--bg-secondary);
            border-top: none !important;
            position: sticky;
            bottom: 0;
            z-index: 10;
            flex-shrink: 0;
            transition: transform 0.2s ease-out;
        }

        #messagesContainer {
            transition: padding-bottom 0.2s ease-out;
        }

        .input-container {
            max-width: 720px;
            margin: 0 auto;
            position: relative;
        }

        .attachments-preview {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            margin-bottom: 10px;
        }

        .attachment-item {
            position: relative;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 5px 10px 5px 5px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            font-size: 12px;
            color: var(--text-secondary);
            max-width: 240px;
            animation: slideIn 0.2s ease-out;
        }
        .attachment-item .attachment-thumb {
            position: relative;
            width: 36px;
            height: 36px;
            border-radius: 6px;
            overflow: hidden;
            background: rgba(255,255,255,0.06);
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .attachment-item .attachment-thumb img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .attachment-item .attachment-thumb .icon {
            width: 18px;
            height: 18px;
            opacity: 0.6;
        }
        .attachment-item .attachment-name {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 160px;
        }
        .attachment-item .attachment-overlay {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(0, 0, 0, 0.55);
            border-radius: 6px;
            opacity: 0;
            transition: opacity 0.18s ease;
            pointer-events: none;
        }
        .attachment-item[data-state="uploading"] .attachment-overlay {
            opacity: 1;
        }
        .attachment-item[data-state="error"] .attachment-overlay {
            opacity: 1;
            background: rgba(220, 38, 38, 0.75);
        }
        .attachment-item[data-state="error"] .attachment-overlay::after {
            content: "!";
            font-size: 18px;
            font-weight: 800;
            color: #fff;
        }
        .attachment-item[data-state="error"] .attachment-overlay .spinner,
        .attachment-item[data-state="uploaded"] .attachment-overlay .spinner { display: none; }
        .attachment-item .spinner {
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255,255,255,0.25);
            border-top-color: #fff;
            border-radius: 50%;
            animation: attSpin 0.8s linear infinite;
        }
        @keyframes attSpin { to { transform: rotate(360deg); } }
        #sendBtn.uploading-blocked { cursor: wait; }

        .attachment-remove {
            width: 16px;
            height: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            border-radius: 3px;
            transition: all 0.15s ease;
        }

        .attachment-remove:hover {
            background: var(--border);
            color: var(--text-primary);
        }

        .input-wrapper {
            display: flex;
            align-items: flex-end;
            gap: 10px;
            padding: 10px 12px;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 12px;
            transition: all 0.2s ease;
            position: relative;
        }

        .input-wrapper:focus-within {
            border-color: var(--border-hover);
        }

        .input-actions {
            display: flex;
            gap: 4px;
        }

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

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

        .input-action .voice-icon-stop,
        .input-action .voice-timer { display: none; }
        .input-action.recording { color: #e04141; position: relative; }
        .input-action.recording .voice-icon-mic { display: none; }
        .input-action.recording .voice-icon-stop { display: inline-block; animation: voice-pulse 1.2s ease-in-out infinite; }
        .input-action.recording .voice-timer {
            display: inline-block;
            position: absolute;
            bottom: -14px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 10px;
            color: #e04141;
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
            pointer-events: none;
        }
        .input-action.transcribing { color: var(--text-muted); }
        .input-action.transcribing .voice-icon-mic { opacity: 0.4; animation: voice-spin 1.4s linear infinite; }
        @keyframes voice-pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.4; }
        }
        @keyframes voice-spin {
            from { transform: rotate(0deg); }
            to   { transform: rotate(360deg); }
        }

        .message-input {
            flex: 1;
            min-height: 20px;
            max-height: 160px;
            padding: 6px 0;
            background: transparent;
            border: none;
            color: var(--text-primary);
            font-size: 14px;
            line-height: 1.5;
            resize: none;
            outline: none;
            font-family: inherit;
        }

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

        .send-btn {
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: var(--text-primary);
            color: var(--bg-primary);
            cursor: pointer;
            border-radius: 8px;
            transition: all 0.2s ease;
            flex-shrink: 0;
        }

        .send-btn:hover:not(:disabled) {
            transform: scale(1.05);
        }

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

        .input-hint {
            text-align: center;
            margin-top: 10px;
            font-size: 11px;
            color: var(--text-muted);
        }

        .input-hint kbd {
            padding: 2px 5px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 4px;
            font-family: inherit;
            font-size: 10px;
        }

        /* Upload Overlay */
        .upload-overlay {
            position: absolute;
            inset: 0;
            background: var(--bg-tertiary);
            border: 1px dashed var(--border-hover);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            visibility: hidden;
            transition: all 0.2s ease;
            pointer-events: none;
        }

        .upload-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .upload-text {
            font-size: 13px;
            color: var(--text-secondary);
        }

        /* Empty State */
        .empty-chats {
            padding: 40px 20px;
            text-align: center;
            color: var(--text-muted);
            font-size: 13px;
        }

        /* Icons */
        .icon {
            width: 16px;
            height: 16px;
            stroke-width: 1.5;
            stroke-linecap: round;
            stroke-linejoin: round;
            fill: none;
            stroke: currentColor;
        }

        .icon-lg {
            width: 18px;
            height: 18px;
        }

        /* File Input */
        .file-input {
            display: none;
        }

        /* Skeleton Loaders */
        .skeleton {
            background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
            background-size: 200% 100%;
            animation: skeletonPulse 1.5s ease-in-out infinite;
            border-radius: 4px;
        }

        @keyframes skeletonPulse {
            0% { background-position: 200% 0; }
            100% { background-position: -200% 0; }
        }

        .skeleton-chat-item {
            height: 40px;
            margin-bottom: 8px;
            border-radius: 6px;
        }

        .skeleton-message {
            height: 60px;
            margin-bottom: 16px;
            border-radius: 12px;
        }

        .skeleton-text {
            height: 14px;
            margin-bottom: 8px;
        }

        .skeleton-text.short {
            width: 60%;
        }

        /* Toast Notifications */
        .toast-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
            display: flex;
            flex-direction: column;
            gap: 8px;
            pointer-events: none;
        }

        .toast {
            pointer-events: auto;
        }

        .toast {
            padding: 12px 16px;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 8px;
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 280px;
            animation: toastSlide 0.3s ease-out;
            box-shadow: 0 4px 20px rgba(0,0,0,0.3);
        }

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

        .toast.success {
            border-left: 3px solid #22c55e;
        }

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

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

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

        .toast.info .toast-icon {
            color: #3b82f6;
        }

        .toast-icon {
            width: 20px;
            height: 20px;
            flex-shrink: 0;
        }

        .toast.success .toast-icon {
            color: #22c55e;
        }

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

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

        .toast-message {
            flex: 1;
            font-size: 13px;
            color: var(--text-primary);
        }

        .toast-close {
            background: none;
            border: none;
            color: var(--text-muted);
            cursor: pointer;
            padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

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

        /* Loading Overlay */
        .loading-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 999;
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transition: all 0.2s ease;
        }

        .loading-overlay.active {
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
        }

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

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

        /* Auth Modal */
        .auth-modal {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
            transition: all 0.3s ease;
        }

        .auth-modal.active {
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
        }

        .auth-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 16px;
            padding: 32px;
            width: 100%;
            max-width: 400px;
            animation: authSlide 0.3s ease-out;
        }

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

        .auth-title {
            font-size: 20px;
            font-weight: 500;
            margin-bottom: 24px;
            text-align: center;
        }

        .auth-input {
            width: 100%;
            padding: 12px 16px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 8px;
            color: var(--text-primary);
            font-size: 14px;
            margin-bottom: 12px;
            outline: none;
        }

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

        .auth-btn {
            width: 100%;
            padding: 12px;
            background: var(--text-primary);
            color: var(--bg-primary);
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            margin-top: 8px;
        }

        .auth-btn:hover {
            opacity: 0.9;
        }

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

        /* Settings & Admin Pages */
        .page-content {
            display: none;
            flex: 1;
            overflow-y: auto;
            padding: 32px 40px;
        }

        .page-content.active {
            display: block;
        }

        .page-header {
            margin-bottom: 32px;
        }

        .page-title {
            font-size: 24px;
            font-weight: 500;
            color: var(--text-primary);
            margin-bottom: 8px;
        }

        .page-subtitle {
            font-size: 14px;
            color: var(--text-muted);
            font-weight: 300;
        }

        /* Settings Menu */
        .settings-container {
            display: flex;
            gap: 40px;
            max-width: 900px;
        }

        .settings-sidebar {
            width: 240px;
            flex-shrink: 0;
            padding-top: max(0px, env(safe-area-inset-top));
            padding-left: max(0px, env(safe-area-inset-left));
        }

        .settings-menu-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 16px;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.15s ease;
            color: var(--text-secondary);
            font-size: 14px;
            font-weight: 400;
            margin-bottom: 2px;
        }

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

        .settings-menu-item.active {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .settings-menu-item svg {
            width: 18px;
            height: 18px;
        }

        .settings-content {
            flex: 1;
            padding-top: max(0px, env(safe-area-inset-top));
            padding-right: max(0px, env(safe-area-inset-right));
        }

        .settings-section {
            display: none;
        }

        .settings-section.active {
            display: block;
        }

        .settings-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 16px;
        }

        .settings-card-title {
            font-size: 16px;
            font-weight: 500;
            color: var(--text-primary);
            margin-bottom: 16px;
        }

        .settings-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid var(--border);
        }

        .settings-row:last-child {
            border-bottom: none;
        }

        .settings-label {
            font-size: 14px;
            color: var(--text-primary);
        }

        .settings-value {
            font-size: 14px;
            color: var(--text-muted);
        }

        .settings-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 4px 10px;
            background: var(--bg-tertiary);
            border-radius: 4px;
            font-size: 12px;
            color: var(--text-secondary);
        }

        .settings-badge.pro {
            background: rgba(99, 102, 241, 0.15);
            color: #818cf8;
        }

        /* Admin Panel */
        .admin-stats {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 16px;
            margin-bottom: 32px;
        }

        .admin-stat-card {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 20px 24px;
        }

        .admin-stat-value {
            font-size: 32px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 4px;
        }

        .admin-stat-label {
            font-size: 12px;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .admin-table-container {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 10px;
            overflow-x: auto;
            overflow-y: hidden;
        }

        .admin-table {
            width: 100%;
            border-collapse: collapse;
            table-layout: fixed;
            min-width: 820px;
            font-size: 13px;
        }

        .admin-table thead th {
            background: var(--bg-tertiary);
            font-size: 11px;
            font-weight: 500;
            color: var(--text-muted);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            text-align: left;
            padding: 10px 12px;
            border-bottom: 1px solid var(--border);
            white-space: nowrap;
        }

        .admin-table thead th.num,
        .admin-table tbody td.num {
            text-align: right;
            font-variant-numeric: tabular-nums;
        }

        .admin-table thead th.actions-col {
            text-align: right;
        }

        .admin-table tbody td {
            padding: 8px 12px;
            color: var(--text-primary);
            font-size: 13px;
            border-bottom: 1px solid var(--border);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            vertical-align: middle;
            height: 48px;
            line-height: 1.3;
        }

        .admin-table tbody tr:last-child td {
            border-bottom: none;
        }

        .admin-table tbody tr:hover {
            background: rgba(255, 255, 255, 0.025);
        }

        .admin-table td.email {
            color: var(--text-secondary);
        }

        .admin-table td.credits {
            font-size: 12px;
            color: var(--text-muted);
        }

        .admin-table td.actions {
            text-align: right;
        }

        .admin-table .actions-inline {
            display: inline-flex;
            gap: 6px;
            justify-content: flex-end;
            align-items: center;
        }

        .admin-role-select {
            padding: 4px 8px;
            background: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 5px;
            color: var(--text-primary);
            font-size: 12px;
            cursor: pointer;
            outline: none;
            max-width: 100%;
        }

        .admin-role-select:hover {
            border-color: var(--border-hover);
        }

        .admin-delete-btn {
            padding: 4px 10px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 5px;
            color: var(--text-muted);
            font-size: 12px;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .admin-add-credits-btn {
            padding: 4px 8px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 5px;
            color: var(--text-secondary);
            font-size: 11px;
            cursor: pointer;
            transition: all 0.15s ease;
            white-space: nowrap;
        }

        .admin-user-credits {
            font-size: 12px;
            color: var(--text-muted);
        }

        .admin-user-email-link {
            color: var(--text-secondary);
            cursor: pointer;
            text-decoration: none;
            border-bottom: 1px dotted var(--border-hover);
        }
        .admin-user-email-link:hover { color: var(--text-primary); }

        /* User detail page (admin → click email) */
        .user-detail-page {
            padding: 20px;
            max-width: 600px;
            margin: 0 auto;
            width: 100%;
        }
        @media (max-width: 768px) {
            .user-detail-page { padding: 16px; max-width: 100%; }
        }
        .user-detail-page-header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 18px;
            padding-bottom: 14px;
            border-bottom: 1px solid var(--border);
        }
        .user-detail-back {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 6px 10px;
            background: transparent;
            border: 1px solid var(--border);
            border-radius: 6px;
            color: var(--text-secondary);
            font-size: 13px;
            cursor: pointer;
            font-family: inherit;
        }
        .user-detail-back:hover { background: var(--bg-tertiary); color: var(--text-primary); }
        .user-detail-back svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
        .user-detail-titles { flex: 1; min-width: 0; }
        .user-detail-name { font-size: 18px; font-weight: 500; color: var(--text-primary); line-height: 1.2; }
        .user-detail-email { font-size: 13px; color: var(--text-muted); margin-top: 2px; word-break: break-all; }
        .user-detail-body { display: flex; flex-direction: column; gap: 18px; }
        .user-detail-meta { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 13px; }
        .user-detail-meta .meta-label { color: var(--text-muted); text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; margin-right: 6px; }
        .user-detail-meta .meta-value { color: var(--text-primary); font-family: 'Fira Code', monospace; font-size: 12px; }
        .user-detail-section {
            background: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 10px;
            padding: 12px 14px;
        }
        .user-detail-section h3 {
            font-size: 12px; letter-spacing: 0.5px; text-transform: uppercase;
            color: var(--text-muted); margin: 0 0 10px; font-weight: 500;
        }
        .credit-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
        .credit-label { width: 70px; font-size: 12px; color: var(--text-secondary); }
        .credit-bar-wrap { flex: 1; }
        .credit-bar { height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; margin-bottom: 4px; }
        .credit-bar-fill { height: 100%; background: linear-gradient(90deg, #22c55e, #16a34a); width: 0%; transition: width 0.3s ease; }
        .credit-bar-fill.warn { background: linear-gradient(90deg, #eab308, #ca8a04); }
        .credit-bar-fill.crit { background: linear-gradient(90deg, #ef4444, #dc2626); }
        .credit-bar-text { font-size: 11px; color: var(--text-muted); font-family: 'Fira Code', monospace; }
        .limits-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 12px; color: var(--text-secondary); }
        @media (max-width: 500px) { .limits-grid { grid-template-columns: 1fr; } }
        .limits-grid label { display: block; }
        .limits-grid .auth-input { margin-top: 4px; margin-bottom: 0; }
        .ud-stats-table { width: 100%; border-collapse: collapse; font-size: 12px; }
        .ud-stats-table th, .ud-stats-table td {
            padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border);
        }
        .ud-stats-table th { color: var(--text-muted); font-weight: 500; text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; }
        .user-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
        .user-detail-actions .auth-btn { margin-top: 0; width: auto; flex: 1 1 auto; min-width: 140px; }

        /* Mobile adaptation for the user-detail page */
        @media (max-width: 768px) {
            .user-detail-body .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 8px;
            }
            .user-detail-body .stats-grid .stat-value { font-size: 16px; }
            .user-detail-body .stats-grid .stat-label { font-size: 11px; }
            .user-detail-body .ud-stats-table {
                display: block;
                overflow-x: auto;
                font-size: 11px;
                white-space: nowrap;
            }
            .user-detail-actions .auth-btn { min-width: 120px; flex-basis: calc(50% - 4px); }
        }
        @media (max-width: 480px) {
            .user-detail-body .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
            .user-detail-body .stats-grid .stat-value { font-size: 15px; }
            .user-detail-actions .auth-btn { flex-basis: 100%; min-width: 0; }
        }

        .admin-add-credits-btn:hover {
            border-color: #22c55e;
            color: #22c55e;
        }

        .admin-delete-btn:hover {
            border-color: #ef4444;
            color: #ef4444;
        }

        .token-stats-card { background: var(--bg-secondary); border-radius: 12px; padding: 20px; margin-top: 24px; }
        .stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 12px; }
        .stat-item { text-align: center; }
        .stat-value { font-size: 24px; font-weight: 600; color: var(--text-primary); display: block; }
        .stat-label { font-size: 12px; color: var(--text-tertiary); text-transform: uppercase; }
        .token-table-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px; padding: 16px 0; margin-top: 16px; overflow: hidden; }
        .token-table-card h4 { padding: 0 16px 12px; margin: 0; font-size: 13px; font-weight: 500; color: var(--text-primary); text-transform: uppercase; letter-spacing: 0.5px; }
        .token-table-card table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
        .token-table-card th { text-align: left; padding: 8px 16px; border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); background: var(--bg-tertiary); color: var(--text-muted); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
        .token-table-card th.num { text-align: right; }
        .token-table-card td { padding: 0 16px; height: 40px; border-bottom: 1px solid var(--border); color: var(--text-primary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
        .token-table-card td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
        .token-table-card tbody tr:last-child td { border-bottom: none; }
        .token-table-card tbody tr:nth-child(odd) { background: rgba(255,255,255,0.02); }
        .token-table-card tbody tr:hover { background: rgba(255,255,255,0.04); }
        .model-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; flex-shrink: 0; vertical-align: middle; position: relative; top: -1px; }
        .model-dot.anthropic { background: #5b8ef0; }
        .model-dot.deepseek  { background: #3dbf7a; }
        .model-dot.moonshot  { background: #a855f7; }
        .model-dot.openai    { background: #f97316; }
        .provider-balances { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-top: 16px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
        .provider-balances h4 { margin: 0; font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; flex-shrink: 0; }
        .balance-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-primary); }
        .balance-item .balance-val { font-weight: 500; font-variant-numeric: tabular-nums; }
        .limit-bar { width: 60px; height: 4px; background: var(--bg-tertiary); border-radius: 2px; display: inline-block; vertical-align: middle; }
        .limit-bar-fill { height: 100%; border-radius: 2px; background: #4a9; }
        .limit-bar-fill.warning { background: #e90; }
        .limit-bar-fill.danger { background: #e44; }

        /* User Profile Dropdown */
        .user-menu-dropdown {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            width: 260px;
            background: var(--bg-elevated);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 8px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.4);
            opacity: 0;
            visibility: hidden;
            transform: translateY(-8px);
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 100;
        }

        .user-menu-dropdown.open {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .user-menu-header {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px;
            border-bottom: 1px solid var(--border);
            margin-bottom: 4px;
        }

        .user-menu-avatar {
            width: 40px;
            height: 40px;
            background: var(--bg-tertiary);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 500;
            font-size: 14px;
            color: var(--text-primary);
        }

        .user-menu-info {
            flex: 1;
        }

        .user-menu-name {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
        }

        .user-menu-email {
            font-size: 12px;
            color: var(--text-muted);
        }

        .user-menu-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 10px 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s ease;
            color: var(--text-secondary);
            font-size: 14px;
        }

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

        .user-menu-item svg {
            width: 18px;
            height: 18px;
        }

        .user-menu-divider {
            height: 1px;
            background: var(--border);
            margin: 4px 0;
        }

        .user-menu-badge {
            margin-left: auto;
            font-size: 11px;
            color: var(--text-muted);
        }

        /* Plan Card */
        .plan-card {
            background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
            border: 1px solid rgba(99, 102, 241, 0.2);
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 24px;
        }

        .plan-name {
            font-size: 20px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 4px;
        }

        .plan-price {
            font-size: 14px;
            color: var(--text-muted);
            margin-bottom: 16px;
        }

        .plan-features {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .plan-feature {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 13px;
            color: var(--text-secondary);
        }

        .plan-feature svg {
            width: 16px;
            height: 16px;
            color: #22c55e;
        }

        /* Responsive */
        .mobile-menu-btn {
            display: none;
            background: none;
            border: none;
            color: var(--text-primary);
            cursor: pointer;
            padding: 8px;
            margin-right: 8px;
        }

        .sidebar-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
            z-index: 99;
        }

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

        .tools-section-mobile-nav { display: none; }

        @media (max-width: 900px) {
            .tools-section-mobile-nav { display: block; }
        }

        @media (max-width: 900px) {
            .mobile-menu-btn {
                display: block;
            }

            .sidebar {
                position: fixed;
                left: 0;
                top: 0;
                bottom: 0;
                z-index: 100;
                transform: translateX(-100%);
            }

            .sidebar.open {
                transform: translateX(0);
            }

            .sidebar.open + .sidebar-overlay {
                display: block;
            }

            .quick-actions {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        /* iPhone Safe Area */
        @supports (padding-top: env(safe-area-inset-top)) {
            .sidebar {
                padding-top: env(safe-area-inset-top);
                padding-bottom: env(safe-area-inset-bottom);
            }
            
            .main-header {
                padding-top: env(safe-area-inset-top);
                height: calc(48px + env(safe-area-inset-top));
            }
            
            .input-area {
                padding-bottom: calc(20px + env(safe-area-inset-bottom));
            }
        }

        @media (max-width: 640px) {
            .quick-actions {
                grid-template-columns: 1fr;
            }

            .welcome-title {
                font-size: 26px;
            }

            .header-nav {
                gap: 2px;
            }
            .header-nav .nav-item {
                padding: 6px 10px;
                font-size: 12px;
            }

            /* Mobile input fixes */
            .messages-container {
                padding: 12px;
            }

            .message {
                padding: 12px 0;
                gap: 10px;
            }

            .message-content {
                font-size: 15px;
                line-height: 1.6;
            }

            .message-content.user {
                background: rgba(255, 255, 255, 0.05);
                border: 1px solid rgba(255, 255, 255, 0.07);
                border-radius: 14px;
                padding: 10px 14px;
            }

            .input-area {
                padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
            }

            .input-wrapper {
                padding: 10px 12px;
            }

            .model-selector-inline {
                display: none;
            }

            .message-input {
                font-size: 16px; /* Prevent iOS zoom */
                min-height: 32px;
            }

            .input-hint {
                display: none;
            }

            /* Welcome mode: logo pinned to visible viewport via JS (--vv-h) */
            .main.welcome-mode .chat-area {
                flex: 1 1 auto;
                padding-bottom: 0;
                overflow: hidden;
                position: relative;
            }
            .main.welcome-mode {
                justify-content: flex-start;
            }
            .main.welcome-mode .welcome-screen {
                position: fixed;
                left: 0;
                right: 0;
                transition: top 0.25s ease-out;
                top: calc(var(--vv-top, 0px) + (var(--vv-h, 100dvh) - env(keyboard-inset-height, 0px)) * 0.5 - 110px);
                padding: 20px;
                z-index: 1;
            }
            .main.welcome-mode .welcome-logo {
                margin-bottom: 16px;
            }
            .main.welcome-mode .input-area {
                padding-top: 0;
            }

            .main-header {
                /* Preserve iOS safe-area top inset so chat name doesn't slide
                   under the status bar / Dynamic Island. The earlier
                   @supports rule sets these for desktop; the narrow-viewport
                   override has to repeat them or it wipes the inset. */
                padding: env(safe-area-inset-top) 12px 0;
                height: calc(48px + env(safe-area-inset-top));
            }

            .header-actions {
                gap: 6px;
            }

            .model-btn-inline {
                padding: 4px 10px;
                font-size: 11px;
            }

            .send-btn {
                width: 36px;
                height: 36px;
            }
        }

        @media (max-width: 768px) {
          .storage-header-btn {
            display: none !important;
          }
          .main-header {
            justify-content: flex-start !important;
            gap: 8px;
          }
          .header-nav {
            justify-content: flex-start !important;
            max-width: none !important;
            flex: 1 1 auto;
            margin-right: auto;
          }
          .header-actions {
            margin-left: auto;
            flex-shrink: 0;
          }
          .chat-input-area, .input-container, .chat-footer {
            position: fixed !important;
            /* env() follows the keyboard smoothly when VirtualKeyboard.overlaysContent
               is active (Chrome 94+). On other browsers env() resolves to 0px and
               interactive-widget=resizes-content handles it (close smooth, open snaps). */
            bottom: env(keyboard-inset-height, 0px) !important;
            left: 0;
            right: 0;
            z-index: 100;
            background: var(--bg-primary);
            will-change: bottom;
          }
          .messages-container, .chat-messages {
            padding-bottom: calc(80px + env(keyboard-inset-height, 0px)) !important;
          }
          .chat-input-area, .input-container, .chat-footer, .input-area {
            transition: bottom 0.25s ease-out, transform 0.25s ease-out;
          }
        }

        /* Auth tabs */
        .auth-tabs {
            display: flex;
            border-bottom: 1px solid var(--border);
            margin-bottom: 24px;
        }
        .auth-tab {
            flex: 1;
            padding: 10px;
            background: none;
            border: none;
            color: var(--text-secondary);
            font-size: 14px;
            cursor: pointer;
            border-bottom: 2px solid transparent;
            margin-bottom: -1px;
            transition: all 0.2s;
        }
        .auth-tab.active {
            color: var(--text-primary);
            border-bottom-color: var(--text-primary);
        }
        .auth-form { display: none; }
        .auth-form.active { display: block; }

        /* Markdown content */
        .message-body pre {
            background: #1e1e1e;
            border-radius: 6px;
            padding: 12px 16px;
            overflow-x: auto;
            margin: 8px 0;
            font-size: 13px;
        }
        html.light .message-body pre { background: #f6f8fa; }
        .message-body code {
            font-family: 'Fira Code', 'Cascadia Code', monospace;
            font-size: 13px;
        }
        .message-body p { margin-bottom: 8px; }
        .message-body ul, .message-body ol {
            padding-left: 20px;
            margin-bottom: 8px;
        }
        .message-body h1, .message-body h2, .message-body h3,
        .message-body h4, .message-body h5, .message-body h6 {
            margin: 12px 0 6px;
            font-size: inherit;
            font-weight: 600;
            line-height: inherit;
        }
        .message-body a { color: #4a9eff; text-decoration: none; }
        .message-body a:hover { text-decoration: underline; }
        .message-body blockquote {
            position: relative;
            margin: 12px 0;
            padding: 12px 16px;
            border-left: 3px solid var(--accent, #6366f1);
            background: rgba(99, 102, 241, 0.06);
            border-radius: 4px 8px 8px 4px;
            color: var(--text-primary);
            font-size: 14px;
            line-height: 1.55;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .message-body blockquote p { margin: 0 0 8px 0; }
        .message-body blockquote p:last-child { margin-bottom: 0; }
        .message-body pre { position: relative; }
        .message-body img { max-width: 100%; max-height: 400px; border-radius: 8px; margin: 6px 0; display: block; object-fit: contain; }
        .msg-attachment-wrap { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
        .msg-attachment-img { max-width: 280px; max-height: 200px; border-radius: 8px; object-fit: cover; cursor: pointer; }
        .msg-attachment-doc { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; color: var(--text-primary); cursor: pointer; }
        .msg-attachment-doc:hover { background: var(--hover-bg); }
        .tool-use-indicator {
            font-size: 12px;
            color: var(--text-muted);
            padding: 4px 0;
            font-style: italic;
        }

/* Boot loader — fades out once the app finishes initializing (see app.js). */
#app-loading { transition: opacity 0.3s ease-out; }

/* Storage upload button */
.storage-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color, #2a2a2e);
    background: var(--card-bg, #1e1e22);
    color: var(--text, #e0e0e0);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    margin-right: 8px;
}
.storage-upload-btn:hover {
    background: var(--hover-bg, #2a2a2e);
    border-color: var(--text-muted, #808085);
}
.storage-upload-btn svg { flex-shrink: 0; }

/* @mention autocomplete dropdown */
.mention-suggest {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 12px;
    right: 12px;
    max-height: 280px;
    overflow-y: auto;
    background: var(--card-bg, #1e1e22);
    border: 1px solid var(--border-color, #2a2a2e);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 100;
    padding: 4px;
}
.mention-suggest.open { display: block; }
.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text, #e0e0e0);
    font-size: 13px;
    line-height: 1.3;
}
.mention-item:hover,
.mention-item.selected {
    background: var(--hover-bg, #2a2a2e);
}
.mention-item svg {
    flex-shrink: 0;
    color: var(--text-muted, #808085);
}
.mention-item.selected svg {
    color: var(--text, #e0e0e0);
}
.mention-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mention-src {
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted, #808085);
    padding: 2px 6px;
    border: 1px solid var(--border-color, #2a2a2e);
    border-radius: 4px;
}

/* Per-message copy button */
.message {
    position: relative;
}
.msg-copy-btn {
    position: absolute;
    bottom: -10px;
    left: 0;
    background: var(--card-bg, #1e1e22);
    border: 1px solid var(--border-color, #2a2a2e);
    color: var(--text-muted, #808085);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    padding: 0;
}
.message:hover .msg-copy-btn,
.message:focus-within .msg-copy-btn {
    opacity: 1;
}
.msg-copy-btn:hover {
    color: var(--text, #fff);
    border-color: var(--text-muted, #808085);
    background: var(--hover-bg, #2a2a2e);
}
.msg-copy-btn.copied {
    color: #4ade80;
    border-color: #4ade80;
    opacity: 1;
}

/* Share button — same style as copy, sits between copy and retry */
.msg-share-btn {
    position: absolute;
    bottom: -10px;
    left: 36px;
    background: var(--card-bg, #1e1e22);
    border: 1px solid var(--border-color, #2a2a2e);
    color: var(--text-muted, #808085);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    padding: 0;
}
.message:hover .msg-share-btn,
.message:focus-within .msg-share-btn {
    opacity: 1;
}
.msg-share-btn:hover {
    color: var(--text, #fff);
    border-color: var(--text-muted, #808085);
    background: var(--hover-bg, #2a2a2e);
}
.msg-share-btn .icon {
    width: 14px;
    height: 14px;
}

/* "Изменить модель ответа" — tier-aware model switcher */
.msg-retry-wrap {
    position: absolute;
    bottom: -10px;
    left: 72px;
}
.msg-retry-btn {
    background: var(--card-bg, #1e1e22);
    border: 1px solid var(--border-color, #2a2a2e);
    color: var(--text-muted, #808085);
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    cursor: pointer;
    opacity: 0;
    font-size: 12px;
    transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.message:hover .msg-retry-btn,
.message:focus-within .msg-retry-btn,
.msg-retry-wrap:focus-within .msg-retry-btn {
    opacity: 1;
}
.msg-retry-btn:hover {
    color: var(--text, #fff);
    border-color: var(--text-muted, #808085);
    background: var(--hover-bg, #2a2a2e);
}
.msg-retry-btn .icon {
    flex: 0 0 auto;
}

/* Message timestamp — hover-only on desktop, hidden on mobile */
.msg-timestamp {
    position: absolute;
    bottom: 12px;
    right: 4px;
    font-size: 11px;
    color: var(--text-muted, #808085);
    opacity: 0;
    transition: opacity 0.15s ease;
    font-variant-numeric: tabular-nums;
    user-select: none;
    pointer-events: none;
    line-height: 1.2;
    white-space: nowrap;
}
.message.user .msg-timestamp {
    right: auto;
    left: 4px;
    bottom: 4px;
}
.message:hover .msg-timestamp,
.message:focus-within .msg-timestamp {
    opacity: 0.75;
}
@media (max-width: 640px), (hover: none) {
    .msg-timestamp { display: none; }
}

/* Message queue — pending bubbles get a small amber badge with cancel/interrupt actions */
.message-queued .message-body {
    opacity: 0.75;
}
.queue-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 8px;
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.25);
    border-radius: 8px;
    font-size: 11px;
    color: #f0b000;
    font-weight: 500;
    max-width: max-content;
}
.queue-badge svg {
    opacity: 0.85;
    flex: 0 0 auto;
}
.queue-badge > span {
    margin-right: 2px;
}
.queue-action {
    width: 18px;
    height: 18px;
    border: none;
    background: rgba(255, 193, 7, 0.2);
    color: #f0b000;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    transition: background 0.15s ease;
}
.queue-action:hover {
    background: rgba(255, 193, 7, 0.35);
}
.queue-interrupt {
    background: rgba(99, 102, 241, 0.2) !important;
    color: #818cf8 !important;
}
.queue-interrupt:hover {
    background: rgba(99, 102, 241, 0.35) !important;
}
.send-btn.queue-blocked {
    cursor: not-allowed;
}

/* ------------------------------------------------------------------
   Sidebar pulse dot — appears on every chat with a live stream so the
   user can see at a glance which conversations are still generating.
   ------------------------------------------------------------------ */
.chat-activity-indicator {
    display: flex;
    align-items: center;
    margin-left: auto;
    flex-shrink: 0;
}
.pulse-dot {
    width: 8px;
    height: 8px;
    background: #6366f1;
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.55);
}
@keyframes pulse {
    0%, 100% { transform: scale(1);   opacity: 1;   }
    50%      { transform: scale(1.3); opacity: 0.7; }
}
/* When the chat-item also has its hover actions, keep the pulse dot
   visible but let the menu button overlap normally. */
.chat-item:hover .chat-activity-indicator {
    opacity: 0.6;
}

/* Model switcher popover (floating, positioned by JS) */
.model-switcher-popover {
    position: fixed;
    background: rgba(30, 30, 35, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px;
    min-width: 240px;
    max-width: 320px;
    max-height: min(70vh, 420px);
    overflow-y: auto;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    z-index: 1000;
    color: var(--text, #fff);
    font-size: 14px;
    animation: msp-fade-in 120ms ease-out;
}
.model-switcher-popover label,
.model-switcher-popover .cta-title,
.model-switcher-popover .cta-body,
.model-switcher-popover .model-separator {
    color: var(--text-primary);
}
.model-switcher-popover .model-options {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
@keyframes msp-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (max-width: 640px) {
    .model-switcher-popover {
        min-width: min(260px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }
}
.model-switcher-popover .model-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text, #fff);
}
.model-switcher-popover .model-options label:hover {
    background: rgba(255,255,255,0.06);
}
.model-switcher-popover .model-options input[type="radio"] {
    accent-color: #6366f1;
    cursor: pointer;
    margin: 0;
}
.model-switcher-popover .model-separator {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 10px 0;
}
.model-switcher-popover .search-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 6px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text, #fff);
    border-radius: 6px;
}
.model-switcher-popover .search-toggle:hover {
    background: rgba(255,255,255,0.06);
}
.model-switcher-popover .search-toggle input[type="checkbox"] {
    accent-color: #6366f1;
    cursor: pointer;
    margin: 0;
}
.model-switcher-popover .send-with-model {
    margin-top: 10px;
    width: 100%;
    padding: 10px 14px;
    background: #6366f1 !important;
    color: #ffffff !important;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: filter 0.15s ease, transform 0.08s ease;
}
.model-switcher-popover .send-with-model:hover {
    filter: brightness(1.1);
}
.model-switcher-popover .send-with-model:active {
    transform: scale(0.98);
}
.model-switcher-popover .send-with-model:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.model-switcher-popover.free-cta {
    text-align: center;
}
.model-switcher-popover .cta-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}
.model-switcher-popover .cta-body {
    font-size: 13px;
    color: var(--text-secondary, #a0a0a5);
    margin-bottom: 12px;
    line-height: 1.5;
}
.model-switcher-popover .cta-upgrade {
    background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
    color: #ffffff !important;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    font-size: 14px;
    transition: filter 0.15s ease;
}
.model-switcher-popover .cta-upgrade:hover {
    filter: brightness(1.08);
}
.msg-copy-btn .icon {
    width: 14px;
    height: 14px;
}
/* Bug #1: на тач-экранах тулбар перекрывал последнюю строку ответа агента.
   По умолчанию скрыт (opacity 0 + pointer-events:none), тап по .message.assistant
   навешивает .tapped и делает тулбар кликабельным; повторный тап снимает.
   :not(.tapped) поднимает специфичность (40), чтобы перебить дефолтное
   .message:focus-within .msg-*-btn { opacity: 1 } (специфичность 20). */
@media (hover: none), (pointer: coarse) {
    .message.assistant:not(.tapped) .msg-copy-btn,
    .message.assistant:not(.tapped) .msg-share-btn,
    .message.assistant:not(.tapped) .msg-retry-btn {
        opacity: 0;
        pointer-events: none;
    }
    .message.assistant:not(.tapped) .msg-retry-wrap {
        pointer-events: none;
    }
    .message.assistant.tapped .msg-copy-btn,
    .message.assistant.tapped .msg-share-btn,
    .message.assistant.tapped .msg-retry-btn {
        opacity: 1;
        pointer-events: auto;
    }
    .message.assistant.tapped .msg-retry-wrap {
        pointer-events: auto;
    }
}

/* Copy + edit icons stacked to the LEFT of user bubble, touching its edge via flex gap.
   order:-1 makes them render before the bubble in the flex row; parent flex-end packs the whole group to the right. */
.msg-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    order: -1;
    align-self: flex-start;
    margin-top: 8px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.message.user:hover .msg-actions,
.message.user:focus-within .msg-actions,
.msg-actions:focus-within {
    opacity: 1;
}
.msg-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-secondary, #a0a0a5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.msg-action-btn:hover {
    background: rgba(255,255,255,0.10);
    color: var(--text, #fff);
    border-color: rgba(255,255,255,0.15);
}
.msg-action-btn.copied {
    background: rgba(34,197,94,0.2);
    color: rgb(34,197,94);
    border-color: rgba(34,197,94,0.3);
}
@media (max-width: 640px), (hover: none) {
    .message.user .msg-actions { opacity: 0; }
    .message.user.tapped .msg-actions,
    .message.user:focus-within .msg-actions {
        opacity: 1;
        pointer-events: auto;
    }
    .msg-action-btn:active { opacity: 1; }
}

/* Inline edit state for user messages */
.message.user.editing .message-content {
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.2);
}
.edit-wrap { display: flex; flex-direction: column; gap: 8px; }
.edit-textarea {
    width: 100%;
    min-height: 60px;
    background: transparent;
    color: var(--text, #fff);
    border: none;
    outline: none;
    resize: vertical;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.55;
    padding: 0;
    box-sizing: border-box;
}
.edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}
.edit-actions button {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: filter 0.15s ease, background 0.15s ease;
}
.edit-actions button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.edit-save {
    background: #6366f1;
    color: #ffffff;
}
.edit-save:hover { filter: brightness(1.08); }
.edit-cancel {
    background: rgba(255,255,255,0.08);
    color: var(--text-secondary, #a0a0a5);
}
.edit-cancel:hover { background: rgba(255,255,255,0.12); }

/* Model option locked state (insufficient role) */
.model-option-locked {
    opacity: 0.4;
    cursor: not-allowed !important;
    filter: grayscale(1);
    position: relative;
}
.model-option-locked:hover {
    background: transparent !important;
}
.model-option-locked .model-radio {
    opacity: 0.3;
}
.model-option-locked .model-name::after {
    content: " \1F512";
    font-size: 11px;
    margin-left: 4px;
    opacity: 0.8;
}

/* ─── Points system (2026-04-21) ─────────────────────────────────── */

.points-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    color: var(--text-primary, #fff);
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    white-space: nowrap;
    line-height: 1;
}
.points-pill:hover {
    background: var(--bg-hover, rgba(255,255,255,0.10));
}
.points-pill.warn {
    color: #f5b84a;
    border-color: rgba(245, 184, 74, 0.35);
}
.points-pill.crit {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.4);
}
.points-pill-tier { font-weight: 600; text-transform: uppercase; letter-spacing: 1px; font-size: 11px; }
.points-pill-sep { opacity: 0.5; }
.points-pill-amount { font-variant-numeric: tabular-nums; }
.points-pill-label { opacity: 0.65; }
.points-pill-reset { opacity: 0.6; font-size: 11px; }

.points-pill-full { display: inline-flex; align-items: center; gap: 6px; }
.points-pill-compact { display: none; font-weight: 600; }

/* Hide the reset date on narrow viewports so the pill stays compact. */
@media (max-width: 640px) {
    .points-pill-reset, .points-pill-sep:last-of-type { display: none; }
    .points-pill-label { display: none; }
    .points-pill-full { display: none; }
    .points-pill-compact { display: inline; }
    .points-pill { padding: 6px 10px; }

    /* Hide the "Tools" / "Блокнот" labels on mobile — icon only */
    .tools-btn .tools-label,
    .notepad-btn .tools-label { display: none; }
    .tools-btn,
    .notepad-btn { padding: 6px 10px; }
}

/* Sender line (message-sender) now contains name · model · points */
.message-sender .sender-name { font-weight: 600; letter-spacing: 1px; text-transform: uppercase; font-size: 11px; opacity: 0.8; }
.message-sender .sender-sep  { opacity: 0.35; margin: 0 2px; }
.message-sender .sender-model { opacity: 0.6; font-size: 11px; }
.message-sender .sender-points { opacity: 0.55; font-size: 11px; font-variant-numeric: tabular-nums; }

/* Points info modal body */
.points-modal-body {
    color: var(--text-primary, #fff);
    font-size: 13.5px;
    line-height: 1.55;
}

.points-modal-balance {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
}
.points-modal-balance.unlimited {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}
.points-modal-balance .balance-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.points-modal-balance .balance-tier {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-secondary, #999);
    text-transform: uppercase;
}
.points-modal-balance .balance-count {
    font-size: 15px;
    color: var(--text-primary, #fff);
    font-variant-numeric: tabular-nums;
}
.points-modal-balance .balance-count b {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary, #fff);
}
.points-modal-balance .balance-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}
.points-modal-balance .balance-bar-fill {
    height: 100%;
    background: var(--text-primary, #fff);
    transition: width 0.3s;
}
.points-modal-balance .balance-bar-fill.mid {
    background: linear-gradient(90deg, #f59e0b, #f97316);
}
.points-modal-balance .balance-bar-fill.high {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}
.points-modal-balance .balance-note {
    font-size: 12px;
    color: var(--text-secondary, #999);
    margin-top: 6px;
}
.points-modal-balance.unlimited .balance-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #fff);
    margin-top: 4px;
}

.points-modal-intro {
    font-size: 13px;
    color: var(--text-secondary, #bbb);
    line-height: 1.5;
    margin-bottom: 12px;
}
.points-modal-subtitle {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary, #fff);
}
.points-modal-list {
    margin: 0 0 12px 0;
    padding-left: 20px;
    font-size: 13px;
    color: var(--text-primary, #fff);
    line-height: 1.8;
}
.points-modal-list li { margin-bottom: 2px; }
.points-modal-list li b { color: var(--text-primary, #fff); }

.points-modal-reset {
    font-size: 12px;
    color: var(--text-secondary, #888);
    text-align: center;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

#pointsModalUpgradeBtn {
    background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
    color: #ffffff !important;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
}
#pointsModalUpgradeBtn:hover {
    filter: brightness(1.1);
}

/* Settings page — collapse left sidebar to icon-only strip on mobile so
   the right content panel (email, ID, password controls) stays readable. */
@media (max-width: 640px) {
    .settings-container {
        gap: 12px;
    }
    .settings-sidebar {
        width: 56px;
        min-width: 56px;
        flex-shrink: 0;
    }
    .settings-sidebar .settings-menu-item {
        justify-content: center;
        padding: 12px 0;
        gap: 0;
        position: relative;
    }
    .settings-sidebar .settings-menu-item > span {
        display: none;
    }
    .settings-sidebar .settings-menu-item.active {
        border-left: 2px solid var(--text-primary, #fff);
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }
    .settings-content {
        flex: 1;
        min-width: 0;
        padding: 0 4px;
    }
    .settings-content .settings-card {
        padding: 16px;
    }
    .settings-content .settings-row {
        flex-wrap: wrap;
        gap: 4px;
    }
    .settings-content .settings-value {
        font-size: 13px;
        word-break: break-all;
        text-align: right;
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Floating copy button shared by blockquotes and code blocks. */
.copy-btn-inline {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary, #aaa);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
    z-index: 2;
}
.message-body blockquote:hover > .copy-btn-inline,
.message-body pre:hover > .copy-btn-inline,
.copy-btn-inline:focus-visible { opacity: 1; }
.copy-btn-inline:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary, #fff);
}
.copy-btn-inline.copied {
    opacity: 1 !important;
    background: rgba(34, 197, 94, 0.2);
    color: rgb(34, 197, 94);
    border-color: rgba(34, 197, 94, 0.3);
}
/* Touch devices have no hover — keep the button faintly visible. */
@media (hover: none), (max-width: 640px) {
    .message-body blockquote > .copy-btn-inline,
    .message-body pre > .copy-btn-inline { opacity: 0.55; }
}

/* ─────────────────────────────────────────────────────────
   IN-APP DEBUG CONSOLE (superadmin/admin only)
   ───────────────────────────────────────────────────────── */
.debug-toggle {
    position: fixed;
    right: calc(12px + env(safe-area-inset-right));
    top: calc(70px + env(safe-area-inset-top));
    bottom: auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(30, 30, 35, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9998;
    opacity: 0.7;
    transition: opacity 0.15s, transform 0.15s;
}
.debug-toggle:hover { opacity: 1; transform: scale(1.08); }

.debug-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 50vh;
    background: rgba(15, 15, 18, 0.98);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.25s;
    display: flex;
    flex-direction: column;
    color: #e5e5e5;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 12px;
}
.debug-panel.open { transform: translateY(0); }

.debug-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 13px;
}
.debug-panel-title { font-weight: 600; color: #ef4444; }
.debug-panel-actions button {
    background: transparent;
    border: none;
    color: #888;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    cursor: pointer;
    margin-left: 4px;
}
.debug-panel-actions button:hover { color: #e5e5e5; }

.debug-panel-log {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
}
.debug-line {
    display: grid;
    grid-template-columns: 72px 44px 1fr;
    gap: 6px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    align-items: flex-start;
}
.debug-line pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: inherit;
    font-size: inherit;
}
.debug-time { color: #666; }
.debug-level { text-transform: uppercase; font-weight: 600; font-size: 10px; padding: 1px 6px; border-radius: 3px; text-align: center; align-self: start; }
.debug-log .debug-level { background: rgba(100, 150, 255, 0.15); color: #7aa8e0; }
.debug-info .debug-level { background: rgba(100, 150, 255, 0.15); color: #7aa8e0; }
.debug-warn .debug-level { background: rgba(250, 180, 50, 0.15); color: #f5b342; }
.debug-error { background: rgba(239, 68, 68, 0.05); }
.debug-error .debug-level { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.debug-debug .debug-level { background: rgba(160, 160, 160, 0.15); color: #999; }

@media (max-width: 640px) {
    .debug-toggle { top: calc(60px + env(safe-area-inset-top)); }
}

/* ─────────────────────────────────────────────────────────
   UNIFIED THEMED MODALS (uiPrompt / uiConfirm)
   ───────────────────────────────────────────────────────── */
.ui-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.15s ease;
    padding: 20px;
}
.ui-modal-overlay.open { opacity: 1; }

.ui-modal {
    background: rgba(28, 28, 32, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 22px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(8px);
    transition: transform 0.15s ease;
}
.ui-modal-overlay.open .ui-modal { transform: translateY(0); }

.ui-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #fff);
    margin-bottom: 8px;
}
.ui-modal-label {
    font-size: 13px;
    color: var(--text-secondary, #999);
    margin-bottom: 8px;
}
.ui-modal-message {
    font-size: 14px;
    color: var(--text-secondary, #bbb);
    line-height: 1.5;
    margin-bottom: 16px;
    white-space: pre-wrap;
}
.ui-modal-input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 14px;
    outline: none;
    margin-bottom: 14px;
    transition: border-color 0.15s;
}
.ui-modal-input:focus {
    border-color: #6366f1;
    background: rgba(255, 255, 255, 0.08);
}
.ui-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.ui-modal-btn {
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.15s, background 0.15s;
    min-width: 90px;
}
.ui-modal-btn.primary {
    background: #6366f1 !important;
    color: #ffffff !important;
}
.ui-modal-btn.primary:hover { filter: brightness(1.1); }
.ui-modal-btn.danger {
    background: #dc2626 !important;
    color: #ffffff !important;
}
.ui-modal-btn.danger:hover { filter: brightness(1.1); }
.ui-modal-btn.secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary, #fff) !important;
    border-color: rgba(255, 255, 255, 0.1);
}
.ui-modal-btn.secondary:hover { background: rgba(255, 255, 255, 0.1); }

@media (max-width: 640px) {
    .ui-modal { max-width: 100%; padding: 18px; }
    .ui-modal-actions { flex-direction: column-reverse; }
    .ui-modal-btn { width: 100%; }
}


/* ============================================================
   Chat Sharing (Task 42)
   - Public /shared/{token} read-only view
   - Share modal opened from chat menu
   ============================================================ */

/* ---- Public shared view ---- */
.shared-view {
    min-height: 100vh;
    background: var(--bg-primary, #0b0b10);
    color: var(--text-primary, #fff);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.shared-header {
    padding: 24px 20px 16px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
}
.shared-logo {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 6px;
    color: #6366f1;
}
.shared-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 6px;
    color: var(--text-primary, #fff);
    word-break: break-word;
}
.shared-meta {
    font-size: 13px;
    color: var(--text-secondary, #8a8a96);
    margin: 0;
}
.shared-messages {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 20px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.shared-msg {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.025);
    line-height: 1.55;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.shared-msg.user {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.25);
    align-self: flex-end;
    max-width: 85%;
}
.shared-msg.assistant {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
    align-self: flex-start;
    max-width: 92%;
}
.shared-msg-header {
    font-size: 12px;
    color: var(--text-secondary, #8a8a96);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.shared-msg-body {
    color: var(--text-primary, #fff);
}
.shared-msg-body pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.45;
}
.shared-msg-body code {
    background: rgba(0, 0, 0, 0.3);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
}
.shared-msg-body pre code { background: transparent; padding: 0; }
.shared-msg-body p:first-child { margin-top: 0; }
.shared-msg-body p:last-child { margin-bottom: 0; }
.shared-cta {
    margin: 16px auto 24px;
    max-width: 800px;
    width: calc(100% - 32px);
    padding: 18px 20px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(139, 92, 246, 0.14));
    border: 1px solid rgba(99, 102, 241, 0.35);
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
}
.shared-cta.muted {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
}
.shared-cta-text {
    flex: 1;
    min-width: 200px;
    font-size: 14px;
    color: var(--text-primary, #fff);
    line-height: 1.5;
}
.shared-cta-btn {
    padding: 10px 18px;
    border-radius: 10px;
    background: #6366f1;
    color: #ffffff;
    border: none;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.shared-cta-btn:hover { filter: brightness(1.1); }
.shared-cta-btn:active { transform: scale(0.98); }
.shared-cta-btn:disabled { opacity: 0.6; cursor: wait; }
.shared-cta-btn.secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #fff);
}
.shared-footer {
    padding: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary, #8a8a96);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.shared-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    font-size: 15px;
    color: var(--text-secondary, #8a8a96);
}
.shared-error {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    text-align: center;
    gap: 12px;
}
.shared-error-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}
.shared-error-text {
    font-size: 14px;
    color: var(--text-secondary, #8a8a96);
    max-width: 420px;
}

@media (max-width: 640px) {
    .shared-header { padding: 18px 14px 12px; }
    .shared-logo { font-size: 20px; }
    .shared-title { font-size: 16px; }
    .shared-messages { padding: 14px 12px 6px; gap: 10px; }
    .shared-msg { padding: 12px 14px; font-size: 14px; }
    .shared-msg.user, .shared-msg.assistant { max-width: 100%; }
    .shared-cta { margin: 10px 12px 18px; width: auto; padding: 14px 16px; }
    .shared-cta-btn { width: 100%; justify-content: center; }
}

/* ---- Share chat modal ---- */
.share-chat-modal {
    max-width: 520px;
    width: calc(100vw - 32px);
}
.share-modal-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.share-modal-subtitle {
    font-size: 13px;
    color: var(--text-secondary, #8a8a96);
    margin: 0 0 4px;
    line-height: 1.5;
}
.share-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 14px;
    color: var(--text-primary, #fff);
}
.share-option:hover { background: rgba(255, 255, 255, 0.05); }
.share-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #6366f1;
    cursor: pointer;
    flex-shrink: 0;
}
.share-option-label {
    flex: 1;
    line-height: 1.4;
}
.share-option-hint {
    display: block;
    font-size: 12px;
    color: var(--text-secondary, #8a8a96);
    margin-top: 2px;
    font-weight: 400;
}
.share-result {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.share-link-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #8a8a96);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0;
}
.share-link-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.share-link-input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    outline: none;
}
.share-link-input:focus { border-color: #6366f1; }
.share-copy-btn {
    padding: 0 14px;
    border-radius: 8px;
    background: #6366f1;
    color: #ffffff;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
    white-space: nowrap;
}
.share-copy-btn:hover { filter: brightness(1.1); }
.share-copy-btn.copied { background: #22c55e; }
.share-existing {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 6px;
    padding-top: 14px;
}
.share-existing-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #8a8a96);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.share-revoke-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    font-size: 12px;
    color: var(--text-secondary, #8a8a96);
    margin-bottom: 6px;
}
.share-revoke-row-token {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.share-revoke-btn {
    padding: 5px 10px;
    border-radius: 6px;
    background: rgba(220, 38, 38, 0.15);
    border: 1px solid rgba(220, 38, 38, 0.35);
    color: #ef4444;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.share-revoke-btn:hover { background: rgba(220, 38, 38, 0.25); }
.share-error {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #ef4444;
    font-size: 13px;
}

@media (max-width: 640px) {
    .share-chat-modal { max-width: 100%; padding: 18px; }
    .share-link-row { flex-direction: column; }
    .share-copy-btn { width: 100%; padding: 9px; }
}

/* ── Async sub-agent chips (ADR-007 Phase 3.1) ─────────────────────────── */
.agent-chips-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px 4px;
    background: transparent;
}

.agent-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.2;
}

.agent-chip-spinner {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-top-color: rgba(255, 255, 255, 0.85);
    animation: agent-chip-spin 0.9s linear infinite;
    flex-shrink: 0;
}

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

.agent-chip-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.agent-chip-cancel {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.55);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 50%;
    transition: color 0.15s ease, background 0.15s ease;
}

.agent-chip-cancel:hover {
    color: rgba(255, 255, 255, 1);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Focus thread view (Perplexity-style) v3 ──────────────────────────
   Adapted from operator's colleague reference (Perplexity-clone React
   pattern). On submit:
     1. renderMessages appends a trailing .messages-spacer inside
        .messages, sized in JS to (containerHeight - userMsgHeight).
     2. _enableQueryFocus schedules an rAF that calls
        scrollIntoView({behavior:'smooth', block:'start'}) on the user
        message. The spacer provides enough scrollHeight that the
        message can actually park at the viewport top.
   No position:sticky, no wrapper min-height — both were sources of
   bugs in earlier attempts (v1: scrollIntoView no-op on sticky;
   v2: smartScrollToBottom scrolling UP because of negative-adjustment
   math under the wrapper's empty space).
   Sticky-bottom (smartScrollToBottom / isNearBottom) explicitly
   ignores .messages-spacer — they look at the last real .message —
   so the long-answer auto-follow continues to work.
   Design: docs/vault/features/focus-thread-view.md. */
.messages-spacer {
    /* height is set inline in renderMessages; this rule just guarantees
       the element doesn't pick up display:flex from .messages or any
       other inherited layout that would distort the empty-space role. */
    flex-shrink: 0;
}

/* scroll-padding-top gives scrollIntoView a small breathing gap above
   the parked element — looks nicer than parking it flush with the
   container's top border. Was originally part of the legacy query-focus
   block; kept because it improves the new focus-thread-view pin too. */
#messagesContainer {
    scroll-padding-top: 12px;
}
