* {
    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;
}

/* STATO ACCOUNT / CREDITO (desktop) */
#topRightStatus {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    z-index: 20;
}

#usageBox {
    position: static;
    background: #fff7dd;
    border: 1px solid #e6c16b;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.3;
    display: none;
    white-space: nowrap;
    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: static;
    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);
    white-space: nowrap;
}

.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 */
    #topRightStatus,
    #styleToggleBox,
    #MassimariToggleBox,
    #uploadBox,
    #docs {
        display: none !important;
    }

    body.show-options #topRightStatus {
        position: static;
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        margin-bottom: 4px;
    }

    body.show-options #userBar {
        display: flex !important;
        justify-content: space-between;
        box-shadow: none;
        margin: 0;
    }

    body.show-options #usageBox {
        display: block !important;
        margin: 0;
        width: fit-content;
        max-width: 100%;
    }

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


/* =========================================================
   LAWYERGURU — VISUAL REFRESH V1
   Solo stile: nessuna modifica alla logica applicativa.
   ========================================================= */

:root {
    --lg-bg: #f7f8fa;
    --lg-panel: #ffffff;
    --lg-panel-soft: #f4f6f8;
    --lg-border: #e3e7eb;
    --lg-border-strong: #d5dbe1;
    --lg-text: #202428;
    --lg-muted: #727a83;
    --lg-green: #0f8f72;
    --lg-green-dark: #0b745d;
    --lg-green-soft: #eaf7f3;
    --lg-blue-soft: #f1f6fb;
    --lg-yellow-soft: #fff9e9;
    --lg-shadow: 0 8px 26px rgba(27, 39, 51, 0.07);
    --lg-shadow-soft: 0 2px 10px rgba(27, 39, 51, 0.05);
    --lg-radius: 12px;
}

body {
    background: var(--lg-bg);
    color: var(--lg-text);
}

/* Sidebar */
#sidebar {
    width: 272px;
    background: #f2f4f6;
    border-right: 1px solid var(--lg-border);
    padding: 20px 16px;
}

#sidebar h3 {
    margin: 2px 4px 14px;
    font-size: 16px;
    line-height: 1;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #56616a;
}

#sidebar > br {
    display: none;
}

#sidebar .btn-primary {
    width: 100%;
    justify-content: center;
    margin-bottom: 18px;
}

.chat-item {
    min-height: 36px;
    margin-bottom: 4px;
    padding: 7px 9px 7px 11px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #343a40;
    transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.chat-item:hover {
    background: #ffffff;
    border-color: var(--lg-border);
    transform: translateX(1px);
}

.chat-item .chat-actions {
    opacity: 0.38;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
}

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

.chat-menu {
    border: 1px solid var(--lg-border);
    border-radius: 10px;
    box-shadow: var(--lg-shadow);
    overflow: hidden;
}

/* Area principale */
#main {
    padding: 22px 26px 18px;
    background: var(--lg-bg);
}

#title {
    max-width: calc(100% - 440px);
    margin: 2px 0 12px;
    font-size: 22px;
    line-height: 1.25;
    font-weight: 650;
    letter-spacing: -0.015em;
    color: #20262b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Stato account */
#topRightStatus {
    top: 18px;
    right: 26px;
    gap: 8px;
    align-items: stretch;
}

#userBar,
#usageBox {
    min-height: 34px;
    border-radius: 9px;
    box-shadow: var(--lg-shadow-soft);
}

#userBar {
    background: var(--lg-blue-soft);
    border-color: #d9e6f2;
    padding: 7px 11px;
    font-size: 13px;
}

#usageBox {
    background: var(--lg-yellow-soft);
    border-color: #eedda5;
    padding: 8px 11px;
    font-size: 12px;
    color: #5b5133;
}

#usageBox b {
    color: #3f3825;
    font-weight: 700;
}

.logout-btn {
    color: #a74646;
    font-size: 12px;
}

/* Toggle test */
#flowToggleBox {
    width: fit-content;
    margin: 0 0 10px;
    padding: 6px 9px;
    border: 1px solid var(--lg-border);
    border-radius: 8px;
    background: rgba(255,255,255,0.7);
    color: var(--lg-muted);
    font-size: 12px;
}

#flowToggleBox label {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Upload */
#uploadBox {
    gap: 8px;
    margin-bottom: 8px;
}

