/* Reset base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    width: 100%;
    min-height: 100dvh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
}

/* Layout principale */
.app-container {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.chat-container {
    width: min(900px, calc(100% - 40px));
    max-width: 100%;
    height: auto;
    min-height: 85vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 20px;
    box-shadow:
        0 25px 50px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.chat-header,
.chat-footer {
    width: 100%;
    flex: 0 0 auto;
}

.chat-messages-container {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
}

.chat-messages {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 30px;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: inherit;
}

/* Header */
.chat-header {
    position: relative;
    padding: 25px 30px;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 12px 24px rgba(15,23,42,0.18);
}

.chat-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    pointer-events: none;
}

.header-content h2 {
    font-size: 1.8rem;
    font-weight: 600;
}

.header-content p {
    margin-top: 6px;
    font-size: 0.95rem;
    opacity: 0.85;
}

/* Menu button migliorato */
.menu-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.28);
    background: linear-gradient(135deg, rgba(102,126,234,0.45), rgba(118,75,162,0.35));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 24px rgba(102,126,234,0.28);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.menu-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 18px 32px rgba(102,126,234,0.35);
    border-color: rgba(255,255,255,0.6);
}

.menu-button:active {
    transform: translateY(-1px);
    box-shadow: 0 10px 18px rgba(102,126,234,0.3);
}

.menu-button i {
    font-size: 18px;
}

/* Dropdown migliorato */
.menu-dropdown {
    position: relative;
}

.dropdown-content {
    position: fixed;
    top: 82px;
    right: 28px;
    min-width: 340px;
    max-height: clamp(400px, 60vh, 520px);
    overflow-y: auto;
    display: none;
    flex-direction: column;
    gap: 20px;
    padding: 26px 24px 24px;
    border-radius: 28px;
    background:
        radial-gradient(140% 140% at 0% 0%, rgba(123,97,255,0.45) 0%, transparent 60%),
        radial-gradient(120% 120% at 100% 100%, rgba(72,149,239,0.4) 0%, transparent 55%),
        linear-gradient(145deg, rgba(18,24,38,0.96), rgba(34,44,68,0.94));
    border: 1px solid rgba(123,142,255,0.35);
    box-shadow:
        0 36px 72px rgba(10,12,24,0.55),
        inset 0 1px 0 rgba(255,255,255,0.08);
    backdrop-filter: blur(18px);
    transform-origin: top right;
    scrollbar-width: thin;
    scrollbar-color: rgba(123,142,255,0.45) transparent;
    color: #eef2ff;
}

.dropdown-content.show {
    display: flex;
}

.dropdown-header {
    padding: 0 0 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: linear-gradient(135deg, rgba(102,126,234,0.35), rgba(118,75,162,0.3));
    border-radius: 18px;
    text-align: center;
    margin: -6px 0 12px;
}

.dropdown-header h3 {
    padding: 18px;
    font-size: 1.38rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #ffffff;
}

.dropdown-section-title {
    font-size: 0.8rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: rgba(226,232,255,0.65);
}

.menu-item-block {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
    border-radius: 20px;
    padding: 18px;
    color: rgba(241,244,255,0.9);
}

.menu-item-block label {
    font-size: 0.92rem;
    color: #f1f4ff;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255,255,255,0.06);
}

.toggle-label { color: #e8ebff; font-size: 0.95rem; font-weight: 600; }

#speedControl {
    width: 100%;
    accent-color: #7186ff;
}

.menu-button-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.menu-button-item {
    flex: 1;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.07);
    color: #e9ecff;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.menu-button-item:hover {
    background: rgba(102,126,234,0.24);
    transform: translateY(-2px);
}

.mode-selector-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.mode-option {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 18px;
    border: 1px solid rgba(123,142,255,0.22);
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(123,142,255,0.18), transparent 70%),
        linear-gradient(150deg, rgba(28,36,58,0.92), rgba(36,46,72,0.88));
    color: rgba(238,240,255,0.92);
    font-size: 0.86rem;
    line-height: 1.45;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.mode-option .mode-emoji {
    font-size: 1.8rem;
    line-height: 1;
    flex-shrink: 0;
}

.mode-option .mode-title {
    font-weight: 600;
    font-size: 1rem;
    color: #ffffff;
    margin-bottom: 4px;
    display: block;
}

.mode-option .mode-description {
    font-size: 0.9rem;
    color: rgba(226,232,255,0.72);
}

.mode-option.active {
    border-color: rgba(123,142,255,0.6);
    box-shadow: 0 22px 45px rgba(18,22,48,0.55);
    transform: translateY(-2px);
    background:
        radial-gradient(140% 140% at 0% 0%, rgba(123,142,255,0.35), transparent 70%),
        linear-gradient(150deg, rgba(34,44,72,0.96), rgba(48,60,92,0.92));
}

.mode-option:hover {
    border-color: rgba(123,142,255,0.45);
    transform: translateY(-1px);
    box-shadow: 0 18px 36px rgba(18,22,48,0.45);
}

