/* Dark Theme with Purple Gradients and Glass Effects - Updated for message layout v2.1 */
/* Enhanced with premium polish, refined shadows, and smooth micro-animations */

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

:root {
    /* Core Purple Palette - Extended with more depth */
    --primary-purple: #8b5cf6;
    --secondary-purple: #a855f7;
    --purple-soft: #9f7aea;
    --purple-glow: rgba(139, 92, 246, 0.4);
    --purple-bloom: rgba(168, 85, 247, 0.25);
    --purple-deep: #7c3aed;
    --purple-muted: rgba(139, 92, 246, 0.15);

    /* Accent Colors for Visual Interest */
    --accent-cyan: #22d3ee;
    --accent-pink: #f472b6;
    --accent-amber: #fbbf24;

    /* Background Layers */
    --dark-bg: #0a0e1a;
    --darker-bg: #0f1423;
    --surface-elevated: rgba(25, 30, 48, 0.95);

    /* Text Colors - Refined contrast */
    --light-text: #f8fafc;
    --muted-text: #94a3b8;
    --dim-text: #64748b;

    /* Glass Effects - More refined */
    --glass-bg: rgba(255, 255, 255, 0.025);
    --glass-bg-hover: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-border-hover: rgba(255, 255, 255, 0.22);
    --glass-glow: rgba(139, 92, 246, 0.08);

    /* Layout Variables */
    --sidebar-width: 260px;
    --sidebar-gap: 8px;
    --page-gutter: clamp(18px, 4vw, 32px);
    --content-padding: clamp(24px, 4.5vw, 56px);
    --content-max-width: 100%;
    --message-radius: 20px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --vertical-gap: 0;

    /* Surface Colors - More refined */
    --surface-overlay: rgba(10, 14, 26, 0.85);
    --surface-muted: rgba(18, 22, 38, 0.78);
    --surface-line: rgba(255, 255, 255, 0.08);
    --surface-strong: rgba(255, 255, 255, 0.18);

    /* Message Specific */
    --message-ai-bg: rgba(20, 24, 42, 0.88);
    --message-user-bg: rgba(124, 104, 248, 0.18);
    --message-user-border: rgba(124, 104, 248, 0.4);
    --message-hover: rgba(255, 255, 255, 0.06);

    /* Composer */
    --composer-offset: clamp(120px, 18vh, 220px);
    --composer-target: clamp(460px, 66%, 100%);
    --council-gap: clamp(12px, 2.5vw, 22px);

    /* Safe Areas */
    --safe-area-top: 0px;
    --safe-area-right: 0px;
    --safe-area-bottom: 0px;
    --safe-area-left: 0px;

    /* Premium Shadows */
    --shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, 0.3), 0 1px 2px -1px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.5), 0 4px 12px -4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px -12px rgba(0, 0, 0, 0.6), 0 8px 24px -8px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px -5px var(--purple-glow), 0 0 40px -10px var(--purple-bloom);
    --shadow-button: 0 4px 14px -4px rgba(139, 92, 246, 0.5), 0 8px 24px -8px rgba(139, 92, 246, 0.3);
    --shadow-button-hover: 0 8px 24px -4px rgba(139, 92, 246, 0.6), 0 16px 40px -8px rgba(139, 92, 246, 0.35);
    --shadow-inset: inset 0 1px 1px rgba(255, 255, 255, 0.06), inset 0 -1px 1px rgba(0, 0, 0, 0.1);

    /* Smooth Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-bounce: 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@supports (padding-top: env(safe-area-inset-top)) {
    :root {
        --safe-area-top: env(safe-area-inset-top);
        --safe-area-right: env(safe-area-inset-right);
        --safe-area-bottom: env(safe-area-inset-bottom);
        --safe-area-left: env(safe-area-inset-left);
    }
}

/* Premium Scrollbar Styling - More Visible */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(139, 92, 246, 0.7), rgba(168, 85, 247, 0.6));
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--primary-purple), var(--secondary-purple));
    background-clip: padding-box;
}

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

/* Firefox scrollbar */
* {
    scrollbar-width: auto;
    scrollbar-color: rgba(139, 92, 246, 0.6) rgba(255, 255, 255, 0.05);
}

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background:
        radial-gradient(ellipse 80% 60% at 20% 10%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse 60% 50% at 80% 80%, rgba(168, 85, 247, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, var(--darker-bg) 0%, var(--dark-bg) 100%);
    color: var(--light-text);
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    min-height: 100dvh;
    height: auto;
    overflow: hidden;
    /* no page scroll; internal panels handle overflow */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    /* Premium text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

body.modal-open {
    overscroll-behavior: contain;
}

/* Dashboard Layout - CSS Driven Toggling */

.dashboard-layout {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    width: 100%;
    position: relative;
    display: flex;
    transition: all 0.3s ease-in-out;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, rgba(15, 20, 35, 0.95) 0%, rgba(10, 14, 26, 0.98) 100%);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transition: transform var(--transition-smooth), box-shadow var(--transition-smooth);
    box-sizing: border-box;
    padding: 1.5em;
    box-shadow:
        4px 0 30px -10px rgba(0, 0, 0, 0.5),
        1px 0 0 0 rgba(255, 255, 255, 0.03) inset;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease-in-out;
    width: calc(100% - var(--sidebar-width));
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Desktop: Sidebar visible by default */
@media (min-width: 901px) {
    body.sidebar-closed .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-closed .main-content {
        margin-left: 0;
        width: 100%;
    }
}

/* Mobile: Sidebar hidden by default */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        /* Slightly wider on mobile for better touch */
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        left: 0 !important;
    }

    /* Overlay for mobile */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 49;
        /* Just below sidebar */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        backdrop-filter: blur(2px);
    }

    body.sidebar-open .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }
}

/* Sidebar toggle button - positioned at bottom of sidebar */
.sidebar-toggle {
    position: absolute;
    bottom: 20px;
    left: 16px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--light-text);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.25) 0%, rgba(139, 92, 246, 0.15) 100%);
    border-color: rgba(139, 92, 246, 0.5);
    transform: scale(1.08);
    box-shadow: var(--shadow-button);
}

.sidebar-toggle .toggle-icon {
    display: inline-block;
    transition: transform var(--transition-smooth);
}

/* Rotate arrow when sidebar is closed */
body.sidebar-closed .sidebar-toggle .toggle-icon {
    transform: rotate(180deg);
}

/* Mobile: hide sidebar toggle in sidebar, show mobile-menu-toggle instead */
@media (max-width: 900px) {
    .sidebar-toggle {
        display: none;
    }
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
}

