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

:root {
    --primary-bg: #ffffff;
    --secondary-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --border-subtle: rgba(0, 0, 0, 0.15);
    --nav-btn-bg: rgba(0, 0, 0, 0.05);
    /* Nuova variabile per sfondo bottoni navbar tema chiaro */
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-border: #a1a1aa;
    --hover-bg: #f1f5f9;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --navbar-height: 50px;
}

[data-theme="dark"] {
    --primary-bg: #121212;
    --secondary-bg: #1e1e1e;
    --card-bg: #252525;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --border-color: #27272a;
    --border-subtle: rgb(53 53 53 / 20%);
    --nav-btn-bg: rgba(255, 255, 255, 0.1);
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-border: #a1a1aa;
    --hover-bg: #252525;
}

[data-theme="midnight"] {
    --primary-bg: #000000;
    --secondary-bg: #111111;
    --card-bg: #111111;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --border-color: #1a1a1a;
    --border-subtle: rgb(47 47 47 / 10%);
    --nav-btn-bg: rgba(255, 255, 255, 0.08);
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-border: #a1a1aa;
    --hover-bg: #1a1a1a;
}

body {
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--primary-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
    overflow: hidden;
    animation: smoothFade 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes smoothFadeUp {
    0% {
        opacity: 0;
        transform: translateY(40px) scale(0.98);
        filter: blur(8px);
    }

    60% {
        opacity: 1;
        transform: translateY(-4px) scale(1.01);
        filter: blur(0);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes smoothFade {
    0% {
        opacity: 0;
        transform: scale(0.95);
        filter: blur(6px);
    }

    100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

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

.navbar,
.sidebar,
.main-content,
.welcome-screen,
.login-container,
.login-card {
    animation: smoothFadeUp 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: transparent;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    transition: all 0.3s ease;
    pointer-events: none;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    pointer-events: all;
}

.menu-btn:hover {
    background: var(--nav-btn-bg);
}

.menu-btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--text-primary);
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: all;
}

.new-chat-btn,
.sadas {
    width: calc(100% - 24px);
    padding: 12px 16px;
    margin: 10px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.new-chat-btn:hover,
.sadas:hover {
    background: var(--hover-bg);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    border-color: var(--accent-color);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--nav-btn-bg);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    fill: var(--text-primary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
}

.user-menu:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.user-menu svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -285px;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    left: 0;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 3px;
    opacity: 0.3;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-primary);
    opacity: 0.6;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 998;
}

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

.new-chat-btn,
.sadas {
    margin: 4px 12px;
    padding: 10px 14px;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    font-weight: 500;
    font-size: 14px;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - 24px);
    text-align: left;
}

.new-chat-btn:hover,
.sadas:hover {
    background: var(--hover-bg);
    transform: none;
}

.new-chat-btn svg,
.sadas svg {
    width: 16px;
    height: 16px;
    stroke: var(--text-secondary);
    flex-shrink: 0;
}

.sidebar-content-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    padding-bottom: 72px;
    /* space for user profile fixed at bottom */
}

/* Sidebar header row with the toggle button */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: calc(var(--navbar-height) / 2 - 18px) 12px 4px;
    min-height: var(--navbar-height);
    flex-shrink: 0;
}

.sidebar-toggle-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: var(--hover-bg);
}

.sidebar-toggle-btn svg {
    width: 22px;
    height: 19px;
    stroke: var(--text-secondary);
    transition: stroke 0.2s;
}

.sidebar-toggle-btn:hover svg {
    stroke: var(--text-primary);
}

/* Utility: show/hide based on viewport */
.mobile-only {
    display: none;
}

.desktop-only {
    display: flex;
}

.chat-history {
    padding: 0 12px 20px;
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
}

.chat-history::-webkit-scrollbar {
    width: 4px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-history-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
    padding: 0 8px;
}

/* === CHAT SEARCH BAR === */
.chat-search-wrapper {
    position: relative;
    margin: 12px 4px 10px;
}

.chat-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-secondary);
    pointer-events: none;
}