.file-label,
.btn-secondary {
    min-height: 36px;
    border: 1px solid var(--lg-border-strong);
    background: var(--lg-panel);
    border-radius: 9px;
    padding: 8px 12px;
    font-size: 13px;
    box-shadow: 0 1px 2px rgba(27,39,51,0.03);
}

.file-label:hover,
.btn-secondary:hover {
    background: var(--lg-panel-soft);
}

#selectedFileName {
    color: var(--lg-muted);
    font-size: 12px;
}

/* Documenti */
#docs {
    margin-top: 4px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.78);
    border: 1px solid var(--lg-border);
    border-radius: 10px;
    max-height: 132px;
    color: #454b51;
    box-shadow: 0 1px 4px rgba(27,39,51,0.025);
}

#docs > b {
    font-size: 12px;
    color: var(--lg-muted);
    font-weight: 600;
}

.doc-item {
    padding: 6px 2px;
    border-bottom: 1px solid #edf0f2;
    font-size: 13px;
}

.doc-item:last-child {
    border-bottom: 0;
}

.doc-delete-btn {
    background: transparent;
    color: #a94b4b;
    border: 1px solid #ebcece;
    padding: 3px 8px;
    border-radius: 7px;
}

.doc-delete-btn:hover {
    background: #fff0f0;
    color: #8f3434;
}

/* Chat */
#chatArea {
    margin-top: 12px;
    padding: 24px;
    gap: 14px;
    background: var(--lg-panel);
    border: 1px solid var(--lg-border);
    border-radius: 16px;
    box-shadow: var(--lg-shadow-soft);
    scroll-behavior: smooth;
}

.message {
    max-width: min(92%, 1180px);
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.62;
    box-shadow: 0 1px 3px rgba(27,39,51,0.04);
}

.message.ai {
    background: #f5f7f8;
    border: 1px solid #e8ebee;
    border-top-left-radius: 5px;
    color: #22272b;
}

.message.user {
    background: var(--lg-green);
    border: 1px solid var(--lg-green);
    border-top-right-radius: 5px;
    color: #ffffff;
}

.message.user .timestamp {
    color: rgba(255,255,255,0.67);
}

.message.ai .timestamp {
    color: #9299a0;
}

/* Markdown dentro risposte AI */
.message.ai h1,
.message.ai h2,
.message.ai h3,
.message.ai h4 {
    margin: 0.7em 0 0.35em;
    line-height: 1.3;
    color: #1f2529;
}

.message.ai h1:first-child,
.message.ai h2:first-child,
.message.ai h3:first-child,
.message.ai h4:first-child {
    margin-top: 0;
}

.message.ai p {
    margin: 0.35em 0;
}

.message.ai ul,
.message.ai ol {
    margin: 0.45em 0;
    padding-left: 1.35em;
}

.message.ai li {
    margin: 0.18em 0;
}

/* Elenchi numerati AI: il numero originale resta testo selezionabile.
   Sopprime il marcatore automatico per non mostrare una numerazione doppia.
   Vale sia durante lo streaming sia nello storico della chat. */
.message.ai .message-content ol {
    list-style: none;
    padding-left: 0;
}
.message.ai .message-content ol > li {
    list-style: none;
}
.message.ai .message-content .lg-explicit-list-number {
    font-variant-numeric: tabular-nums;
}

.message.ai blockquote {
    margin: 0.55em 0;
    padding: 6px 12px;
    border-left: 3px solid #b9c3ca;
    color: #596168;
    background: #eef1f3;
    border-radius: 0 7px 7px 0;
}

.message.ai code {
    background: #e9edf0;
    border-radius: 5px;
    padding: 1px 5px;
    font-size: 0.92em;
}

.message.ai strong {
    color: #171b1e;
    font-weight: 700;
}

/* Indicatore elaborazione */
.message.typing {
    width: fit-content;
    max-width: 320px;
    background: transparent;
    border: 0;
    box-shadow: none;
    color: var(--lg-muted);
    font-style: normal;
    font-size: 13px;
    padding: 7px 4px;
}

/* Input */
#inputBar {
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--lg-border-strong);
    border-radius: 14px;
    background: var(--lg-panel);
    box-shadow: var(--lg-shadow);
    align-items: flex-end;
}

#msg {
    border: 0;
    outline: 0;
    background: transparent;
    border-radius: 9px;
    padding: 10px 11px;
    font-size: 16px;
    line-height: 1.45;
    min-height: 42px;
}

#msg::placeholder {
    color: #9aa1a8;
}