.home-btn,
.new-chat-btn-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12) 0%, rgba(139, 92, 246, 0.06) 100%);
    border: 1px solid rgba(139, 92, 246, 0.25);
    border-radius: var(--radius);
    color: var(--light-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition-base);
    gap: 10px;
    position: relative;
    overflow: hidden;
}

.home-btn::before,
.new-chat-btn-link::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(139, 92, 246, 0.15) 0%, transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.home-btn:hover,
.new-chat-btn-link:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(139, 92, 246, 0.1) 100%);
    border-color: rgba(139, 92, 246, 0.45);
    transform: translateY(-2px);
    box-shadow: var(--shadow-button);
}

.home-btn:hover::before,
.new-chat-btn-link:hover::before {
    opacity: 1;
}

.home-btn:active,
.new-chat-btn-link:active {
    transform: translateY(0);
}

.icon {
    font-size: 16px;
}

.mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-button,
.send-button {
    align-self: center;
}

.message img {
    max-width: 100%;
    height: auto;
}

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

.chat-workspace {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 0 calc(var(--composer-offset) + 24px + var(--safe-area-bottom)) 24px;
    gap: 24px;
    box-sizing: border-box;
    scrollbar-gutter: stable;
    scroll-padding-bottom: calc(var(--composer-offset) + 24px + var(--safe-area-bottom));
}

.chat-workspace .messages {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    align-items: stretch;
    overflow: visible;
}

.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* New modern top bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding-top: calc(14px + var(--safe-area-top));
    padding-bottom: 14px;
    padding-left: 16px;
    padding-right: 16px;
    margin-left: 0;
    margin-right: 0;
    min-height: 72px;
    background: linear-gradient(180deg, rgba(10, 14, 26, 0.92) 0%, rgba(10, 14, 26, 0.88) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    position: sticky;
    top: var(--safe-area-top);
    z-index: 40;
    width: 100%;
    box-shadow: 0 4px 24px -8px rgba(0, 0, 0, 0.4);
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.85;
}

.top-bar-left,
.top-bar-middle,
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-left {
    flex: 0 0 auto;
}

.top-bar-middle {
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
    overflow: hidden;
}

.top-bar-right {
    flex: 0 0 auto;
    margin-left: auto;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

.top-actions.top-actions-primary {
    gap: 12px;
}

.mobile-control-wrapper {
    position: relative;
    display: none;
}

.mobile-control-bar {
    display: flex;
    align-items: stretch;
    gap: 12px;
    padding: 0 var(--content-padding);
    margin: 4px 0 0;
}

.mobile-control-btn {
    flex: 1;
    background: var(--surface-overlay);
    border: 1px solid var(--surface-line);
    border-radius: 16px;
    padding: 10px 14px;
    color: var(--light-text);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.mobile-control-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.18);
}

.mobile-control-btn:active {
    transform: translateY(1px);
}

.mobile-control-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.7;
}

.mobile-control-value {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
}

.mobile-mode-popover,
.mode-settings-popover {
    position: absolute;
    top: calc(100% + 12px);
    background: rgba(10, 14, 24, 0.95);
    border: 1px solid var(--surface-line);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 24px 48px -28px rgba(0, 0, 0, 0.85);
    z-index: 120;
    pointer-events: auto;
}

.mobile-mode-popover {
    left: var(--content-padding);
    right: var(--content-padding);
}

.mode-settings-popover {
    min-width: 220px;
}

.mobile-mode-option {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 12px;
    color: var(--light-text);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.mobile-mode-option:hover,
.mobile-mode-option.is-active {
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.4);
}

.mode-toggle-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 999px;
    padding: 4px;
}

.top-action-btn {
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    color: var(--light-text);
    padding: 10px 18px;
    font-size: 0.84rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.top-action-btn.ghost {
    background: transparent;
    border-color: transparent;
}

.top-action-btn.ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
}

.top-action-btn.primary {
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: #fff;
    box-shadow: 0 20px 36px -22px rgba(139, 92, 246, 0.65);
}

.top-action-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 24px 38px -20px rgba(139, 92, 246, 0.75);
}

.top-action-btn.is-active {
    background: rgba(139, 92, 246, 0.18);
    border-color: rgba(139, 92, 246, 0.45);
    box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.4);
}

.top-action-btn[data-count]:after {
    content: attr(data-count);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    font-size: 0.7rem;
    font-weight: 600;
}

.top-action-btn .action-label {
    font-size: 0.68rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.72;
}

.top-action-btn .action-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.top-action-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.top-action-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
}

#change-model-btn {
    padding: 12px 18px;
}

#change-model-btn,
#mode-settings-btn {
    position: relative;
}

.top-action-icon {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
}

.icon-btn.is-active {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.4);
}

#mode-settings-btn[data-count]::after {
    content: attr(data-count);
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary-purple), var(--secondary-purple));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 6px 14px rgba(139, 92, 246, 0.35);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--light-text);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.26);
    transform: translateY(-1px);
}

.logout-btn.small {
    padding: 8px 16px;
    font-size: 0.78rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: var(--light-text);
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.logout-btn.small:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.32);
}

/* Hero state */
.hero-state {
    text-align: center;
    margin: 20px auto 20px;
    max-width: 760px;
    padding: 0 20px;
    animation: fadeIn .6s ease;
}

.hero-title {
    font-size: 2.4rem;
    margin: 0 0 28px;
    font-weight: 600;
    letter-spacing: .5px;
}

.category-pills {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: balance;
    margin-bottom: 30px;
}

.pill {
    background: linear-gradient(145deg, #2a2030, #1d1924);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e6d9f7;
    padding: 12px;
    border-radius: 34px;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    transition: .3s all;
}

.pill:before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.18), transparent 70%);
    opacity: 0;
    transition: .4s opacity;
}

.pill:hover:before {
    opacity: .9;
}

.pill:hover {
    transform: translateY(-3px);
    border-color: rgba(255, 255, 255, 0.3);
}

