.material-symbols-outlined {
    user-select: none;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24
}

:root {
    --accent: #165cb7;
    --accent-hover: #2469c4;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Google Sans Flex", sans-serif;
    font-variation-settings:
        "slnt" 0,
        "wdth" 100,
        "GRAD" 0,
        "ROND" 100;
}

html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

body {
    display: flex;
    height: calc(var(--vh, 1vh) * 100);
    background-color: #282828;
    overflow: hidden;
}

#sidebar {
    width: 260px;
    background: #0a0a0a;
    color: white;
    display: flex;
    flex-direction: column;
    padding: 10px;
    transition: transform 0.3s, width 0.3s;
    border-right: rgba(255, 255, 255, 0.05) 2px solid;
    z-index: 10;
}

.disappear {
    transition: opacity 0.3s, width 0.3s;
    text-wrap: nowrap;
}

/* Gestione Sidebar Desktop */
@media (min-width: 721px) {
    #sidebar.hidden {
        width: 60px;
    }

    #sidebar.hidden .disappear {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        width: 0;
        padding: 0;
    }
}

#chatList {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

.chat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    height: 40px;
    margin-bottom: 5px;
    background: none;
    border-radius: 5px;
    cursor: pointer;
    appearance: none;
    border: none;
    color: white;
    font-size: 14px;
}

.bottom {
    margin-bottom: 0px !important;
}

.chat-item.icon-container {
    width: 40px;
}

.chat-item:hover {
    background: #333;
}

.chat-item:hover .delete-chat {
    color: #ff4d4d;
}

.recents-text {
    padding-left: 8px;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: small;
    margin-top: 5px;
    user-select: none;
}

.settings-text {
    font-weight: 600;
    font-size: 16px;
    user-select: none;
}

.modal-title-container {
    display: flex;
    align-items: center;
    gap: 5px;
}

.delete-chat {
    color: #ff4d4d00;
    cursor: pointer;
    margin-left: 8px;
    font-weight: bold;
    user-select: none;
}

.sidebar-buttons-container {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background-color: #0c0c0e;
    overflow-x: hidden;
}

/* Cerchio Blu Gradientoso */
.glow-bg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85vh;
    height: 85vh;
    max-width: 900px;
    max-height: 900px;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent) 40%, transparent) 0%, color-mix(in srgb, var(--accent) 5%, transparent) 50%, transparent 70%);
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease;
}

/* Mostra il gradiente solo se la chat è vuota */
#main.is-empty .glow-bg {
    opacity: 1;
    visibility: visible;
}

#main.is-empty .warning {
    opacity: 0;
}

img {
    height: 25px;
    user-select: none;
}

#topbar {
    display: flex;
    align-items: center;
    background: #0a0a0a;
    border-bottom: rgba(255, 255, 255, 0.05) 2px solid;
    padding: 15px;
    height: 60px;
    color: white;
    gap: 15px;
    z-index: 5;
}

#hamburgerMobile {
    display: none;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
    height: 24px;
    width: 24px;
    align-items: center;
    justify-content: center;
}

#messages {
    flex: 1;
    padding: 10px 18%;
    overflow-y: auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    z-index: 2;
}

.chat-template {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    color: #ffffff;
    font-size: 38px;
    font-weight: 400;
    letter-spacing: -0.5px;
    user-select: none;
    pointer-events: none;
    animation: fadeIn 0.4s ease forwards;
    margin-bottom: 24px;
    /* Spazio compatto e preciso sopra la barra */
}

#main.is-empty #messages {
    flex: none;
    margin-top: auto;
    /* Inizio della magia: spinge il blocco al centro dall'alto */
    padding-top: 0;
    padding-bottom: 0;
}

#main.is-empty #inputContainer {
    margin-top: 0;
    margin-bottom: auto;
    /* Fine della magia: bilancia dal basso e incolla tutto al centro esatto stile Gemini */
}

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

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

.msg-wrapper {
    display: flex;
    width: 100%;
    margin: 6px 0;
}

.msg-wrapper.user {
    justify-content: flex-end;
}

.msg-wrapper.assistant {
    justify-content: flex-start;
}

