/* ============================================
   CortexNet Chat - Modern Dark Theme
   ============================================ */

:root {
    /* Dark Theme (default) */
    --bg-primary: #08080f;
    --bg-secondary: #10101a;
    --bg-tertiary: #181825;
    --bg-hover: #1e1e2e;
    --bg-active: #252538;

    --text-primary: #e8e8f0;
    --text-secondary: #9898ac;
    --text-tertiary: #64647a;
    --text-muted: #46465a;

    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-color: #6366f1;
    --accent-rgb: 99, 102, 241;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);

    /* User message bubble */
    --user-bubble-bg: #1e2035;
    --user-bubble-text: #e8e8f0;

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --border-color: rgba(255, 255, 255, 0.07);
    --border-light: rgba(255, 255, 255, 0.03);
    --border-primary: rgba(255, 255, 255, 0.07);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 40px var(--accent-glow);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --sidebar-width: 272px;
    --header-height: 58px;

    --font-sans: 'Space Grotesk', 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

[data-theme="light"] {
    --bg-primary: #f7f7fb;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f6;
    --bg-hover: #e8e8f0;
    --bg-active: #dddde8;

    --text-primary: #16162a;
    --text-secondary: #44445a;
    --text-tertiary: #64647a;
    --text-muted: #94949e;

    --user-bubble-bg: #e8e8f4;
    --user-bubble-text: #16162a;

    --border-color: rgba(0, 0, 0, 0.09);
    --border-light: rgba(0, 0, 0, 0.04);
    --border-primary: rgba(0, 0, 0, 0.09);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.07);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.13);
}

/* ============================================
   Color themes per model (CortexNet / Gemini / GPT)
   Zmieniają tylko akcent, nie tło/tekst
   ============================================ */

body.theme-cortexnet {
    /* CortexNet – fioletowy akcent (to co wcześniej było dla Gemini) */
    --accent-primary: #4f46e5;
    --accent-secondary: #a855f7;
    --accent-color: #4f46e5;
    --accent-rgb: 79, 70, 229;
    --accent-glow: rgba(79, 70, 229, 0.35);
    --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
}

body.theme-gemini {
    /* Gemini – mocniejszy, czystszy niebieski */
    --accent-primary: #1d4ed8; /* indygo / intensywny niebieski */
    --accent-secondary: #60a5fa; /* jaśniejszy niebieski akcent */
    --accent-color: #1d4ed8;
    --accent-rgb: 29, 78, 216;
    --accent-glow: rgba(37, 99, 235, 0.55);
    --accent-gradient: linear-gradient(135deg, #1d4ed8 0%, #2563eb 40%, #60a5fa 100%);
}

body.theme-gpt {
    /* ChatGPT – ciemniejsza zieleń */
    --accent-primary: #059669;
    --accent-secondary: #047857;
    --accent-color: #059669;
    --accent-rgb: 5, 150, 105;
    --accent-glow: rgba(5, 150, 105, 0.35);
    --accent-gradient: linear-gradient(135deg, #047857 0%, #059669 40%, #10b981 100%);
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ============================================
   App Container
   ============================================ */

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

.app-container::before {
    content: '';
    position: absolute;
    top: -20%;
    left: -20%;
    width: 60%;
    height: 60%;
    pointer-events: none;
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.25), transparent 70%);
    filter: blur(40px);
    opacity: 0.7;
    transform: translate3d(var(--parallax-offset-x, 0), var(--parallax-offset-y, 0), 0);
    transition: transform 0.15s ease-out;
    z-index: 0;
}

.theme-gemini .app-container::before {
    background: radial-gradient(circle at center, rgba(37, 99, 235, 0.3), transparent 70%);
}

.theme-gpt .app-container::before {
    background: radial-gradient(circle at center, rgba(16, 185, 129, 0.25), transparent 70%);
}

.theme-cortexnet .app-container::before {
    background: radial-gradient(circle at center, rgba(244, 114, 182, 0.25), transparent 70%);
}

/* Tryb focus - maksymalne skupienie na treści rozmowy */
body.focus-mode .sidebar {
    transform: translateX(-100%);
    width: 0;
    min-width: 0;
    border-right: none;
}

body.focus-mode .token-stats-panel {
    opacity: 0;
    pointer-events: none;
}

body.focus-mode .chat-header .header-actions .btn-icon:not(#toggleFocusMode) {
    opacity: 0;
    pointer-events: none;
}

body.focus-mode .messages-container {
    padding-top: 12px;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal), width var(--transition-normal), background var(--transition-normal), border-color var(--transition-normal);
    z-index: 100;
    position: relative;
    overflow: hidden;
}

/* Glassmorphism only in dark mode, subtle */
[data-theme="dark"] .sidebar {
    background: rgba(18, 18, 26, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
}

[data-theme="light"] .sidebar {
    background: var(--bg-secondary);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Na desktopie sidebar można schować */
.sidebar.hidden {
    width: 0;
    min-width: 0;
    transform: translateX(-100%);
    border-right: none;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    opacity: 0;
    position: absolute;
    height: 100%;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    position: relative;
    z-index: 10;
}

.sidebar-header .header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 10;
}

.sidebar-header .header-actions .btn-icon {
    position: relative;
    z-index: 11;
}

/* Na desktopie ukryj przycisk closeSidebar (używamy openSidebar w headerze) */
@media (min-width: 769px) {
    .sidebar-header #closeSidebar {
        display: none !important;
    }
    
    /* Na desktopie pokaż openSidebarBtn w głównym headerze */
    .chat-header #openSidebar {
        display: flex;
    }
}