.suggested-prompts {
    list-style: none;
    margin: 0 0 38px;
    padding: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.suggested-prompts li {
    padding: 16px 10px 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    text-align: left;
    font-size: .95rem;
    color: #dedbe8;
    position: relative;
    transition: .25s all;
}

.suggested-prompts li:after {
    content: "→";
    position: absolute;
    right: 10px;
    opacity: 0;
    transition: .25s transform, .25s opacity;
}

.suggested-prompts li:hover {
    background: rgba(255, 255, 255, 0.05);
    padding-left: 18px;
}

.suggested-prompts li:hover:after {
    opacity: 1;
    transform: translateX(4px);
}

.consent-banner {
    font-size: .7rem;
    color: #a19cab;
    opacity: .9;
    margin: 10px 0 20px;
}

.consent-banner a {
    color: var(--primary-purple);
    text-decoration: none;
}

.consent-banner a:hover {
    text-decoration: underline;
}

/* Messages hidden state */
.hidden {
    display: none;
}

/* When messages become visible again, ensure they have proper styling */
.chat-workspace .messages:not(.hidden) {
    display: flex;
    flex-direction: column;
}

/* Composer */
.dashboard-layout .composer {
    position: relative;
    width: min(100%, var(--composer-target));
    max-width: var(--content-max-width);
    margin: 16px auto 0;
    display: block;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 10;
    padding: 0 24px calc(32px + var(--safe-area-bottom));
}

.composer.message-form {
    width: 100%;
    display: block;
    box-sizing: border-box;
}

.composer .composer-container {
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}

.composer-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.model-picker-compact {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.model-picker-compact select.compact {
    background: rgba(255, 255, 255, 0.07);
    color: #e9e4f5;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.75rem;
    min-width: 90px;
    cursor: pointer;
    appearance: none;
}

.model-picker-compact select.compact:focus {
    outline: none;
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, .35);
}

.input-row {
    width: 100%;
}

.input-container {
    display: flex;
    align-items: flex-end;
    background: linear-gradient(135deg, rgba(16, 21, 36, 0.95) 0%, rgba(12, 16, 28, 0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    padding: 16px 20px;
    backdrop-filter: blur(24px) saturate(1.1);
    -webkit-backdrop-filter: blur(24px) saturate(1.1);
    box-shadow:
        0 24px 68px -32px rgba(0, 0, 0, 0.75),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset,
        0 -1px 1px rgba(255, 255, 255, 0.04) inset;
    gap: 12px;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input-container:focus-within {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow:
        0 24px 68px -32px rgba(0, 0, 0, 0.75),
        0 0 0 1px rgba(139, 92, 246, 0.15) inset,
        0 0 30px -10px rgba(139, 92, 246, 0.2);
}

.input-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.composer-meta {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
}

.composer-model-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.18) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 1px solid rgba(139, 92, 246, 0.32);
    color: #efe9ff;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 12px 24px -16px rgba(139, 92, 246, 0.45);
}

.composer-model-pill:hover,
.composer-model-pill:focus-visible {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.28) 0%, rgba(139, 92, 246, 0.16) 100%);
    border-color: rgba(139, 92, 246, 0.6);
    box-shadow: 0 18px 36px -18px rgba(139, 92, 246, 0.55);
}

.composer-model-pill:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.35), 0 18px 36px -18px rgba(139, 92, 246, 0.5);
}

.composer-model-icon {
    font-size: 0.9rem;
}

.composer-model-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.1;
}

.composer-model-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.64);
    letter-spacing: 0.12em;
}

.composer-model-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #f7f5ff;
    text-transform: none;
    letter-spacing: 0;
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    align-self: flex-end;
}

