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

:root {
    --sa-top: env(safe-area-inset-top, 0px);
    --sa-bottom: env(safe-area-inset-bottom, 0px);
    --sa-left: env(safe-area-inset-left, 0px);
    --sa-right: env(safe-area-inset-right, 0px);

    --primary-bg: #ffffff;
    --secondary-bg: #f8fafc;
    --card-bg: #ffffff;
    --card-bg-rgb: 255, 255, 255;
    --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;
    --menu-bg: var(--card-bg);
    --menu-border: var(--border-color);
    --menu-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    --popup-bg: var(--card-bg);
    --popup-border: var(--border-color);
}

/* Global Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}


[data-theme="dark"] {
    --primary-bg: #121212;
    --secondary-bg: #1e1e1e;
    --card-bg: #252525;
    --card-bg-rgb: 37, 37, 37;
    --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;
    --card-bg-rgb: 17, 17, 17;
    --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;
}

html {
    background: var(--primary-bg);
}

body {
    font-family: '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);
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

/* Platform Specific Refinements */
html.is-ios body {
    /* Prevent rubber-banding on iOS */
    position: fixed;
    width: 100%;
}

@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: 'Outfit', '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: 'Outfit', '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: 24px;
}

/* Suggestion chips on welcome screen */
.welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-width: 560px;
    margin: 0 auto;
}

.welcome-chip {
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.welcome-chip:hover {
    background: var(--hover-bg);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.welcome-chip i {
    color: var(--accent-color);
    font-size: 13px;
    margin-right: 2px;
}

.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: 4px 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 {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.message-content table::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.message-content table::-webkit-scrollbar-track {
    background: rgba(128, 128, 128, 0.1);
    border-radius: 4px;
}

.message-content table::-webkit-scrollbar-thumb {
    background: rgba(161, 161, 170, 0.6);
    border-radius: 4px;
}

.message-content table::-webkit-scrollbar-thumb:hover {
    background: rgba(161, 161, 170, 0.9);
}

.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;
    word-break: normal;
    overflow-wrap: normal;
    min-width: 100px;
}

.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);
}

.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 {
    padding: 10px 24px 30px;
    background: transparent;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    z-index: 10;
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
    min-height: 60px;
    height: auto;
    background: rgba(var(--card-bg-rgb, 255, 255, 255), 0.7);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 12px;
    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.1);
}

[data-theme="dark"] .input-wrapper,
[data-theme="midnight"] .input-wrapper {
    background: rgba(30, 30, 30, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

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

.message-input {
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    resize: none;
    font-family: inherit;
    overflow-y: auto;
}

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

.input-disclaimer {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 8px;
    opacity: 0.7;
    width: 100%;
    line-height: 1.4;
}

/* Bottom Actions Row */
.input-actions-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 4px;
}

.actions-left,
.actions-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Rounded Buttons */
.plus-btn,
.mic-btn,
.send-btn,
.smart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    color: var(--text-secondary);
}

.plus-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--border-subtle);
    font-size: 14px;
}

.plus-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    transform: scale(1.05);
}

.smart-btn {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--border-subtle);
    font-size: 13px;
    font-weight: 600;
    gap: 6px;
    color: var(--text-primary);
}

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

.mic-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
}

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

.send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--text-primary);
    color: var(--primary-bg);
    font-size: 14px;
}

