/* ===== Quantaris — stile condiviso del portale ===== */
:root {
    --bg: #05070f;
    --bg-2: #0a0e1c;
    --surface: #0f1426;
    --surface-2: #141a31;
    --border: rgba(120, 140, 255, 0.14);
    --border-strong: rgba(120, 140, 255, 0.28);
    --text: #e6e9f5;
    --text-muted: #8f97b8;
    --cyan: #22c7f5;
    --blue: #2563eb;
    --indigo: #3b2fd9;
    --violet: #8b2be2;
    --grad: linear-gradient(135deg, var(--cyan) 0%, var(--blue) 50%, var(--violet) 100%);
    --grad-soft: linear-gradient(135deg, rgba(34,199,245,.14), rgba(37,99,235,.14), rgba(139,43,226,.14));
    --glow: 0 0 24px rgba(37, 99, 235, .45), 0 0 48px rgba(139, 43, 226, .25);
    --ok: #2dd4a4;
    --warn: #f5b942;
    --danger: #ff4d7a;
    --radius: 14px;
    --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(34,199,245,.08), transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(139,43,226,.1), transparent 45%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: 'Orbitron', sans-serif; letter-spacing: .02em; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }

/* ----- Barra superiore ----- */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 12px 24px;
    background: rgba(5, 7, 15, .85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: 'Orbitron', sans-serif; font-weight: 900; letter-spacing: .16em; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { width: 42px; height: 34px; }
.brand small { font-family: 'Inter', sans-serif; font-weight: 500; letter-spacing: .04em; font-size: .78rem; color: var(--text-muted); margin-left: 4px; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.topbar-user .who { text-align: right; line-height: 1.2; }
.topbar-user .who small { display: block; color: var(--text-muted); font-size: .75rem; }

/* ----- Bottoni ----- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
    font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
    transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .25s, border-color .25s, color .25s;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 0 14px rgba(37,99,235,.35); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--glow); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-danger { background: transparent; border-color: rgba(255,77,122,.5); color: var(--danger); }
.btn-danger:hover { background: rgba(255,77,122,.1); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* ----- Form ----- */
.field { display: grid; gap: 6px; }
.field label { font-size: .82rem; font-weight: 500; color: var(--text-muted); }
input, select, textarea {
    width: 100%; padding: 11px 14px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-size: 1rem; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 110px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }
select option { background: var(--surface); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-muted); cursor: pointer; }
.checkbox input { width: auto; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: .9rem; border: 1px solid; }
.alert-error { color: var(--danger); border-color: rgba(255,77,122,.4); background: rgba(255,77,122,.08); }
.alert-ok { color: var(--ok); border-color: rgba(45,212,164,.4); background: rgba(45,212,164,.08); }

/* ----- Card e pannelli ----- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 1rem; }
.panel-body { padding: 18px; }

/* ----- Badge ----- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; letter-spacing: .02em; border: 1px solid var(--border-strong); color: var(--text-muted); white-space: nowrap; }
.badge.p-critica { color: #fff; background: var(--danger); border-color: var(--danger); }
.badge.p-alta { color: var(--warn); border-color: rgba(245,185,66,.5); }
.badge.p-media { color: var(--cyan); border-color: rgba(34,199,245,.4); }
.badge.p-bassa { color: var(--text-muted); }
.badge.s-in_analisi { color: var(--violet); border-color: rgba(139,43,226,.5); }
.badge.s-da_programmare { color: var(--warn); border-color: rgba(245,185,66,.5); }
.badge.s-programmato, .badge.s-in_lavorazione { color: var(--cyan); border-color: rgba(34,199,245,.5); }
.badge.s-in_attesa_cliente { color: var(--warn); border-color: rgba(245,185,66,.5); }
.badge.s-risolto { color: var(--ok); border-color: rgba(45,212,164,.5); }
.badge.s-chiuso { color: var(--text-muted); }

/* ----- Layout a due colonne (lista + dettaglio) ----- */
.workspace { display: grid; grid-template-columns: 360px 1fr; gap: 20px; padding: 20px 24px; max-width: 1400px; margin: 0 auto; align-items: start; }
.list { display: grid; gap: 8px; max-height: calc(100vh - 210px); overflow-y: auto; padding: 12px; }
.list-empty { padding: 24px 12px; text-align: center; color: var(--text-muted); font-size: .9rem; }
.ticket-item {
    display: grid; gap: 6px; padding: 12px 14px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--border); background: var(--bg-2); text-align: left; width: 100%;
    transition: border-color .2s, background .2s, transform .2s;
}
.ticket-item:hover { border-color: var(--border-strong); transform: translateX(2px); }
.ticket-item.active { border-color: var(--cyan); background: rgba(34,199,245,.06); box-shadow: inset 3px 0 0 var(--cyan); }
.ticket-item .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ticket-item .code { font-family: 'Orbitron', sans-serif; font-size: .72rem; color: var(--text-muted); letter-spacing: .08em; }
.ticket-item .subject { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-item .meta { font-size: .76rem; color: var(--text-muted); display: flex; gap: 6px; flex-wrap: wrap; }

.detail-empty { display: grid; place-items: center; text-align: center; gap: 12px; padding: 80px 24px; color: var(--text-muted); }
.detail-empty > i { font-size: 2.4rem; color: var(--cyan); opacity: .6; }

.ticket-header { display: grid; gap: 10px; }
.ticket-header .code { font-family: 'Orbitron', sans-serif; font-size: .78rem; letter-spacing: .1em; color: var(--cyan); }
.ticket-header h2 { font-size: 1.25rem; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.description { white-space: pre-wrap; color: var(--text); background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: .92rem; }
.section-title { font-family: 'Inter', sans-serif; font-size: .78rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted); margin: 22px 0 10px; }

.ai-card { border-radius: 12px; padding: 16px; background: var(--grad-soft); border: 1px solid var(--border-strong); }
.ai-card .ai-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.ai-card .ai-head i { color: var(--cyan); }
.ai-card ol { padding-left: 20px; display: grid; gap: 4px; font-size: .9rem; margin-top: 8px; }
.analyzing { display: flex; align-items: center; gap: 10px; color: var(--violet); }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.slot { border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 14px; background: var(--bg-2); display: grid; gap: 8px; }
.slot.confirmed { border-color: var(--ok); background: rgba(45,212,164,.06); }
.slot .when { font-weight: 600; }
.slot .when::first-letter, .day h3::first-letter { text-transform: uppercase; }
.slot .who { font-size: .82rem; color: var(--text-muted); }

/* ----- Conversazione ----- */
.thread { display: grid; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: .9rem; white-space: pre-wrap; word-wrap: break-word; border: 1px solid var(--border); }
.msg .msg-meta { font-size: .72rem; color: var(--text-muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.msg.client { justify-self: end; background: rgba(37,99,235,.14); border-color: rgba(37,99,235,.35); border-bottom-right-radius: 4px; }
.msg.tech { justify-self: start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.ai { justify-self: start; background: var(--grad-soft); border-color: rgba(139,43,226,.35); border-bottom-left-radius: 4px; }
.msg.system { justify-self: center; max-width: 100%; background: transparent; border: none; color: var(--text-muted); font-size: .8rem; text-align: center; padding: 2px 8px; }
.msg.internal { border-style: dashed; border-color: var(--warn); background: rgba(245,185,66,.06); }
.msg.mine.tech { justify-self: end; }
.reply { display: grid; gap: 10px; margin-top: 16px; }
.reply-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ----- Modale ----- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(2,3,8,.75); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal form { display: grid; gap: 14px; }

/* ----- Tab ----- */
.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--border); overflow-x: auto; max-width: 1400px; margin: 0 auto; }
.tab { background: none; border: none; padding: 14px 16px; cursor: pointer; color: var(--text-muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--cyan); }
a.tab { display: inline-flex; align-items: center; gap: 6px; }
a.tab:hover { text-decoration: none; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--border); }
.toolbar select { width: auto; flex: 1; min-width: 120px; padding: 8px 10px; font-size: .85rem; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(139,43,226,.3); border-top-color: var(--violet); animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; padding: 12px 18px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: .9rem; max-width: calc(100vw - 32px); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ----- Tabelle ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }

.page { max-width: 1400px; margin: 0 auto; padding: 20px 24px; display: grid; gap: 20px; }

pre.draft { white-space: pre-wrap; font-family: inherit; font-size: .88rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; max-height: 420px; overflow-y: auto; }

/* ----- Responsive ----- */
.back-btn { display: none !important; }
@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; padding: 16px; }
    .workspace.show-detail .list-pane { display: none; }
    .workspace:not(.show-detail) .detail-pane { display: none; }
    .list { max-height: none; }
    .back-btn { display: inline-flex !important; }
    .topbar { padding: 10px 16px; }
    .topbar-user .who { display: none; }
    .brand small { display: none; }
    .topbar-user { gap: 8px; }
    .tabs { padding: 0 8px; }
    .page { padding: 16px; }
    .msg { max-width: 95%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Schermi molto stretti: la barra in alto non deve far scorrere la pagina in orizzontale */
@media (max-width: 420px) {
    .topbar { padding: 10px 12px; gap: 8px; }
    .brand { font-size: .9rem; letter-spacing: .08em; gap: 6px; }
    .brand img { width: 34px; height: 28px; }
    .topbar .btn-sm { padding: 6px 10px; }
}