.attachment-button {
    background: none;
    border: none;
    color: var(--muted-text);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-button.has-files {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

.input-container.drag-over {
    background: rgba(139, 92, 246, 0.1);
    border: 2px dashed var(--primary-purple);
    border-radius: 12px;
}

/* Message attachments */
.message-attachments {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-item {
    display: inline-block;
}

.attachment-image {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.2s ease;
}

.attachment-image:hover {
    transform: scale(1.05);
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 6px;
    color: var(--light-text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.attachment-link:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.5);
    text-decoration: none;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-button);
    position: relative;
    overflow: hidden;
}

.send-button::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: linear-gradient(135deg, var(--primary-purple), var(--secondary-purple));
    opacity: 0;
    filter: blur(8px);
    transition: opacity var(--transition-base);
    z-index: -1;
}

.send-button:hover {
    background: linear-gradient(135deg, var(--secondary-purple) 0%, #c084fc 100%);
    transform: translateY(-2px) scale(1.05);
    box-shadow: var(--shadow-button-hover);
}

.send-button:hover::before {
    opacity: 0.6;
}

.send-button:active {
    transform: translateY(0) scale(0.98);
}

.send-button:disabled {
    background: rgba(71, 85, 105, 0.6);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.7;
}

.send-button:disabled::before {
    display: none;
}

.message-input.autosize {
    resize: none;
    flex: 1;
    background: transparent;
    background-color: transparent;
    border: none;
    color: #fff;
    -webkit-text-fill-color: #fff;
    font-size: 0.95rem;
    line-height: 1.4;
    max-height: 120px;
    overflow-y: auto;
    padding: 10px 0;
    font-family: inherit;
    min-height: 32px;
    caret-color: var(--light-text);
}

.message-input.autosize:focus {
    outline: none;
}

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

@media (max-width: 1100px) {
    :root {
        --sidebar-width: 320px;
    }
}

@media (min-width: 901px) {
    .sidebar {
        position: fixed;
        top: var(--safe-area-top);
        left: 0;
        width: var(--sidebar-width);
        height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
        height: calc(100dvh - var(--safe-area-top) - var(--safe-area-bottom));
        z-index: 100;
        overflow-x: hidden;
    }

    .dashboard-layout:not(.sidebar-hidden) .main-content>.top-bar {
        width: calc(100% + var(--sidebar-gap));
        margin-left: calc(-1 * (var(--page-gutter) + var(--safe-area-left) + var(--sidebar-gap)));
        padding-left: calc(var(--content-padding) + var(--page-gutter) + var(--safe-area-left) + var(--sidebar-gap));
    }

    .mobile-only,
    .sidebar-overlay {
        display: none !important;
    }
}

@media (max-width: 900px) {
    :root {
        --page-gutter: 12px;
        --content-padding: 20px;
        --sidebar-gap: 8px;
    }

    body {
        overflow-x: hidden;
        padding: 0;
    }

    .dashboard-layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .main-content {
        width: 100%;
        margin-left: 0;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
    }

    .top-bar {
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
        padding-top: calc(8px + var(--safe-area-top));
        padding-bottom: 8px;
        min-height: 56px;
        top: 0;
        left: 0;
        right: 0;
    }

    .top-bar-left {
        gap: 8px;
        order: 1;
        flex: 0 0 auto;
    }

    .top-bar-middle {
        order: 2;
        flex: 0 0 auto;
        display: flex;
        justify-content: center;
        width: auto;
    }

    .top-actions.top-actions-primary {
        width: auto;
        gap: 8px;
        flex-wrap: nowrap;
        align-items: center;
    }

    .top-action-btn {
        flex: 0 0 auto;
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
        gap: 0;
    }

    .top-action-text,
    .top-action-btn .action-label,
    .top-action-btn .action-value {
        display: none;
    }

    .top-action-glyph {
        font-size: 1.2rem;
    }

    .app-title {
        display: none;
    }

    .top-bar-right {
        order: 3;
        margin-left: auto;
        gap: 8px;
        flex: 0 0 auto;
    }

    .chat-workspace {
        padding: 16px var(--content-padding) calc(var(--composer-offset) + 16px + var(--safe-area-bottom));
        gap: 18px;
    }

    .chat-workspace .messages {
        gap: 16px;
    }

    .dashboard-layout .composer {
        width: 100%;
        max-width: none;
        padding: 0 var(--content-padding) calc(24px + var(--safe-area-bottom));
        margin-top: 12px;
    }

    .message {
        max-width: 100%;
    }

    .council-grid .council-card,
    .council-stream-grid .council-card {
        flex-basis: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .message-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

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

    .sidebar {
        position: fixed;
        top: var(--safe-area-top);
        left: -100%;
        width: 88%;
        max-width: 320px;
        height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
        height: calc(100dvh - var(--safe-area-top) - var(--safe-area-bottom));
        z-index: 1000;
        border-radius: 0;
        border-right: 1px solid var(--glass-border);
        padding: 24px;
    }

    .sidebar.active {
        left: 0;
    }

    .attachment-button,
    .send-button {
        align-self: center;
    }

    .message-text pre {
        max-width: 100%;
        overflow-x: auto;
        font-size: 0.85rem;
        padding: 0.5em;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    .mobile-control-bar {
        padding: 0 var(--content-padding);
        margin-top: 8px;
        gap: 12px;
    }

    .mobile-control-btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .mobile-mode-popover {
        left: var(--content-padding);
        right: var(--content-padding);
    }

    .mode-settings-popover {
        min-width: 200px;
    }
}

@media (max-width: 480px) {

    .attachment-button,
    .send-button {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .input-container {
        padding: 12px 16px;
        min-height: 72px;
        border-radius: 18px;
    }

    .mobile-control-bar {
        gap: 8px;
    }

    .mobile-mode-popover,
    .mode-settings-popover {
        border-radius: 14px;
        padding: 10px;
    }

    .top-action-btn {
        padding: 8px 12px;
    }

    .top-action-btn .action-label {
        font-size: 0.62rem;
    }

    .top-action-btn .action-value {
        font-size: 0.86rem;
    }

    .top-action-glyph {
        font-size: 1.2rem;
    }

    .message-input.autosize {
        font-size: 1.05rem;
        line-height: 1.6;
        min-height: 48px;
    }

    /* Hide theme toggle on very small screens */
    #theme-toggle {
        display: none;
    }

    /* Make logout button icon-only */
    .logout-btn.small {
        padding: 8px;
        font-size: 0;
    }

    .logout-btn.small::before {
        content: '↪';
        font-size: 1rem;
    }
}

/* Consent footer now in normal flow under composer */
.consent-footer {
    text-align: center;
    font-size: 0.65rem;
    opacity: 0.8;
    margin: 16px 0 0 0;
}

/* Styling for model picker dropdowns */

/* Premium scrollbar styles are defined at the top of the file */

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

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

/* Navigation Links */
.nav-links {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    text-align: center;
}

.nav-links a {
    margin: 0 15px;
    text-decoration: none;
    color: var(--primary-purple);
    font-weight: 500;
    transition: color 0.3s ease;
}

.nav-links a:hover {
    color: var(--secondary-purple);
    text-decoration: underline;
}

/* Model Picker */
.model-picker {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.model-picker label {
    color: var(--muted-text);
    margin-right: 10px;
}

.model-picker select {
    background: var(--glass-bg);
    color: var(--light-text);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 8px 12px;
    margin-right: 15px;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.model-picker select:focus {
    outline: none;
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

/* Messages Container */
.messages {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Hide messages initially for new chat */
.messages.hidden {
    display: none;
}

/* Message Styles */
.message {
    margin: 0;
    padding: 20px 24px;
    border-radius: var(--message-radius);
    max-width: min(92%, 1180px);
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: var(--surface-muted);
    color: var(--light-text);
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
    overflow-wrap: break-word;
    word-wrap: break-word;
    min-height: fit-content;
    box-shadow:
        0 8px 24px -12px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.02) inset;
    transition:
        transform var(--transition-base),
        border-color var(--transition-base),
        box-shadow var(--transition-base),
        background var(--transition-base);
}

.message:hover {
    background: var(--message-hover);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow:
        0 16px 40px -16px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    transform: translateY(-2px);
}

.user-message {
    margin-left: auto;
    text-align: left;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(124, 104, 248, 0.1) 100%);
    border: 1px solid rgba(139, 92, 246, 0.35);
    color: var(--light-text);
    box-shadow:
        0 8px 24px -12px rgba(139, 92, 246, 0.4),
        0 0 0 1px rgba(139, 92, 246, 0.05) inset;
}

.user-message:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(124, 104, 248, 0.15) 100%);
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow:
        0 16px 40px -16px rgba(139, 92, 246, 0.5),
        0 0 0 1px rgba(139, 92, 246, 0.08) inset;
}

.ai-message {
    margin-right: auto;
    background: linear-gradient(135deg, rgba(20, 24, 44, 0.9) 0%, rgba(18, 22, 38, 0.95) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--light-text);
}

.ai-message:hover {
    background: linear-gradient(135deg, rgba(25, 30, 52, 0.92) 0%, rgba(22, 26, 42, 0.96) 100%);
    border-color: rgba(255, 255, 255, 0.14);
}

.message-content {
    margin: 0;
    padding: 0;
    white-space: normal;
    line-height: 1.55;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    gap: 12px;
}

.message-toolbar {
    align-self: flex-end;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: -4px;
}

.copy-message-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted-text);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.copy-message-btn:hover,
.copy-message-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--surface-line);
    color: var(--light-text);
}

.copy-message-btn:focus-visible {
    outline: 2px solid var(--primary-purple);
    outline-offset: 2px;
}

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

.copy-message-btn svg {
    width: 16px;
    height: 16px;
}

.copy-message-btn[data-copied]::after {
    position: absolute;
    top: -150%;
    right: 50%;
    transform: translateX(50%);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    box-shadow: 0 10px 16px -12px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    pointer-events: none;
}

.copy-message-btn[data-copied="true"]::after {
    content: 'Copied';
    background: var(--surface-strong);
    color: var(--light-text);
}

.copy-message-btn[data-copied="false"]::after {
    content: 'Copy failed';
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
}

.message-text {
    white-space: normal;
    /* preserves whitespace within message text */
    margin: 0;
    padding: 0;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

/* Remove any top/bottom margin created by first/last child elements in message text (p, h*, lists, etc.) */
.message-text> :first-child {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.message-text> :last-child {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Streaming indicator styles - Modern typing animation */
.streaming-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
    padding: 4px 8px;
    background: rgba(139, 92, 246, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.streaming-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-purple);
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Also clamp common block elements at boundaries in message text */
.message-text p:first-of-type {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.message-text p:last-of-type {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

.message-text :is(h1, h2, h3, h4, h5, h6):first-of-type {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.message-text :is(h1, h2, h3, h4, h5, h6):last-of-type {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

.message-text :is(ul, ol):first-of-type {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.message-text :is(ul, ol):last-of-type {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Also clamp code blocks and quotes at boundaries */
.message-text pre:first-of-type {
    margin-top: 0 !important;
}

.message-text pre:last-of-type {
    margin-bottom: 0 !important;
}

.message-text blockquote:first-of-type {
    margin-top: 0 !important;
}

.message-text blockquote:last-of-type {
    margin-bottom: 0 !important;
}

/* In case renderers emit stray <br> at boundaries, hide them */
.message-text>br:first-child,
.message-text>br:last-child {
    display: none;
}

/* Keep code blocks readable */
.message-text pre,
.message-text code {
    white-space: pre;
    /* preserve formatting for code only */
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    line-height: 1.3;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.message-text pre {
    padding: 0.8em;
    margin: 0.5em 0;
    overflow-x: auto;
}

.message-text code:not(pre code) {
    padding: 0.2em 0.4em;
    font-size: 0.9em;
}

.message-content strong {
    font-weight: 600;
    display: block;
    /* put label on its own line to control spacing */
    margin: 0;
    /* remove all margins */
    padding: 0;
    /* remove all padding */
    line-height: 1;
    /* tighter line height */
}

.message-meta {
    font-size: 0.78rem;
    opacity: 0.75;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--surface-line);
    gap: 16px;
}

.message-actions {
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

/* Ensure timestamp is always visible */
.message-meta span {
    opacity: 1;
}

.branch-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--light-text);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.alternate-response-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--light-text);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.alternate-response-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.26);
}

.alternate-response-btn[data-loading="true"] {
    opacity: 0.6;
    cursor: wait;
    pointer-events: none;
}

.alternate-response-btn[data-error="true"] {
    background: rgba(239, 68, 68, 0.16);
    border-color: rgba(239, 68, 68, 0.35);
    color: #ffecec;
}

.alternate-response-container {
    margin-top: 12px;
}

.alternate-response-panel {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--surface-line);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.85rem;
}

.alternate-response-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.alternate-response-label {
    font-weight: 600;
    font-size: 0.8rem;
}

.alternate-response-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--light-text);
    padding: 8px 10px;
    font-size: 0.85rem;
}

.alternate-response-select:focus {
    outline: 2px solid rgba(255, 255, 255, 0.35);
    outline-offset: 2px;
}

.alternate-response-actions {
    display: flex;
    gap: 8px;
}

.alternate-generate-btn {
    background: var(--brand-purple, #7b5cff);
    border: none;
    color: #fff;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.alternate-generate-btn:hover {
    background: var(--brand-purple-strong, #6a4ae3);
}

.alternate-cancel-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--light-text);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.alternate-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.alternate-response-hint {
    font-size: 0.75rem;
    opacity: 0.75;
}

.alternate-response-empty {
    font-size: 0.8rem;
    opacity: 0.8;
}

.branch-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.28);
    color: var(--light-text);
}

/* Message Form */
.message-form {
    display: flex;
    gap: 10px;
}

/* Model modalities icons - Modern Design */
.modality-icons {
    display: inline-flex;
    gap: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.modalities-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.input-modalities,
.output-modalities {
    display: flex;
    gap: 4px;
    align-items: center;
}

.modality-divider {
    width: 1px;
    height: 16px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.2) 100%);
    margin: 0 4px;
}

/* Custom tooltips for modality icons */
.modality-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s ease;
    position: relative;
    overflow: visible;

    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.modality-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
    z-index: 1000;
    margin-bottom: 5px;
    max-width: 200px;
    word-wrap: break-word;
    text-align: center;
}

.modality-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Fallback tooltips for specific modalities if data-tooltip is missing */
.modality-icon[data-modality="text"]::after {
    content: "Accepts text input" !important;
}

.modality-icon[data-modality="image"]::after {
    content: "Accepts image input" !important;
}

.modality-icon[data-modality="audio"]::after {
    content: "Accepts audio input" !important;
}

.modality-icon[data-modality="file"]::after {
    content: "Accepts file input" !important;
}

/* Ensure tooltips are visible and properly positioned */
.modality-icon:hover {
    transform: scale(1.15) translateY(-1px);
    filter: brightness(1.2);
    z-index: 10;
}

.modality-icon:hover {
    transform: scale(1.15) translateY(-1px);
    filter: brightness(1.2);
}

.modality-icon::before {
    transition: none;
}

/* Input modality icons - more vibrant */
.input-modality {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, rgba(34, 197, 94, 0.08) 100%);
    border: 1px solid rgba(34, 197, 94, 0.3);
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.1);
}