/* Na mobile pokaż przycisk closeSidebar */
@media (max-width: 768px) {
    .sidebar-header #closeSidebar {
        display: flex;
    }
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    text-decoration: none;
    color: inherit;
}

.logo:hover {
    opacity: 0.8;
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.model-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: var(--font-sans);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 12px 16px;
    padding: 11px 20px;
    background: linear-gradient(-45deg,
        var(--accent-primary),
        var(--accent-secondary),
        #a855f7,
        var(--accent-primary));
    background-size: 400% 400%;
    animation: gradientShift 8s ease infinite;
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.3);
    will-change: transform, box-shadow;
    position: relative;
    overflow: hidden;
}

.new-chat-btn:hover {
    transform: translateY(-1px) scale(1.01);
    box-shadow: var(--shadow-md), 0 0 26px var(--accent-glow);
}

.new-chat-btn:active {
    transform: translateY(0) scale(0.99);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversations-list::-webkit-scrollbar {
    width: 4px;
}

.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

/* Firefox */
.conversations-list {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Skeletony dla listy konwersacji */
.conversations-skeleton {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px;
}

.conversations-skeleton-item {
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.03) 0%,
        rgba(255,255,255,0.08) 20%,
        rgba(255,255,255,0.03) 40%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.conversation-item.active {
    background: var(--bg-active);
    border-color: var(--border-color);
}

.conversation-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent-gradient);
    border-radius: 0 3px 3px 0;
}

.conversation-item .icon {
    width: 18px;
    height: 18px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.conversation-item .title {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item.active .title {
    color: var(--text-primary);
}

.conversation-item .actions {
    display: none;
    gap: 4px;
}

.conversation-item:hover .actions {
    display: flex;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-light);
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg-primary);
}

/* ============================================
   Chat Header
   ============================================ */

.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-menu-btn {
    display: none;
}

.model-selector {
    position: relative;
    flex: 1;
    max-width: 300px;
}

.model-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    cursor: pointer;
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out, background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    width: 100%;
}

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

.model-btn svg {
    width: 18px;
    height: 18px;
    color: var(--accent-primary);
}

.model-btn .chevron {
    margin-left: auto;
    color: var(--text-tertiary);
    transition: transform var(--transition-fast);
}

.model-btn.open .chevron {
    transform: rotate(180deg);
}

.model-btn.switched {
    transform: scale(1.03);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast);
    z-index: 1000;
    max-height: 500px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.model-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

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

.model-tab {
    flex: 1;
    min-width: 80px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    white-space: nowrap;
    flex-shrink: 0;
}

.model-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.model-tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: var(--bg-secondary);
}

.model-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 4px 0;
}

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

.model-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-light);
}

.model-option:last-child {
    border-bottom: none;
}

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

.model-option.selected {
    background: var(--bg-active);
}

.model-option-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.model-option-icon {
    width: 18px;
    height: 18px;
    border-radius: 4px;
}

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

.model-option .description {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.model-option .price-info {
    font-size: 0.75rem;
    color: var(--success);
    font-family: var(--font-mono);
}

/* ============================================
   Role Selector (podobny do model dropdown)
   ============================================ */

.role-selector-wrapper {
    position: relative;
    width: 100%;
}

.role-selector-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: 8px;
}

.role-selector-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color);
}

.role-selector-btn svg {
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.role-selector-wrapper.active .role-selector-btn svg {
    transform: rotate(180deg);
}

.role-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast);
    z-index: 1000;
    max-height: 400px;
    overflow: hidden;
}

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

.role-list {
    max-height: 350px;
    overflow-y: auto;
    padding: 4px 0;
}

.role-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-light);
}

.role-option:last-child {
    border-bottom: none;
}

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

.role-option.selected {
    background: var(--bg-active);
}

.role-option-icon {
    font-size: 1.2rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.role-option-name {
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}

.role-option-description {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

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

/* Delikatne ostrzeżenie (shake) dla destrukcyjnych przycisków, np. clearChat */
#clearChat:hover {
    animation: dangerShake 0.25s ease-in-out;
}

@keyframes dangerShake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-1px); }
    50% { transform: translateX(1px); }
    75% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

/* ============================================
   Messages Container
   ============================================ */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
    width: 5px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

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

/* Firefox */
.messages-container {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* ============================================
   Welcome Screen
   ============================================ */

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    text-align: center;
    padding: 40px 20px;
    animation: fadeIn 0.6s ease;
}

.welcome-screen .suggestions {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
}

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

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

.welcome-screen.hidden {
    display: none;
}

.welcome-icon {
    width: 100px;
    height: 100px;
    margin-bottom: 24px;
    animation: float 3s ease-in-out infinite;
}

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

.welcome-icon img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-lg);
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.welcome-screen h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 12px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: var(--font-sans);
}

