/* ===== Asistenza DevSoft — console operatori e admin (stesso linguaggio visivo di LogiDev) ===== */

:root {
    color-scheme: light;
    --primary: #f47b25;
    --primary-rgb: 244, 123, 37;
    --primary-hover: #e06b15;
    --background: #f8f7f5;
    --foreground: #1b1511;
    --muted: #6f6259;
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgb(153 147 144 / 35%);
    --surface: rgba(0, 0, 0, 0.04);
    --surface-hover: rgba(var(--primary-rgb), 0.1);
    --input-bg: rgba(0, 0, 0, 0.05);
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --radius: 0.6rem;
    --radius-lg: 1rem;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.dark {
    color-scheme: dark;
    --background: #1a120c;
    --foreground: #f8f7f5;
    --muted: #c9bfb8;
    --glass-bg: rgba(40, 28, 20, 0.72);
    --glass-border: rgba(138, 114, 96, 0.25);
    --surface: rgba(255, 255, 255, 0.05);
    --surface-hover: rgba(var(--primary-rgb), 0.16);
    --input-bg: rgba(255, 255, 255, 0.06);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--foreground);
    background:
        radial-gradient(900px 500px at 10% -10%, rgba(var(--primary-rgb), 0.16), transparent 60%),
        radial-gradient(700px 500px at 110% 110%, rgba(128, 0, 32, 0.10), transparent 60%),
        var(--background);
    background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin-bottom: 0.75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* ---------- topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--foreground); font-weight: 500; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--primary); }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.2); }
.brand-lg { font-size: 1.35rem; margin-bottom: 0.25rem; }