.input-modality:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.25) 0%, rgba(34, 197, 94, 0.15) 100%);
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 4px 8px rgba(34, 197, 94, 0.2);
}

/* Output modality icons - more subtle */
.output-modality {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.08) 100%);
    border: 1px solid rgba(139, 92, 246, 0.3);
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.1);
}

.output-modality:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.25) 0%, rgba(139, 92, 246, 0.15) 100%);
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 4px 8px rgba(139, 92, 246, 0.2);
}

/* Modern emoji icons for different modalities */
.modality-icon.text:before {
    content: "\1F4AC";
}

.modality-icon.image:before {
    content: "\1F4F7";
}

.modality-icon.audio:before {
    content: "\1F3A4";
}

.modality-icon.file:before {
    content: "\1F4CE";
}

.message-input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--glass-bg);
    color: var(--light-text);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

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

/* Send Button */
.send-button {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.send-button:hover {
    background: linear-gradient(135deg, var(--secondary-purple) 0%, #c084fc 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.send-button:disabled {
    background: #475569;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Loading and HTMX Indicators */
.loading {
    opacity: 0.6;
}

.htmx-indicator {
    display: none;
    color: var(--primary-purple);
}

.send-button .spinner-icon,
.send-button .stop-icon,
.send-button .htmx-indicator {
    display: none;
}

.send-button.streaming {
    background: #475569;
    cursor: pointer;
}

.send-button.streaming .spinner-icon {
    display: inline;
    animation: spin 1s linear infinite;
}

.send-button.streaming .send-icon {
    display: none;
}

.send-button.streaming:hover .spinner-icon {
    display: none;
}

.send-button.streaming:hover .stop-icon {
    display: inline;
}

.send-button.htmx-request:not(.streaming) .htmx-indicator {
    display: inline;
    animation: spin 1s linear infinite;
}

.send-button.htmx-request:not(.streaming) .send-icon,
.send-button.htmx-request:not(.streaming) .stop-icon {
    display: none;
}

.send-button.htmx-request:not(.streaming) {
    background: #475569;
    cursor: not-allowed;
}

.message-form.streaming .message-input,
.message-form.streaming .attachment-button {
    opacity: 0.6;
    pointer-events: none;
}

/* Branch Tree Styles */
.branch-container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.conversation-thread {
    margin-left: calc(var(--level) * 20px);
}

.branch-tree {
    padding: 20px 0;
}

.message-node {
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 16px;
    margin: 8px auto;
    max-width: 600px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: fit-content;
}

.message-node:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
    border-color: var(--primary-purple);
}

.message-node.user-message {
    border-color: var(--primary-purple);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(168, 85, 247, 0.1) 100%);
}

.user-message:hover {
    background-color: rgba(0, 123, 255, 0.1);
    /* Slightly different tint for user messages */
}

.ai-message:hover {
    background-color: rgba(255, 193, 7, 0.1);
    /* Slightly different tint for AI messages */
}

.message-node.ai-message {
    border-color: #6366f1;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
}

.ai-message .message-content {
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    /* changed from pre-line */
    max-width: 100%;
    hyphens: auto;
    line-height: 1.35;
    text-align: left;
}

.user-message .message-content {
    text-align: right;
}

.ai-message .message-text {
    text-align: left;
    white-space: normal;
}

.user-message .message-text {
    text-align: right;
    white-space: normal;
}

/* Optimize spacing for AI message paragraphs and elements */
.ai-message .message-content p {
    margin: 0 0 0.6em 0;
}

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

.ai-message .message-content p:first-child {
    margin-top: 0;
}

.ai-message .message-content ul,
.ai-message .message-content ol {
    margin: 0.4em 0;
    padding-left: 1.2em;
}

.ai-message .message-content li {
    margin: 0.1em 0;
}

.ai-message .message-content h1,
.ai-message .message-content h2,
.ai-message .message-content h3,
.ai-message .message-content h4,
.ai-message .message-content h5,
.ai-message .message-content h6 {
    margin: 0.4em 0 0.3em 0;
    line-height: 1.3;
}

.ai-message .message-content blockquote {
    margin: 0.4em 0;
    padding-left: 1em;
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.message-author {
    font-weight: 600;
    color: var(--light-text);
}

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

.message-text {
    color: var(--light-text);
    line-height: 1.4;
    margin: 8px 0;
}

.branch-tree .message-actions {
    text-align: center;
    margin-top: 12px;
}

/* Ensure inline actions in chat bubbles don't add vertical gap */
.message .message-meta .message-actions {
    margin-top: 0;
}

.message-actions a {
    display: inline-block;
    padding: 6px 12px;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.message-actions a:hover {
    background: linear-gradient(135deg, var(--secondary-purple) 0%, #c084fc 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

.connection-line {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 20px 0;
}

.vertical-line {
    width: 3px;
    height: 50px;
    background: linear-gradient(180deg, var(--primary-purple) 0%, #6366f1 100%);
    border-radius: 3px;
    position: relative;
}

.message-counter {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-purple);
}

.branch-point {
    text-align: center;
    margin: 30px 0;
}

.branch-split {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 40px;
    margin-top: 20px;
}

.branch-path {
    position: relative;
    padding: 20px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.expand-button {
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--muted-text);
    transition: all 0.2s ease;
    margin: 10px;
}

.expand-button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary-purple);
    color: var(--light-text);
}

.collapsed {
    display: none;
}

.no-messages {
    text-align: center;
    color: var(--muted-text);
    font-style: italic;
    padding: 40px;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

/* Dashboard Styles */
.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
}


.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    border-radius: 8px;
    margin-bottom: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
}

.user-name {
    font-weight: 500;
    color: white;
}

.new-chat-btn {
    width: 100%;
    padding: 10px;
    background: #8b5cf6;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    color: white;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    display: block;
    transition: all 0.3s ease;
    align-self: center;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.search-container {
    margin-top: 10px;
    margin-bottom: 15px;
}

.search-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--light-text);
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

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

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    width: 100%;
    margin-top: 10px;
}


.chat-header {
    padding: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.chat-header h1 {
    color: var(--light-text);
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.header-actions a {
    padding: 8px 15px;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.header-actions a:hover {
    background: linear-gradient(135deg, var(--secondary-purple) 0%, #c084fc 100%);
    transform: translateY(-2px);
}

.logout-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
}

.logout-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
}

.chat-area {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--muted-text);
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    margin: 12px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.welcome-message {
    text-align: center;
    max-width: 400px;
}

.welcome-message h2 {
    color: var(--light-text);
    margin-bottom: 10px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--muted-text);
}

.spinner {
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: 2px solid var(--primary-purple);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.chat-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.chat-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--primary-purple), var(--secondary-purple));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(139, 92, 246, 0.35);
    transform: translateX(2px);
    box-shadow: var(--shadow-sm);
}