.welcome-screen .welcome-subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 1.1rem;
}

/* Guest prompt */
.guest-prompt {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
    margin-bottom: 32px;
    text-align: center;
}

.guest-prompt p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 1rem;
}

.guest-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.guest-btn {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.guest-btn.primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
}

.guest-btn.primary:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

/* Hide guest prompt for logged in users */
.guest-prompt.hidden {
    display: none;
}

.suggestions {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

@media (min-width: 769px) {
    .suggestions,
    .welcome-screen .suggestions {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px;
        max-width: 700px;
    }
}

.suggestion-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 80px;
    position: relative;
    overflow: hidden;
}

@media (min-width: 769px) {
    .suggestion-btn {
        padding: 20px 24px;
        min-height: 100px;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
    }
    
    .suggestion-btn svg {
        width: 24px;
        height: 24px;
    }
}

.suggestion-btn:hover {
    background: var(--bg-tertiary);
    border-color: rgba(var(--accent-rgb), 0.4);
    color: var(--text-primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md), 0 0 20px rgba(var(--accent-rgb), 0.08);
}

.suggestion-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-fast);
    border-radius: inherit;
}

.suggestion-btn:hover::after {
    opacity: 0.04;
}

.suggestion-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--accent-primary);
}

/* ============================================
   Messages
   ============================================ */

.messages {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    position: relative; /* Aby wiadomości były nad particle */
    z-index: 1; /* Nad particle (z-index 0) */
}

.message {
    display: flex;
    gap: 16px;
    animation: messageIn 0.4s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent-gradient);
    color: white;
}

.message.model .message-avatar {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--accent-primary);
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

.message-avatar .avatar-img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.message-content {
    flex: 1;
    min-width: 0;
    position: relative;
}

.message.user .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Responsive dla akcji wiadomości */
@media (max-width: 768px) {
    .message-actions {
        position: static;
        flex-direction: row;
        margin-top: 8px;
        opacity: 0.6;
        right: auto;
        left: auto;
    }
    
    .message.user .message-actions {
        left: auto;
        right: auto;
    }
    
    .message-content {
        margin-right: 0;
        margin-left: 0;
    }
    
    .message {
        padding-right: 0;
        padding-left: 0;
    }
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    max-width: 85%;
    margin-bottom: 6px;
    line-height: 1.65;
}

.message.user .message-bubble {
    background: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-bottom-right-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.message.model .message-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.message-bubble p {
    margin-bottom: 12px;
}

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

/* Wskaźnik odpowiedzi na wiadomość */
.message-reply-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 85%;
}

.message.user .message-reply-indicator {
    margin-left: auto;
    margin-right: 0;
}

.message-reply-indicator:hover {
    background: var(--bg-hover);
    color: var(--accent-primary);
    transform: translateX(4px);
}

.message-reply-indicator svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}

.message-reply-indicator .reply-indicator-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Animacja powiększenia wiadomości przy przewijaniu */
@keyframes messageHighlight {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.08);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.message-highlight {
    animation: messageHighlight 1s ease-in-out;
    background-color: var(--bg-hover) !important;
    transition: background-color 0.3s ease, transform 0.3s ease;
    transform-origin: center;
}

.message-highlight .message-bubble {
    box-shadow: 0 0 30px rgba(var(--accent-rgb, 99, 102, 241), 0.5);
    border: 2px solid rgba(var(--accent-rgb, 99, 102, 241), 0.3);
    transition: box-shadow 0.3s ease, border 0.3s ease;
}

.message-bubble a {
    color: var(--accent-secondary);
    text-decoration: none;
}

.message-bubble a:hover {
    text-decoration: underline;
}

/* Code blocks in messages */
.message-bubble pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
}

.message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.875em;
}

.message-bubble :not(pre) > code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.message.user .message-bubble pre {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

.message.user .message-bubble :not(pre) > code {
    background: rgba(255, 255, 255, 0.15);
}

/* Lists in messages */
.message-bubble ul, .message-bubble ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin-bottom: 6px;
}

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

.attachment-preview {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.attachment-preview img {
    max-width: 200px;
    max-height: 150px;
    display: block;
}

.attachment-preview .file-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
}

.attachment-preview .file-icon svg {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px 20px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ============================================
   Input Area
   ============================================ */

.input-area {
    padding: 16px 24px 24px;
    background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
}

/* Dropzone overlay nad polem wiadomości */
.dropzone {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 24px 96px;
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.12), rgba(15, 23, 42, 0.9));
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    z-index: 900;
}

.dropzone.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.dropzone-inner {
    max-width: 640px;
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    border-radius: 20px;
    border: 1px dashed rgba(129, 140, 248, 0.8);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.9), 0 0 40px rgba(129, 140, 248, 0.45);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.dropzone-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: radial-gradient(circle at top left, rgba(129, 140, 248, 0.35), rgba(37, 99, 235, 0.15));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.dropzone-icon svg {
    width: 24px;
    height: 24px;
}

.dropzone-text p {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
}