#msg:focus {
    box-shadow: inset 0 0 0 1px rgba(15,143,114,0.18);
    background: #fcfdfd;
}

#sendBtn {
    min-width: 78px;
    min-height: 40px;
    padding: 9px 16px;
    border-radius: 10px;
    background: var(--lg-green);
    transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

#sendBtn:hover {
    background: var(--lg-green-dark);
    transform: translateY(-1px);
}

#sendBtn:disabled {
    opacity: 0.55;
    cursor: default;
    transform: none;
}

.btn-primary {
    background: var(--lg-green);
    border-radius: 9px;
    box-shadow: 0 2px 8px rgba(15,143,114,0.16);
}

.btn-primary:hover {
    background: var(--lg-green-dark);
}

/* Login */
#loginOverlay {
    backdrop-filter: blur(3px);
    background: rgba(28, 35, 41, 0.38);
}

.login-box {
    border: 1px solid var(--lg-border);
    box-shadow: 0 20px 55px rgba(27,39,51,0.18);
}

.login-box input {
    border: 1px solid var(--lg-border-strong);
    border-radius: 8px;
}

.login-box button {
    border: 0;
    border-radius: 8px;
    background: var(--lg-green);
    color: white;
    cursor: pointer;
}

/* Mobile */
@media (max-width: 800px) {
    #main {
        padding: 8px 9px 8px;
        background: #f7f8fa;
    }

    #mobileTopBar {
        min-height: 46px;
        margin: -2px 0 4px;
        padding: 4px 2px;
        border-bottom: 1px solid var(--lg-border);
    }

    #mobileTopBarTitle {
        font-size: 16px;
        letter-spacing: -0.01em;
    }

    .icon-button {
        width: 38px;
        height: 38px;
        border-radius: 9px;
        font-size: 20px;
    }

    .icon-button:active {
        background: #eceff1;
    }

    #title {
        max-width: 100%;
        margin: 4px 1px 8px;
        font-size: 18px;
    }

    body.show-options #topRightStatus {
        margin: 2px 0 8px;
        gap: 6px;
    }

    body.show-options #userBar,
    body.show-options #usageBox {
        width: 100%;
        min-height: 38px;
        border-radius: 10px;
    }

    body.show-options #usageBox {
        width: 100%;
    }

    #flowToggleBox {
        margin-bottom: 8px;
    }

    #docs {
        max-height: 115px;
        border-radius: 10px;
    }

    #chatArea {
        margin-top: 7px;
        padding: 12px 10px;
        border-radius: 13px;
        gap: 10px;
    }

    .message {
        max-width: 94%;
        padding: 10px 12px;
        border-radius: 11px;
        font-size: 15px;
        line-height: 1.55;
    }

    .message.user {
        max-width: 88%;
    }

    #inputBar {
        position: relative;
        padding: 6px;
        margin-top: 7px;
        margin-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        border-radius: 13px;
    }

    #msg {
        min-height: 42px;
        padding: 9px 8px;
        font-size: 15px;
    }

    #sendBtn {
        min-width: 64px;
        min-height: 38px;
        padding: 8px 12px;
        border-radius: 9px;
        font-size: 13px;
    }

    #sidebar {
        background: #f3f5f6;
        border-right: 0;
        padding: 18px 14px;
    }
}

/* Schermi desktop stretti: evita collisioni del titolo con account/credito */
@media (min-width: 801px) and (max-width: 1120px) {
    #title {
        max-width: calc(100% - 360px);
        font-size: 20px;
    }

    #topRightStatus {
        gap: 6px;
    }

    #userBar {
        max-width: 175px;
        overflow: hidden;
    }

    #userName {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* =========================================================
   LAWYERGURU — REGISTRAZIONE / ATTIVAZIONE ACCOUNT
   ========================================================= */
.registration-box {
    width: 460px;
    max-width: calc(100vw - 32px);
}

.registration-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.registration-grid > div {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-help {
    margin: 0 0 4px;
    color: #5f6871;
    font-size: 14px;
    line-height: 1.45;
}

.auth-note {
    color: #7a828a;
    font-size: 12px;
    line-height: 1.35;
    margin-top: -6px;
}

.auth-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
}

.auth-check input {
    margin-top: 2px;
    flex: 0 0 auto;
}

.auth-primary-btn,
.auth-link-btn {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
}

.auth-primary-btn {
    border: none;
    background: #0f8f72;
    color: white;
    font-weight: 600;
}