.chat-search-input {
    width: 100%;
    padding: 8px 10px 8px 30px;
    background: var(--hover-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, sans-serif;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.chat-search-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.chat-search-input:focus {
    border-color: var(--accent-border);
    background: var(--card-bg);
    box-shadow: 0 0 0 3px rgba(161, 161, 170, 0.1);
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    text-align: left;
    width: 100%;
    color: var(--text-primary);
    transition: all 0.2s ease;
    cursor: pointer;
}

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

.chat-item.active {
    background-color: var(--accent-color);
    color: white;
}

.chat-item.active .chat-item-time,
.chat-item.active .chat-item-title {
    color: white;
}

.chat-item-main {
    flex-grow: 1;
    cursor: pointer;
    overflow: hidden;
    min-width: 0;
}

.chat-item-title {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-item-actions {
    display: flex;
    gap: 4px;
    opacity: 1;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

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

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

.chat-action-btn.delete-btn {
    width: 56px;
    height: 32px;
}

.chat-action-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    pointer-events: none;
}

.chat-action-btn i {
    font-size: 14px;
    color: currentColor;
    pointer-events: none;
    visibility: visible;
    opacity: 1;
}

.chat-action-btn.delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.chat-action-btn.rename-btn:hover {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.chat-item.active .chat-action-btn {
    color: white;
}

.chat-item.active .chat-action-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.main-content {
    margin-left: 0;
    padding-top: var(--navbar-height);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
    /* Ensure main content doesn't scroll itself */
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 0 24px;
    overflow: hidden;
    /* Important for children flex/scroll */
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
}

.welcome-logo {
    width: 80px;
    height: 80px;
    border-radius: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.welcome-logo img {
    width: 71px;
    height: 71px;
    object-fit: contain;
    border-radius: 16px;
}

.welcome-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #c4c4c4, #818181);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    display: none;
    min-height: 0;
    /* Important for flex-grow to scroll correctly */
}

.messages-area::-webkit-scrollbar {
    width: 6px;
}

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

.messages-area::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 3px;
    opacity: 0.3;
}

.messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-primary);
    opacity: 0.6;
}

.message {
    margin-bottom: 20px;
    display: flex;
    width: 100%;
    flex-direction: column;
}

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

.message.ai,
.message.assistant {
    align-items: flex-start;
}

.message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    width: fit-content;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user .message-content {
    background: #00000052;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai .message-content,
.message.assistant .message-content {
    background: var(--secondary-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-content h1 {
    font-size: 1.5em;
    font-weight: 700;
    margin: 12px 0 6px 0;
    color: var(--text-primary);
    border-bottom: 1.5px solid var(--border-color);
    padding-bottom: 4px;
}

.message-content h2 {
    font-size: 1.4em;
    font-weight: bold;
    margin: 10px 0 6px 0;
    color: var(--text-primary);
}

.message-content h3 {
    font-size: 1.25em;
    font-weight: bold;
    margin: 8px 0 4px 0;
    color: var(--text-primary);
}

.message-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: var(--secondary-bg);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

.message-content pre {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.4;
}

.message-content pre code {
    background: none;
    border: none;
    padding: 0;
}

.message-content ul,
.message-content ol {
    margin: 4px 0 4px 20px;
    padding-left: 0;
}

.message-content li {
    margin: 2px 0;
    line-height: 1.5;
}

.message-content a {
    color: var(--accent-color);
    text-decoration: underline;
}

.message-content a:hover {
    color: var(--accent-hover);
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    text-align: left;
    font-size: 0.95em;
    line-height: 1.4;
    vertical-align: top;
}

.message-content th {
    background: rgba(128, 128, 128, 0.05);
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    min-width: 100px;
}

.message-content tr td:first-child {
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(128, 128, 128, 0.02);
    min-width: 120px;
    width: 120px;
}

.markdown-hr {
    border: none;
    border-top: 1.5px solid var(--border-color);
    margin: 8px 0;
    opacity: 0.4;
}


.message-content blockquote {
    border-left: 4px solid var(--accent-color);
    margin: 16px 0;
    padding: 8px 16px;
    background: var(--secondary-bg);
    border-radius: 0 8px 8px 0;
    font-style: italic;
}

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

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.message.ai .message-actions {
    opacity: 1;
    transform: translateY(0);
}

.action-btn {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    font-size: 12px;
}

.action-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-border);
    transform: translateY(-1px);
}

.action-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-border);
}