.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 0.35rem 0.7rem; border-radius: var(--radius); font-weight: 600; font-size: 0.9rem; }
.nav a:hover { background: var(--surface-hover); color: var(--foreground); text-decoration: none; }
.nav a.active { background: rgba(var(--primary-rgb), 0.15); color: var(--primary); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.topbar-right .user { font-weight: 600; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 0.45rem; color: inherit; text-decoration: none; }
.topbar-right .user:hover span:last-child { text-decoration: underline; }
.avatar-sm, .avatar-lg { border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-sm { width: 26px; height: 26px; }
.avatar-lg { width: 96px; height: 96px; }
.avatar-initials {
    display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
    background: rgba(var(--primary-rgb), 0.18); color: var(--primary);
}
.avatar-sm.avatar-initials { font-size: 0.75rem; }
.avatar-lg.avatar-initials { font-size: 2.2rem; }
.profile-photo { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.profile-photo-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.profile-photo-actions form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.msg .who .avatar-msg { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; vertical-align: -4px; margin-right: 0.3rem; }
.transfer-box { max-width: 480px; }
.transfer-list { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.6rem 0; max-height: 45vh; overflow-y: auto; }
.transfer-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; border: 1px solid var(--glass-border); border-radius: var(--radius); cursor: pointer; }
.transfer-item input { width: auto; }
.transfer-item .name { flex: 1; font-weight: 600; }
.transfer-warn { color: #b45309; font-size: 0.85rem; }
.transfer-box textarea { min-height: 4.5rem; resize: vertical; }
.stars { color: #f59e0b; letter-spacing: 0.05em; white-space: nowrap; }
.transfer-box .form-label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.88rem; }
.msg-system.transfer-note { font-style: normal; border: 1px dashed var(--glass-border); border-radius: var(--radius); padding: 0.35rem 0.6rem; }
/* Su schermi larghi il contenitore del menu non esiste per il layout: nav e pulsanti restano nella barra. */
.topbar-menu { display: contents; }
.topbar .menu-btn { display: none; } /* piu' specifico di .icon-btn, definito dopo */

/* ---------- notifiche (campanella) ---------- */
.notif { position: relative; }
.notif-btn.on { color: var(--primary); border-color: rgba(var(--primary-rgb), 0.55); }
.notif-panel {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 340px; padding: 0.9rem;
    max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px); overflow-y: auto;
    background: var(--background); border: 1px solid var(--glass-border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.notif-row { display: flex; gap: 0.9rem; align-items: flex-start; justify-content: space-between; }
.notif-title { font-weight: 700; }
.notif-desc { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.4; }
.notif-status { font-size: 0.82rem; margin-top: 0.7rem; }
.notif-status.warn { color: #b45309; }
.dark .notif-status.warn { color: #fbbf24; }
#notifTest { margin-top: 0.6rem; }
.notif-check { display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 0.7rem; font-size: 0.82rem; cursor: pointer; }
.notif-check input { width: auto; margin-top: 0.15rem; accent-color: var(--primary); }
.notif-section { margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1px solid var(--glass-border); }
.sound-row { display: flex; gap: 0.5rem; margin-top: 0.45rem; }
.sound-row select { flex: 1; padding: 0.4rem 0.6rem; }
.sound-row .btn { flex-shrink: 0; }
.sound-volume { display: flex; gap: 0.55rem; align-items: center; margin-top: 0.55rem; color: var(--muted); font-size: 0.8rem; }
.sound-volume input[type="range"] { flex: 1; padding: 0; background: none; accent-color: var(--primary); box-shadow: none; }
.sound-volume span { min-width: 2.6rem; text-align: right; font-variant-numeric: tabular-nums; }
.notif-section .notif-desc { margin-top: 0.5rem; }
.sound-banner { cursor: pointer; }

.switch { position: relative; flex-shrink: 0; width: 46px; height: 26px; margin-top: 0.1rem; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch input:disabled { cursor: not-allowed; }
.switch-track {
    position: absolute; inset: 0; border-radius: 999px; background: var(--input-bg);
    border: 1px solid var(--glass-border); transition: background 150ms ease, border-color 150ms ease;
}
.switch-track::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 150ms ease;
}
.switch input:checked + .switch-track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid rgba(var(--primary-rgb), 0.6); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }

.page { padding: 1.25rem; }
/* Console: barra in alto + pagina che occupa il resto dello schermo (dvh: giusto anche con le barre del browser mobile). */
body.full-height { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.full-height .page { flex: 1; min-height: 0; padding: 0.9rem; }

/* ---------- controlli ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    border: 1px solid transparent; border-radius: var(--radius);
    padding: 0.5rem 1rem; font: inherit; font-weight: 600; cursor: pointer;
    background: var(--surface); color: var(--foreground);
    transition: background 150ms ease, border-color 150ms ease;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--glass-border); }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--glass-border);
    background: transparent; color: var(--foreground); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); }

input, select, textarea {
    width: 100%; font: inherit; color: var(--foreground);
    background: var(--input-bg); border: 1px solid transparent; border-radius: var(--radius);
    padding: 0.55rem 0.75rem; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(var(--primary-rgb), 0.6); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15); }
input[type="checkbox"] { width: auto; }
textarea.code { font-family: Consolas, 'Cascadia Mono', monospace; font-size: 0.85rem; min-height: 55vh; }

.form { display: flex; flex-direction: column; gap: 0.85rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.88rem; }
.form label.check { flex-direction: row; align-items: center; gap: 0.5rem; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.85rem; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.check-group { border: 1px solid var(--glass-border); border-radius: var(--radius); padding: 0.6rem 0.85rem 0.75rem; margin: 0; }
.check-group legend { font-weight: 600; font-size: 0.88rem; padding: 0 0.3rem; }
.check-group .check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.35rem 1rem; margin-top: 0.35rem; }
.check-group .check { font-weight: 400; }
.form-section { margin-top: 0.6rem; font-size: 1rem; }
.hours-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.5rem 0.85rem; margin-top: 0.45rem; }
.hours-grid label { font-weight: 600; font-size: 0.82rem; }
.preview-box { border: 1px dashed var(--glass-border); border-radius: var(--radius); padding: 0.55rem 0.75rem; font-size: 0.9rem; white-space: pre-wrap; }
.assigned { font-size: 0.9rem; }
.assigned-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; margin-top: 0.35rem; }

.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); margin-bottom: 0.9rem; font-size: 0.9rem; }
.alert-error { background: rgba(239, 68, 68, 0.12); color: var(--error); }
.alert-success { background: rgba(34, 197, 94, 0.12); color: #15803d; }
.dark .alert-success { color: #4ade80; }
.alert-warning { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.dark .alert-warning { color: #fbbf24; }

.card { padding: 1.25rem; margin-bottom: 1rem; }
.narrow { max-width: 520px; margin: 3rem auto; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--glass-border); vertical-align: top; }
.table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:hover td { background: var(--surface); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.85rem; margin-top: 1rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.inline-field { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; }
.inline-field select, .inline-field input { width: auto; }

.badge {
    display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
    font-size: 0.72rem; font-weight: 700; background: var(--surface); color: var(--muted); white-space: nowrap;
}
.badge.st-ai { background: rgba(59, 130, 246, 0.14); color: var(--info); }
.badge.st-wait { background: rgba(245, 158, 11, 0.18); color: #b45309; }
.dark .badge.st-wait { color: #fbbf24; }
.badge.st-op { background: rgba(var(--primary-rgb), 0.16); color: var(--primary); }
.badge.st-done { background: rgba(34, 197, 94, 0.14); color: #15803d; }
.dark .badge.st-done { color: #4ade80; }
.badge.st-urgent { background: rgba(239, 68, 68, 0.15); color: var(--error); }
.badge.ok { background: rgba(34, 197, 94, 0.14); color: #15803d; }
.badge.off { background: rgba(239, 68, 68, 0.12); color: var(--error); }

pre.secret {
    white-space: pre-wrap; word-break: break-all; background: var(--input-bg);
    padding: 0.75rem; border-radius: var(--radius); font-size: 0.8rem; user-select: all;
}

/* ---------- login ---------- */

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; padding: 2rem; }
.login-card .muted { margin-bottom: 1.25rem; }

/* ---------- console ---------- */

.console {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 300px;
    gap: 0.9rem;
    height: 100%;
}
.pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

.tabs { display: flex; gap: 0.2rem; padding: 0.6rem 0.6rem 0; flex-wrap: wrap; }
.tab {
    border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: 0.82rem;
    padding: 0.4rem 0.6rem; border-radius: var(--radius); cursor: pointer;
}
.tab:hover { background: var(--surface-hover); }
.tab.active { background: rgba(var(--primary-rgb), 0.15); color: var(--primary); }
.tab .count:not(:empty) {
    display: inline-block; min-width: 1.3em; padding: 0 0.35em; margin-left: 0.2rem;
    border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.72rem; text-align: center;
}
.search { padding: 0.6rem; }
.notify-banner {
    display: flex; gap: 0.6rem; align-items: center; margin: 0 0.6rem 0.6rem; padding: 0.5rem 0.7rem;
    border-radius: var(--radius); background: rgba(var(--primary-rgb), 0.12); font-size: 0.82rem;
}

.conv-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 0.4rem 0.6rem; }
.conv-item { padding: 0.65rem 0.7rem; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; }
.conv-item + .conv-item { margin-top: 0.2rem; }
.conv-item:hover { background: var(--surface-hover); }
.conv-item.selected { background: rgba(var(--primary-rgb), 0.14); border-color: rgba(var(--primary-rgb), 0.35); }
.conv-top { display: flex; justify-content: space-between; gap: 0.5rem; }
.conv-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 0.78rem; flex-shrink: 0; }
.conv-tenant { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 0.15rem; }
.conv-badges { display: flex; gap: 0.3rem; margin-top: 0.35rem; flex-wrap: wrap; }
.conv-empty { color: var(--muted); padding: 2rem 1rem; text-align: center; }

.empty-state { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }

.chat { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-header {
    display: flex; justify-content: space-between; align-items: center; gap: 0.6rem 1rem; flex-wrap: wrap;
    padding: 0.8rem 1rem; border-bottom: 1px solid var(--glass-border);
}
.chat-title { flex: 1 1 auto; min-width: 0; }
.chat-back, .info-btn, .pane-head, .lbl-short { display: none; }
.chat-title .name { font-weight: 700; font-size: 1.02rem; }
.chat-title .sub { font-size: 0.82rem; margin-top: 0.15rem; }
.chat-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.ai-summary {
    margin: 0.7rem 1rem 0; padding: 0.7rem 0.9rem; border-radius: var(--radius);
    background: rgba(59, 130, 246, 0.09); border-left: 3px solid var(--info); font-size: 0.88rem; white-space: pre-wrap;
}
.ai-summary-title { font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--info); margin-bottom: 0.25rem; }

.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.55rem; }
.msg { display: flex; }
.msg .bubble { max-width: 78%; padding: 0.55rem 0.8rem; border-radius: 0.9rem; background: var(--surface); }
.msg-user .bubble { background: var(--surface); border-bottom-left-radius: 0.25rem; }
.msg-ai { justify-content: flex-end; }
.msg-ai .bubble { background: rgba(59, 130, 246, 0.1); border-bottom-right-radius: 0.25rem; }
.msg-operator { justify-content: flex-end; }
.msg-operator .bubble { background: rgba(var(--primary-rgb), 0.14); border-bottom-right-radius: 0.25rem; }
.msg.internal .bubble { opacity: 0.8; border: 1px dashed var(--glass-border); }
.msg.streaming .bubble { outline: 1px dashed rgba(59, 130, 246, 0.4); }
.msg-system { justify-content: center; color: var(--muted); font-size: 0.8rem; font-style: italic; text-align: center; }
.msg .who { font-size: 0.72rem; font-weight: 700; color: var(--muted); margin-bottom: 0.15rem; }
.msg .text { overflow-wrap: anywhere; }
.msg .text p + p, .msg .text ul, .msg .text ol, .msg .text pre { margin-top: 0.4rem; }
.msg .text ul, .msg .text ol { padding-left: 1.2rem; }
.msg .text code { font-family: Consolas, monospace; font-size: 0.85em; background: var(--input-bg); padding: 0 0.25rem; border-radius: 4px; }
.msg .text pre { background: var(--input-bg); padding: 0.5rem; border-radius: 6px; overflow-x: auto; }
.msg .text .md-h { font-weight: 700; }
.msg .time { font-size: 0.7rem; color: var(--muted); margin-top: 0.2rem; text-align: right; }

.tool-call { margin-top: 0.4rem; font-size: 0.8rem; }
.tool-call summary { cursor: pointer; color: var(--info); font-weight: 600; }
.tool-call pre { white-space: pre-wrap; word-break: break-word; background: var(--input-bg); padding: 0.5rem; border-radius: 6px; margin-top: 0.3rem; max-height: 240px; overflow: auto; }
.tool-error summary { color: var(--error); }

.typing { padding: 0 1rem 0.4rem; color: var(--muted); font-size: 0.82rem; font-style: italic; }

.composer { display: flex; gap: 0.6rem; padding: 0.7rem 1rem; border-top: 1px solid var(--glass-border); align-items: flex-end; }
/* altezza dal testo (console.js); due righe di partenza, come prima, per i suggerimenti lunghi */
.composer textarea { resize: none; min-height: 64px; max-height: 180px; overflow-y: hidden; }
.send-btn { height: 44px; flex-shrink: 0; }

/* ---------- immagini ---------- */
.attach-btn { width: 44px; height: 44px; flex-shrink: 0; color: var(--muted); }
.attach-btn:hover { color: var(--primary); }
.previews { display: flex; gap: 0.5rem; padding: 0.7rem 1rem 0; border-top: 1px solid var(--glass-border); overflow-x: auto; }
.previews:not([hidden]) + .composer { border-top: none; }
.preview { position: relative; flex-shrink: 0; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; border: 1px solid var(--glass-border); }
.preview button {
    position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: none; cursor: pointer;
    background: #1b1511; color: #fff; font-size: 13px; line-height: 20px; padding: 0;
}
.msg .images { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.35rem; margin: 0.2rem 0 0.3rem; }
.msg .images img {
    width: 100%; height: 140px; object-fit: cover; border-radius: 0.6rem; cursor: zoom-in; display: block;
    background: var(--surface);
}
.msg .images.single { grid-template-columns: minmax(0, 1fr); }
.msg .images.single img { width: auto; height: auto; max-width: 100%; max-height: 320px; object-fit: contain; }
.chat.dragging .messages { outline: 2px dashed rgba(var(--primary-rgb), 0.55); outline-offset: -8px; }
.lightbox {
    position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 2rem;
    background: rgba(0, 0, 0, 0.85); cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }

/* ---------- traduzioni ---------- */
.chat-tools { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.translate-toggle[aria-pressed="true"] { background: rgba(var(--primary-rgb), 0.15); border-color: rgba(var(--primary-rgb), 0.5); color: var(--primary); }
.translate-btn { height: 44px; flex-shrink: 0; padding: 0 0.75rem; }
.translate-btn.busy { opacity: 0.6; cursor: progress; }
.translation {
    margin-top: 0.4rem; padding: 0.35rem 0.6rem; border-left: 3px solid rgba(var(--primary-rgb), 0.6);
    border-radius: 0 6px 6px 0; background: var(--input-bg); font-size: 0.9em; overflow-wrap: anywhere; white-space: normal;
}
.translation::before {
    content: 'RO'; display: block; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.05em; color: var(--primary); margin-bottom: 0.1rem;
}
.translation.pending, .translation.same { color: var(--muted); font-style: italic; }
.translation.error { color: var(--error); }
.translation p + p, .translation ul, .translation ol { margin-top: 0.3rem; }
.translation ul, .translation ol { padding-left: 1.2rem; }
.msg .time { display: flex; justify-content: flex-end; align-items: center; gap: 0.6rem; }
.tr-btn, .text-btn { border: none; background: none; padding: 0; font: inherit; color: var(--primary); cursor: pointer; font-weight: 700; }
.tr-btn:hover, .text-btn:hover { text-decoration: underline; }
.composer-note { padding: 0 1rem 0.6rem; font-size: 0.8rem; color: var(--muted); }
.conn-banner {
    margin: 0 0.6rem 0.6rem; padding: 0.5rem 0.7rem; border-radius: var(--radius);
    background: rgba(239, 68, 68, 0.12); color: var(--error); font-size: 0.82rem; font-weight: 600;
}

.pane-info .info { flex: 1; min-height: 0; overflow-y: auto; }
.pane-head {
    align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--glass-border);
    font-weight: 700;
}
.info-backdrop { display: none; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.45); }
.info { padding: 1rem; font-size: 0.86rem; }
.info-section + .info-section { margin-top: 1rem; }
.info-section h4 { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.35rem; }
.info dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.6rem; }
.info dt { color: var(--muted); }
.info dd { overflow-wrap: anywhere; }
.info pre.errors { white-space: pre-wrap; font-size: 0.75rem; background: rgba(239, 68, 68, 0.08); color: var(--error); padding: 0.5rem; border-radius: 6px; }
.prev-conv { display: block; font-size: 0.8rem; padding: 0.3rem 0; color: var(--foreground); }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-box { max-width: 420px; width: 100%; padding: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* ===================== RESPONSIVE ===================== */

/* Tablet: elenco + conversazione; i dettagli dell'utente si aprono a destra, sopra la chat. */
@media (max-width: 1200px) {
    .console { grid-template-columns: 300px minmax(0, 1fr); }
    .pane-info { display: none; }
    .info-btn { display: inline-flex; }
    .console.info-open .pane-info {
        display: flex; position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
        width: min(380px, 100%); border-radius: 0; background: var(--background);
        padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    }
    .console.info-open .pane-head { display: flex; }
    .console.info-open .info-backdrop { display: block; }
}

/* Barra in alto: sotto i 1024 px navigazione, tema e uscita vanno nel menu. */
@media (max-width: 1024px) {
    .console { grid-template-columns: 260px minmax(0, 1fr); gap: 0.6rem; }
    .topbar {
        gap: 0.6rem; padding: 0.5rem 0.75rem;
        padding-left: max(0.75rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-top: max(0.5rem, env(safe-area-inset-top));
    }
    .topbar .menu-btn { display: inline-flex; margin-left: auto; width: 40px; height: 40px; }
    /* niente backdrop-filter: renderebbe la barra il riferimento dei pannelli "fixed" al suo interno (campanella) */
    .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--background); }
    .topbar-menu {
        display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
        flex-direction: column; gap: 0.6rem; padding: 0.6rem 0.75rem 0.8rem;
        background: var(--background); border-bottom: 1px solid var(--glass-border); box-shadow: var(--shadow);
    }
    .topbar-menu.open { display: flex; }
    .topbar-menu .nav { flex-direction: column; gap: 0.1rem; }
    .topbar-menu .nav a { padding: 0.7rem 0.8rem; font-size: 1rem; }
    .topbar-menu .topbar-right { margin-left: 0; padding-top: 0.6rem; border-top: 1px solid var(--glass-border); }
    .topbar-menu .topbar-right .user { flex: 1; }
    /* nel menu il riquadro delle notifiche e' un pannello fisso in basso, largo quanto lo schermo, che scorre se serve */
    .topbar-menu .notif { position: static; }
    .topbar-menu .notif-panel {
        position: fixed; top: auto; left: 0.75rem; right: 0.75rem; bottom: max(0.75rem, env(safe-area-inset-bottom));
        width: auto; z-index: 40; max-height: calc(100vh - 1.5rem); max-height: calc(100dvh - 1.5rem);
    }
}