.auth-primary-btn:hover:not(:disabled) {
    background: #0b745d;
}

.auth-primary-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.auth-link-btn {
    border: 1px solid #d7dde3;
    background: #fff;
    color: #38424b;
}

.auth-link-btn:hover {
    background: #f5f7f8;
}

.auth-status {
    min-height: 0;
    font-size: 13px;
    line-height: 1.4;
}

.auth-error {
    color: #b42318;
}

.turnstile-wrap {
    min-height: 65px;
    display: flex;
    align-items: center;
}

@media (max-width: 800px) {
    .registration-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .registration-box {
        width: 92%;
        max-width: 460px;
        max-height: 92dvh;
        overflow-y: auto;
    }
}


/* FIX REGISTRAZIONE: bottone secondario leggibile anche in hover */
.login-box .auth-link-btn {
    border: 1px solid #d7dde3;
    background: #ffffff;
    color: #38424b;
}

.login-box .auth-link-btn:hover {
    background: #f5f7f8;
    color: #202428;
}

/* FIX REGISTRAZIONE: impedisce a Nome/Cognome di uscire dal box */
.registration-grid > div {
    min-width: 0;
}

.registration-grid input,
.registration-box > input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

/* Link Privacy/Termini nel form */
.auth-check a {
    color: #0f8f72;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-check a:hover {
    color: #0b745d;
}


/* =========================================================
   LAWYERGURU — BRAND SIDEBAR + GUIDA AI PROMPT
   ========================================================= */

.sidebar-brand-block {
    padding: 0 4px 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--lg-border);
}

.sidebar-brand-link {
    display: block;
    width: 100%;
    padding: 4px 2px 12px;
    text-decoration: none;
}

.sidebar-brand-logo {
    display: block;
    width: 180px;
    max-width: 100%;
    height: auto;
    max-height: 46px;
    object-fit: contain;
    object-position: left center;
}

.prompt-guide-button {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
    border: 1px solid #cfe6de;
    border-radius: 10px;
    background: #ffffff;
    color: #27574b;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.prompt-guide-button:hover {
    background: var(--lg-green-soft);
    border-color: #abd8c9;
    transform: translateY(-1px);
}

.prompt-guide-icon {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: var(--lg-green);
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    flex: 0 0 auto;
}

/* Overlay guida */
.prompt-guide-overlay {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(14, 34, 32, .48);
    backdrop-filter: blur(5px);
}

.prompt-guide-overlay.open {
    display: flex;
}

body.prompt-guide-open {
    overflow: hidden;
}

.prompt-guide-modal {
    width: min(860px, 100%);
    max-height: min(88vh, 900px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #dce8e4;
    border-radius: 22px;
    box-shadow: 0 28px 80px rgba(10, 34, 28, .22);
}

.prompt-guide-header {
    position: relative;
    padding: 28px 68px 22px 30px;
    background:
        radial-gradient(circle at 86% 16%, rgba(15,143,112,.13), transparent 34%),
        #f6faf8;
    border-bottom: 1px solid #dfeae6;
}

.prompt-guide-eyebrow {
    margin-bottom: 7px;
    color: var(--lg-green);
    font-size: 11px;
    line-height: 1;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .12em;
}

.prompt-guide-header h2 {
    margin: 0;
    color: #17231f;
    font-size: 28px;
    line-height: 1.15;
    letter-spacing: -.025em;
}

.prompt-guide-header p {
    margin: 8px 0 0;
    color: #65716c;
    font-size: 14px;
    line-height: 1.45;
}

.prompt-guide-close {
    position: absolute;
    top: 19px;
    right: 22px;
    width: 38px;
    height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid #d7e1dd;
    border-radius: 10px;
    background: rgba(255,255,255,.82);
    color: #59645f;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.prompt-guide-close:hover {
    background: #ffffff;
    color: #24322d;
}

.prompt-guide-content {
    padding: 24px 28px 30px;
    overflow-y: auto;
}

.prompt-guide-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 14px;
    padding: 17px 0;
    border-bottom: 1px solid #edf1ef;
}

.prompt-guide-item:first-child {
    padding-top: 2px;
}

.prompt-guide-number {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--lg-green-soft);
    color: var(--lg-green-dark);
    font-size: 13px;
    font-weight: 800;
}

.prompt-guide-item h3 {
    margin: 1px 0 6px;
    color: #24302c;
    font-size: 16px;
    line-height: 1.3;
}