.msg-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-wrapper.user .msg-box {
    max-width: 50%;
    align-items: flex-end;
}

.msg-wrapper.assistant .msg-box {
    max-width: 100%;
    width: 100%;
    align-items: flex-start;
}

.msg {
    font-size: 15px;
    padding: 13px;
    border-radius: 12px 2px 12px 12px;
    color: white;
    white-space: normal;
    width: fit-content;
    display: flex;
    flex-direction: column;
    gap: 10px;
    white-space: pre-wrap;
    word-wrap: anywhere;
}

.msg.user {
    background: var(--accent);
}

.msg.assistant {
    width: 100%;
}

.msg-action-row {
    display: flex;
    width: 100%;
    margin-top: 4px;
    min-height: 22px;
}

.msg-action-row.user {
    justify-content: flex-end;
}

.msg-action-row.assistant {
    justify-content: flex-start;
}

.copy-btn,
.tts-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: color 0.2s, opacity 0.2s, visibility 0.2s;
    opacity: 0;
    visibility: hidden;
    margin-left: 13px;
    margin-right: 0px;
}

.copy-btn:hover,
.tts-btn:hover {
    color: #ffffff;
}

.msg-wrapper:hover .copy-btn,
.msg-wrapper:hover .tts-btn {
    opacity: 1;
    visibility: visible;
}

/* Container di Input Generale */
#inputContainer {
    display: flex;
    flex-direction: column;
    margin: 10px auto;
    z-index: 2;
    transition: all 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    width: 52vw;
}

#inputBar {
    display: flex;
    padding: 7px;
    background: #1e1f20;
    border: rgba(255, 255, 255, 0.08) 1px solid;
    border-radius: 30px;
    width: 100%;
    align-items: end;
    gap: 5px;
}

#input {
    flex: 1;
    padding: 10px;
    appearance: none;
    background: none;
    color: white;
    font-family: "Google Sans Flex", sans-serif;
    border: none;
    outline: none;
    font-size: 15px;
    field-sizing: content;
    max-height: 190px;
    resize: none;
    min-height: 40px;
}

button.send {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background-color: #303134;
    color: #80868b;
    border: none;
}

button.send:disabled {
    background-color: #303134 !important;
    color: #4a4d51 !important;
    cursor: not-allowed;
}

button.send:not(:disabled) {
    background-color: var(--accent);
    color: white;
    cursor: pointer;
}

button.sticker-menu,
button.dictate {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background-color: var(--accent)00;
    color: white;
    border: none;
}

button.send:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

button.sticker-menu:hover,
button.dictate:hover {
    background-color: hsla(0, 0%, 80%, 0.1);
    cursor: pointer;
}

button.dictate.recording {
    background: #d32f2f;
    color: white;
}

.warning {
    width: 100%;
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 10px;
}

/* Gestione responsive Mobile - Sostituisci interamente questo blocco */
@media (max-width: 720px) {
    #hamburgerMobile {
        display: flex;
    }

    #messages {
        margin-top: 60px;
        padding: 15px;
    }

    #inputContainer {
        margin: 15px;
        width: calc(100% - 30px);
    }

    /* Mantiene il centramento verticale anche su mobile */
    #main.is-empty #messages {
        flex: none;
    }

    #sidebar {
        width: 80%;
        position: fixed;
        height: 100vh;
        height: 100dvh;
        border: none;
        top: 0;
        left: 0;
        z-index: 1000;
        border-right: rgba(255, 255, 255, 0.1) 2px solid;
        transform: translateX(0);
        transition: transform 0.3s ease;
        display: flex;
    }

    /* Impedisce al .hidden globale di fare display:none, così l'animazione swipe funziona */
    #sidebar.hidden {
        transform: translateX(-100%);
        display: flex !important;
    }

    #topbar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 999;
    }

    .msg-wrapper .copy-btn,
    .msg-wrapper .tts-btn {
        opacity: 1;
        visibility: visible;
    }
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: modalFadeIn 0.18s ease-out;
}

.modal {
    width: 420px;
    max-height: 400px;
    background: #101010;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: white;
    animation: modalPopIn 0.22s cubic-bezier(0.2, 1, 0.2, 1);
    transform-origin: center;
}