.dropzone-text span {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.attachments-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.attachments-preview:empty {
    display: none;
}

.attachment-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: radial-gradient(circle at top left, rgba(129, 140, 248, 0.16), rgba(15, 23, 42, 0.96));
    border: 1px solid rgba(129, 140, 248, 0.5);
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.6);
    animation: slideIn 0.25s ease;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast), background 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.attachment-item img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.8);
    flex-shrink: 0;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.attachment-item:hover img {
    transform: scale(1.04);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.9);
}

.attachment-item .file-info {
    display: flex;
    flex-direction: column;
}

.attachment-item .file-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-item .file-size {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.attachment-item .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--error);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: transform var(--transition-fast);
}

/* Badge typu pliku przy załączniku (PDF/DOCX/PNG itp.) */
.attachment-item .file-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.6);
}

.attachment-item .file-badge--pdf {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(248, 113, 113, 0.9);
    color: #fecaca;
}

.attachment-item .file-badge--doc,
.attachment-item .file-badge--docx {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(96, 165, 250, 0.9);
    color: #bfdbfe;
}

.attachment-item .file-badge--xls,
.attachment-item .file-badge--xlsx {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(52, 211, 153, 0.9);
    color: #bbf7d0;
}

.attachment-item .file-badge--ppt,
.attachment-item .file-badge--pptx {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(251, 146, 60, 0.9);
    color: #fed7aa;
}

.attachment-item .file-badge--txt,
.attachment-item .file-badge--json,
.attachment-item .file-badge--csv {
    background: rgba(148, 163, 184, 0.15);
    border-color: rgba(148, 163, 184, 0.9);
    color: #e5e7eb;
}

.attachment-item .remove-btn:hover {
    transform: scale(1.1);
}

.input-form {
    max-width: 900px;
    margin: 0 auto;
}

.input-options {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.generate-image-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    padding: 8px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    position: relative;
    font-family: var(--font-sans);
    outline: none;
}

.generate-image-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.generate-image-btn.active {
    color: var(--accent-color);
    background: var(--bg-secondary);
    border-color: var(--accent-color);
    font-weight: 500;
    box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2), 0 0 12px rgba(var(--accent-rgb), 0.3);
    animation: glow-pulse 2s ease-in-out infinite;
}

.generate-image-btn.active svg {
    color: var(--accent-color);
}

.generate-image-btn span {
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

@keyframes glow-pulse {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2), 0 0 12px rgba(var(--accent-rgb), 0.3);
    }
    50% {
        box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.3), 0 0 16px rgba(var(--accent-rgb), 0.4);
    }
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    transition: all var(--transition-fast);
    position: relative;
    overflow: visible;
    box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
    border-color: rgba(var(--accent-rgb), 0.5);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12), var(--shadow-md);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 200px;
}

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

.send-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.4);
}

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

.send-btn:not(:disabled):hover {
    transform: translateY(-1px) scale(1.04);
    box-shadow: var(--shadow-glow);
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

.send-btn .stop-icon {
    display: none;
}

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

.send-btn.streaming .stop-icon {
    display: block;
}

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

/* ============================================
   Buttons
   ============================================ */

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

.attach-btn {
    color: var(--text-tertiary);
}

.attach-btn:hover {
    color: var(--accent-primary);
    background: transparent;
}

/* Theme toggle */
#toggleTheme .icon-sun {
    display: none;
}

#toggleTheme .icon-moon {
    display: block;
}

[data-theme="light"] #toggleTheme .icon-sun {
    display: block;
}

[data-theme="light"] #toggleTheme .icon-moon {
    display: none;
}

/* ============================================
   Context Menu
   ============================================ */

.context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: all var(--transition-fast);
    z-index: 1000;
}

.context-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.context-menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 400px;
    backdrop-filter: blur(20px);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.toast.removing {
    animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--error);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

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

.toast.success .toast-icon {
    color: var(--success);
}

.toast.error .toast-icon {
    color: var(--error);
}

.toast.warning .toast-icon {
    color: var(--warning);
}

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

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        z-index: 1000;
        padding-bottom: 120px;
    }
    
    .sidebar.open {
        transform: translateX(0) !important;
    }
    
    .sidebar.hidden {
        transform: translateX(-100%) !important;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
    }
    
    /* Overlay dla mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        animation: fadeIn 0.2s ease;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    .mobile-menu-btn {
        display: flex;
    }
    
    /* Ukryj przycisk closeSidebar na desktopie, pokaż na mobile */
    .sidebar-header .header-actions {
        display: flex;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .messages-container {
        padding: 16px;
    }
    
    .input-area {
        padding: 12px 16px 16px;
    }
    
    .suggestions {
        grid-template-columns: 1fr !important;
    }
    
    .welcome-screen h1 {
        font-size: 1.5rem;
    }
    
    .message-bubble {
        max-width: 95%;
    }
    
    .model-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .model-tab {
        min-width: 90px;
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .model-dropdown {
        max-width: calc(100vw - 32px);
        left: 16px;
        right: 16px;
    }
}

@media (max-width: 480px) {
    .model-selector {
        max-width: none;
        flex: 1;
    }
    
    .header-actions {
        display: none;
    }
    
    .input-wrapper {
        padding: 10px 12px;
    }
    
    .input-hint {
        display: none;
    }
}

/* ============================================
   Animations for streaming text
   ============================================ */

.streaming-text {
    animation: none;
}

.streaming-text::after {
    content: '▋';
    animation: cursor-blink 1s infinite;
    color: var(--accent-primary);
}

@keyframes cursor-blink {
    0%, 50% {
        opacity: 1;
    }
    51%, 100% {
        opacity: 0;
    }
}

/* ============================================
   Empty state
   ============================================ */

.empty-conversations,
.login-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-conversations svg,
.login-prompt svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-conversations p,
.login-prompt p {
    font-size: 0.9rem;
}

.login-prompt svg {
    color: var(--accent-primary);
    opacity: 0.7;
}

/* Disabled states */
.new-chat-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.new-chat-btn:disabled:hover {
    transform: none;
    box-shadow: var(--shadow-sm), 0 0 20px var(--accent-glow);
}

.input-wrapper textarea:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.attach-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

.suggestion-btn:disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--border-color);
}