.chat-item:hover::before {
    opacity: 0.5;
}

.chat-item.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.08) 100%);
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow:
        var(--shadow-sm),
        0 0 20px -10px rgba(139, 92, 246, 0.4);
}

.chat-item.active::before {
    opacity: 1;
}

.chat-title {
    font-weight: 600;
    color: var(--light-text);
    margin-bottom: 5px;
}

.chat-preview {
    color: var(--muted-text);
    font-size: 0.9em;
    margin-bottom: 5px;
}

.chat-time {
    color: var(--muted-text);
    font-size: 0.8em;
}

/* Auth Forms */
.auth-container {
    max-width: 420px;
    margin: 60px auto;
    background: linear-gradient(135deg, rgba(18, 22, 38, 0.95) 0%, rgba(12, 16, 28, 0.98) 100%);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    padding: 48px 40px;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 32px 80px -20px rgba(0, 0, 0, 0.6),
        0 0 1px rgba(255, 255, 255, 0.1) inset,
        0 0 80px -40px rgba(139, 92, 246, 0.25);
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
}

.logo {
    text-align: center;
    margin-bottom: 36px;
}

.logo .brand-mark {
    width: 160px;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 20px;
    filter: drop-shadow(0 12px 24px rgba(139, 92, 246, 0.35));
    transition: filter var(--transition-base);
}