.overlay.closing {
    animation: modalFadeIn 0.15s ease-out reverse forwards;
}

.modal.closing {
    animation: modalPopIn 0.18s cubic-bezier(0.2, 1, 0.2, 1) reverse forwards;
}

.search {
    max-height: 300px !important;
}

#searchInput {
    padding: 10px;
    border-radius: 8px;
    border: 0px solid rgba(255, 255, 255, 0.15);
    background: none;
    color: white;
    outline: none;
}

hr {
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#searchResults {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.search-item {
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    background: none;
}

.search-item:hover {
    background: #2a2a2a;
}

.hidden {
    display: none;
}

.chat-item.active {
    background: #333;
}

.chat-item.active .delete-chat {
    color: #ff4d4d;
}

#newChat,
#searchChatBtn,
#settingsMenuBtn {
    justify-content: flex-start;
    gap: 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.grid-option {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c1c1c;
    border-radius: 8px;
    cursor: pointer;
}

.grid-option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sticker {
    width: 140px;
    height: auto;
    vertical-align: middle;
    margin: 0 4px;
}

.sticker-only-bubble {
    background: none !important;
    padding: 0 !important;
}

#stickerGrid {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
}

.sticker-row {
    display: flex;
    margin: 8px 0;
}

.sticker-row.user {
    justify-content: flex-end;
}

.sticker-row.assistant {
    justify-content: flex-start;
}

.sticker-big {
    width: 140px;
    height: 140px;
    object-fit: contain;
}

.color-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: 0.2s;
}

.color-option:hover {
    transform: scale(1.05);
}

.color-option.active {
    border-color: white;
}

.custom-color {
    font-size: 12px;
    text-align: center;
    background: #1c1c1c;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.color-option,
.custom-color {
    position: relative;
}

.color-option.active::after,
.custom-color.active::after {
    content: "done";
    font-family: "Material Symbols Outlined";
    font-size: 24px;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;

    padding: 40px 20px;
    text-align: center;

    color: #888;
    user-select: none;
}

.search-empty .material-symbols-outlined {
    font-size: 48px;
    opacity: 0.7;
}

.search-empty span:last-child {
    font-size: 15px;
}

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

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

/* Quando la barra diventa multi-linea */
#inputBar.multi-line {
    flex-wrap: wrap;
    border-radius: 24px;
}

/* La textarea prende tutto lo spazio in alto */
#inputBar.multi-line #input {
    flex: 1 0 100%;
    width: 100%;
    margin-bottom: 12px; /* Spazio tra testo e bottoni */
}

/* Forza il tasto sticker a stare a sinistra in basso */
#inputBar.multi-line button.sticker-menu {
    order: 2;
    margin-right: auto; /* Spinge tutto il resto a destra */
}

/* Forza il tasto send a stare a destra in basso */
#inputBar.multi-line button.send {
    order: 3;
    margin-left: auto;
}

#dictate.recording {
    background-color: #e53935 !important;
}

#dictate.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Nasconde input e sticker durante la registrazione */
#inputBar.recording-mode #input,
#inputBar.recording-mode #stickerBtn {
    display: none !important;
}

#dictateVisualizer {
    display: none;
    flex: 1;
    align-items: center;
    gap: 10px;
    padding: 0 10px;
}

#inputBar.recording-mode #dictateVisualizer {
    display: flex;
}

.dot-row {
    flex: 1;
    display: flex;
    align-items: center;      /* centra verticalmente i dot man mano che crescono */
    justify-content: center;
    gap: 4px;
    height: 32px;
}

.dot-row .dot {
    width: 6px;
    height: 6px;
    border-radius: 3px;       /* fisso in px, NON in %: così non diventa mai una pillola */
    background: var(--accent, #4caf50);
    opacity: 0.5;
    transition: opacity 0.08s ease;
    flex-shrink: 0;
}

.dictate-timer {
    font-size: 13px;
    color: rgba(255,255,255,0.6);
    min-width: 38px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

#dictate.recording {
    background-color: #e53935 !important;
}

#dictate.loading {
    opacity: 0.6;
    pointer-events: none;
}

#dictateVisualizer {
    height: 100%;
}