/* Code block copy button */
.code-block-wrapper {
    position: relative;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 6px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
}

.code-block-wrapper:hover .copy-code-btn {
    opacity: 1;
}

.copy-code-btn:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

/* Loading state */
.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   User Menu
   ============================================ */

.user-menu {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.user-info:hover {
    background: var(--bg-hover);
}

.user-info svg {
    width: 22px;
    height: 22px;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.user-info span {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-stats-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 18px;
    margin-top: 12px;
    margin-bottom: 8px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: all var(--transition-normal);
    background: var(--accent-gradient);
    color: white;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.user-stats-btn:hover {
    opacity: 0.95;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.user-stats-btn:active {
    transform: translateY(0);
}

.user-stats-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

.auth-buttons {
    display: flex;
    gap: 8px;
}

.auth-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    transition: all var(--transition-fast);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.auth-btn.primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
}

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

.logged-in-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.logged-in-menu .auth-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
}

.logged-in-menu .auth-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5;
}

.logged-in-menu .admin-btn {
    background: linear-gradient(135deg, #9333ea 0%, #7c3aed 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(147, 51, 234, 0.3);
}

.logged-in-menu .admin-btn:hover {
    opacity: 0.95;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(147, 51, 234, 0.4);
}

.logged-in-menu .admin-btn:active {
    transform: translateY(0);
}

.logged-in-menu .logout-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.logged-in-menu .logout-btn:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.logged-in-menu .logout-btn:active {
    transform: translateY(0);
}

/* ============================================
   Token Stats Panel
   ============================================ */

.token-stats-panel {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-right: auto;
}

.token-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.token-stat svg {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
}

.token-stat.cost {
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
    color: var(--success);
    font-weight: 600;
    font-family: var(--font-mono);
}

.token-stat.cost .currency-symbol {
    font-weight: 700;
    color: var(--success);
    margin-right: 2px;
}

.modal-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    margin-right: 12px;
}

/* ============================================
   Pricing Modal
   ============================================ */

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal.visible {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(var(--accent-rgb), 0.05);
    max-width: 600px;
    width: 90%;
    max-height: 82vh;
    overflow: hidden;
    transform: scale(0.95) translateY(20px);
    transition: transform var(--transition-normal), background var(--transition-normal), border-color var(--transition-normal);
}

/* Glassmorphism only in dark mode */
[data-theme="dark"] .modal-content {
    background: rgba(18, 18, 26, 0.95);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] .modal-content {
    background: var(--bg-secondary);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.modal.visible .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    flex: 1;
}

.modal-close {
    color: var(--text-tertiary);
}

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

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.pricing-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.pricing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.pricing-table th,
.pricing-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.pricing-table th {
    font-weight: 600;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pricing-table td {
    color: var(--text-primary);
}

.pricing-table tr:hover td {
    background: var(--bg-hover);
}

.pricing-table .price {
    font-family: var(--font-mono);
    color: var(--success);
}

.pricing-table .free-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--success);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.pricing-table .paid-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--warning);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.pricing-source {
    margin-top: 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.pricing-source a {
    color: var(--accent-primary);
    text-decoration: none;
}

.pricing-source a:hover {
    text-decoration: underline;
}

/* ============================================
   Auth Pages
   ============================================ */

.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(var(--accent-rgb), 0.15) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 120%, rgba(139, 92, 246, 0.08) 0%, transparent 60%);
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%236366f1' fill-opacity='0.03'%3E%3Ccircle cx='30' cy='30' r='1'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}

.auth-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(var(--accent-rgb), 0.06);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    position: relative;
    animation: authCardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header .logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.auth-header h1 {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 8px;
    font-family: var(--font-sans);
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-error {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-md);
    color: var(--error);
    font-size: 0.9rem;
}

.auth-error svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: all var(--transition-fast);
    width: 100%;
}

.form-group input:focus {
    outline: none;
    border-color: rgba(var(--accent-rgb), 0.5);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
    background: var(--bg-secondary);
}

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

.auth-submit {
    padding: 14px 24px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-top: 8px;
    width: 100%;
    box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.35);
}

.auth-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.45);
}

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