.send-btn:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.send-btn.voice-mode-btn {
    background: linear-gradient(135deg, #f0f9ff 0%, #bae6fd 100%);
    color: #0284c7;
    box-shadow: 0 2px 10px rgba(186, 230, 253, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn.voice-mode-btn:hover {
    background: linear-gradient(135deg, #ffffff 0%, #e0f2fe 100%);
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

.voice-mode-icon {
    width: 16px;
    height: 16px;
    animation: pulseIcon 2s infinite ease-in-out;
}

@keyframes pulseIcon {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

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

/* Plus Menu Popup */
.plus-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 0;
    width: 250px;
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 6px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none !important;
    flex-direction: column;
    z-index: 1001;
    animation: menuFadeIn 0.2s cubic-bezier(0.19, 1, 0.22, 1);
}

.plus-menu.active {
    display: flex !important;
}

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

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

.plus-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.plus-menu-item:hover {
    background: var(--hover-bg);
    transform: translateX(4px);
}

.plus-menu-item i {
    width: 20px;
    font-size: 16px;
    color: var(--text-secondary);
}

.plus-menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 4px 8px;
}

.plus-menu-toggle {
    margin-left: auto;
    width: 34px;
    height: 20px;
    position: relative;
    cursor: pointer;
}

.toggle-track {
    width: 100%;
    height: 100%;
    background: var(--border-subtle);
    border-radius: 10px;
    transition: all 0.3s;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.plus-menu-item.active .toggle-track {
    background: var(--accent-color);
}

.plus-menu-item.active .toggle-thumb {
    left: 17px;
}

.eco-leaf-icon {
    color: var(--text-secondary);
    transition: color 0.3s;
}

.plus-menu-item.eco-active .eco-leaf-icon {
    color: #22c55e !important;
}

.plus-menu-item.eco-active .toggle-track {
    background: #22c55e !important;
}

.plus-menu-item.eco-active .toggle-thumb {
    left: 17px;
}

/* Active Mode Tag (Image Gen / Deep Search pill shown in input) */
#activeModeTag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    margin-bottom: 4px;
}

.mode-tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    background: var(--hover-bg);
    border: 1px solid var(--border-subtle);
    font-size: 13px;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tag-pill:hover {
    background: var(--border-subtle);
}

.mode-tag-pill i {
    font-size: 13px;
    color: var(--accent-color);
}

.mode-tag-pill .mode-tag-close {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 2px;
    cursor: pointer;
}

/* Pill-style image / file previews */
#imagePreviewContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 4px 2px;
    margin-bottom: 2px;
}

.preview-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    background: var(--hover-bg);
    border: 1px solid var(--border-subtle);
    font-size: 13px;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    cursor: pointer;
    max-width: 160px;
    transition: background 0.2s;
}

.preview-pill:hover {
    background: var(--border-subtle);
}

.preview-pill img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.preview-pill .pill-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.preview-pill .pill-remove {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--text-secondary);
    color: var(--primary-bg);
    font-size: 9px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}

.preview-pill .pill-remove:hover {
    background: #ef4444;
}


.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: 5px;
    }
}

/* --- 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: 4px 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: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(-5px);
    z-index: 10;
    max-width: calc(100% - 20px);
    flex-wrap: wrap;
    justify-content: flex-end;
}

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

.img-btn {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    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 i {
    font-size: 14px;
}

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

/* Adattamento per anteprime molto piccole (es. 70px) */
.gen-image-wrapper[style*="width:70px"] .img-hover-actions,
.gen-image-wrapper[style*="width: 70px"] .img-hover-actions {
    top: 5px;
    right: 5px;
    gap: 4px;
}

.gen-image-wrapper[style*="width:70px"] .img-btn,
.gen-image-wrapper[style*="width: 70px"] .img-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
}

.gen-image-wrapper[style*="width:70px"] .img-btn i,
.gen-image-wrapper[style*="width: 70px"] .img-btn i {
    font-size: 10px;
}

/* =============================
   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: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-subtle);
    margin-right: 12px;
    flex-shrink: 0;
}

#userProfile .chevron-icon {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 14px;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#userProfile.user-profile-btn {
    display: flex;
    align-items: center;
    width: calc(100% - 24px);
    margin: 12px;
    padding: 10px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}

#userProfile.user-profile-btn:hover {
    background: var(--hover-bg);
}

.profile-divider {
    margin: 0 12px;
    list-style: none;
    /* In caso sia un li usato per divider */
}

/* === ACCOUNT MENU === */
.account-menu-overlay {
    position: fixed;
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 2000;
    display: none !important;
    flex-direction: column;
    padding: 8px;
    min-width: 240px;
    animation: menuSlideUp 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.account-menu-overlay.active {
    display: flex !important;
}

@keyframes menuSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }

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

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-primary);
    text-decoration: none;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    width: 100%;
    text-align: left;
}

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