.like-btn.active {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.dislike-btn.active {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

.retry-btn:hover {
    background: #f59e0b;
    border-color: #f59e0b;
}

.input-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 24px 55px;
    background: var(--primary-bg);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    width: 100%;
    max-width: 100%;
    min-height: 60px;
    height: auto;
    background: var(--card-bg);
    border: 1.5px solid var(--accent-color);
    border-radius: 24px;
    padding: 2px;
    margin: 0;
    position: relative;
    box-sizing: border-box;
    overflow: visible;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.input-wrapper:hover {
    border-color: #94a3b8;
}

.input-wrapper:focus-within {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 4px rgba(161, 161, 170, 0.15);
}

.char-counter {
    display: none !important;
}

.char-counter.visible {
    opacity: 0.8;
}

.char-counter.limit-warning {
    color: #f59e0b;
}

.char-counter.limit-exceeded {
    color: #ef4444;
}

#imagePreviewContainer {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, 90px);
    gap: 8px;
    width: 100%;
    padding: 12px 12px 8px 12px;
    margin: 0;
    order: 1;
    background: transparent;
    box-sizing: border-box;
}

.preview-item {
    width: 90px;
    height: 90px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background-color: var(--secondary-bg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.preview-item:hover {
    transform: scale(1.05);
}

.preview-remove-btn {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    border: none;
    border-radius: 0;
    cursor: pointer;
}

.preview-item:hover .preview-remove-btn {
    opacity: 1;
}

.preview-remove-btn i {
    color: white;
    font-size: 20px;
}

.message-input {
    width: 100%;
    height: 60px;
    min-height: 60px;
    flex-shrink: 0;
    padding: 18px 110px 18px 56px;
    margin: 0;
    order: 2;
    background: transparent;
    border: none;
    outline: none;
    box-shadow: none;
    line-height: 1.5;
    color: var(--text-primary);
    font-size: 16px;
    box-sizing: border-box;
    resize: none;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-family: inherit;
}

.message-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.message-input::-webkit-scrollbar {
    width: 4px;
}

.message-input::-webkit-scrollbar-track {
    background: transparent;
}

.message-input::-webkit-scrollbar-thumb {
    background: var(--text-secondary);
    border-radius: 2px;
    opacity: 0.3;
}

.ai .message-content .code-container {
    max-width: 100%;
}

.upload-btn,
.mic-btn,
.send-btn {
    position: absolute;
    bottom: 10px;
    top: auto;
    transform: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 50;
    transition: all 0.2s ease;
}

.upload-btn {
    left: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
}

.upload-btn:hover {
    background: var(--secondary-bg);
    color: var(--accent-color);
}

.mic-btn {
    right: 54px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
}

.mic-btn:hover {
    background: var(--secondary-bg);
    color: var(--accent-color);
}

.mic-btn.is-recording {
    color: #ef4444;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.send-btn {
    right: 8px;
    background: var(--accent-color);
    color: white;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn.stop-mode {
    background: #ef4444;
    border-color: #dc2626;
    color: white;
    border-radius: 50%;
    animation: stopPulse 2s infinite;
}

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

@keyframes stopPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.send-btn:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}



.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    color: var(--text-secondary);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {

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

    30% {
        transform: translateY(-10px);
    }
}

#toastContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: clamp(280px, 90%, 350px);
}

.toast {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    font-size: 14px;
    font-weight: 500;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

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

.toast.success .toast-icon {
    color: #10b981;
}

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

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

.secret-modal-overlay,
.delete-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.secret-modal-content {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    text-align: center;
    width: 90%;
    max-width: 320px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.secret-modal-content h2 {
    margin-top: 0;
    margin-bottom: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.secret-modal-content p {
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

.secret-modal-content input,
#renameInput,
#feedbackReason {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--secondary-bg);
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 16px;
    text-align: center;
    font-family: inherit;
}

#feedbackReason {
    min-height: 100px;
    resize: vertical;
    text-align: left;
}

.secret-modal-content input:focus,
#renameInput:focus,
#feedbackReason:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.secret-modal-content button,
.modal-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--accent-color);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

.secret-modal-content button:hover,
.modal-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-btn {
    flex: 1;
}

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

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

.delete-modal-content {
    background: #1f2937;
    padding: 32px;
    border-radius: 16px;
    border: 1px solid #374151;
    width: 90%;
    max-width: 320px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.delete-icon-container {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.delete-icon {
    width: 48px;
    height: 48px;
    color: #9ca3af;
    fill: #ef4444;
    transition: transform 0.3s ease;
}

.delete-modal-content:hover .delete-icon {
    animation: deleteBounce 0.6s ease;
}

@keyframes deleteBounce {

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

    25% {
        transform: translateY(-10px);
    }

    50% {
        transform: translateY(0);
    }

    75% {
        transform: translateY(-5px);
    }
}

.delete-title {
    font-size: 18px;
    font-weight: 700;
    color: #e5e7eb;
    margin: 16px 0 8px 0;
}

.delete-subtitle {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 24px;
    padding: 0 8px;
}

.delete-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.delete-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.delete-btn-cancel {
    background: #374151;
    color: #d1d5db;
    border-color: #4b5563;
}

.delete-btn-cancel:hover {
    background: #4b5563;
    border-color: #4b5563;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.delete-btn-confirm {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    margin-left: 8px;
}

.delete-btn-confirm:hover {
    background: transparent;
    color: #ef4444;
    border-color: #ef4444;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

#shortcutsModal .secret-modal-content {
    max-width: 440px;
}

.shortcuts-list {
    margin: 24px 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    font-size: 15px;
    color: var(--text-primary);
}

.shortcut-item .keys {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.shortcut-item kbd {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-bottom-width: 3px;
    border-radius: 6px;
    padding: 4px 10px;
    font-family: monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

#closeShortcutsBtn {
    width: auto;
    padding: 10px 20px;
    margin-top: 10px;
}

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-bg) 0%, var(--secondary-bg) 100%);
    padding: 24px;
}

.login-card {
    background: var(--card-bg);
    padding: 48px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 64px rgba(0, 0, 0, 0.1);
}

.login-logo {
    width: 64px;
    height: 64px;
    border-radius: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.login-logo img {
    width: 70px;
    height: 70px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.form-input {
    padding: 16px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

.form-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.auth-btn {
    padding: 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    width: 100%;
}

.google-btn:hover {
    background: var(--secondary-bg);
}

.github-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: #24292e;
    border: 1px solid #24292e;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    width: 100%;
    margin-top: 12px;
}

.github-btn:hover {
    background: #333;
    border-color: #333;
}

.github-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.divider {
    display: flex;
    align-items: center;
    margin: 24px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

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

.divider::before {
    margin-right: 16px;
}

.divider::after {
    margin-left: 16px;
}

.auth-switch {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-switch a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
}

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

.MathJax {
    font-size: 1.1em;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100vw;
        left: -100vw;
    }

    .sidebar.open {
        left: 0;
    }

    .chat-container {
        padding: 0 16px;
    }

    .input-container {
        padding: 16px;
    }

    .navbar {
        padding: 0 16px;
    }

    .input-wrapper {
        margin-bottom: 30px;
    }
}

/* --- MULTI-CHANNEL VERIFICATION STYLES --- */
.otp-methods-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 15px;
    margin-top: 25px;
}

.otp-method-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.otp-method-card:hover {
    background: var(--hover-bg);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.method-icon {
    width: 45px;
    height: 45px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.otp-method-card span {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.phone-input-container {
    display: flex;
    background: var(--input-bg);
    border: 2px solid var(--border-subtle);
    border-radius: 16px;
    margin-top: 25px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.phone-input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.country-selector {
    position: relative;
    border-right: 1px solid var(--border-subtle);
}

.selected-country {
    padding: 15px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
    min-width: 90px;
}

.selected-country .code {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.country-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 280px;
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-top: none;
    border-radius: 0 0 16px 16px;
    z-index: 100;
    display: none;
    flex-direction: column;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    max-height: 250px;
}

.country-dropdown.active {
    display: flex;
}

.country-search {
    padding: 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.country-search input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.country-options {
    overflow-y: auto;
}

.country-option {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.country-option .country-flag { font-size: 1.2rem; }
.country-option .country-name { flex: 1; font-size: 0.9rem; color: var(--text-secondary); }
.country-option .country-code { font-weight: 600; color: var(--text-primary); }

#phoneNumberInput {
    flex: 1;
    background: transparent !important;
    border: none !important;
    padding: 15px !important;
    font-size: 1.1rem !important;
    color: var(--text-primary) !important;
    outline: none !important;
}

.verification-note {
    margin-top: 15px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.8;
}

.otp-back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    z-index: 10;
}

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



@media (max-width: 480px) {
    #toastContainer {
        top: 10px;
        left: 10px;
        right: 10px;
        width: auto;
    }

    .message-actions {
        gap: 4px;
    }

    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    .secret-modal-content,
    .delete-modal-content {
        width: 95%;
        max-width: none;
        margin: 0 10px;
    }
}

@media (min-width: 1024px) {
    .sidebar-overlay {
        display: none;
    }
}

.lightbox-overlay {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    /* Sfoca la chat dietro */
    align-items: center;
    justify-content: center;
    cursor: default;
    animation: fadeIn 0.3s ease;
}

.lightbox-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    cursor: default;
    transform: scale(1);
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #ffffff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    line-height: 1;
}

.lightbox-close:hover {
    color: var(--accent-color);
    transform: scale(1.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

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

.gen-image-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 12px 0;
    line-height: 0;
}

.gen-image-wrapper img {
    display: block;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.gen-image-wrapper img:hover {
    filter: brightness(0.95);
}

.img-hover-actions {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 12px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(-5px);
    z-index: 10;
}

.gen-image-wrapper:hover .img-hover-actions {
    opacity: 1;
    transform: translateY(0);
}

.img-btn {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.img-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    transform: scale(1.1);
}

/* =============================
   SEARCH INDICATOR ANIMATION
   ============================= */
.search-indicator-bubble {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-radius: 20px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
}

.search-icon-pulse {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-ring 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

.search-icon-pulse i {
    font-size: 12px;
    color: var(--text-secondary);
}

@keyframes pulse-ring {

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

    50% {
        transform: scale(1.15);
        opacity: 0.7;
    }
}

/* Shimmer text - light theme (dark shades) */
.search-shimmer-text {
    font-weight: 600;
    font-size: 15px;
    background: linear-gradient(90deg,
            #1a1a1a 0%,
            #555555 25%,
            #888888 50%,
            #555555 75%,
            #1a1a1a 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer-text 1.8s linear infinite;
}

/* Shimmer text - dark theme (light shades) */
[data-theme="dark"] .search-shimmer-text {
    background: linear-gradient(90deg,
            #ffffff 0%,
            #aaaaaa 25%,
            #666666 50%,
            #aaaaaa 75%,
            #ffffff 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer-text 1.8s linear infinite;
}

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

    100% {
        background-position: -200% center;
    }
}

/* =============================
   USER PROFILE FIXED AT BOTTOM
   ============================= */
#userProfile {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 10;
    background: var(--card-bg) !important;
    border-top: 1px solid var(--border-subtle) !important;
    border-radius: 0 !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 12px 16px !important;
    backdrop-filter: blur(10px) !important;
}

.user-info-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
    min-width: 0;
}

.user-name-text {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.user-email-text {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#userProfile img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-subtle);
    margin-left: 12px;
    flex-shrink: 0;
}

/* =============================
   MINI SIDEBAR (DESKTOP)
   ============================= */
@media (min-width: 769px) {
    .sidebar {
        left: 0 !important;
        width: var(--sidebar-collapsed-width);
    }

    .sidebar.open {
        width: var(--sidebar-width);
    }

    .main-content {
        margin-left: var(--sidebar-collapsed-width);
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open~.main-content {
        margin-left: var(--sidebar-width);
    }

    /* Text hiding in collapsed state */
    .sidebar:not(.open) .new-chat-btn span,
    .sidebar:not(.open) .sadas span,
    .sidebar:not(.open) .chat-history,
    .sidebar:not(.open) .chat-search-wrapper {
        opacity: 0;
        pointer-events: none;
        display: none;
    }

    /* Adjust buttons in collapsed state */
    .sidebar:not(.open) .new-chat-btn,
    .sidebar:not(.open) .sadas {
        width: 48px;
        height: 48px;
        padding: 0;
        border: 1px solid var(--border-subtle);
        justify-content: center;
        margin: 10px auto;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.03);
    }

    .sidebar:not(.open) .new-chat-btn:hover,
    .sidebar:not(.open) .sadas:hover {
        background: var(--hover-bg);
        transform: scale(1.05);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
        border-color: var(--accent-border);
    }

    .sidebar:not(.open) .new-chat-btn svg,
    .sidebar:not(.open) .sadas svg {
        margin: 0;
    }

    /* Center the toggle btn in collapsed state */
    .sidebar:not(.open) .sidebar-header {
        justify-content: center;
        padding: 0;
        height: var(--navbar-height);
        display: flex;
        align-items: center;
    }

    /* Adjust User Profile in collapsed state */
    .sidebar:not(.open) #userProfile {
        justify-content: center !important;
        padding: 16px 0 !important;
        background: transparent !important;
        border-top: 1px solid var(--border-subtle) !important;
        box-shadow: none !important;
    }

    .sidebar:not(.open) .user-info-container {
        display: none !important;
    }

    .sidebar:not(.open) #userProfile img {
        margin-left: 0 !important;
        width: 44px !important;
        height: 44px !important;
        border: 2px solid var(--border-subtle) !important;
        transition: transform 0.3s ease;
    }

    .sidebar:not(.open) #userProfile:hover img {
        transform: scale(1.1);
        border-color: var(--accent-border) !important;
    }

    /* === HOVER EXPANSION LOGIC === */
    .sidebar {
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
    }

    .sidebar:not(.open):hover {
        width: var(--sidebar-width);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        z-index: 1001;
    }

    .sidebar:not(.open):hover .new-chat-btn span,
    .sidebar:not(.open):hover .sadas span,
    .sidebar:not(.open):hover .chat-history,
    .sidebar:not(.open):hover .chat-search-wrapper {
        opacity: 1;
        pointer-events: auto;
        display: block;
        animation: fadeIn 0.3s forwards;
    }

    .sidebar:not(.open):hover .new-chat-btn,
    .sidebar:not(.open):hover .sadas {
        width: calc(100% - 24px);
        padding: 10px 14px;
        border: 1px solid var(--border-subtle);
        justify-content: flex-start;
        margin: 4px 12px;
    }

    .sidebar:not(.open):hover .new-chat-btn svg,
    .sidebar:not(.open):hover .sadas svg {
        margin-right: 0;
    }

    /* Restore sidebar-header alignment on hover */
    .sidebar:not(.open):hover .sidebar-header {
        justify-content: flex-start;
        padding: calc(var(--navbar-height) / 2 - 18px) 12px 4px;
    }

    .sidebar:not(.open):hover #userProfile {
        justify-content: space-between !important;
        padding: 12px 16px !important;
    }

    .sidebar:not(.open):hover .user-info-container {
        display: flex !important;
        animation: fadeIn 0.3s forwards;
    }

    .sidebar:not(.open):hover #userProfile img {
        margin-left: 12px !important;
    }

    /* === NO-HOVER LOCK: prevent re-expansion when closing === */
    .sidebar.sidebar-no-hover:not(.open):hover {
        width: var(--sidebar-collapsed-width) !important;
        box-shadow: none !important;
        z-index: 999 !important;
    }

    .sidebar.sidebar-no-hover:not(.open):hover .new-chat-btn span,
    .sidebar.sidebar-no-hover:not(.open):hover .sadas span,
    .sidebar.sidebar-no-hover:not(.open):hover .chat-history,
    .sidebar.sidebar-no-hover:not(.open):hover .chat-search-wrapper,
    .sidebar.sidebar-no-hover:not(.open):hover .user-info-container {
        display: none !important;
        opacity: 0 !important;
    }

    .sidebar.sidebar-no-hover:not(.open):hover .new-chat-btn,
    .sidebar.sidebar-no-hover:not(.open):hover .sadas {
        width: 44px !important;
        padding: 12px 0 !important;
        border: none !important;
        justify-content: center !important;
        margin: 4px auto !important;
    }

    .sidebar.sidebar-no-hover:not(.open):hover .sidebar-header {
        justify-content: center !important;
        padding: calc(var(--navbar-height) / 2 - 18px) 0 4px !important;
    }
}

/* =============================
   MOBILE RESPONSIVE (PHONE)
   ============================= */
@media (max-width: 768px) {

    /* On mobile, sidebar is a full overlay drawer — disable mini sidebar logic */
    .sidebar {
        left: -100% !important;
        width: 80% !important;
        max-width: 300px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .sidebar.open {
        left: 0 !important;
        width: 80% !important;
    }

    /* On mobile: hide desktop sidebar toggle, show navbar hamburger */
    .desktop-only {
        display: none !important;
    }

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

    /* Main content takes full width on mobile */
    .main-content {
        margin-left: 0 !important;
    }

    /* Smaller navbar on mobile */
    .navbar {
        padding: 0 12px;
    }

    .logo {
        font-size: 16px;
    }

    /* Mobile Navbar Buttons Effect */
    .menu-btn.mobile-only,
    .user-menu,
    .theme-toggle {
        background: var(--nav-btn-bg) !important;
        border-radius: 12px !important;
        border: 1px solid var(--border-subtle) !important;
        width: 38px !important;
        height: 38px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .user-menu {
        background: rgba(239, 68, 68, 0.1) !important;
        /* Manteniamo rossiccio ma con lo stile nuovo */
        border: 1px solid rgba(239, 68, 68, 0.2) !important;
        color: #ef4444 !important;
    }

    .user-menu:hover {
        background: #ef4444 !important;
        color: white !important;
    }

    /* Adjust chat container for smaller screens */
    .chat-container {
        padding: 0 12px;
        max-width: 100%;
    }

    /* Welcome screen responsive */
    .welcome-screen {
        padding: 20px 16px;
    }

    .welcome-logo {
        width: 60px;
        height: 60px;
        margin-bottom: 16px;
    }

    .welcome-logo img {
        width: 52px;
        height: 52px;
    }

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

    .welcome-subtitle {
        font-size: 15px;
        margin-bottom: 20px;
    }

    /* Message bubbles take more width on small screens */
    .message-content {
        max-width: 92%;
    }

    /* Input container bottom padding — accounts for mobile browser bars + safe area */
    .input-container {
        padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 60px);
        max-width: 100%;
    }

    /* Input row spacing */
    .input-wrapper {
        border-radius: 20px;
    }

    /* Buttons inside the input row */
    .upload-btn,
    .mic-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

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

    /* Message textarea font size — prevents iOS auto-zoom on focus */
    .message-input {
        font-size: 16px !important;
    }

    /* Sidebar buttons in drawer mode */
    .new-chat-btn,
    .sadas {
        margin: 6px 12px;
        padding: 12px 14px;
        width: calc(100% - 24px);
    }

    /* Code blocks — allow horizontal scroll without breaking layout */
    .message-content pre {
        overflow-x: auto;
        font-size: 0.8em;
        max-width: 100%;
    }

    /* Action buttons smaller on mobile */
    .message-actions {
        gap: 6px;
    }

    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }

    /* Modals full width on small screens */
    .secret-modal-content {
        width: 92%;
        max-width: 360px;
        padding: 20px;
    }

    /* User profile in sidebar — compact on mobile */
    #userProfile {
        padding: 12px 16px calc(env(safe-area-inset-bottom, 20px) + 12px) !important;
        border-radius: 0 !important;
        background: var(--card-bg) !important;
        border-top: 1px solid var(--border-subtle) !important;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1) !important;
        z-index: 100 !important;
    }

    .user-info-container {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    .user-name-text {
        font-weight: 600 !important;
        font-size: 14px !important;
        color: var(--text-primary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin-bottom: 2px !important;
    }

    .user-email-text {
        font-size: 11px !important;
        color: var(--text-secondary) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    #userProfile img {
        width: 40px !important;
        height: 40px !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        border: 1px solid var(--border-subtle) !important;
        margin-left: 12px !important;
        flex-shrink: 0 !important;
    }
}

/* Chat items */
.chat-item {
    padding: 8px 10px;
}

.chat-item-title {
    font-size: 13px;
}

.chat-item-time {
    font-size: 11px;
}

/* Hide text-only labels in navbar if needed */
.navbar-right .user-menu span {
    display: none;
}

/* =============================
   OTP MODAL REFINEMENT
   ============================= */
.otp-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
}

.otp-modal-overlay.active {
    display: flex;
}

.otp-modal-content {
    background: var(--card-bg);
    width: 95%;
    max-width: 400px;
    border-radius: 24px;
    padding: 40px 30px !important;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-subtle);
    position: relative;
    animation: modalSlideUp 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.otp-logo {
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
}

.otp-logo img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 20px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.otp-icon {
    display: none;
    /* Removed in favor of logo */
}

.otp-email-display {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 10px 0 25px;
}

#otpInput {
    background: var(--input-bg) !important;
    border: 2px solid var(--border-subtle) !important;
    border-radius: 16px !important;
    height: 70px !important;
    font-size: 2.2rem !important;
    letter-spacing: 0.5rem !important;
    text-align: center !important;
    font-family: 'Fira Code', 'Cascadia Code', monospace !important;
    color: var(--text-primary) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    width: 100% !important;
    max-width: 280px !important;
    margin: 0 auto;
}

#otpInput:focus {
    border-color: var(--accent-color) !important;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15) !important;
    transform: translateY(-2px);
}