.auth-footer {
    margin-top: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.back-link {
    display: inline-block;
    margin-top: 16px;
    color: var(--text-tertiary) !important;
    font-size: 0.85rem;
}

/* ============================================
   Responsive Token Stats
   ============================================ */

@media (max-width: 768px) {
    .token-stats-panel {
        display: none;
    }
    
    .user-menu {
        padding: 10px 12px;
    }
    
    .auth-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 24px;
    }
    
    .modal-content {
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
}

/* ============================================
   Settings Modal
   ============================================ */

.settings-modal {
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.settings-modal .modal-body {
    overflow-y: auto;
}

.modal-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
}

.settings-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-primary);
}

.settings-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.settings-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.toggle-text h3 {
    margin: 0 0 4px;
}

.toggle-text .settings-hint {
    margin: 0;
}

/* Nowoczesny przełącznik (switch) */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(148, 163, 184, 0.5);
    transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.7);
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: #0f172a;
    border-radius: 50%;
    transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.9);
}

.switch input:checked + .slider {
    background: linear-gradient(135deg, #6366f1 0%, #22d3ee 100%);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7);
}

.switch input:checked + .slider:before {
    transform: translateX(18px);
    background-color: #e5f2ff;
    box-shadow: 0 6px 16px rgba(56, 189, 248, 0.7);
}

.switch .slider:active:before {
    width: 20px;
}

.settings-hint {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

.settings-textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color var(--transition-fast);
}

.settings-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.settings-textarea::placeholder {
    color: var(--text-tertiary);
}

.settings-row {
    margin-bottom: 20px;
}

.settings-row:last-child {
    margin-bottom: 0;
}

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

.settings-row label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex: 1;
}

.settings-reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.settings-reset-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: rotate(180deg);
}

.settings-reset-btn svg {
    width: 16px;
    height: 16px;
}

.settings-default-hint {
    color: var(--text-tertiary);
    font-size: 0.85em;
    font-style: italic;
    margin-left: 4px;
}

.settings-value {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-primary);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.settings-row input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    cursor: pointer;
}

.settings-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: transform var(--transition-fast);
}

.settings-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.settings-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border-primary);
    margin-top: 20px;
}

/* Specjalny układ przycisków w modalu pamięci użytkownika:
   wyśrodkowane i oderwane od dolnej krawędzi */
#userMemoryModal .modal-footer {
    justify-content: center;
    padding-bottom: 16px;
}

/* Taki sam układ przycisków w modalu ustawień konwersacji */
#settingsModal .modal-footer {
    justify-content: center;
    padding-bottom: 16px;
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-secondary.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
    margin-top: 8px;
}

.btn-primary {
    padding: 10px 20px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   Message Animations & Status
   ============================================ */

/* Animacja wejścia wiadomości - wspólna baza */
.message.animate-in {
    opacity: 0;
}

/* Delikatnie inne wejście dla użytkownika i AI */
.message.user.animate-in {
    animation: messageInUser 0.22s ease-out forwards;
}

.message.model.animate-in {
    animation: messageInAI 0.24s ease-out forwards;
}

@keyframes messageInUser {
    from {
        opacity: 0;
        transform: translateY(8px) translateX(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateX(0);
    }
}

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

/* Status indicator (myślenie, wyszukiwanie) */
.status-indicator {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    padding: 8px 0;
    animation: statusPulse 1.5s ease-in-out infinite;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

@keyframes statusPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Typewriter effect dla streamingu */
.streaming-content .typewriter-char {
    animation: typewriterFadeIn 0.05s ease-out forwards;
}

@keyframes typewriterFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================
   Message Sources (Web Search)
   ============================================ */

.message-sources {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-primary);
}

.sources-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.sources-header svg {
    width: 14px;
    height: 14px;
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.source-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    transition: all var(--transition-fast);
    max-width: 250px;
}

.source-link:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.source-link svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.source-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Scroll to Bottom Button */
.scroll-to-bottom-btn {
    position: absolute !important;
    right: -52px !important;
    bottom: 12px !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity var(--transition-normal), visibility var(--transition-normal), transform var(--transition-normal);
    padding: 0;
    z-index: 10;
    margin: 0 !important;
}

.scroll-to-bottom-btn:hover {
    background: var(--accent-secondary);
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: scale(1);
}

.scroll-to-bottom-btn svg {
    width: 20px;
    height: 20px;
}

@media (max-width: 768px) {
    .scroll-to-bottom-btn {
        right: -48px;
        width: 36px;
        height: 36px;
    }
    
    .scroll-to-bottom-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* Ogólny efekt shimmer dla skeletonów */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}
/* ============================================
   Model Selector - Provider Icons
   ============================================ */

.model-option-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-option-icon {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    object-fit: contain;
}

/* ============================================
   KaTeX Math Rendering
   ============================================ */

.message-bubble .katex {
    font-size: 1em;
}

.message-bubble .katex-display {
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

.message-bubble .katex-display > .katex {
    text-align: left;
}

/* ============================================
   Provider Badge in Model Dropdown
   ============================================ */

.model-option {
    position: relative;
}

.model-option[data-provider="openai"]::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #10a37f;
    border-radius: 3px 0 0 3px;
}

.model-option[data-provider="google"]::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #4285f4;
    border-radius: 3px 0 0 3px;
}

/* ============================================
   Responsive adjustments
   ============================================ */

@media (max-width: 768px) {
    .sources-list {
        flex-direction: column;
    }
    
    .source-link {
        max-width: 100%;
    }
}

/* ============================================
   User Stats Modal
   ============================================ */

.stats-modal {
    max-width: 550px;
}

.stats-info-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
}