/* Area messaggi */
.chat-messages-container {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
}

.chat-messages {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 30px;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: inherit;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.4);
}

.message {
    max-width: 80%;
    padding: 18px 24px;
    margin: 18px 0;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 15px;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

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

.user-message {
    margin-left: auto;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-bottom-right-radius: 8px;
    box-shadow: 0 10px 25px rgba(102,126,234,0.35);
}

.ai-message {
    margin-right: auto;
    background: linear-gradient(135deg, #ffffff 0%, #f3f4f6 100%);
    color: #1f2937;
    border: 2px solid rgba(102,126,234,0.12);
    border-bottom-left-radius: 8px;
    box-shadow: 0 6px 18px rgba(15,23,42,0.12);
}

.component-message {
    margin-right: auto;
    background: linear-gradient(135deg, #e1f5fe 0%, #b3e5fc 100%);
    color: #0c5460;
    border-left: 4px solid #03a9f4;
}

/* Stato “pensando” */
.thinking {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 70%;
    padding: 14px 20px;
    margin: 14px 0;
    border-radius: 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-left: 4px solid #667eea;
}

.dot-flashing {
    position: relative;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #667eea;
    animation: dotFlashing 1s infinite linear alternate;
}

.dot-flashing::before,
.dot-flashing::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #667eea;
    animation: dotFlashing 1s infinite alternate;
}

.dot-flashing::before { left: -15px; animation-delay: 0.5s; }
.dot-flashing::after { left: 15px; animation-delay: 1s; }

@keyframes dotFlashing {
    0% { background-color: #667eea; }
    50%,100% { background-color: rgba(102,126,234,0.25); }
}

/* Quick buttons */
.quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-bottom: 18px;
}

.quick-btn {
    padding: 10px 16px;
    border-radius: 25px;
    border: none;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: 0.3s;
}

.quick-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s;
}

.quick-btn:hover::before {
    transform: translateX(100%);
}

.btn-primary { background: linear-gradient(135deg, #3498db, #2980b9); }
.btn-success { background: linear-gradient(135deg, #2ecc71, #27ae60); }
.btn-danger  { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.btn-warning { background: linear-gradient(135deg, #f39c12, #e67e22); }

/* Input */
.chat-footer {
    padding: 25px 30px;
    background: linear-gradient(to top, #ffffff 0%, #f8f9fa 100%);
    border-top: 1px solid rgba(0,0,0,0.08);
    border-radius: 0 0 20px 20px;
}

.chat-input {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    padding: 18px;
    border-radius: 24px;
    background: #fff;
    border: 2px solid rgba(102,126,234,0.12);
    box-shadow:
        0 6px 18px rgba(102,126,234,0.12),
        inset 0 1px 0 rgba(255,255,255,0.6);
    transition: 0.3s;
}

.chat-input:focus-within {
    border-color: rgba(102,126,234,0.4);
    box-shadow: 0 12px 30px rgba(102,126,234,0.25);
}

.chat-input textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    min-height: 28px;
    max-height: 160px;
    font-size: 15px;
    line-height: 1.5;
    background: transparent;
    color: #1f2937;
}

.chat-input textarea::placeholder {
    color: #9ca3af;
}

.btn-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(102,126,234,0.35);
    transition: 0.3s;
}

.btn-send:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 14px 30px rgba(102,126,234,0.45);
}

/* Fun mode */
.fun-mode .chat-header {
    background: linear-gradient(45deg, #FF5722, #FF9800, #FFEB3B, #4CAF50, #2196F3, #9C27B0);
    background-size: 400% 400%;
    animation: gradientShift 10s ease infinite;
}

.fun-mode .message.ai-message {
    background: linear-gradient(135deg, #FFD54F 0%, #FFC107 100%);
    color: #333;
}

.fun-mode .btn-send {
    background: linear-gradient(135deg, #FF5722, #9C27B0);
}

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

/* Modal */
.modal {
    backdrop-filter: blur(10px);
}

.modal-content {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    box-shadow:
        0 25px 50px rgba(0,0,0,0.25),
        0 0 0 1px rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    overflow: hidden;
}

.modal-header {
    padding: 20px 24px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}

.modal#welcomeModal {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
    backdrop-filter: blur(16px);
    background: rgba(13,17,27,0.55);
}

.welcome-modal {
    max-width: 520px;
    max-height: 90vh;
    border-radius: 28px;
    background:
        radial-gradient(140% 140% at 0% 0%, rgba(123,97,255,0.45) 0%, transparent 60%),
        radial-gradient(120% 120% at 100% 100%, rgba(72,149,239,0.4) 0%, transparent 55%),
        linear-gradient(145deg, rgba(18,24,38,0.96), rgba(34,44,68,0.94));
    border: 1px solid rgba(123,142,255,0.35);
    box-shadow: 0 36px 72px rgba(10,12,24,0.55), inset 0 1px 0 rgba(255,255,255,0.08);
    overflow: hidden;
    color: #eef2ff;
    display: flex;
    flex-direction: column;
}

.welcome-modal .modal-header {
    padding: 26px 30px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: linear-gradient(135deg, rgba(102,126,234,0.35), rgba(118,75,162,0.3));
    display: flex;
    align-items: center;
    justify-content: center; /* Centra il titolo */
    flex-shrink: 0;
}

.welcome-modal .modal-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.welcome-modal .close-modal {
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: rgba(255,255,255,0.75);
    transition: transform 0.2s ease, color 0.2s ease;
}

.welcome-modal .close-modal:hover {
    color: #ffffff;
    transform: scale(1.05);
}

.welcome-modal .modal-body {
    padding: 28px 32px 34px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(123,142,255,0.45) transparent;
}

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

.welcome-modal .modal-body::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(123,142,255,0.75), rgba(72,149,239,0.65));
    border-radius: 10px;
}

.welcome-hero {
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: rgba(226,232,255,0.9);
}

.welcome-kicker {
    font-size: 0.78rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: rgba(123,142,255,0.75);
}

.welcome-hero h3 {
    font-size: 1.46rem;
    font-weight: 700;
    line-height: 1.4;
    color: #ffffff;
}

.welcome-body {
    font-size: 0.98rem;
    line-height: 1.7;
    color: rgba(226,232,255,0.86);
}

.mode-picker {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.section-label {
    font-size: 0.82rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: rgba(226,232,255,0.65);
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 16px;
    border-radius: 18px;
    border: 1px solid rgba(123,142,255,0.18);
    background:
        radial-gradient(120% 120% at 0% 0%, rgba(123,142,255,0.22), transparent 70%),
        linear-gradient(145deg, rgba(26,33,54,0.86), rgba(36,46,72,0.82));
    color: rgba(241,244,255,0.9);
    cursor: pointer;
    text-align: left;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.mode-card .mode-icon {
    font-size: 1.4rem;
}

.mode-card .mode-name {
    font-weight: 600;
    font-size: 1.02rem;
    color: #ffffff;
}

.mode-card .mode-desc {
    font-size: 0.9rem;
    line-height: 1.5;
    color: rgba(226,232,255,0.72);
}

.mode-card:hover {
    transform: translateY(-4px);
    border-color: rgba(123,142,255,0.45);
    box-shadow: 0 18px 36px rgba(21,27,45,0.45);
}

.mode-card.active {
    border-color: rgba(123,142,255,0.75);
    box-shadow: 0 26px 52px rgba(21,27,45,0.55);
    background:
        radial-gradient(140% 140% at 0% 0%, rgba(113,134,255,0.35), transparent 70%),
        linear-gradient(150deg, rgba(34,42,70,0.95), rgba(48,60,92,0.9));
}

.welcome-actions {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.welcome-actions .btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.welcome-actions .btn-primary {
    padding: 14px 34px;
    border-radius: 999px;
    background: linear-gradient(135deg, #7186ff, #8f6bff);
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.03em;
    border: none;
    box-shadow: 0 16px 32px rgba(113,134,255,0.35);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.welcome-actions .btn-primary:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 22px 40px rgba(113,134,255,0.45);
}

/* Responsive */
@media (max-width: 768px) {
    html, body {
        background: #f5f7fa;
        overflow: auto;
    }

    .app-container {
        display: block;
        padding: 0;
        min-height: 100dvh;
    }

    .chat-container {
        width: 100%;
        max-width: 100%;
        min-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-header {
        padding: 20px;
    }

    .chat-messages {
        padding: 20px 16px 120px;
    }

    .message {
        max-width: 85%;
        font-size: 14px;
        padding: 14px 18px;
    }

    .chat-footer {
        padding: 18px;
    }

    .chat-input {
        padding: 14px;
    }
}

@media (max-width: 640px) {
    .modal#welcomeModal {
        padding: 16px;
        align-items: flex-start;
        padding-top: 5vh;
    }
    .welcome-modal {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 20px;
    }
    .welcome-modal .modal-header,
    .welcome-modal .modal-body {
        padding: 22px 20px;
    }
    .welcome-hero h3 {
        font-size: 1.3rem;
    }
    .mode-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .mode-card {
        padding: 16px 14px;
    }
    .mode-card .mode-name {
        font-size: 0.95rem;
    }
    .mode-card .mode-desc {
        font-size: 0.85rem;
    }
    .welcome-actions .btn-primary {
        width: 100%;
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .modal#welcomeModal {
        padding: 10px;
        padding-top: 2vh;
    }
    .welcome-modal {
        border-radius: 16px;
    }
    .welcome-modal .modal-header,
    .welcome-modal .modal-body {
        padding: 18px 16px;
    }
    .welcome-hero h3 {
        font-size: 1.2rem;
    }
    .welcome-body {
        font-size: 0.9rem;
    }
}