/* ==========================================================================
    PREMIUM DESIGN SYSTEM (AiChat Pro)
   ========================================================================== */

/* 1. Glassmorphism */
.glass-panel {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.dark .glass-panel {
    background: rgba(31, 41, 55, 0.7); /* gray-800 with opacity */
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

.glass-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(229, 231, 235, 0.5);
    z-index: 40;
}

.dark .glass-header {
    background: rgba(17, 24, 39, 0.85);
    border-bottom: 1px solid rgba(55, 65, 81, 0.5);
}

/* 2.1 AiChat Generation Inputs — works in both standalone pages and inline mode */
.AiChat-field {
    padding: 0.75rem 1rem;
    outline: none !important;
    box-shadow: none !important;
}

.AiChat-field:focus {
    outline: none !important;
    box-shadow: none !important;
    border-color: transparent !important;
}

/* Legacy selector for standalone pages */
.librechat-form-page .AiChat-field {
    padding: 0.75rem 1rem;
    outline: none;
}

.librechat-form-page .AiChat-field:focus {
    outline: none !important;
}

/* 2. Premium Inputs */
.input-premium {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(209, 213, 219, 0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.dark .input-premium {
    background: rgba(31, 41, 55, 0.5);
    border: 1px solid rgba(75, 85, 99, 0.8);
    color: #f3f4f6;
}

.input-premium:focus {
    background: #ffffff;
    border-color: #6366f1;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}

.dark .input-premium:focus {
    background: #1f2937;
    border-color: #818cf8;
    box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.15), 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* 3. Gradient Text */
.text-gradient-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.text-gradient-purple {
    background: linear-gradient(135deg, #c026d3 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.text-gradient-blue {
    background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dark .text-gradient-primary {
    background: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
}

.dark .text-gradient-blue {
    background: linear-gradient(135deg, #60a5fa 0%, #22d3ee 100%);
}

/* 4. Animated Background Helpers */
.bg-animated-gradient {
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 5. Better Scrollbars (Refined) */
.scrollbar-premium::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

.scrollbar-premium::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.3);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: background-color 0.2s;
}

.scrollbar-premium::-webkit-scrollbar-thumb:hover {
    background-color: rgba(107, 114, 128, 0.6);
}

.dark .scrollbar-premium::-webkit-scrollbar-thumb:hover {
    background-color: rgba(156, 163, 175, 0.5);
}

/* 6. Card Hover Effects */
.hover-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.hover-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.dark .hover-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Utility Animations */
@keyframes pulse-subtle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.animate-pulse-subtle {
    animation: pulse-subtle 3s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-float {
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

/* ==================== Enhanced Formatting Styles ==================== */

/* Prose enhancements for formatted output */
.prose h1, .prose h2, .prose h3 {
    margin-top: 1.2em;
    margin-bottom: 0.5em;
    font-weight: 700;
    line-height: 1.3;
}

.prose h2 {
    border-bottom: 1px solid rgba(156, 163, 175, 0.3);
    padding-bottom: 0.3em;
}

.prose blockquote {
    border-left: 4px solid #6366f1;
    background: rgba(99, 102, 241, 0.05);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    border-radius: 0 0.5rem 0.5rem 0;
}

.dark .prose blockquote {
    background: rgba(99, 102, 241, 0.1);
    border-left-color: #818cf8;
}

.prose hr {
    border-color: rgba(156, 163, 175, 0.3);
    margin: 1.5rem 0;
}

/* Chart container */
.chart-container {
    max-width: 600px;
    margin: 1rem auto;
}

/* Generated image container */
.generated-image-container {
    max-width: 512px;
}

.generated-image-container img {
    max-height: 512px;
    object-fit: contain;
}

/* Mermaid diagrams */
.mermaid {
    background: transparent !important;
    text-align: center;
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(156, 163, 175, 0.2);
}

.dark .mermaid {
    background: rgba(17, 24, 39, 0.5) !important;
}

/* KaTeX formulas */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5rem 0;
}

/* Enhanced table styles */
.table-scroll-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    border-radius: 0.5rem;
    border: 1px solid rgba(156, 163, 175, 0.3);
    background: rgba(255, 255, 255, 0.92);
}

.dark .table-scroll-wrapper {
    background: rgba(17, 24, 39, 0.88);
}

.table-export-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: rgba(99, 102, 241, 0.05);
    border-bottom: 1px solid rgba(156, 163, 175, 0.15);
}

.dark .table-export-bar {
    background: rgba(99, 102, 241, 0.1);
}

.table-export-btn {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    color: #6366f1;
    background: transparent;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.table-export-btn:hover {
    background: rgba(99, 102, 241, 0.1);
}

.dark .table-export-btn {
    color: #a5b4fc;
}

.dark .table-export-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

/* iChat media result cards */
.media-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 2rem;
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(255, 255, 255, 0.92);
    color: #334155;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
    cursor: pointer;
}

.dark .media-action-btn {
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    border-color: rgba(71, 85, 105, 0.9);
}

.media-action-btn:hover { border-color: rgba(59, 130, 246, 0.72); }
.media-action-btn--blue:hover { border-color: rgba(37, 99, 235, 0.78); }
.media-action-btn--emerald { background: #059669; color: #fff; border-color: #047857; }
.media-action-btn--emerald:hover { background: #047857; border-color: #065f46; }
.media-action-btn--amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.media-action-btn--rose:hover { border-color: rgba(225, 29, 72, 0.72); }
.media-action-btn--violet:hover { border-color: rgba(124, 58, 237, 0.72); }

.media-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(255, 255, 255, 0.92);
    color: #334155;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
}

.media-icon-btn:hover {
    border-color: rgba(37, 99, 235, 0.72);
    transform: translateY(-1px);
}

.media-icon-btn--amber {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

.media-result-shell {
    overflow: hidden;
    border-radius: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(248, 250, 252, 0.92);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.dark .media-result-shell {
    background: rgba(15, 23, 42, 0.72);
    border-color: rgba(71, 85, 105, 0.7);
}

.media-result-shell__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem 0.45rem;
}

.media-result-shell__title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #0f172a;
}

.dark .media-result-shell__title {
    color: #f8fafc;
}

.media-result-shell__dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: #64748b;
}

.media-result-shell__dot--amber { background: #d97706; }
.media-result-shell__dot--emerald { background: #059669; }
.media-result-shell__dot--rose { background: #e11d48; }
.media-result-shell__dot--violet { background: #7c3aed; }

.media-result-shell__actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.media-result-shell__meta {
    padding: 0 1rem 0.75rem;
    color: #64748b;
    font-size: 0.75rem;
}

.dark .media-result-shell__meta {
    color: #94a3b8;
}

.media-result-shell--amber {
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(255, 251, 235, 0.95);
}

.dark .media-result-shell--amber {
    border-color: rgba(245, 158, 11, 0.45);
    background: rgba(120, 53, 15, 0.22);
}

.media-result-shell--emerald {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(236, 253, 245, 0.95);
}

.dark .media-result-shell--emerald {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(6, 78, 59, 0.22);
}

.media-result-shell--rose {
    border-color: rgba(244, 63, 94, 0.35);
    background: rgba(255, 241, 242, 0.95);
}

.dark .media-result-shell--rose {
    border-color: rgba(244, 63, 94, 0.45);
    background: rgba(136, 19, 55, 0.22);
}

.media-result-shell--violet {
    border-color: rgba(139, 92, 246, 0.35);
    background: rgba(245, 243, 255, 0.95);
}

.dark .media-result-shell--violet {
    border-color: rgba(139, 92, 246, 0.45);
    background: rgba(76, 29, 149, 0.22);
}

.media-image-stage {
    position: relative;
}

.media-image-stage .image-card-result {
    cursor: zoom-in;
}

.media-image-overlay {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    display: flex;
    gap: 0.35rem;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.media-image-stage:hover .media-image-overlay,
.media-image-stage:focus-within .media-image-overlay {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.image-params-panel {
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.95), rgba(241, 245, 249, 0.9));
}

.dark .image-params-panel {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.82));
}

.media-tier-range {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 0.45rem;
    border-radius: 999px;
    background: linear-gradient(90deg, #60a5fa 0%, #a78bfa 55%, #f472b6 100%);
    cursor: pointer;
}

.media-tier-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    border: 2px solid #ffffff;
    background: #334155;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}

.media-tier-range::-moz-range-thumb {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    border: 2px solid #ffffff;
    background: #334155;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}

.media-resolution-chip {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(148, 163, 184, 0.4);
    color: #475569;
    cursor: pointer;
}

.media-resolution-chip--active {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.38);
    color: #1d4ed8;
}

.dark .media-resolution-chip {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(71, 85, 105, 0.85);
    color: #cbd5e1;
}

.dark .media-resolution-chip--active {
    background: rgba(59, 130, 246, 0.24);
    border-color: rgba(96, 165, 250, 0.55);
    color: #bfdbfe;
}

.media-chip {
    display: inline-flex;
    align-items: center;
    min-height: 1.35rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.24);
}

.media-card-warning {
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: 0.75rem;
    background: rgba(255, 251, 235, 0.85);
    color: #92400e;
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
}

.dark .media-card-warning {
    background: rgba(120, 53, 15, 0.18);
    color: #fcd34d;
}

.media-audio-player {
    display: block;
    min-width: min(100%, 16rem);
    min-height: 2.5rem;
}

/* ── Vocal split card ──────────────────────────────────── */
.vocal-track {
    border-radius: 0.625rem;
    padding: 0.625rem 0.75rem;
    background: rgba(255,255,255,0.6);
    border: 1px solid rgba(139,92,246,0.2);
}
.dark .vocal-track {
    background: rgba(0,0,0,0.25);
    border-color: rgba(139,92,246,0.3);
}
.vocal-track--empty {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.55;
    padding: 0.5rem 0.75rem;
}
.vocal-track__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.vocal-track__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}
.vocal-track__label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #5b21b6;
}
.dark .vocal-track__label {
    color: #c4b5fd;
}
.vocal-track__unavail {
    font-size: 0.75rem;
    color: #9ca3af;
}

.media-video-frame {
    width: 100%;
    aspect-ratio: var(--media-aspect-ratio, 16 / 9);
    min-height: 11rem;
    max-height: 26rem;
    border-radius: 0.75rem;
    overflow: hidden;
    background: #020617;
}

.media-video-frame video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.image-prompt-editor,
.media-input,
.media-select {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 0.625rem;
    background: rgba(255, 255, 255, 0.96);
    color: #111827;
    padding: 0.5rem 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.dark .image-prompt-editor,
.dark .media-input,
.dark .media-select {
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    border-color: rgba(71, 85, 105, 0.9);
}

.media-field-label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: min(100%, 12rem);
    color: #64748b;
    font-size: 0.7rem;
    font-weight: 700;
}

.dark .media-field-label { color: #cbd5e1; }

.image-reference-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(5.25rem, 1fr));
    gap: 0.5rem;
    padding: 0 0.75rem 0.75rem;
}

.image-reference-thumb,
.image-history-item {
    min-width: 0;
    border: 1px solid rgba(148, 163, 184, 0.32);
    border-radius: 0.625rem;
    overflow: hidden;
    background: rgba(248, 250, 252, 0.92);
}

.dark .image-reference-thumb,
.dark .image-history-item { background: rgba(15, 23, 42, 0.72); }

.image-reference-thumb img,
.image-history-item img,
.image-history-placeholder {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
}

.image-reference-thumb span,
.image-history-item span {
    display: block;
    padding: 0.25rem 0.375rem;
    color: #64748b;
    font-size: 0.68rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-history-strip {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4.75rem, 1fr));
    gap: 0.5rem;
}

.image-history-placeholder { background: linear-gradient(135deg, #e2e8f0, #f8fafc); }
.dark .image-history-placeholder { background: linear-gradient(135deg, #1e293b, #0f172a); }

.html-page-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 14rem;
    background: #eff6ff;
    overflow: hidden;
}

.html-page-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.html-page-thumb--fallback span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 0.75rem;
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
    font-weight: 800;
    letter-spacing: 0;
}

.dark .html-page-thumb { background: #0f172a; }
.dark .html-page-thumb--fallback span { background: rgba(96, 165, 250, 0.12); color: #93c5fd; }

.media-3d-viewer {
    position: relative;
    min-height: 20rem;
    border-radius: 0.75rem;
    overflow: hidden;
    background: #f3f0ff;
}

.dark .media-3d-viewer { background: #1e1b4b; }

.media-3d-viewer model-viewer {
    display: block;
    width: 100%;
    height: 20rem;
}

.media-3d-viewer model-viewer:not(:defined) { display: none; }

.media-3d-viewer model-viewer:defined + .model-viewer-fallback { display: none; }

.model-viewer-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 20rem;
    padding: 1rem;
    text-align: center;
    color: #5b21b6;
    background: rgba(245, 243, 255, 0.92);
}

.dark .model-viewer-fallback {
    color: #ddd6fe;
    background: rgba(46, 16, 101, 0.3);
}

.prose table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    font-size: 0.875rem;
    overflow: hidden;
    margin: 0;
}

.prose thead th {
    background: rgba(99, 102, 241, 0.08);
    font-weight: 600;
    text-align: left;
    vertical-align: bottom;
    white-space: nowrap;
    padding: 0.625rem 0.75rem;
    border-bottom: 2px solid rgba(99, 102, 241, 0.2);
}

.dark .prose thead th {
    background: rgba(99, 102, 241, 0.15);
}

.prose tbody td {
    padding: 0.5rem 0.75rem;
    vertical-align: top;
    border-bottom: 1px solid rgba(156, 163, 175, 0.15);
}

.prose tbody tr:hover {
    background: rgba(99, 102, 241, 0.03);
}

.dark .prose tbody tr:hover {
    background: rgba(99, 102, 241, 0.08);
}

/* Code block enhancement */
.code-block-wrapper {
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Lists enhancement */
.prose ul {
    list-style-type: disc;
    padding-left: 1.5rem;
}

.prose ol {
    list-style-type: decimal;
    padding-left: 1.5rem;
}

.prose li {
    margin-bottom: 0.25rem;
}

/* Inline code */
.prose code:not([class]) {
    background: rgba(99, 102, 241, 0.08);
    color: #6366f1;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-weight: 500;
}

.dark .prose code:not([class]) {
    background: rgba(129, 140, 248, 0.15);
    color: #a5b4fc;
}

/* ====================================================================
   WATCH / SMARTWATCH LAYOUT (≤280px)
   OLED-optimized: pure black backgrounds, compact layout, voice-first
   ==================================================================== */
@media (max-width: 280px) {
    /* -- OLED Black Theme Override (saves battery on OLED) -- */
    body, body.dark,
    .bg-white, .dark\:bg-gray-800,
    .bg-gray-100, .dark\:bg-\[\#212121\] {
        background-color: #000000 !important;
    }
    .dark\:bg-gray-800, .bg-white {
        background-color: #000000 !important;
    }
    /* Cards / panels */
    .dark\:bg-gray-700, .bg-gray-50,
    .dark\:bg-\[\#212121\] {
        background-color: #111111 !important;
    }
    /* Borders dimmed */
    .border-gray-200, .dark\:border-white\/10,
    .border-gray-300, .dark\:border-gray-700,
    .dark\:border-gray-600 {
        border-color: #1a1a1a !important;
    }

    /* -- Hide sidebars completely -- */
    .md\:hidden { display: none !important; }

    /* -- Top toolbar: ultra-compact -- */
    .flex.items-center.justify-between.px-4.py-2 {
        padding: 2px 6px !important;
        gap: 2px !important;
        min-height: 24px !important;
        border-bottom: none !important;
        background: transparent !important;
    }
    /* Hide model selector details, keep only icon */
    .model-selector button span.text-sm { display: none !important; }
    .model-selector button svg.h-4 { display: none !important; }
    .model-selector button span[x-show="attachedAgent"] { display: none !important; }
    .model-selector { min-width: unset !important; }
    .model-selector button { padding: 2px 4px !important; gap: 2px !important; }
    /* Hide share button & settings */
    button[title="Поделиться"],
    button[title="Настройки"] { display: none !important; }

    /* -- Chat scroll area -- */
    #scroll-container {
        padding: 4px 12px 100px !important;
    }

    /* -- Messages: compact, no avatars -- */
    .message-bubble {
        padding: 5px 8px !important;
        font-size: 10px !important;
        line-height: 1.35 !important;
        border-radius: 10px !important;
        max-height: 80px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* User bubble: right-aligned feel */
    .message-bubble:has(+ .flex-shrink-0) {
        margin-left: 10% !important;
    }
    /* Avatar icons: hide on watch */
    .flex-shrink-0 .w-8.h-8,
    .flex-shrink-0 .w-10.h-10 {
        width: 16px !important;
        height: 16px !important;
        font-size: 8px !important;
    }
    /* Message row gap */
    .flex.gap-4, .flex.gap-3 {
        gap: 3px !important;
    }

    /* -- Greeting: compact -- */
    .text-2xl, .md\:text-3xl {
        font-size: 12px !important;
    }
    .mb-8 { margin-bottom: 8px !important; }

    /* -- Input area: compact, transparent, voice-first -- */
    #chat-input-area {
        padding: 3px 6px !important;
        padding-bottom: max(3px, env(safe-area-inset-bottom)) !important;
        background: transparent !important;
        border-top: none !important;
    }
    /* Input container */
    .chat-input-container {
        padding: 4px !important;
        gap: 3px !important;
        border-radius: 16px !important;
        background: #111111 !important;
    }
    /* Textarea */
    .chat-input {
        font-size: 11px !important;
        min-height: 20px !important;
        line-height: 20px !important;
    }
    /* Attach button: smaller */
    .chat-input-container .flex-shrink-0 button.w-8 {
        width: 24px !important;
        height: 24px !important;
    }
    .chat-input-container .flex-shrink-0 button.w-8 svg {
        width: 14px !important;
        height: 14px !important;
    }
    /* Voice button: hero size — primary input on watch */
    button[title="Голосовой ввод"],
    button[title="Остановить запись"] {
        width: 36px !important;
        height: 36px !important;
        background: #f85149 !important;
        color: #fff !important;
        box-shadow: 0 2px 12px rgba(248, 81, 73, 0.4) !important;
        order: -1; /* Move mic to the left */
    }
    button[title="Голосовой ввод"] svg,
    button[title="Остановить запись"] svg {
        width: 18px !important;
        height: 18px !important;
    }
    /* Send button: compact */
    .chat-input-container button.bg-black,
    .chat-input-container button.dark\:bg-white {
        width: 24px !important;
        height: 24px !important;
    }
    .chat-input-container button.bg-black svg,
    .chat-input-container button.dark\:bg-white svg {
        width: 14px !important;
        height: 14px !important;
    }

    /* -- Attached files: smaller -- */
    .mb-3.flex.flex-wrap { gap: 3px !important; }
    .mb-3 .h-20 { height: 36px !important; width: 36px !important; }

    /* -- Voice mode settings: hide on watch -- */
    .bg-blue-50.dark\:bg-blue-900\/20.rounded-lg { display: none !important; }

    /* -- Agent preview: compact -- */
    .inline-flex.items-center.gap-3.px-4 {
        gap: 3px !important;
        padding: 4px 6px !important;
        font-size: 9px !important;
    }
    .inline-flex .w-10.h-10 { width: 20px !important; height: 20px !important; font-size: 12px !important; }

    /* -- Model dropdown: compact -- */
    .model-selector .absolute {
        width: 160px !important;
        max-height: 180px !important;
        font-size: 10px !important;
    }
    .model-selector .absolute .px-4.py-3 {
        padding: 4px 8px !important;
    }
    .model-selector .absolute .w-8.h-8 {
        width: 16px !important;
        height: 16px !important;
    }

    /* -- Hide premium indicator, reasoning panels on watch -- */
    .input-premium { display: none !important; }

    /* -- Scrollbar hide -- */
    #scroll-container::-webkit-scrollbar,
    .message-bubble::-webkit-scrollbar {
        display: none;
    }
    #scroll-container,
    .message-bubble {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    /* -- Ambient circular glow (decorative) -- */
    body::after {
        content: '';
        position: fixed;
        top: 2px; left: 2px; right: 2px; bottom: 2px;
        border-radius: 50%;
        border: 1px solid rgba(88, 166, 255, 0.06);
        pointer-events: none;
        z-index: 9998;
    }
}

/* ===== Watch: Round screen enhancements (iChat) ===== */
body.watch-round-ichat {
    border-radius: 50%;
    overflow: hidden;
}
body.watch-round-ichat .flex.items-center.justify-between.px-4.py-2 {
    padding-top: 18px !important;
    padding-left: 36px !important;
    padding-right: 36px !important;
    justify-content: center !important;
}
body.watch-round-ichat #scroll-container {
    padding-left: 24px !important;
    padding-right: 24px !important;
}
body.watch-round-ichat #chat-input-area {
    padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
    padding-left: 32px !important;
    padding-right: 32px !important;
}
body.watch-round-ichat .message-bubble {
    max-height: 56px;
}

/* ===== Ultra-tiny watch (≤200px, iChat) ===== */
@media (max-width: 200px) {
    /* Hide toolbar completely */
    .flex.items-center.justify-between.px-4.py-2 {
        display: none !important;
    }
    #scroll-container {
        padding: 2px 18px 80px !important;
    }
    .message-bubble {
        font-size: 8px !important;
        padding: 3px 5px !important;
        max-height: 48px;
    }
    .text-2xl { font-size: 10px !important; }
    /* Voice-only: hide textarea */
    .chat-input { display: none !important; }
    /* Hide attach + send, keep only mic */
    .chat-input-container .flex-shrink-0:not(:has(button[title="Голосовой ввод"]):not(:has(button[title="Остановить запись"]))) {
        display: none !important;
    }
    .chat-input-container {
        justify-content: center !important;
        background: transparent !important;
        border: none !important;
    }
}

/* ========================= Source Link Tooltips ========================= */
.prose .source-link {
    text-decoration: none !important;
    border-bottom: 1.5px dotted rgba(59, 130, 246, 0.5);
    transition: border-color 0.15s ease, color 0.15s ease;
}
.prose .source-link:hover {
    border-bottom-color: rgba(59, 130, 246, 0.9);
}
.dark .prose .source-link {
    border-bottom-color: rgba(96, 165, 250, 0.4);
}
.dark .prose .source-link:hover {
    border-bottom-color: rgba(96, 165, 250, 0.8);
}
.source-tooltip {
    background: #1f2937;
    color: #f3f4f6;
    font-size: 12px;
    line-height: 1.4;
    padding: 6px 10px;
    border-radius: 8px;
    max-width: 280px;
    word-break: break-word;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.source-tooltip.visible {
    opacity: 1;
}
.source-tooltip .source-tooltip-domain {
    font-weight: 600;
    color: #93c5fd;
}
.source-tooltip .source-tooltip-hint {
    color: #9ca3af;
    font-size: 10px;
    margin-top: 2px;
}
.source-tooltip .source-tooltip-arrow,
.source-tooltip .source-tooltip-arrow::before {
    position: absolute;
    width: 8px;
    height: 8px;
    background: inherit;
}
.source-tooltip .source-tooltip-arrow {
    visibility: hidden;
}
.source-tooltip .source-tooltip-arrow::before {
    visibility: visible;
    content: '';
    transform: rotate(45deg);
}
.source-tooltip[data-popper-placement^='top'] > .source-tooltip-arrow {
    bottom: -4px;
}
.source-tooltip[data-popper-placement^='bottom'] > .source-tooltip-arrow {
    top: -4px;
}
.source-tooltip[data-popper-placement^='left'] > .source-tooltip-arrow {
    right: -4px;
}
.source-tooltip[data-popper-placement^='right'] > .source-tooltip-arrow {
    left: -4px;
}

/* === Mobile Sidebar Improvements === */
/* Ensure sidebar is properly hidden/shown on mobile */
@media (max-width: 768px) {
    /* Sidebar container should be position fixed to overlay content */
    aside[x-cloak] {
        display: none !important;
    }

    /* Hide overlay when sidebar is closed */
    aside:not(.open-sidebar) ~ .fixed {
        display: none;
    }
    
    /* Mobile hamburger menu button - ensure visibility */
    .md\:hidden[class*="hamburger"],
    button[class*="md:hidden"] {
        z-index: 50;
        position: relative;
    }
    
    /* Sidebar should be accessible when opened */
    aside.translate-x-0 {
        display: block;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease-in-out;
    }
    
    /* Ensure sidebar scroll doesn't affect main scroll */
    aside .overflow-y-auto {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Keep mobile logic class-driven: fixed only when composer is explicitly pinned. */
    #chat-input-area {
        max-width: 100%;
    }

    #chat-input-area.aichat-input-area--bottom-fixed {
        position: fixed;
        bottom: var(--aichat-composer-fixed-bottom, max(5px, env(safe-area-inset-bottom)));
        left: var(--aichat-composer-fixed-left, max(1rem, env(safe-area-inset-left)));
        right: var(--aichat-composer-fixed-right, max(1rem, env(safe-area-inset-right)));
        margin-bottom: 0;
        padding-bottom: 0;
    }

    #scroll-container.aichat-scroll-shell--composer-fixed {
        padding-bottom: calc(var(--aichat-input-bottom-padding, 8rem) + env(safe-area-inset-bottom));
    }
}