.stats-info-box h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.stats-info-box p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
}

.stats-info-box p:last-child {
    margin-bottom: 0;
}

.stats-total {
    margin-bottom: 24px;
}

.stats-total h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-item.highlight {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.stat-item.highlight .stat-label {
    color: rgba(255,255,255,0.8);
}

.stat-value {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.stat-item.highlight .stat-value {
    color: white;
}

.stats-providers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.provider-stats {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.provider-stats.gemini {
    border-left: 3px solid #4285f4;
}

.provider-stats.openai {
    border-left: 3px solid #10a37f;
}

.provider-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.provider-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.provider-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stats-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 4px 0;
    color: var(--text-secondary);
}

.stats-row.total {
    border-top: 1px solid var(--border-primary);
    margin-top: 8px;
    padding-top: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.stats-summary {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 12px 16px;
}

.stats-summary .stats-row {
    padding: 6px 0;
}

@media (max-width: 600px) {
    .stats-providers {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Skip Reasoning Button
   ============================================ */

.skip-reasoning-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.skip-reasoning-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.skip-reasoning-btn svg {
    width: 16px;
    height: 16px;
}

.skip-reasoning-btn span {
    font-weight: 600;
}

/* Retry button */
.retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.retry-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
}

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

/* Wygenerowany obraz */
.generated-image-container {
    margin: 12px 0;
}

.generated-image {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: block;
    margin: 0 auto;
}

.generated-image-prompt {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ============================================
   Message Actions (Copy, Edit, Reply)
   ============================================ */

.message {
    position: relative;
}

.message-actions {
    display: flex;
    flex-direction: row;
    gap: 4px;
    position: static;
    margin-top: 10px; /* większy odstęp od treści wiadomości */
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    justify-content: flex-start;
}

/* Większy odstęp, gdy zmienia się nadawca wiadomości (użytkownik ↔ model) */
.message.user + .message.model,
.message.model + .message.user {
    margin-top: 16px;
}

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

.message-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.message-action-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: scale(1.05);
    opacity: 1;
}

.message-action-btn svg {
    width: 14px;
    height: 14px;
}

/* ============================================
   Settings Select
   ============================================ */

.settings-select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.settings-select:hover {
    border-color: var(--accent-primary);
}

.settings-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.1);
}

/* ============================================
   Reply Context (Kontekst odpowiedzi)
   ============================================ */

.reply-context {
    margin-bottom: 12px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-left: 4px solid var(--accent-primary);
    border-radius: var(--radius-md);
    animation: slideDown 0.3s ease;
}

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

.reply-context-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.reply-context-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.reply-context-close:hover {
    background: var(--bg-secondary);
    color: var(--accent-primary);
}

.reply-context-close svg {
    width: 14px;
    height: 14px;
}

.reply-context-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* Library View Inline */
.library-view {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.library-view::-webkit-scrollbar {
    width: 8px;
}

.library-view::-webkit-scrollbar-track {
    background: transparent;
}

.library-view::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

.library-header-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.library-header-inline h2 {
    margin: 0;
    font-size: 1.6rem;
    color: var(--text-primary);
}

.library-header-inline h2::after {
    content: '';
    display: block;
    margin-top: 6px;
    width: 42px;
    height: 3px;
    border-radius: 999px;
    background: var(--accent-gradient);
}

.library-tabs-inline {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn-inline {
    padding: 8px 14px;
    background: rgba(15,23,42,0.6);
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 999px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tab-btn-inline:hover {
    color: var(--text-primary);
    border-color: var(--accent-primary);
    background: rgba(37, 99, 235, 0.15);
}

.tab-btn-inline.active {
    color: var(--accent-color);
    background: rgba(37, 99, 235, 0.25);
    border-color: var(--accent-color);
    box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.4), 0 10px 30px rgba(15,23,42,0.65);
}

.library-content-inline {
    min-height: 400px;
}

.library-grid-inline {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(268.75px, 268.75px));
    gap: 18px;
}

/* Skeletony dla biblioteki */
.library-skeleton {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.library-skeleton-item {
    height: 120px;
    border-radius: var(--radius-md);
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.03) 0%,
        rgba(255,255,255,0.08) 20%,
        rgba(255,255,255,0.03) 40%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

.library-item-inline {
    position: relative;
    background: radial-gradient(circle at top left, rgba(148,163,184,0.18), transparent 55%),
                radial-gradient(circle at bottom right, rgba(79,70,229,0.22), transparent 55%),
                var(--bg-secondary);
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast), background 0.3s ease;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(14px);
}

.library-item-inline:hover {
    transform: translateY(-4px) translateZ(0);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.85);
    border-color: rgba(129, 140, 248, 0.8);
}

.library-item-image-inline {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: radial-gradient(circle at center, rgba(15,23,42,1), rgba(15,23,42,0.7));
    border-bottom: 1px solid rgba(148,163,184,0.35);
    cursor: pointer;
    transition: opacity var(--transition-fast);
    display: block;
}

.library-item-image-inline:hover {
    opacity: 0.9;
}

.library-item-image {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: contain;
    background: radial-gradient(circle at center, rgba(15,23,42,1), rgba(15,23,42,0.7));
    border-bottom: 1px solid rgba(148,163,184,0.35);
    display: block;
}

.library-item-file-inline {
    padding: 32px 20px 24px;
    text-align: center;
    background: radial-gradient(circle at top, rgba(15,23,42,0.95), rgba(15,23,42,0.8));
    border-bottom: 1px solid rgba(148,163,184,0.35);
}

.library-item-file-icon-inline {
    width: 40px;
    height: 40px;
    margin: 0 auto 8px;
    color: var(--accent-secondary);
}

.library-item-info-inline {
    padding: 12px 14px 14px;
}

.library-item-name-inline {
    font-weight: 500;
    margin-bottom: 4px;
    word-break: break-word;
    font-size: 0.92rem;
    color: var(--text-primary);
}

.library-item-meta-inline {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.library-item-actions-inline {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.library-item-btn-inline {
    flex: 1;
    padding: 6px 12px;
    background: rgba(15,23,42,0.9);
    border: 1px solid rgba(148,163,184,0.6);
    border-radius: 999px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    text-decoration: none;
    text-align: center;
}

.library-item-btn-inline:hover {
    background: rgba(37, 99, 235, 0.2);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.45);
}

.library-item-btn-inline.delete {
    color: var(--error-color);
    border-color: rgba(248, 113, 113, 0.7);
}

.library-item-btn-inline.delete:hover {
    background: rgba(248, 113, 113, 0.18);
    color: #fecaca;
}

/* ============ Global confirm modal ============ */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
}

.confirm-modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.3);
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 16px;
    row-gap: 12px;
    animation: modal-in 0.18s ease-out;
}

