* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: flex;
    height: 100vh;
    color: #222;
}

/* SIDEBAR */
#sidebar {
    width: 260px;
    background: #f3f3f3;
    height: 100vh;
    padding: 15px;
    overflow-y: auto;
    border-right: 1px solid #ccc;
    flex-shrink: 0;
}

#sidebar h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

/* MAIN CHAT */
#main {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

#title {
    margin: 0 0 10px 0;
}

/* USAGE BOX */
#usageBox {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #fff7dd;
    border: 1px solid #e6c16b;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.3;
    display: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#usageBox b {
    font-size: 12px;
}

/* TOGGLE + UPLOAD */
#styleToggleBox,
#MassimariToggleBox,
#uploadBox {
    margin-bottom: 10px;
}

#styleToggleBox,
#MassimariToggleBox {
    display: none;
}


#uploadBox {
    display: none;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* File input */
input[type="file"] {
    display: none;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #e5e5e5;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.15s ease;
    font-size: 14px;
}

.file-label:hover {
    background: #d4d4d4;
}

#selectedFileName {
    font-size: 14px;
    color: #555;
}

/* Documenti */
#docs {
    margin-top: 10px;
    padding: 10px;
    background: #fafafa;
    border: 1px solid #ddd;
    max-height: 150px;
    overflow-y: auto;
}

#docsList {
    list-style: none;
    padding-left: 0;
    margin: 5px 0 0 0;
}

.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    gap: 10px;
}

.doc-delete-btn {
    border: none;
    background: #e74c3c;
    color: white;
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
}

.doc-delete-btn:hover {
    background: #c0392b;
}

/* CHAT AREA */
#chatArea {
    margin-top: 15px;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 12px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 17px;
    line-height: 1.55;
    white-space: pre-wrap;
    display: flex;
    flex-direction: column;
}

.message.ai {
    background: #f1f1f1;
    color: #1a1a1a;
    align-self: flex-start;
}

.message.user {
    background: #10a37f;
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.message .timestamp {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #e0e0e0;
}

.message.user .timestamp {
    text-align: right;
}

.message.ai .timestamp {
    text-align: left;
}

/* AI typing */
.message.typing {
    font-style: italic;
    background: #f1f1f1;
    color: #555;
}

/* INPUT AREA */
#inputBar {
    margin-top: 10px;
    padding: 10px;
    border-radius: 12px;
    background: #f3f3f3;
    border: 1px solid #ddd;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#msg {
    flex: 1;
    border-radius: 8px;
    border: 1px solid #ccc;
    padding: 8px;
    resize: none;
    font-family: inherit;
    font-size: 17px;
    min-height: 40px;
    max-height: 200px;
    overflow-y: hidden;
}

#sendBtn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    background: #10a37f;
    color: white;
    cursor: pointer;
    font-weight: bold;
}

#sendBtn:hover {
    background: #0d8a6b;
}

/* Chat list + menu */
.chat-item {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 5px;
    background: #eaeaea;
    cursor: pointer;
    border-radius: 5px;
}

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

.chat-item .chat-actions {
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

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

.chat-menu {
    position: absolute;
    right: 5px;
    top: 30px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    z-index: 100;
    display: none;
    flex-direction: column;
    width: 130px;
}

.chat-menu button {
    background: white;
    border: none;
    padding: 8px 10px;
    text-align: left;
    width: 100%;
    cursor: pointer;
    font-size: 14px;
}

.chat-menu button:hover {
    background: #f0f0f0;
}

/* Icone */
.icon-pencil::before {
    content: "✏️";
}

.icon-trash::before {
    content: "🗑️";
}

/* Modern buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: 0.15s ease;
}

.btn-primary {
    background: #10a37f;
    color: white;
}

.btn-primary:hover {
    background: #0d8a6b;
}

.btn-secondary {
    background: #e5e5e5;
    color: #333;
}

.btn-secondary:hover {
    background: #d4d4d4;
}

/* ===== TOP BAR MOBILE & OVERLAY (desktop: nascosti) ===== */
#mobileTopBar {
    display: none; /* solo mobile */
}

.icon-button {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 22px;
    padding: 4px 8px;
}

#mobileTopBarTitle {
    font-weight: 600;
    font-size: 18px;
}

#sidebarOverlay {
    display: none; /* solo mobile */
}

/* ===== USER BAR (desktop) ===== */
#userBar {
    position: absolute;
    top: 20px;
    right: 200px;    /* si posiziona a sinistra del riquadro Usage */
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    background: #eef7ff;
    border: 1px solid #a9c8e8;
    padding: 6px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    z-index: 20;
}

#userBar .separator {
    margin: 0 4px;
    color: #777;
}

.logout-btn {
    cursor: pointer;
    color: #c0392b;
    font-weight: bold;
}

.logout-btn:hover {
    text-decoration: underline;
}

/* ===== LOGIN OVERLAY ===== */
#loginOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.login-box {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 380px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    font-size: 16px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

.login-box input {
    padding: 8px 10px;
    font-size: 15px;
}

.login-box button {
    padding: 8px 10px;
    font-size: 15px;
}

.login-label {
    font-size: 14px;
    margin-top: 6px;
    margin-bottom: -4px;
    font-weight: 600;
}

/* ============================================
   RESPONSIVE MOBILE (layout chat-first)
   ============================================ */
@media (max-width: 800px) {
    body {
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
        overflow: hidden;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Sidebar a scomparsa */
    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        z-index: 2000;
        transition: left 0.25s ease;
        box-shadow: 4px 0 12px rgba(0,0,0,0.25);
    }

    body.sidebar-open #sidebar {
        left: 0;
    }

    /* Overlay scuro quando sidebar aperta */
    #sidebarOverlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 1500;
    }

    body.sidebar-open #sidebarOverlay {
        display: block;
    }

    #main {
        padding: 10px;
        height: auto;
        min-height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    /* Top bar mobile visibile */
    #mobileTopBar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 6px;
    }

    #title {
        margin-top: 4px;
        font-size: 18px;
    }

    /* Chat fullscreen-style */
    #chatArea {
        padding: 12px;
        margin-top: 8px;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    #inputBar {
        padding: 8px;
        margin-top: 6px;
        margin-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        flex-shrink: 0;
        border-radius: 12px;
    }

    #msg {
        font-size: 15px;
    }

    .message {
        max-width: 100%;
        font-size: 15px;
    }

    /* Tutto il resto a scomparsa, visibile solo quando body.show-options */
    #userBar,
    #usageBox,
    #styleToggleBox,
    #MassimariToggleBox,
    #uploadBox,
    #docs {
        display: none !important;
    }

    body.show-options #userBar {
        position: static;
        display: flex !important;
        box-shadow: none;
        margin-bottom: 4px;
    }

    body.show-options #usageBox {
        position: static;
        display: block !important;
        margin-top: 4px;
        margin-bottom: 4px;
    }
	
	body.show-options #styleToggleBox,
	body.show-options #MassimariToggleBox,
	body.show-options #uploadBox,
	body.show-options #docs {
		display: block !important;
		margin-top: 6px;
	}

    /* Box login adattato */
    .login-box {
        width: 90%;
        max-width: 380px;
    }
}