.prompt-guide-item p {
    margin: 0 0 7px;
    color: #5f6965;
    font-size: 14px;
    line-height: 1.55;
}

.prompt-example {
    margin-top: 10px;
    padding: 11px 13px;
    border-left: 3px solid #8bcab6;
    border-radius: 0 8px 8px 0;
    background: #f7faf9;
    color: #47534e;
    font-size: 13px;
    line-height: 1.5;
    font-style: italic;
}

.prompt-perfect {
    margin-top: 24px;
    padding: 20px 22px;
    border: 1px solid #bfe2d6;
    border-radius: 14px;
    background: linear-gradient(135deg, #eff9f6, #e4f5ef);
}

.prompt-perfect-label {
    margin-bottom: 8px;
    color: var(--lg-green-dark);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.prompt-perfect p {
    margin: 0;
    color: #33463f;
    font-size: 14px;
    line-height: 1.6;
}

@media (max-width: 800px) {
    .sidebar-brand-logo {
        width: 165px;
        max-height: 43px;
    }

    .prompt-guide-overlay {
        align-items: flex-end;
        padding: 12px;
    }

    .prompt-guide-modal {
        max-height: 90vh;
        border-radius: 18px;
    }

    .prompt-guide-header {
        padding: 23px 58px 18px 22px;
    }

    .prompt-guide-header h2 {
        font-size: 24px;
    }

    .prompt-guide-content {
        padding: 20px 20px 24px;
    }
}

@media (max-width: 520px) {
    .prompt-guide-overlay {
        padding: 0;
    }

    .prompt-guide-modal {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border: 0;
        border-radius: 0;
    }

    .prompt-guide-item {
        grid-template-columns: 30px minmax(0, 1fr);
        gap: 11px;
    }

    .prompt-guide-number {
        width: 28px;
        height: 28px;
    }

    .prompt-guide-item h3 {
        font-size: 15px;
    }

    .prompt-guide-item p,
    .prompt-perfect p {
        font-size: 13.5px;
    }
}


/* =========================================================
   FIX MOBILE — SCROLL CHAT DOPO SELEZIONE CASO
   ========================================================= */
@media (max-width: 800px) {
    html,
    body {
        width: 100%;
        height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    body {
        height: 100dvh;
        min-height: 100dvh;
    }

    #main {
        height: 100dvh;
        min-height: 0;
        max-height: 100dvh;
        overflow: hidden;
    }

    #chatArea {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
    }

    #inputBar {
        flex: 0 0 auto;
    }
}


/* =========================================================
   NUOVA CHAT: link guida + intero caso cliccabile
   ========================================================= */

.chat-item {
    cursor: pointer;
}

.chat-item > span:first-child {
    flex: 1 1 auto;
    min-width: 0;
}

.inline-prompt-guide-link {
    display: inline;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: var(--lg-green-dark);
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.inline-prompt-guide-link:hover {
    color: var(--lg-green);
}


/* =========================================================
   FIX MENU ⋯ DEI CASI — niente sovrapposizione col tab sotto
   ========================================================= */

.chat-item.menu-open {
    z-index: 300;
    transform: none;
}

.chat-item.menu-open .chat-actions {
    opacity: 1;
    background: #e9edf0;
}

.chat-item.menu-open .chat-menu {
    z-index: 301;
}


/* =========================================================
   RIPRISTINO PUNTINI ANIMATI — "LawyerGuru sta elaborando..."
   ========================================================= */

.message.typing {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    width: fit-content;
}

.message.typing::after {
    content: "";
    width: 1.4em;
    display: inline-block;
    text-align: left;
    animation: lawyerGuruThinkingDots 1.2s steps(4, end) infinite;
}

@keyframes lawyerGuruThinkingDots {
    0%   { content: ""; }
    25%  { content: "."; }
    50%  { content: ".."; }
    75%, 100% { content: "..."; }
}


/* =========================================================
   FIX MOBILE — ULTIMI CASI VISIBILI NELLA SIDEBAR
   ========================================================= */
@media (max-width: 800px) {
    #sidebar {
        height: 100dvh;
        max-height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    }

    #chatList {
        min-height: 0;
        padding-bottom: 18px;
    }
}


/* =========================================================
   FIX MOBILE — TITOLO DELLA CHAT NON COMPRESSO
   ========================================================= */
@media (max-width: 800px) {
    #title {
        flex: 0 0 auto;
        min-height: 24px;
        line-height: 1.25;
        overflow: visible;
        white-space: normal;
    }
}