.otp-resend-container {
    margin-top: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#resendTimerText {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

#otpCountdown {
    font-weight: 700;
    color: var(--accent-color);
}

.resend-link-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: underline;
    transition: all 0.2s ease;
    padding: 5px 10px;
}

.resend-link-btn:disabled {
    color: var(--text-muted);
    cursor: not-allowed;
    text-decoration: none;
    opacity: 0.5;
}

.otp-exit-hint {
    margin-top: 30px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.7;
}

/* =============================
   THEME SELECTION MODAL
   ============================= */
.theme-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
    overflow: visible !important;
}

.theme-modal-overlay.active {
    display: flex;
}

.theme-modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 440px;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-subtle);
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    position: relative;
    overflow: visible !important;
}

.theme-modal-overlay.active .theme-modal-content {
    transform: translateY(0);
}

.theme-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.theme-modal-title-group {
    display: flex;
    flex-direction: column;
}

.theme-modal-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.theme-modal-shortcut {
    font-size: 13px;
    color: #666666;
    font-weight: 500;
}

.theme-modal-close {
    background: transparent;
    border: none;
    color: #999999;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-modal-close:hover {
    background: var(--nav-btn-bg);
    color: var(--text-primary);
}

.theme-select-container {
    position: relative;
    width: 100%;
}