.logo .brand-mark:hover {
    filter: drop-shadow(0 16px 32px rgba(139, 92, 246, 0.5));
}

.logo h1 {
    color: var(--light-text);
    font-size: 2.2rem;
    font-weight: 700;
    margin: 0 0 12px;
    letter-spacing: -0.02em;
}

.logo p {
    color: var(--muted-text);
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 10px;
    color: var(--light-text);
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
}

input[type="email"],
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.04);
    color: var(--light-text);
    font-size: 1rem;
    transition:
        border-color var(--transition-base),
        box-shadow var(--transition-base),
        background var(--transition-base);
    box-sizing: border-box;
}

input[type="email"]:hover,
input[type="text"]:hover,
input[type="password"]:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
}

input[type="email"]:focus,
input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: rgba(139, 92, 246, 0.6);
    background: rgba(255, 255, 255, 0.06);
    box-shadow:
        0 0 0 3px rgba(139, 92, 246, 0.15),
        0 0 20px -5px rgba(139, 92, 246, 0.25);
}

input[type="email"]::placeholder,
input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: var(--dim-text);
}

.auth-form button {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.02em;
    transition: all var(--transition-base);
    margin-bottom: 24px;
    box-shadow: var(--shadow-button);
    position: relative;
    overflow: hidden;
}

.auth-form button::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: linear-gradient(135deg, var(--primary-purple), var(--secondary-purple));
    opacity: 0;
    filter: blur(12px);
    transition: opacity var(--transition-base);
    z-index: -1;
}

.auth-form button:hover {
    background: linear-gradient(135deg, var(--secondary-purple) 0%, #c084fc 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-button-hover);
}

.auth-form button:hover::before {
    opacity: 0.5;
}

.auth-form button:active {
    transform: translateY(0);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.register-link,
.login-link {
    text-align: center;
    margin-top: 20px;
}

.register-link a,
.login-link a {
    color: var(--primary-purple);
    text-decoration: none;
    transition: color 0.3s ease;
}

.register-link a:hover,
.login-link a:hover {
    color: var(--secondary-purple);
    text-decoration: underline;
}

.password-requirements {
    font-size: 0.85rem;
    color: var(--muted-text);
    margin-top: 5px;
}

/* Responsive Design */
@media (max-width: 768px) {

    .chat-container,
    .branch-container,
    .dashboard-container {
        margin: 0 10px;
        padding: 20px;
    }

    .message-form {
        flex-direction: column;
    }

    .branch-split {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .message-node {
        margin: 10px 0;
    }
}

/* Modal Styles */
.modal {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px) saturate(1.2);
    -webkit-backdrop-filter: blur(8px) saturate(1.2);
    justify-content: center;
    align-items: center;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }

    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

.modal-content {
    background: linear-gradient(135deg, rgba(15, 20, 35, 0.98) 0%, rgba(10, 14, 26, 0.99) 100%);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 32px 80px -20px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset,
        0 0 60px -30px rgba(139, 92, 246, 0.2);
    text-align: center;
    animation: modalSlideIn 0.25s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.98);
    }

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h2 {
    margin: 0;
    color: var(--light-text);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.close-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 22px;
    color: var(--muted-text);
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
}

.close-btn:hover {
    color: var(--light-text);
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.modal-body {
    padding: 24px;
    text-align: center;
}

.settings-section {
    margin-bottom: 32px;
}

.add-memory-btn {
    text-align: center;
    display: flex;
}

.settings-section h3 {
    margin: 0 0 8px 0;
    color: var(--light-text);
    font-size: 1.2rem;
    font-weight: 600;
}

.settings-section p {
    color: var(--muted-text);
    margin: 0 0 20px 0;
    line-height: 1.5;
}

#memory-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

#memory-form textarea {
    width: 100%;
    max-width: 500px;
    padding: 12px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: var(--glass-bg);
    color: var(--light-text);
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
}

#memory-form textarea:focus {
    outline: none;
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

#memory-form textarea::placeholder {
    color: var(--muted-text);
    opacity: 0.8;
}

#memory-form button {
    align-self: center;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 14px;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    color: white;
}

#memory-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px -8px rgba(139, 92, 246, 0.4);
}

#memory-list {
    max-height: 300px;
    overflow-y: auto;
    border-radius: 8px;
}

#memory-list h3 {
    color: var(--light-text);
    margin-bottom: 15px;
    font-size: 1.1rem;
    text-align: center;
}

#memory-list ul {
    list-style-type: none;
    padding-left: 0;
}

.memory-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    margin-left: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
}

.memory-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    transform: translateY(-1px);
}

.memory-text {
    flex: 1;
    color: var(--light-text);
    line-height: 1.4;
    word-break: break-word;
}

.memory-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

.edit-memory,
.delete-memory {
    padding: 6px 12px;
    font-size: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: var(--glass-bg);
    color: var(--muted-text);
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
}

.edit-memory:hover {
    background: var(--primary-purple);
    color: white;
    border-color: var(--primary-purple);
}

.delete-memory:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.no-memories,
.error {
    text-align: center;
    padding: 32px 20px;
    color: var(--muted-text);
    font-style: italic;
    border-radius: 8px;
    background: var(--glass-bg);
    border: 1px dashed var(--glass-border);
}

.error {
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.1);
}

/* Model Selector Modal Styles */
.model-modal,
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: calc(var(--safe-area-top) + 24px) 24px calc(var(--safe-area-bottom) + 24px);
    box-sizing: border-box;
}

.model-modal.hidden,
.modal-overlay.hidden {
    display: none !important;
}

.modal-content {
    background: rgba(15, 18, 32, 0.94);
    color: var(--light-text);
    padding: 24px;
    border-radius: 18px;
    max-width: 640px;
    max-height: 80%;
    overflow-y: auto;
    width: min(640px, 92%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 28px 64px -32px rgba(0, 0, 0, 0.78);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    margin: 0;
    flex: 1;
    text-align: center;
    font-size: 1.2rem;
}

.back-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--light-text);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.25s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.close-modal {
    background: none;
    border: none;
    color: var(--light-text);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.25s ease;
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 640px) {

    .model-modal,
    .modal-overlay {
        align-items: flex-start;
        padding: calc(var(--safe-area-top) + 16px) 16px calc(var(--safe-area-bottom) + 16px);
    }

    .modal-content {
        width: 100%;
        max-width: none;
        max-height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom) - 32px);
        max-height: calc(100dvh - var(--safe-area-top) - var(--safe-area-bottom) - 32px);
        margin: 0;
    }
}