.menu-item i {
    width: 18px;
    text-align: center;
    color: var(--text-secondary);
}

.menu-item.danger {
    color: #ef4444;
}

.menu-item.danger i {
    color: #ef4444 !important;
}

.menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.08);
}

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

/* Sub-menu panel (Flyout) */
.submenu-panel {
    display: none;
    flex-direction: column;
    position: absolute;
    right: -245px;
    /* Spostato a destra del menu principale */
    top: -1px;
    /* Allineato in alto */
    background: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    padding: 8px;
    min-width: 240px;
    z-index: 2001;
    animation: submenuFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes submenuFadeIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

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

.submenu-panel.active {
    display: flex;
}

/* Freccia a destra del menu 'Aiuto' */
.menu-item .arrow-icon {
    margin-left: auto;
    font-size: 12px;
    opacity: 0.7;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.menu-item:hover .arrow-icon {
    opacity: 1;
    transform: translateX(2px);
}



/* === LANGUAGE POPUP === */
.lang-popup-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px 0;
}

.lang-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

.lang-item:hover {
    border-color: var(--accent-color);
    background: var(--hover-bg);
}

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

/* =============================
   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,
    .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;
        margin-left: 8px;
        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%;
    }

    /* Welcome chips on mobile — smaller, wrap neatly */
    .welcome-chips {
        gap: 6px;
        padding: 0 4px;
    }

    .welcome-chip {
        font-size: 13px;
        padding: 7px 13px;
        border-radius: 16px;
    }

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

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

    /* Buttons inside the input row */
    .upload-btn,
    .mic-btn,
    .camera-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;
        padding-left: 12px !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 !important;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
}

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

.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 !important;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
    overflow: visible !important;
}

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

.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: 5px;
    }
}

/* --- GUEST DEMO MODE UI --- */
.limit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: rgba(15, 15, 15, 0.5);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    will-change: transform, opacity;
    transform: translateZ(0);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    animation: fadeIn 0.3s ease;
}

.limit-content {
    text-align: center;
    color: white;
    padding: 20px;
}

.limit-content h3 {
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.cta-register-btn,
.cta-register-overlay-btn {
    border: none;
    cursor: pointer;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.2s;
    pointer-events: all;
}

.cta-register-overlay-btn {
    background: #FFFFFF;
    color: #000000;
    margin-top: 15px;
    padding: 10px 20px;
}

.cta-register-overlay-btn:hover {
    background: #e0e0e0;
    transform: scale(1.05);
}

body[data-theme='light'] .cta-register-btn {
    background: #000000;
    color: #FFFFFF;
}

body[data-theme='dark'] .cta-register-btn {
    background: #FFFFFF;
    color: #000000;
}

body[data-theme='midnight'] .cta-register-btn {
    background: #FFFFFF;
    color: #000000;
}

body[data-theme='system'] .cta-register-btn {
    background: #000000;
    color: #FFFFFF;
}

.cta-register-btn:hover {
    transform: scale(1.05);
}

/* ====== NEW PREFERENCES MODALS ====== */
.preferences-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: none !important;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.preferences-modal-overlay.active {
    display: flex !important;
}

.preferences-modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 440px;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-subtle);
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.pref-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.pref-modal-header.centered-header {
    justify-content: center;
    position: relative;
}

.pref-modal-header.centered-header h2 {
    margin: 0;
}

.pref-modal-header.centered-header .pref-modal-close {
    position: absolute;
    right: 0;
}

.pref-modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.pref-modal-close {
    background: var(--nav-btn-bg);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.profile-edit-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.profile-image-wrapper {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
}

.profile-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-hover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    opacity: 0;
    transition: opacity 0.2s;
}

.profile-image-wrapper:hover .image-hover-overlay {
    opacity: 1;
}

.pref-input-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pref-input-group label {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.pref-input-group input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.pref-input-group input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.pref-modal-footer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 30px;
}

.pref-btn-primary {
    background: #ffffff;
    color: #000000;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

[data-theme="light"] .pref-btn-primary {
    background: #0f172a;
    color: #ffffff;
}

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

.pref-btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    padding: 8px 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    outline: none !important;
}