.confirm-modal .modal-icon {
    grid-row: span 2;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.confirm-modal .modal-icon svg {
    width: 32px;
    height: 32px;
    color: var(--error-color);
}

.confirm-modal .modal-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.confirm-modal .modal-message {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.confirm-modal .modal-input {
    margin-top: 8px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

.confirm-modal .modal-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.confirm-modal .modal-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.confirm-modal .modal-actions .btn {
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 14px;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.confirm-modal .modal-actions .btn.secondary {
    background: transparent;
    color: var(--text-primary);
    border-color: rgba(148, 163, 184, 0.5);
}

.confirm-modal .modal-actions .btn.danger {
    background: var(--error-color);
    color: white;
}

.confirm-modal .modal-actions .btn:hover {
    opacity: 0.9;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   Mobile UX — touch targets, thumb zone, polish
   ============================================ */

/* Prevent iOS auto-zoom on input focus (font-size must be ≥16px) */
@media (max-width: 768px) {
    .input-wrapper textarea,
    .input-wrapper input,
    .form-group input,
    .form-group textarea,
    select {
        font-size: 16px !important;
    }

    /* Touch targets ≥ 44px for all interactive elements */
    .btn-icon,
    .send-btn,
    .mobile-menu-btn,
    .new-chat-btn,
    .model-tab,
    .conversation-item,
    .sidebar-action-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Send button — larger on mobile, easier thumb reach */
    .send-btn {
        width: 44px;
        height: 44px;
        border-radius: 14px;
        flex-shrink: 0;
    }

    /* Input area — account for mobile bottom bar (safe-area-inset) */
    .input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    /* Messages — full width bubbles on small screens */
    .message.user .message-bubble,
    .message.model .message-bubble {
        max-width: 100%;
    }

    /* Conversation list items — bigger tap target */
    .conversation-item {
        padding: 12px 16px;
    }

    /* Sidebar — full safe area height */
    .sidebar {
        padding-bottom: max(120px, calc(80px + env(safe-area-inset-bottom)));
    }

    /* Model selector — scrollable on mobile */
    .model-tabs {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .model-tabs::-webkit-scrollbar {
        display: none;
    }

    /* Welcome screen — better vertical centering on short phones */
    .welcome-screen {
        padding: 20px 16px;
        justify-content: flex-start;
        padding-top: max(40px, 10vh);
    }

    /* Suggestions — single column, full-width */
    .suggestion-btn {
        width: 100%;
        text-align: left;
        padding: 14px 16px;
        min-height: 52px;
    }

    /* Scroll-to-bottom — visible on mobile */
    .scroll-to-bottom-btn {
        right: 16px;
        bottom: 90px;
    }

    /* Chat header — compact */
    .chat-header-title {
        font-size: 0.95rem;
    }

    /* Action buttons in header — only essential ones */
    .chat-header .header-actions .btn-icon:not(.mobile-menu-btn):not([data-action="new-chat"]) {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Extra small — tighten further */
    .messages-container {
        padding: 12px 10px;
    }

    .message-bubble {
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .input-wrapper {
        padding: 8px 10px;
        gap: 8px;
    }

    /* Model tabs — show only icon on very small screens */
    .model-tab .tab-label {
        display: none;
    }
    .model-tab {
        min-width: 44px;
        padding: 10px;
        justify-content: center;
    }
    .model-tab .tab-icon {
        margin-right: 0;
    }
}