.theme-select-trigger {
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    padding: 14px 20px;
    border-radius: 12px;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
    z-index: 5;
}

.theme-select-trigger:hover {
    border-color: var(--accent-color);
    background: var(--hover-bg);
}

.theme-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: slideDown 0.3s cubic-bezier(0.19, 1, 0.22, 1);
}

.theme-dropdown.active {
    display: flex;
}

.theme-option {
    padding: 14px 20px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    border-bottom: 1px solid var(--border-subtle);
}

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

.theme-option:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.theme-option.selected {
    color: var(--accent-color);
    background: rgba(99, 102, 241, 0.1);
}

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

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

/* --- PREMIUM CODE BLOCKS --- */
.code-container {
    margin: 16px 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    background: var(--card-bg);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--secondary-bg);
    border-bottom: 1px solid var(--border-color);
}

.code-lang {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: 'Inter', sans-serif;
}

.copy-code-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    font-weight: 500;
}

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

.copy-code-btn.copied {
    border-color: #10b981;
    color: #10b981;
}

.code-content-wrapper {
    position: relative;
    max-height: none;
    transition: max-height 0.4s ease-in-out;
}

.code-container.collapsible:not(.expanded) .code-content-wrapper {
    max-height: 160px;
    overflow: hidden;
}

.code-expand-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(to top, var(--card-bg) 30%, transparent);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
    z-index: 10;
    pointer-events: none;
}