.pref-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent-color) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pref-btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2) !important;
    padding: 8px 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    outline: none !important;
}

.pref-btn-danger:hover {
    background: #ef4444;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}


/* === CUSTOM VOICE CARD SELECTOR === */
.custom-voice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.voice-option-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.voice-option-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(148, 163, 184, 0.4);
}

.voice-option-card.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.15);
}

[data-theme="light"] .voice-option-card {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .voice-option-card:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .voice-option-card.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: #3b82f6;
}

.voice-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--nav-btn-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-primary);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.voice-option-card.active .voice-icon {
    background: #3b82f6;
    color: white;
}

.voice-details {
    display: flex;
    flex-direction: column;
}

.v-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.v-desc {
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.8;
}

@media (max-width: 480px) {
    .custom-voice-grid {
        grid-template-columns: 1fr;
    }
}

/* Language List */
.lang-content {
    max-height: 80vh;
}

.lang-scroll-area {
    overflow-y: auto;
    margin-right: -10px;
    padding-right: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.lang-scroll-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.lang-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: background 0.2s;
}

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

.lang-option .lang-check {
    color: var(--text-primary);
    font-size: 14px;
    opacity: 0;
}

.lang-option.selected .lang-check {
    opacity: 1;
}

.lang-list-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 8px 0;
}

/* Submenu a tendina su mobile (Accordion) anziché laterale (Flyout) */
@media (max-width: 768px) {
    .submenu-panel {
        position: relative !important;
        right: 0 !important;
        top: 0 !important;
        min-width: 100% !important;
        margin-top: 8px !important;
        box-shadow: none !important;
        background: var(--hover-bg) !important;
        border-radius: 8px !important;
        border: none !important;
    }
}

/* ==============================================================================
   DEEP RESEARCH UI
   ============================================================================== */

.deep-research-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px 20px;
    min-width: 280px;
    max-width: 520px;
    font-family: 'Inter', sans-serif;
}

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

.dr-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--accent-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: drSpin 0.8s linear infinite;
    flex-shrink: 0;
}

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

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

.dr-steps {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dr-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0;
    transition: color 0.3s;
}

.dr-step.done {
    color: var(--text-primary);
}

.dr-step-icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.dr-step-dots {
    margin-left: auto;
    display: flex;
    gap: 3px;
}

.dr-step-dots span {
    display: block;
    width: 4px;
    height: 4px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: drPulse 1.2s infinite;
}

.dr-step-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.dr-step-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes drPulse {

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

    50% {
        opacity: 1;
        transform: scale(1);
    }
}

.dr-step.done .dr-step-dots {
    color: #22c55e;
    font-weight: 700;
}

.deep-research-result {
    font-family: 'Inter', sans-serif;
}

.dr-result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.dr-result-header i {
    color: var(--accent-color);
}

.dr-sources-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.dr-source-card {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    background: var(--hover-bg);
    border: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--accent-color);
    text-decoration: none;
    transition: background 0.2s;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dr-source-card:hover {
    background: var(--border-subtle);
    text-decoration: underline;
}

/* ==============================================================================
   NEW INPUT BAR — MOBILE REFINEMENTS (max-width: 768px)
   ============================================================================== */