/* Telefono */
@media (max-width: 768px) {
    body { font-size: 15px; }
    /* niente zoom automatico di iOS quando si tocca un campo */
    input, select, textarea { font-size: 16px; }
    h1 { font-size: 1.2rem; }
    .page { padding: 0.75rem; padding-left: max(0.75rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right)); }
    .card { padding: 1rem; }
    .narrow { margin: 1.5rem auto; }
    .form-actions .btn { flex: 1 1 auto; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 36px; }
    .modal-actions .btn { flex: 1; }
    .lightbox { padding: 0.75rem; }
    .login-card { padding: 1.5rem; }

    /* Console: una schermata alla volta (elenco -> conversazione -> dettagli), a tutto schermo. */
    body.full-height .page { padding: 0; }
    body.chat-open .topbar { display: none; }
    .console { display: block; height: 100%; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
    .console > .pane { height: 100%; border-radius: 0; border-left: none; border-right: none; box-shadow: none; }
    .console .pane-chat { display: none; }
    .console.chat-open .pane-list { display: none; }
    .console.chat-open .pane-chat { display: flex; }
    .chat-back { display: inline-flex; }
    .chat-back, .info-btn { width: 40px; height: 40px; flex-shrink: 0; }

    .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 0.5rem 0.5rem 0; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { flex-shrink: 0; white-space: nowrap; padding: 0.5rem 0.7rem; }
    .search { padding: 0.5rem; }
    .conv-list { padding: 0 0.35rem calc(0.6rem + env(safe-area-inset-bottom)); }
    .conv-item { padding: 0.75rem; }

    .chat-header { gap: 0.45rem 0.5rem; padding: 0.45rem 0.6rem 0.5rem; padding-top: max(0.45rem, env(safe-area-inset-top)); flex-wrap: wrap; }
    .chat-title { flex: 1 1 0; }
    .chat-title .name, .chat-title .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .chat-title .name { font-size: 0.98rem; }
    .chat-title .sub { font-size: 0.78rem; }
    /* strumenti e azioni su una sola riga che scorre di lato */
    .chat-tools { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .chat-tools::-webkit-scrollbar { display: none; }
    .chat-actions { flex-wrap: nowrap; }
    .chat-tools .btn { flex-shrink: 0; white-space: nowrap; }
    .lbl-full { display: none; }
    .lbl-short { display: inline; }

    .ai-summary { margin: 0.5rem 0.6rem 0; max-height: 28vh; overflow-y: auto; font-size: 0.85rem; }
    .messages { padding: 0.75rem 0.6rem; }
    .msg .bubble { max-width: 88%; }
    .msg .images img { height: 120px; }
    .msg .images.single img { max-height: 260px; }
    .tr-btn { padding: 0.25rem 0.15rem; }
    .typing { padding: 0 0.75rem 0.3rem; }
    .previews { padding: 0.6rem 0.6rem 0; }

    .composer {
        gap: 0.4rem; padding: 0.5rem 0.6rem;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }
    .composer textarea { min-height: 42px; max-height: 140px; padding: 0.55rem 0.7rem; }
    .attach-btn, .send-btn { width: 42px; height: 42px; padding: 0; }
    .translate-btn { height: 42px; padding: 0 0.6rem; }
    .translate-btn svg, .send-label { display: none; }
    .composer-note { padding: 0 0.75rem 0.5rem; }

    .console.info-open .pane-info { width: 100%; }

    /* Tabelle dell'amministrazione: una scheda per riga, con il titolo della colonna accanto al valore (theme.js). */
    .table-wrap:has(> table.table-stack) { overflow-x: visible; }
    table.table-stack thead { display: none; }
    table.table-stack, table.table-stack tbody, table.table-stack tr { display: block; width: 100%; }
    table.table-stack tr { padding: 0.55rem 0; border-bottom: 1px solid var(--glass-border); }
    table.table-stack tr:last-child { border-bottom: none; }
    table.table-stack tr:hover td { background: none; }
    table.table-stack td, table.table-stack td.num {
        display: grid; grid-template-columns: minmax(6.5rem, 40%) minmax(0, 1fr); gap: 0.6rem; justify-items: start;
        padding: 0.2rem 0; border: none; text-align: left; overflow-wrap: anywhere;
    }
    table.table-stack td::before {
        content: attr(data-label); color: var(--muted); font-size: 0.72rem; font-weight: 700;
        text-transform: uppercase; letter-spacing: 0.03em; padding-top: 0.15rem;
    }
    table.table-stack td[data-label=""] { display: block; }
    table.table-stack td[data-label=""]::before { content: none; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stat-value { font-size: 1.25rem; }
}

/* ---------- Admin > Runtime ---------- */
.runtime-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.runtime-form input:not([type="checkbox"]) { width: auto; flex: 1; min-width: 12rem; }
.runtime-form input.short { flex: 0 0 6rem; min-width: 0; }
.runtime-form .check { display: inline-flex; gap: 0.35rem; align-items: center; font-weight: 600; }