.code-container.expanded .code-expand-overlay {
    position: relative;
    height: auto;
    background: none;
    padding: 10px 0;
}

.expand-code-btn {
    pointer-events: auto;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.expand-code-btn:hover {
    background: var(--hover-bg);
    transform: translateY(-1px);
    border-color: var(--accent-color);
}

.expand-code-btn i {
    transition: transform 0.3s ease;
}

.code-container.expanded .expand-code-btn i {
    transform: rotate(180deg);
}

pre {
    background: var(--card-bg);
    padding: 16px;
    margin: 0;
    overflow-x: auto;
    position: relative;
}

code {
    font-family: 'Fira Code', 'Cascadia Code', 'Source Code Pro', monospace;
    font-size: 0.9em;
    color: #e2e8f0;
    line-height: 1.5;
}

/* Custom Scrollbar for Code Blocks and Chat Area */
pre::-webkit-scrollbar,
.messages-area::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

pre::-webkit-scrollbar-track,
.messages-area::-webkit-scrollbar-track {
    background: var(--primary-bg);
}

pre::-webkit-scrollbar-thumb,
.messages-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    border: 2px solid var(--primary-bg);
}

pre::-webkit-scrollbar-thumb:hover,
.messages-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* For Firefox */
pre,
.messages-area {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--primary-bg);
}

/* Code Preview Styles */
.run-code-btn {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.run-code-btn:hover {
    background: #10b981;
    color: white;
}

.run-code-btn.active {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.preview-container {
    display: none;
    width: 100%;
    background: white;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    margin-top: -1px;
    min-height: 200px;
    max-height: 500px;
    animation: slideIn 0.3s ease;
}

.preview-container.active {
    display: block;
}

.code-iframe {
    width: 100%;
    height: 100%;
    min-height: 250px;
    border: none;
}

.code-content-wrapper.preview-mode pre {
    display: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

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

/* Inline code */
:not(pre)>code {
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100vw;
        left: -100vw;
    }

    .sidebar.open {
        left: 0;
    }

    .chat-container {
        padding: 0 16px;
    }

    .input-container {
        padding: 16px;
    }

    .navbar {
        padding: 0 16px;
    }

    .input-wrapper {
        margin-bottom: 30px;
    }
}