@media (max-width: 768px) {

    /* Input wrapper — tighter on mobile */
    .input-wrapper {
        border-radius: 18px;
        padding: 10px 10px 8px;
    }

    /* Textarea — 16px prevents iOS auto-zoom */
    .message-input {
        font-size: 16px !important;
        min-height: 26px;
        padding-top: 2px;
        padding-bottom: 2px;
    }

    /* Bottom action bar — compact */
    .input-actions-bottom {
        padding-top: 6px;
        gap: 6px;
    }

    /* Plus button — slightly smaller */
    .plus-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    /* Mic and send buttons — smaller */
    .mic-btn,
    .send-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    /* Plus menu — open ABOVE the button, full-width on very small screens */
    .plus-menu {
        bottom: calc(100% + 8px);
        left: 0;
        right: auto;
        min-width: min(280px, 90vw);
        max-width: 90vw;
        border-radius: 16px;
        padding: 6px 4px;
    }

    .plus-menu-item {
        padding: 11px 14px;
        font-size: 14px;
        gap: 10px;
        border-radius: 10px;
    }

    /* Mode tag pill — full width */
    #activeModeTag {
        padding: 4px 2px;
    }

    .mode-tag-pill {
        font-size: 12px;
        padding: 4px 10px;
    }

    /* Image preview pills — wrap nicely */
    #imagePreviewContainer {
        gap: 5px;
        padding: 5px 2px 2px;
    }

    .preview-pill {
        max-width: 140px;
        font-size: 12px;
        padding: 5px 8px;
        border-radius: 10px;
    }

    .preview-pill img {
        width: 24px;
        height: 24px;
    }

    /* Deep research panel — full width */
    .deep-research-panel {
        max-width: 100%;
        min-width: 0;
        border-radius: 14px;
        padding: 14px 16px;
    }

    .dr-title {
        font-size: 13px;
    }

    .dr-step {
        font-size: 12px;
    }

    /* Deep research report */
    .deep-research-result .dr-sources-bar {
        gap: 5px;
    }

    .dr-source-card {
        font-size: 11px;
        padding: 3px 8px;
        max-width: 160px;
    }

    /* Input container — extra bottom padding for address bar and safe area */
    .input-container {
        padding: 10px 10px calc(var(--sa-bottom) + 15px);
        padding-left: calc(var(--sa-left) + 10px);
        padding-right: calc(var(--sa-right) + 10px);
    }

    /* iOS search bar/address bar tweak */
    .is-ios .input-container {
        padding-bottom: calc(var(--sa-bottom) + 25px);
    }
}

/* Extra-small screens (320px phones) */
@media (max-width: 380px) {
    .plus-menu {
        min-width: calc(100vw - 24px);
        left: 0;
    }

    .preview-pill {
        max-width: 120px;
    }

    .plus-btn,
    .mic-btn,
    .send-btn {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }
}


/* ==========================================================================
   WEATHER CARD UI - MODERN & PREMIUM (WIDE DASHBOARD & BREAKOUT)
   ========================================================================== */
.message.weather-message {
    width: 100% !important;
    align-items: flex-start !important;
    /* Changed from center to side-aligned (laterali) */
    margin: 30px 0 !important;
}

.message.weather-message .message-content {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    max-width: 1000px !important;
    width: 100% !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.weather-card {
    background: #ffffff;
    border-radius: 35px;
    padding: 35px;
    width: 100%;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.08);
    color: #000000;
    font-family: 'Inter', -apple-system, sans-serif;
    position: relative;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    animation: breakoutReveal 1s cubic-bezier(0.22, 1, 0.36, 1);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

[data-theme='dark'] .weather-card,
[data-theme='midnight'] .weather-card {
    background: #111111;
    color: #ffffff;
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.weather-header {
    margin-bottom: 25px;
}

.weather-location {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 10px;
    display: block;
    letter-spacing: -0.04em;
    opacity: 0.9;
}

.weather-current-group {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 25px;
    margin-bottom: 40px;
}

.weather-temp {
    font-size: 100px;
    font-weight: 950;
    line-height: 0.9;
    letter-spacing: -0.07em;
}

.weather-desc {
    font-size: 30px;
    font-weight: 600;
    opacity: 0.7;
}

.weather-forecast {
    display: flex;
    justify-content: flex-start;
    /* Changed from space-between to side-aligned (laterali) */
    align-items: center;
    gap: 15px;
    overflow-x: auto;
    padding: 20px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme='dark'] .weather-forecast,
[data-theme='midnight'] .weather-forecast {
    border-top-color: rgba(255, 255, 255, 0.1);
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* CUSTOM SCROLLBAR - Premium SREBPS Style */
.weather-forecast::-webkit-scrollbar {
    height: 6px;
    display: block;
    /* Force visible for customization */
}

.weather-forecast::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
    border-radius: 10px;
}

[data-theme='dark'] .weather-forecast::-webkit-scrollbar-track,
[data-theme='midnight'] .weather-forecast::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

.weather-forecast::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    transition: background 0.3s;
}

[data-theme='dark'] .weather-forecast::-webkit-scrollbar-thumb,
[data-theme='midnight'] .weather-forecast::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
}

