/* ============================================================
   MaxMauri Chat AI — Design System v2
   Dark · Inter · Indigo accent
   ============================================================ */

@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/inter-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/inter-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/inter-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/inter-700.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 800; font-display: swap; src: url('/fonts/inter-800.woff2') format('woff2'); }

:root {
    --bg: #080b12;
    --bg-glow-1: rgba(77, 107, 254, .14);
    --bg-glow-2: rgba(99, 102, 241, .08);
    --panel: #0f1420;
    --panel-2: #141a29;
    --panel-3: #1a2233;
    --elevated: #1e2739;
    --hover: #232e45;
    --border: #232e45;
    --border-strong: #31405f;
    --text: #e8edf8;
    --text-2: #a7b4cd;
    --text-3: #64748f;
    --accent: #4d6bfe;
    --accent-2: #6a5cff;
    --accent-soft: rgba(77, 107, 254, .16);
    --accent-softer: rgba(77, 107, 254, .08);
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #f87171;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 24px 60px rgba(0,0,0,.5);
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-image:
        radial-gradient(1100px 500px at 15% -10%, var(--bg-glow-1), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, var(--bg-glow-2), transparent 55%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection { background: rgba(77,107,254,.35); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3550; border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4a6e; background-clip: content-box; }

/* ============================================================
   LOGIN
   ============================================================ */
.auth-container {
    width: 100%;
    max-width: 420px;
    background: linear-gradient(180deg, rgba(20,26,41,.92), rgba(15,20,32,.96));
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 44px 38px 36px;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,.02) inset;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeUp .45s ease;
    position: relative;
    overflow: hidden;
}
.auth-container::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2), #38bdf8);
}
.auth-container .logo {
    width: 64px; height: 64px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 10px 30px rgba(77,107,254,.4);
    margin-bottom: 18px;
}
.auth-container .logo svg { width: 34px; height: 34px; }
.auth-container h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
    background: linear-gradient(90deg, #fff, #c7d2fe);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
}
.auth-container .subtitle { font-size: .85rem; color: var(--text-2); margin-bottom: 26px; }

.auth-container .error, .auth-container .success {
    width: 100%;
    font-size: .8rem;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 14px;
    display: none;
    line-height: 1.45;
}
.auth-container .error.show { display: block; background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.35); color: #fda4a4; }
.auth-container .success.show { display: block; background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.35); color: #6ee7b7; }

.auth-container form { width: 100%; display: flex; flex-direction: column; gap: 16px; }
.auth-container label {
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: -10px;
}
.auth-container .field {
    position: relative;
    display: flex;
    align-items: center;
}
.auth-container .field svg {
    position: absolute;
    left: 13px;
    width: 17px; height: 17px;
    color: var(--text-3);
    pointer-events: none;
}
.auth-container input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    background: var(--panel-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: var(--font);
    font-size: .9rem;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.auth-container input::placeholder { color: var(--text-3); }
.auth-container input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--elevated);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-container .btn-primary {
    width: 100%;
    margin-top: 4px;
    padding: 13px;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    font-family: var(--font);
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    box-shadow: 0 8px 24px rgba(77,107,254,.35);
    transition: transform .12s ease, box-shadow .15s ease, filter .15s ease;
}
.auth-container .btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 12px 30px rgba(77,107,254,.45); }
.auth-container .btn-primary:active { transform: translateY(0); }
.auth-container .btn-primary:disabled { opacity: .6; cursor: not-allowed; filter: saturate(.7); transform: none; }
.auth-container .btn-primary .spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.auth-container .auth-foot { margin-top: 20px; font-size: .72rem; color: var(--text-3); text-align: center; line-height: 1.6; }

/* ============================================================
   LAYOUT APP
   ============================================================ */
.app {
    display: none;
    max-width: 1440px;
    width: 100%;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    grid-template-columns: 292px 1fr;
    gap: 12px;
}
.app.show { display: grid; }

.sidebar {
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    box-shadow: var(--shadow-md);
}

.sidebar h3 {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-3);
    display: flex; align-items: center; gap: 8px;
}
.sidebar h3 svg { width: 14px; height: 14px; }