.modal-description {
    margin: 0 0 18px;
    font-size: 0.9rem;
    color: var(--muted-text);
}

.modal-footer {
    margin-top: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

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

.modal-btn {
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    color: var(--light-text);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--primary-purple) 0%, var(--secondary-purple) 100%);
    border: none;
    color: #fff;
    box-shadow: 0 16px 34px -20px rgba(139, 92, 246, 0.62);
}

.modal-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 22px 36px -18px rgba(139, 92, 246, 0.7);
}

.modal-btn.ghost {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.05);
}

.modal-btn.ghost:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.26);
}

.modal-btn.tertiary {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted-text);
}

.modal-btn.tertiary:hover {
    color: var(--light-text);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
}

.council-modal-content {
    max-width: 520px;
}

.council-modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.council-label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-text);
}

.council-models-select {
    width: 100%;
    min-height: 240px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    color: var(--light-text);
    padding: 10px;
    font-family: inherit;
    font-size: 0.92rem;
    max-height: 320px;
    overflow-y: auto;
}

.council-models-select option {
    padding: 6px 8px;
}

.council-models-select optgroup {
    color: var(--muted-text);
    font-weight: 600;
    padding: 4px 0;
}

.council-help {
    font-size: 0.75rem;
    color: var(--muted-text);
}

.council-selection-count {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.72);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    margin: 0;
    flex: 1;
    text-align: center;
    font-size: 1.2rem;
}

.back-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--light-text);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.25s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.close-modal {
    background: none;
    border: none;
    color: var(--light-text);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.25s ease;
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
}

.providers-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.provider-btn {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--light-text);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.provider-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.models-for-provider {
    margin-top: 20px;
}

.models-for-provider h4 {
    margin: 0 0 15px 0;
    color: var(--light-text);
    font-size: 1.1rem;
}

.model-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.model-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.model-name {
    color: var(--light-text);
    font-weight: 500;
}

.modalities {
    display: flex;
    gap: 5px;
}

/* Image Display and Modal Styles */
.message-image {
    margin-top: 8px;
    width: 100%;
}

.image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.image-thumbnail {
    max-width: 300px;
    max-height: 200px;
    width: auto;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s ease;
    display: block;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 4px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.image-thumbnail:hover {
    opacity: 0.9;
}

.image-expand-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-container:hover .image-expand-btn {
    opacity: 1;
}

.image-expand-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.image-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    border-radius: 16px;
    padding: 10px;
    box-sizing: border-box;
}

.image-modal-content {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modal-image {
    max-width: 800px;
    max-height: 600px;
    width: auto;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(255, 255, 255, 0.3);
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.image-close-btn {
    position: absolute;
    top: -20px;
    right: -20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 1001;
}

.image-close-btn:hover {
    background: rgba(255, 0, 0, 0.8);
}

.council-selection-count {
    font-size: 0.8rem;
    color: var(--muted-text);
}

.council-grid,
.council-stream-grid {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: var(--council-gap);
    align-items: stretch;
    justify-content: flex-start;
}

.council-grid[data-count="1"],
.council-stream-grid[data-count="1"] {
    justify-content: center;
}

.council-grid .council-card,
.council-stream-grid .council-card {
    flex: 1 1 calc(32% - var(--council-gap));
    min-width: 220px;
}

.council-grid[data-count="1"] .council-card,
.council-stream-grid[data-count="1"] .council-card {
    flex-basis: 100%;
    max-width: 100%;
}

.council-grid[data-count="2"] .council-card,
.council-stream-grid[data-count="2"] .council-card {
    flex-basis: calc(48% - var(--council-gap));
}

.council-grid[data-count="3"] .council-card,
.council-stream-grid[data-count="3"] .council-card {
    flex-basis: calc(32% - var(--council-gap));
}

.council-grid[data-count="4"] .council-card,
.council-stream-grid[data-count="4"] .council-card,
.council-grid[data-count="5"] .council-card,
.council-stream-grid[data-count="5"] .council-card,
.council-grid[data-count="6"] .council-card,
.council-stream-grid[data-count="6"] .council-card,
.council-grid[data-count="7"] .council-card,
.council-stream-grid[data-count="7"] .council-card,
.council-grid[data-count="8"] .council-card,
.council-stream-grid[data-count="8"] .council-card {
    flex-basis: calc(24% - var(--council-gap));
}

.council-grid[data-count]:not([data-count="1"]):not([data-count="2"]):not([data-count="3"]) .council-card,
.council-stream-grid[data-count]:not([data-count="1"]):not([data-count="2"]):not([data-count="3"]) .council-card {
    flex-basis: calc(24% - var(--council-gap));
}

.council-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: calc(var(--radius) + 2px);
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

.council-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    color: var(--light-text);
    margin-bottom: 0.5rem;
}

.council-provider {
    margin-left: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted-text);
}

.council-card-body {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--light-text);
}

.council-card-body p {
    margin-bottom: 0.6rem;
}

.council-card-body p:last-child {
    margin-bottom: 0;
}

.council-select-form {
    margin-top: 0.75rem;
}

.council-select-btn {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: linear-gradient(135deg, var(--primary-purple), var(--secondary-purple));
    color: white;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.council-select-btn:hover {
    transform: translateY(-1px);
}

.council-stream {
    border: 1px solid var(--glass-border);
    border-radius: calc(var(--radius) + 2px);
    padding: 0.9rem;
    background: rgba(255, 255, 255, 0.05);
}

.council-progress {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}

.council-progress.hidden {
    display: none;
}

.council-progress-indicator {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid var(--primary-purple);
    border-top-color: transparent;
    animation: council-spin 0.8s linear infinite;
}

.council-progress-text {
    font-size: 0.85rem;
    color: var(--muted-text);
}

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

.streaming-card {
    opacity: 0.9;
}

.council-error {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: rgba(220, 38, 38, 0.12);
    color: #ef4444;
    font-size: 0.85rem;
}

.council-selected {
    border-left: 3px solid var(--primary-purple);
    padding-left: 0.85rem;
    margin-bottom: 1rem;
}

.council-selected-label {
    font-weight: 600;
    color: var(--primary-purple);
    margin-bottom: 0.5rem;
}

.council-minimized {
    border-top: 1px solid var(--glass-border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.council-minimized-title {
    font-size: 0.85rem;
    color: var(--muted-text);
}

.council-minimized-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.council-minimized .council-select-form {
    width: auto;
    margin: 0;
}

.council-minimized .council-select-btn {
    width: auto;
    font-size: 0.8rem;
    padding: 0.35rem 0.65rem;
}

.council-empty {
    font-size: 0.85rem;
    color: var(--muted-text);
}