.weather-forecast::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color, #3b82f6);
}

.forecast-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 14px;
    border-radius: 24px;
    min-width: 75px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
}

.forecast-item.active {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme='dark'] .forecast-item.active,
[data-theme='midnight'] .forecast-item.active {
    background: rgba(255, 255, 255, 0.08);
}

.forecast-day {
    font-size: 14px;
    font-weight: 800;
    margin-bottom: 12px;
    color: rgba(0, 0, 0, 0.4);
    text-align: center;
    text-transform: uppercase;
}

[data-theme='dark'] .forecast-day,
[data-theme='midnight'] .forecast-day {
    color: rgba(255, 255, 255, 0.5);
}

.forecast-item.active .forecast-day {
    color: inherit;
    opacity: 1;
}

.forecast-icon {
    font-size: 34px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.forecast-item:hover {
    transform: translateY(-6px);
    background: rgba(0, 0, 0, 0.03);
}

[data-theme='dark'] .forecast-item:hover,
[data-theme='midnight'] .forecast-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

@keyframes wideReveal {
    from {
        opacity: 0;
        filter: blur(10px);
        transform: translateY(10px);
    }

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

/* Specific Weather Icons - High Contrast */
.wi-sunny {
    color: #facc15;
}

.wi-cloudy {
    color: #94a3b8;
}

.wi-rainy {
    color: #3b82f6;
}

.wi-snowy {
    color: #93c5fd;
}

.wi-thunderstorm {
    color: #fbbf24;
}

.wi-moon {
    color: #f1f5f9;
}

@media (max-width: 900px) {
    .weather-card {
        padding: 24px;
        max-width: 100%;
    }

    .weather-temp {
        font-size: 70px;
    }
}

/* === GROK-STYLE HEADER & MODEL SELECTOR === */
.grok-navbar-center {
    display: flex;
    justify-content: center;
    flex: 1;
    position: relative;
    z-index: 100;
}

.grok-selector {
    display: flex;
    align-items: center;
}

.grok-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    height: 38px;
}

.grok-btn:hover {
    background: var(--hover-bg);
    opacity: 0.8;
}

.grok-plus-icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.grok-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.grok-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    top: auto;
    left: 50%;
    transform: translateX(-50%) translateY(10px) scale(0.95);
    background: #1a1a1f;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 8px;
    width: 280px;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    gap: 4px;
    z-index: 2000;
    transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
}

.grok-menu.active {
    display: flex;
    transform: translateX(-50%) translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.grok-menu .model-option {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    text-align: left;
}

.grok-menu .model-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.grok-menu .model-text {
    display: flex;
    flex-direction: column;
}

.grok-menu .model-text strong {
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
}

.grok-menu .model-text span {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 2px;
}

.grok-menu .check-icon {
    position: absolute;
    right: 14px;
    width: 16px;
    height: 16px;
    color: var(--accent-color);
    opacity: 0;
}

.grok-menu .model-option.active .check-icon {
    opacity: 1;
}

@media (max-width: 480px) {
    .grok-menu {
        width: 90vw;
    }
}

/* === GROK MENU — THEME OVERRIDES === */

/* Light theme: white card with dark text */
[data-theme='light'] .grok-menu {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme='light'] .grok-menu .model-text strong {
    color: #0f0f0f;
}

[data-theme='light'] .grok-menu .model-text span {
    color: rgba(0, 0, 0, 0.5);
}

[data-theme='light'] .grok-menu .model-option:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme='light'] .grok-menu .check-icon {
    color: #3b82f6;
}

/* Midnight theme: pure black, ultra-subtle border */
[data-theme='midnight'] .grok-menu {
    background: #000000;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.9), 0 2px 8px rgba(0, 0, 0, 0.5);
}

[data-theme='midnight'] .grok-menu .model-text strong {
    color: #f0f0f0;
}

[data-theme='midnight'] .grok-menu .model-text span {
    color: rgba(255, 255, 255, 0.4);
}