/* --- Utente --- */
.user-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.user-info .user-row {
    display: flex; align-items: center; gap: 10px;
}
.user-info .avatar {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .95rem; color: #fff;
    box-shadow: 0 6px 16px rgba(77,107,254,.35);
}
.user-info .username {
    font-size: .88rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-info .user-row select.lang-side {
    flex-shrink: 0;
    margin-left: auto;
    padding: 4px 6px;
    font-size: .7rem;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    background: var(--panel-3);
    color: var(--text-2);
    max-width: 118px;
    cursor: default;
    opacity: .95;
}
.user-info .user-meta { font-size: .72rem; color: var(--text-3); }
.user-info .btn-group { display: flex; gap: 8px; }
.user-info .btn-group button {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 10px;
    font-size: .76rem; font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--panel-3);
    color: var(--text-2);
    cursor: pointer;
    transition: all .15s ease;
}
.user-info .btn-group button svg { width: 14px; height: 14px; }
.user-info .btn-group .admin-btn { border-color: rgba(251,191,36,.4); color: #fcd34d; background: rgba(251,191,36,.08); }
.user-info .btn-group .admin-btn:hover { background: rgba(251,191,36,.16); }
.user-info .btn-group .logout-btn:hover { border-color: rgba(248,113,113,.5); color: #fca5a5; background: rgba(248,113,113,.08); }

/* --- Limite dollari --- */
.limit-info {
    background: var(--panel-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}
.limit-info .limit-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.limit-info .limit-label { font-size: .72rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.limit-info .limit-label svg { width: 14px; height: 14px; color: var(--yellow); }
.limit-info .limit-value { font-size: .8rem; font-weight: 700; color: var(--text); }
.limit-info .limit-value.green { color: var(--green); }
.limit-info .limit-value.yellow { color: var(--yellow); }
.limit-info .limit-value.red { color: var(--red); }
.limit-info .limit-sub { font-size: .7rem; color: var(--text-3); margin-bottom: 10px; }
.limit-info .progress-bar {
    height: 7px;
    background: var(--panel);
    border-radius: 99px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.limit-info .progress-bar .fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--accent), #38bdf8);
    transition: width .5s ease;
}
.limit-info .progress-bar .fill.green { background: linear-gradient(90deg, #10b981, var(--green)); }
.limit-info .progress-bar .fill.yellow { background: linear-gradient(90deg, #f59e0b, var(--yellow)); }
.limit-info .progress-bar .fill.red { background: linear-gradient(90deg, #ef4444, var(--red)); }

/* --- SSH --- */
.ssh-form { display: flex; flex-direction: column; gap: 8px; }
.ssh-form input {
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .8rem;
    font-family: var(--font);
    transition: border-color .15s, box-shadow .15s;
}
.ssh-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ssh-form .row { display: flex; gap: 8px; }
.ssh-form .row input:first-child { flex: 1; }
.ssh-form button {
    padding: 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    color: var(--text-2);
    font-family: var(--font);
    font-size: .8rem; font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: all .15s;
}
.ssh-form button svg { width: 14px; height: 14px; }
.ssh-form button:hover { border-color: var(--accent); color: var(--text); background: var(--elevated); }
.ssh-status {
    font-size: .74rem;
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--panel);
}
.ssh-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.ssh-status.connected { color: var(--green); }
.ssh-status.connected::before { background: var(--green); box-shadow: 0 0 8px rgba(52,211,153,.6); }
.ssh-status.disconnected { color: var(--text-3); }
.ssh-status.disconnected::before { background: #64748f; }

/* --- File browser --- */
.file-source { display: flex; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; }
.file-source button {
    flex: 1;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-3);
    font-size: .74rem; font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    transition: all .15s;
}
.file-source button svg { width: 13px; height: 13px; }
.file-source button:hover { color: var(--text-2); }
.file-source button.active { background: var(--accent-soft); color: var(--text); }
.file-nav { display: flex; gap: 6px; }
.file-nav input {
    flex: 1;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .76rem;
    font-family: var(--mono);
}
.file-nav input:focus { outline: none; border-color: var(--accent); }
.file-nav button {
    width: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    color: var(--text-2);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.file-nav button svg { width: 14px; height: 14px; }
.file-nav button:hover { color: var(--text); border-color: var(--accent); }
.file-browser {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-height: 140px;
    max-height: 260px;
    overflow-y: auto;
    font-size: .76rem;
}
.file-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px;
    cursor: pointer;
    transition: background .12s;
    border-radius: 6px;
    margin: 2px 4px;
}
.file-item:hover { background: var(--hover); }
.file-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.file-item .name svg { width: 15px; height: 15px; flex-shrink: 0; }
.file-item .name svg.folder { color: #fbbf24; }
.file-item .name svg.file { color: var(--text-3); }
.file-item .size { color: var(--text-3); font-size: .68rem; }
.file-item.directory .name { color: var(--text-2); font-weight: 500; }
.file-item .actions button {
    border: none; background: transparent;
    color: var(--text-3);
    cursor: pointer;
    padding: 3px;
    border-radius: 5px;
    display: flex; align-items: center;
    transition: all .12s;
}
.file-item .actions button svg { width: 13px; height: 13px; }
.file-item .actions button:hover { color: var(--accent); background: var(--accent-soft); }

/* --- Contesto file --- */
.context-actions { display: flex; gap: 8px; }
.context-actions button {
    flex: 1;
    padding: 9px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-size: .74rem; font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: all .15s;
}
.context-actions button svg { width: 13px; height: 13px; }
.context-actions button:hover { border-color: var(--accent); color: var(--text); background: var(--accent-softer); }
.context-file {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .74rem;
}
.context-file .filename { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.context-file .remove {
    border: none; background: transparent; color: var(--text-3); cursor: pointer;
    display: flex; align-items: center; padding: 2px; border-radius: 5px;
    transition: all .12s;
}
.context-file .remove svg { width: 13px; height: 13px; }
.context-file .remove:hover { color: var(--red); background: rgba(248,113,113,.1); }

/* --- Temperatura & modello --- */
.temp-row { display: flex; align-items: center; gap: 10px; }
.temp-row label { font-size: .72rem; color: var(--text-2); white-space: nowrap; }
.temp-row input[type=range] {
    flex: 1; appearance: none; -webkit-appearance: none;
    height: 4px; border-radius: 99px;
    background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--border-strong) var(--fill, 50%));
    outline: none; cursor: pointer;
}
.temp-row input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px; height: 15px; border-radius: 50%;
    background: #fff;
    border: 3px solid var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
    cursor: pointer;
}
.temp-row span { font-size: .74rem; color: var(--text); min-width: 30px; text-align: right; font-weight: 600; }
.shortcut { font-size: .68rem; color: var(--text-3); text-align: center; padding: 2px 0 0; }
.shortcut kbd {
    background: var(--panel-3);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 1px 6px;
    font-family: var(--font);
    font-size: .66rem;
}

/* ============================================================
   CENTRO CHAT
   ============================================================ */
.chat-center {
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
}
.chat-header {
    padding: 14px 18px;
    background: rgba(20,26,41,.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    z-index: 5;
}
.chat-header .header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-header .menu-btn {
    display: none;
    width: 36px; height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    color: var(--text-2);
    cursor: pointer;
    align-items: center; justify-content: center;
    transition: all .15s;
}
.chat-header .menu-btn svg { width: 18px; height: 18px; }
.chat-header .menu-btn:hover { color: var(--text); border-color: var(--accent); }
.chat-header .chat-title { min-width: 0; }
.chat-header .chat-title h2 {
    font-size: .98rem; font-weight: 700; letter-spacing: -.01em;
    display: flex; align-items: center; gap: 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header .chat-title h2 svg { width: 19px; height: 19px; color: var(--accent); flex-shrink: 0; }
.chat-header .chat-title .status-line { display: flex; align-items: center; gap: 6px; font-size: .7rem; color: var(--text-3); margin-top: 2px; }
.chat-header .chat-title .status-line .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px rgba(52,211,153,.7); }
.chat-header .header-right { display: flex; align-items: center; gap: 10px; }
.chat-header .badge {
    font-size: .7rem;
    font-weight: 600;
    background: var(--accent-soft);
    border: 1px solid rgba(77,107,254,.35);
    padding: 4px 12px;
    border-radius: 99px;
    color: #a5b4fc;
    letter-spacing: .02em;
}
.chat-header .tools-btn {
    display: none;
    width: 36px; height: 36px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--panel-3);
    color: var(--text-2);
    cursor: pointer;
    align-items: center; justify-content: center;
    transition: all .15s;
}
.chat-header .tools-btn svg { width: 18px; height: 18px; }
.chat-header .tools-btn:hover { color: var(--text); border-color: var(--accent); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* --- Messaggi --- */
.message {
    max-width: 84%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: .88rem;
    line-height: 1.6;
    animation: msgIn .25s ease;
    position: relative;
}
.message .msg-head {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 5px;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.message .msg-head svg { width: 13px; height: 13px; }
.message .msg-actions { position: absolute; top: -11px; right: 10px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.message:hover .msg-actions { opacity: 1; }
.copy-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 9px;
    font-size: .68rem; font-weight: 600;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: var(--elevated);
    color: var(--text-2);
    cursor: pointer;
    font-family: var(--font);
    transition: all .15s;
    box-shadow: var(--shadow-sm);
}
.copy-btn svg { width: 12px; height: 12px; }
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.copy-btn.copied { color: var(--green); border-color: rgba(52,211,153,.5); }

.message .content { white-space: pre-wrap; word-break: break-word; }
.message .content:empty::after { content: '\200b'; }

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #3d5afe, #4d6bfe);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 6px 20px rgba(77,107,254,.28);
}
.message.user .msg-head { color: rgba(255,255,255,.8); justify-content: flex-end; }
.message.user .copy-btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }

.message.assistant {
    align-self: flex-start;
    background: var(--panel-3);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}
.message.assistant .msg-head { color: var(--text-3); }

.message.system {
    align-self: center;
    background: var(--panel-3);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: .76rem;
    max-width: 92%;
    text-align: center;
    border-radius: 99px;
    padding: 7px 18px;
    display: flex; align-items: center; gap: 8px;
}
.message.system .msg-head { display: none; }
.message.system svg { width: 14px; height: 14px; color: var(--accent); flex-shrink: 0; }

.message .msg-time { font-size: .62rem; color: var(--text-3); margin-top: 6px; text-align: right; }
.message.user .msg-time { color: rgba(255,255,255,.65); }

/* --- Markdown --- */
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 8px; line-height: 1.35; letter-spacing: -.01em; }
.md h1 { font-size: 1.25rem; } .md h2 { font-size: 1.12rem; } .md h3 { font-size: 1rem; } .md h4 { font-size: .92rem; }
.md h1:first-child, .md h2:first-child, .md h3:first-child, .md h4:first-child { margin-top: 0; }
.md p { margin: 6px 0; }
.md p:first-child { margin-top: 0; } .md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md a { color: #8ab4ff; text-decoration: none; border-bottom: 1px solid rgba(138,180,255,.35); }
.md a:hover { border-bottom-color: #8ab4ff; }
.md blockquote {
    margin: 10px 0;
    padding: 8px 14px;
    border-left: 3px solid var(--accent);
    background: var(--accent-softer);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-2);
}
.md hr { border: none; border-top: 1px solid var(--border-strong); margin: 14px 0; }
.md table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: .82rem; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 7px 11px; text-align: left; }
.md th { background: var(--elevated); font-weight: 600; }
.md tr:nth-child(even) td { background: rgba(255,255,255,.015); }
.md img { max-width: 100%; border-radius: var(--radius-sm); }
.md code {
    font-family: var(--mono);
    font-size: .8em;
    background: rgba(100,116,143,.18);
    padding: 2px 6px;
    border-radius: 5px;
    color: #c4b5fd;
}
.md pre {
    position: relative;
    background: #0b0e16;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin: 12px 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.md pre code {
    display: block;
    padding: 14px 16px;
    overflow-x: auto;
    font-size: .78rem;
    line-height: 1.6;
    background: transparent;
    color: #d6dce8;
}
.md pre .code-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 14px;
    background: var(--panel-3);
    border-bottom: 1px solid var(--border);
    font-size: .66rem;
    color: var(--text-3);
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.md pre .code-head .code-lang { display: flex; align-items: center; gap: 6px; }
.md pre .code-head .code-lang svg { width: 12px; height: 12px; color: var(--accent); }
.md pre .code-head .copy-btn { padding: 2px 8px; font-size: .64rem; }
.md pre:has(.code-head) code { padding-top: 10px; }
.message.user .md code, .message.user .md pre { background: rgba(0,0,0,.25); border-color: rgba(255,255,255,.2); }
.message.user .md pre { background: rgba(0,0,0,.3); }
.message.user .md a { color: #cfe0ff; }
.message.user .md blockquote { border-left-color: rgba(255,255,255,.7); background: rgba(255,255,255,.08); }


/* --- Card documenti generati (pdf/docx/xlsx/pptx) --- */
.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px 0;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--panel-3), var(--panel-2));
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    animation: fc-in .25s ease;
}
@keyframes fc-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.file-card .fc-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    flex-shrink: 0;
}
.file-card .fc-icon svg { width: 20px; height: 20px; }
.file-card .fc-info { flex: 1; min-width: 0; }
.file-card .fc-name {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    font-family: var(--mono);
    word-break: break-all;
}
.file-card .fc-meta {
    font-size: .68rem;
    color: var(--text-3);
    margin-top: 2px;
}
.file-card .fc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s, opacity .15s;
    white-space: nowrap;
}
.file-card .fc-btn svg { width: 14px; height: 14px; }
.file-card .fc-btn:hover:not(:disabled) { background: var(--accent-2); transform: translateY(-1px); }
.file-card .fc-btn:disabled { opacity: .65; cursor: default; }
.file-card .fc-btn:active:not(:disabled) { transform: translateY(0); }

.file-card.pdf .fc-icon { background: rgba(248,113,113,.12); color: var(--red); }
.file-card.image .fc-icon { background: rgba(52,211,153,.12); color: var(--green); }
.file-card.zip .fc-icon { background: rgba(251,191,36,.12); color: var(--yellow); }
.file-card.audio .fc-icon { background: rgba(138,180,255,.12); color: #8ab4ff; }
.file-card.video .fc-icon { background: rgba(192,132,252,.12); color: #c084fc; }
.file-card.code .fc-icon { background: rgba(52,211,153,.1); color: var(--green); }
.file-card .fc-note { margin-top: 2px; font-size: .68rem; color: var(--text-3); }
.file-card.image { flex-direction: column; align-items: stretch; }
.file-card .fc-thumb { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius-sm); }
.message.user .file-card { background: rgba(0,0,0,.22); border-color: rgba(255,255,255,.22); }


/* --- Allegati nei messaggi --- */
.attachments { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.attachment {
    display: flex; align-items: center; gap: 11px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 9px 12px;
    transition: all .15s;
    text-decoration: none;
    color: var(--text);
    min-width: 0;
}
.attachment:hover { border-color: var(--accent); background: var(--elevated); }
.attachment .att-icon {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
}
.attachment .att-icon svg { width: 19px; height: 19px; }
.attachment.image .att-icon { background: rgba(52,211,153,.12); color: var(--green); }
.attachment.pdf .att-icon { background: rgba(248,113,113,.12); color: var(--red); }
.attachment.zip .att-icon { background: rgba(251,191,36,.12); color: var(--yellow); }
.attachment.audio .att-icon { background: rgba(138,180,255,.12); color: #8ab4ff; }
.attachment.video .att-icon { background: rgba(192,132,252,.12); color: #c084fc; }
.attachment.code .att-icon { background: rgba(52,211,153,.1); color: var(--green); }
.attachment .att-meta { flex: 1; min-width: 0; }
.attachment .att-name { font-size: .8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-size { font-size: .68rem; color: var(--text-3); }
.attachment .att-dl { color: var(--text-3); display: flex; align-items: center; transition: color .15s; }
.attachment .att-dl svg { width: 15px; height: 15px; }
.attachment:hover .att-dl { color: var(--accent); }
.attachment.att-image-preview { flex-direction: column; align-items: stretch; padding: 8px; gap: 8px; }
.attachment.att-image-preview img { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius-sm); }
.message.user .attachment { background: rgba(0,0,0,.22); border-color: rgba(255,255,255,.22); }

/* --- Indicatore digitazione --- */
.typing-msg { display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.typing-dots { display: flex; gap: 5px; }
.typing-dots span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
.typing-label { font-size: .72rem; color: var(--text-3); }

/* --- Empty state --- */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 30px 24px 60px;
    text-align: center;
    animation: fadeIn .4s ease;
}
.empty-state .empty-logo {
    width: 72px; height: 72px;
    border-radius: 22px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 16px 40px rgba(77,107,254,.4);
}
.empty-state .empty-logo svg { width: 38px; height: 38px; color: #fff; }
.empty-state .empty-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.empty-state .empty-sub { font-size: .84rem; color: var(--text-2); max-width: 420px; line-height: 1.6; }
.flight-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 16px auto 2px;
    padding: 11px 22px;
    border-radius: 999px;
    border: 1px solid rgba(76, 141, 255, .45);
    background: linear-gradient(135deg, rgba(76, 141, 255, .20), rgba(76, 141, 255, .06));
    color: #cfe0ff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
.flight-cta:hover {
    background: linear-gradient(135deg, rgba(76, 141, 255, .32), rgba(76, 141, 255, .12));
    box-shadow: 0 0 0 4px rgba(76, 141, 255, .12);
    transform: translateY(-1px);
}
.flight-btn svg { width: 17px; height: 17px; color: #6ea5ff; }

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 720px;
    margin-top: 8px;
}
.suggestion-chip {
    text-align: left;
    padding: 13px 15px;
    background: var(--panel-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-size: .8rem;
    font-family: var(--font);
    line-height: 1.5;
    cursor: pointer;
    transition: all .18s ease;
    display: flex; flex-direction: column; gap: 6px;
}
.suggestion-chip svg { width: 16px; height: 16px; color: var(--accent); }
.suggestion-chip:hover {
    border-color: var(--accent);
    background: var(--elevated);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--text);
}

.suggestion-groups {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 720px;
    margin-top: 10px;
}
.suggestion-group-title {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-3);
    text-align: left;
    margin: 4px 0 2px;
}
.suggestion-group + .suggestion-group .suggestion-group-title {
    margin-top: 18px;
}
.suggestion-groups .suggestion-grid { margin-top: 8px; }

/* --- Input chat --- */
.chat-input {
    padding: 12px 16px 16px;
    background: linear-gradient(180deg, transparent, rgba(15,20,32,.6));
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-input-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--panel-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 10px 10px 10px 14px;
    transition: border-color .15s, box-shadow .15s;
    position: relative;
}
.chat-input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.chat-input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    color: var(--text);
    font-family: var(--font);
    font-size: .9rem;
    line-height: 1.55;
    max-height: 160px;
    min-height: 24px;
    padding: 4px 0;
    outline: none;
}
.chat-input-box textarea::placeholder { color: var(--text-3); }
.icon-btn {
    width: 38px; height: 38px; flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--text); background: var(--hover); }
.icon-btn.attach-btn { border: 1px dashed var(--border-strong); }
.icon-btn.attach-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-softer); }
.send-btn {
    width: 40px; height: 40px; flex-shrink: 0;
    border: none;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(77,107,254,.35);
    transition: all .15s;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: saturate(.6); box-shadow: none; }
.send-btn .spinner { width: 17px; height: 17px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }

/* --- Chip allegati pending --- */
.attach-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chip {
    display: flex; align-items: center; gap: 8px;
    background: var(--panel-3);
    border: 1px solid var(--border-strong);
    border-radius: 99px;
    padding: 6px 8px 6px 12px;
    font-size: .76rem;
    color: var(--text-2);
    animation: chipIn .2s ease;
    max-width: 260px;
}
.attach-chip svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--accent); }
.attach-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .chip-size { color: var(--text-3); font-size: .66rem; flex-shrink: 0; }
.attach-chip button {
    border: none; background: transparent; color: var(--text-3);
    cursor: pointer; padding: 3px; border-radius: 50%;
    display: flex; align-items: center;
    transition: all .12s;
}
.attach-chip button svg { width: 12px; height: 12px; color: inherit; }
.attach-chip button:hover { color: var(--red); background: rgba(248,113,113,.12); }
.attach-chip .chip-state { font-size: .66rem; flex-shrink: 0; border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.attach-chip .chip-load { color: var(--yellow); background: rgba(251,191,36,.1); }
.attach-chip .chip-ok { color: var(--green); background: rgba(52,211,153,.1); }
.attach-chip .chip-err { color: var(--red); background: rgba(248,113,113,.1); }

/* ============================================================
   MODALI
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(4,6,12,.75);
    backdrop-filter: blur(6px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn .2s ease;
    padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--panel-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    max-width: 820px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalIn .25s ease;
}
.modal-header {
    padding: 16px 22px;
    background: var(--panel-3);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    display: flex; align-items: center; gap: 9px;
}
.modal-header h3 svg { width: 18px; height: 18px; color: var(--accent); }
.modal-header .close-btn {
    background: transparent; border: none;
    color: var(--text-3);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: all .15s;
    display: flex; align-items: center;
}
.modal-header .close-btn svg { width: 18px; height: 18px; }
.modal-header .close-btn:hover { color: var(--red); background: rgba(248,113,113,.1); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }

.admin-create-form {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-bottom: 18px;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.admin-create-form input {
    flex: 1; min-width: 130px;
    padding: 10px 12px;
    background: var(--panel-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: .82rem;
    font-family: var(--font);
}
.admin-create-form select { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.1); color: #fff; font-size: 14px; box-sizing: border-box; }
.admin-create-form select option { background: #1a1a2e; color: #fff; }
.admin-create-form select:focus { outline: none; border-color: #6c63ff; box-shadow: 0 0 0 3px rgba(108,99,255,0.2); }
.admin-create-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-create, .btn-edit, .btn-save-limit, .btn-activate, .btn-suspend, .btn-promote, .btn-demote, .btn-delete {
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn-create { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 14px rgba(77,107,254,.3); }
.btn-create:hover { filter: brightness(1.1); }
.btn-save-limit { background: var(--accent-soft); color: #a5b4fc; border: 1px solid rgba(77,107,254,.4); }
.btn-save-limit:hover { background: var(--accent); color: #fff; }
.btn-activate { background: rgba(52,211,153,.14); color: var(--green); border: 1px solid rgba(52,211,153,.4); }
.btn-activate:hover { background: var(--green); color: #04210f; }
.btn-suspend { background: rgba(251,191,36,.12); color: var(--yellow); border: 1px solid rgba(251,191,36,.4); }
.btn-suspend:hover { background: var(--yellow); color: #231a02; }
.btn-promote { background: rgba(138,180,255,.12); color: #8ab4ff; border: 1px solid rgba(138,180,255,.4); }
.btn-promote:hover { background: #8ab4ff; color: #0b1020; }
.btn-demote { background: rgba(167,139,250,.12); color: #c4b5fd; border: 1px solid rgba(167,139,250,.4); }
.btn-demote:hover { background: #c4b5fd; color: #150b2e; }
.btn-delete { background: rgba(248,113,113,.12); color: var(--red); border: 1px solid rgba(248,113,113,.4); }
.btn-delete:hover { background: var(--red); color: #2a0505; }

.admin-user-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.admin-user-item .avatar {
    width: 36px; height: 36px; flex-shrink: 0;
    border-radius: 10px;
    background: var(--accent-soft);
    color: #a5b4fc;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.admin-user-item .user-info-mini { flex: 1; min-width: 150px; }
.admin-user-item .name { font-weight: 600; font-size: .85rem; }
.admin-user-item .email { font-size: .72rem; color: var(--text-3); margin-top: 1px; }
.admin-user-item .user-limit { font-size: .72rem; color: var(--text-2); }
.admin-user-item .user-limit .limit-value { font-weight: 700; }
.admin-user-item .user-limit .limit-value.green { color: var(--green); }
.admin-user-item .user-limit .limit-value.yellow { color: var(--yellow); }
.admin-user-item .user-limit .limit-value.red { color: var(--red); }
.admin-user-item .user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-user-item .user-actions button { padding: 6px 10px; font-size: .7rem; }
.admin-empty {
    text-align: center;
    padding: 30px;
    color: var(--text-3);
    font-size: .84rem;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-wrap {
    position: fixed;
    bottom: 22px;
    right: 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--elevated);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    color: var(--text);
    font-size: .82rem;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    animation: toastIn .3s ease;
    max-width: 340px;
}
.toast svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--accent); }
.toast.success { border-left-color: var(--green); } .toast.success svg { color: var(--green); }
.toast.error { border-left-color: var(--red); } .toast.error svg { color: var(--red); }
.toast.warning { border-left-color: var(--yellow); } .toast.warning svg { color: var(--yellow); }
.toast.hide { animation: toastOut .3s ease forwards; }

/* ============================================================
   ANIMAZIONI
   ============================================================ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }
@keyframes chipIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1180px) {
    body { padding: 14px; }
    .app { grid-template-columns: 260px 1fr; height: calc(100vh - 28px); height: calc(100dvh - 28px); }
}
@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; height: 100dvh; gap: 0; }
    body { padding: 0; }
    .app .sidebar { display: none; }
    .sidebar {
        position: fixed;
        top: 0; bottom: 0;
        width: min(320px, 88vw);
        z-index: 300;
        border-radius: 0;
        border: none;
        box-shadow: var(--shadow-lg);
        transition: transform .28s ease;
        padding: 18px;
    }
    .sidebar { left: 0; transform: translateX(-105%); }
    .sidebar.open { display: flex; transform: translateX(0); }
    .chat-header .menu-btn, .chat-header .tools-btn { display: inline-flex; }
    .chat-center { border-radius: 0; border: none; }
    .drawer-backdrop {
        position: fixed; inset: 0;
        background: rgba(4,6,12,.6);
        backdrop-filter: blur(3px);
        z-index: 290;
        opacity: 0;
        pointer-events: none;
        transition: opacity .25s;
    }
    .drawer-backdrop.show { opacity: 1; pointer-events: auto; }
    .message { max-width: 92%; }
    .chat-input { padding: 10px 12px 14px; }
    .suggestion-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
    .auth-container { padding: 34px 24px 28px; border-radius: var(--radius-lg); }
    .chat-header { padding: 12px 14px; }
    .chat-header .badge { display: none; }
    .chat-messages { padding: 16px 12px 8px; }
    .message { max-width: 96%; }
}

/* ===== Conversazioni (sidebar) ===== */
.conv-list { display:flex; flex-direction:column; gap:6px; margin-top:8px; flex:1 1 auto; min-height:0; max-height:none; overflow-y:auto; }
.conv-empty { color:var(--muted,#8892a6); font-size:12px; padding:8px 4px; }
.conv-item { display:flex; align-items:center; gap:6px; padding:8px 10px; border-radius:10px; background:rgba(255,255,255,.04); cursor:pointer; transition:background .15s; }
.conv-item:hover { background:rgba(255,255,255,.08); }
.conv-item.active { background:rgba(78,168,222,.15); outline:1px solid rgba(78,168,222,.4); }
.conv-body { flex:1; min-width:0; }
.conv-title { font-size:13px; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.conv-date { font-size:11px; opacity:.55; margin-top:2px; }
.conv-del { flex:none; width:22px; height:22px; display:flex; align-items:center; justify-content:center; border:none; background:transparent; color:inherit; opacity:.5; border-radius:6px; cursor:pointer; }
.conv-del:hover { opacity:1; background:rgba(248,113,113,.15); color:#f87171; }
.new-chat-btn { width:100%; margin-top:8px; padding:8px 10px; border-radius:10px; border:1px dashed rgba(255,255,255,.2); background:transparent; color:inherit; cursor:pointer; font-size:13px; transition:.15s; }
.new-chat-btn:hover { border-color:rgba(78,168,222,.6); color:#4ea8de; background:rgba(78,168,222,.08); }
.conv-toolbar { display:flex; gap:6px; margin-top:8px; }
.conv-toolbar .new-chat-btn { flex:1; }
.cat-add-btn { flex:none; padding:8px 11px; border-radius:10px; border:1px dashed rgba(255,255,255,.25); background:transparent; color:var(--muted,#8892a6); cursor:pointer; font-size:14px; transition:all .15s; }
.cat-add-btn:hover { border-color:rgba(78,168,222,.65); color:#4ea8de; background:rgba(78,168,222,.08); }
.cat-section { display:flex; flex-direction:column; gap:6px; margin-top:6px; }
.cat-header { display:flex; align-items:center; gap:4px; padding:6px 4px 2px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--muted,#8892a6); user-select:none; position:sticky; top:0; z-index:2; background:var(--panel-2,#12182a); border-radius:8px 8px 0 0; }
.cat-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cat-count { background:rgba(255,255,255,.08); border-radius:8px; padding:1px 6px; font-size:10px; font-weight:600; }
.cat-btn { flex:none; background:none; border:none; padding:2px 4px; border-radius:6px; font-size:11px; line-height:1; cursor:pointer; opacity:0; transition:opacity .15s, background .15s; }
.cat-header:hover .cat-btn { opacity:.75; }
.cat-btn:hover { opacity:1; background:rgba(255,255,255,.12); }
.conv-move { flex:none; width:22px; height:22px; display:flex; align-items:center; justify-content:center; border:none; background:transparent; color:inherit; opacity:0; border-radius:6px; cursor:pointer; font-size:12px; transition:opacity .15s, background .15s; }
.conv-item:hover .conv-move { opacity:.5; }
.conv-move:hover { opacity:1; background:rgba(255,255,255,.12); }
.cat-menu { position:fixed; z-index:9999; min-width:190px; max-width:260px; max-height:260px; overflow-y:auto; padding:6px; background:#1b2333; border:1px solid rgba(255,255,255,.14); border-radius:12px; box-shadow:0 10px 30px rgba(0,0,0,.45); }
.cat-menu-opt { display:block; width:100%; text-align:left; padding:8px 10px; border:none; border-radius:8px; background:none; color:#e6edf3; font-size:13px; cursor:pointer; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cat-menu-opt:hover { background:rgba(78,168,222,.16); }
.cat-menu-opt.active { color:#4ea8de; font-weight:600; }


.btn-edit { background: #17a2b8 !important; }
.btn-edit:hover { background: #138496 !important; }