[data-theme='midnight'] .grok-menu .model-option:hover {
    background: rgba(255, 255, 255, 0.05);
}


/* === CAPTCHA HIDER === */
.grecaptcha-badge {
    visibility: hidden !important;
}

/* === RECAPTCHA FOOTER === */
.recaptcha-footer {
    width: 100%;
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    padding: 15px 10px;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.recaptcha-footer:hover {
    opacity: 1;
}

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

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

.message-content.has-image {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
}

.gen-image-wrapper {
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.gen-image-wrapper img {
    border: 1px solid rgba(255, 255, 255, 0.08); /* Bordo sottile e discreto */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease;
}

[data-theme="light"] .gen-image-wrapper img {
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* ==============================================================================
   IMAGE GENERATION LOADING — SPHERE DOT GRID STYLE (ENHANCED)
   ============================================================================== */

.img-gen-loader {
    width: 100%;
    max-width: 480px;
    border-radius: 24px;
    background: var(--card-bg, #1c1c1e);
    padding: 20px 24px 15px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    animation: imgLoaderEntrance 0.3s ease-out;
    overflow: hidden;
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

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

.img-gen-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #ffffff);
    margin-bottom: 12px;
    letter-spacing: -0.02em;
    transition: opacity 0.3s ease;
    line-height: 1.2;
}

/* Griglia di punti animata con effetto sfera */
.img-gen-dots-grid {
    display: grid;
    grid-template-columns: repeat(14, 1fr);
    gap: 10px;
    margin-bottom: 5px;
    width: 100%;
}

.img-gen-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, var(--text-primary, #ffffff), var(--text-muted, rgba(255,255,255,0.2)));
    box-shadow: 0 0 6px var(--text-muted, rgba(255,255,255,0.1));
    animation: dotSphereWave 2.8s ease-in-out infinite;
    opacity: 0.15;
}

@keyframes dotSphereWave {
    0%, 100% { 
        opacity: 0.12; 
        transform: scale(0.85);
        filter: blur(0.3px);
    }
    50% { 
        opacity: 0.95; 
        transform: scale(1.25);
        box-shadow: 0 0 12px var(--accent-color, #6366f1);
        filter: blur(0);
    }
}

/* Timer pulito e compatto */
.img-gen-timer {
    font-size: 12px;
    color: var(--text-muted, rgba(255,255,255,0.35));
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.5s ease;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.img-gen-timer.visible { opacity: 1; }

/* === MENTIONS LIST === */
.mentions-list {
    position: absolute;
    bottom: 100%;
    left: 0;
    width: 280px;
    max-height: 300px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    z-index: 1000;
    padding: 8px;
    animation: modalSlideUp 0.2s ease-out;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    font-size: 14px;
}

.mention-item:hover, .mention-item.active {
    background: var(--hover-bg);
}

.mention-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.mention-icon img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}


/* === SETTINGS MODAL === */
.settings-modal-content {
    display: flex;
    width: 800px;
    max-width: 95vw;
    height: 550px;
    max-height: 85vh;
    background: var(--card-bg);
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: modalSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.settings-sidebar {
    width: 220px;
    background: var(--secondary-bg);
    padding: 24px 12px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

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

.settings-sidebar-item.active {
    background: var(--card-bg);
    color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.settings-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

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

.settings-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.settings-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.settings-body::-webkit-scrollbar {
    width: 6px;
}

.settings-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}


.settings-tab-content {
    display: none;
}

.settings-tab-content.active {
    display: block;
}

/* === CONNECTORS LIST === */
.connectors-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

.connector-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    gap: 12px;
}


.connector-item:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.connector-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.connector-name {
    font-size: 14px;
    font-weight: 600;
}

.connector-status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* === ACCOUNT SETTINGS === */
.account-settings {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.account-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
}

.account-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.account-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.account-value {
    font-size: 16px;
    font-weight: 500;
}

@media (max-width: 768px) {
    .settings-modal-content {
        flex-direction: column;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .settings-sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 12px;
        height: auto;
    }
    .settings-sidebar-item {
        padding: 8px 12px;
        white-space: nowrap;
    }
}