/* =============================================================================
   Mondo Hi-Tech HelpDesk — Foglio di stile
   Copyright (c) Mondo Hi-Tech
   Mobile-first, responsive, senza dipendenze esterne.
   ============================================================================= */

:root {
  /* Colori del marchio (campionati dal logo Mondo Hi-Tech) */
  --brand: #0080a8;
  --brand-dark: #006a8c;
  --brand-darker: #04526c;
  --brand-light: #00a8d8;
  --brand-50: #e9f5fa;
  --brand-100: #d2ebf4;
  --slate: #1d5a74;          /* blu profondo per etichette e testi secondari */
  --slate-dark: #0b4a63;     /* blu scuro per i titoli */
  --slate-darker: #05425c;   /* blu notte per sidebar, toast, codice */

  --bg: #f1f7fb;
  --surface: #ffffff;
  --text: #16303d;
  --muted: #5b7d8e;
  --border: #d6e6ee;
  --border-strong: #b5d0dc;

  --success: #16a34a;
  --success-bg: #e8f7ee;
  --warning: #d97706;
  --warning-bg: #fef3e2;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --info: #0080a8;
  --info-bg: #e9f5fa;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 70, 100, .06), 0 4px 16px rgba(0, 70, 100, .07);
  --shadow-lg: 0 10px 40px rgba(0, 70, 100, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  --header-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
/* Evita che testi o grafici non comprimibili allarghino le griglie oltre lo schermo (Firefox/Safari) */
.dash-grid > *, .two-col > *, .ticket-layout > *, .kb-grid > *, .admin-grid > *, .action-grid > *, .stat-grid > *,
.form-row > *, .filter-bar > *, .reply-options > *, .card, .card-body, .card-header > * { min-width: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--slate-dark); font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
.h5 { font-size: 1rem; margin: 1.2em 0 .6em; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); }
p { margin: 0 0 1em; }
code, pre { font-family: var(--mono); font-size: .9em; }
pre.code-block { background: var(--slate-darker); color: #e6f3f8; padding: 14px; border-radius: var(--radius-sm); overflow: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.text-muted { color: var(--muted); }
.text-small { font-size: .86rem; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-brand { color: var(--brand); }
.fw-600 { font-weight: 600; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hide-mobile { display: none; }
@media (min-width: 768px) { .hide-mobile { display: initial; } .hide-desktop { display: none !important; } }

/* -----------------------------------------------------------------------------
   Bottoni
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .93rem; line-height: 1.2; cursor: pointer;
  text-decoration: none; transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 3px solid rgba(0, 128, 168, .35); outline-offset: 1px; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--brand-dark); color: #fff; }
.btn-secondary:hover { background: var(--brand-darker); color: #fff; }
.btn-outline { background: var(--surface); color: var(--brand); border-color: var(--brand); }
.btn-outline:hover { background: var(--brand-50); color: var(--brand-dark); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-light:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: .84rem; }
.btn-lg { padding: 13px 22px; font-size: 1.02rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; width: 36px; height: 36px; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* -----------------------------------------------------------------------------
   Form
   -------------------------------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-group label, .form-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; color: var(--slate-dark); }
.form-group .hint { display: block; font-size: .82rem; color: var(--muted); margin-top: 5px; }
.required::after { content: " *"; color: var(--danger); }
.form-control, .form-select, textarea.form-control {
  width: 100%; padding: 10px 12px; font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none; min-height: 42px;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7680' viewBox='0 0 16 16'%3E%3Cpath d='M4.6 6l3.4 3.4L11.4 6l.9.9-4.3 4.3L3.7 6.9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px;
}
.form-control:focus, .form-select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0, 128, 168, .18); }
.form-control.is-invalid { border-color: var(--danger); }
textarea.form-control { min-height: 140px; resize: vertical; line-height: 1.5; }
.form-control-sm { padding: 6px 10px; min-height: 34px; font-size: .88rem; }
.form-row { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 640px) { .form-row { grid-template-columns: 1fr 1fr; } .form-row-3 { grid-template-columns: 1fr 1fr 1fr; } }
.form-check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; font-size: .93rem; }
.form-check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.file-input { position: relative; }
.file-input input[type=file] { font-size: .9rem; width: 100%; padding: 8px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--bg); }
.file-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: .85rem; color: var(--muted); }
.honeypot { position: absolute; left: -9999px; top: -9999px; opacity: 0; height: 0; width: 0; }
input[type=color].form-control { padding: 4px; height: 42px; width: 64px; }

/* -----------------------------------------------------------------------------
   Card, alert, badge
   -------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--border); background: #f6fafc; border-radius: 0 0 var(--radius) var(--radius); }
.card-link { display: block; color: inherit; transition: transform .15s, box-shadow .15s; }
.card-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); color: inherit; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; font-size: .93rem; }
.alert-success { background: var(--success-bg); border-color: #b7e4c7; color: #14532d; }
.alert-error, .alert-danger { background: var(--danger-bg); border-color: #f5c2c2; color: #7f1d1d; }
.alert-warning { background: var(--warning-bg); border-color: #f8dcb0; color: #7c3a03; }
.alert-info { background: var(--info-bg); border-color: #b9dfec; color: #0d4a60; }
.alert .close { margin-left: auto; background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; line-height: 1; padding: 0 4px; }
.alert .close:hover { opacity: 1; }
.flash-container { margin-bottom: 8px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; line-height: 1.4; white-space: nowrap; vertical-align: middle; }
.badge-soft { background: var(--brand-50); color: var(--brand-dark); }
.badge-gray { background: #e4eff5; color: var(--slate); }
.badge-success { background: var(--success-bg); color: #166534; }
.badge-warning { background: var(--warning-bg); color: #9a3412; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.count-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; font-size: .74rem; font-weight: 700; background: var(--brand-light); color: #fff; }

.avatar { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: .85rem; flex: none; letter-spacing: .02em; }
.avatar-staff { background: var(--brand-dark); }
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.15rem; }

/* -----------------------------------------------------------------------------
   Tabelle (responsive: su mobile diventano schede)
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 11px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--brand-dark); font-weight: 700; background: #f3f9fc; white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr:hover { background: #f5fafd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .row-link { color: var(--text); font-weight: 600; }
.table .row-link:hover { color: var(--brand); }
.table td.actions { text-align: right; white-space: nowrap; }
.table tr.unanswered td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
/* Modalità a schede: tabelle semplici sotto i 768px, tabelle ampie (es. coda ticket) sotto i 1024px */
@media (max-width: 767px) {
  .table-responsive thead { display: none; }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-responsive tr { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 0 0 10px; padding: 8px 0; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 70, 100, .04); }
  .table-responsive tbody tr:hover { background: var(--surface); }
  .table-responsive td { border: 0; display: block; position: relative; padding: 4px 14px 4px 124px; text-align: left !important; white-space: normal; min-height: 29px; line-height: 1.45; }
  .table-responsive td::before { content: attr(data-label); position: absolute; left: 14px; top: 7px; width: 102px; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; line-height: 1.4; }
  .table-responsive td.no-label { padding-left: 14px; }
  .table-responsive td.no-label::before { display: none; }
  .table-responsive td.actions { text-align: right !important; padding-top: 8px; }
  .table-responsive td br { display: inline; }
  .table-responsive td.bulk-cell { position: absolute; right: 10px; top: 8px; width: auto; min-height: 0; padding: 0; z-index: 2; }
  .table-responsive td:first-child { box-shadow: none; }
  .table-responsive tr.unanswered { border-left: 4px solid var(--warning); }
  .table-responsive tr.overdue { border-left: 4px solid var(--danger); }
}
@media (max-width: 1023px) {
  .table-cards-lg thead { display: none; }
  .table-cards-lg, .table-cards-lg tbody, .table-cards-lg tr, .table-cards-lg td { display: block; width: 100%; }
  .table-cards-lg tr { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 0 0 10px; padding: 8px 0; background: var(--surface); box-shadow: 0 1px 2px rgba(0, 70, 100, .04); }
  .table-cards-lg tbody tr:hover { background: var(--surface); }
  .table-cards-lg td { border: 0; display: block; position: relative; padding: 4px 14px 4px 124px; text-align: left !important; white-space: normal; min-height: 29px; line-height: 1.45; }
  .table-cards-lg td::before { content: attr(data-label); position: absolute; left: 14px; top: 7px; width: 102px; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; line-height: 1.4; }
  .table-cards-lg td.no-label { padding-left: 14px; }
  .table-cards-lg td.no-label::before { display: none; }
  .table-cards-lg td.actions { text-align: right !important; padding-top: 8px; }
  .table-cards-lg td br { display: inline; }
  .table-cards-lg td.bulk-cell { position: absolute; right: 10px; top: 8px; width: auto; min-height: 0; padding: 0; z-index: 2; }
  .table-cards-lg td:first-child { box-shadow: none; }
  .table-cards-lg tr.unanswered { border-left: 4px solid var(--warning); }
  .table-cards-lg tr.overdue { border-left: 4px solid var(--danger); }
}

/* Su tablet e telefoni in orizzontale le schede si dispongono su due colonne */
@media (min-width: 640px) and (max-width: 1023px) {
  .table-cards-lg tbody, .table-responsive tbody { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
  .table-cards-lg tr, .table-responsive tr { margin: 0; }
}

/* -----------------------------------------------------------------------------
   Paginazione, tab, dropdown, stato vuoto
   -------------------------------------------------------------------------- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 16px 0 0; padding: 0; list-style: none; }
.pagination a, .pagination span { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .9rem; }
.pagination a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.pagination .disabled { opacity: .45; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: .88rem; font-weight: 600; }
.tabs a:hover { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs a.active .count-badge { background: rgba(255, 255, 255, .25); }

.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 5px; color: var(--text); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu .divider { height: 1px; background: var(--border); margin: 6px 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 54px; height: 54px; color: var(--brand-light); margin-bottom: 10px; }
.empty h3 { color: var(--slate); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; margin: 0; }
.kv dd { margin: 0; word-break: break-word; }

/* -----------------------------------------------------------------------------
   Layout AREA CLIENTI
   -------------------------------------------------------------------------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40; }
.site-header .inner { max-width: 1140px; margin: 0 auto; padding: 0 16px; height: var(--header-h); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand-logo img { height: 40px; width: auto; display: block; }
.brand-logo { display: flex; align-items: center; }
.nav-toggle { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; color: var(--slate); }
.nav-toggle svg { width: 22px; height: 22px; }
.site-nav { display: none; position: absolute; left: 0; right: 0; top: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 10px 16px 14px; flex-direction: column; gap: 4px; }
.site-nav.open { display: flex; }
.site-nav a, .site-nav .nav-btn { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--slate-dark); font-weight: 600; font-size: .95rem; background: none; border: 0; font-family: inherit; cursor: pointer; width: 100%; text-align: left; }
.site-nav a:hover, .site-nav .nav-btn:hover { background: var(--brand-50); color: var(--brand-dark); text-decoration: none; }
.site-nav a.active { color: var(--brand); }
.site-nav .nav-cta { background: var(--brand); color: #fff; }
.site-nav .nav-cta:hover { background: var(--brand-dark); color: #fff; }
.site-nav form { margin: 0; }
@media (min-width: 900px) {
  .nav-toggle { display: none; }
  .site-nav { display: flex; position: static; flex-direction: row; align-items: center; gap: 2px; padding: 0; border: 0; box-shadow: none; background: none; }
  .site-nav a, .site-nav .nav-btn { width: auto; padding: 8px 12px; font-size: .9rem; }
  .site-nav .nav-cta { margin-left: 8px; }
}
.site-main { max-width: 1140px; margin: 0 auto; padding: 24px 16px 40px; min-width: 0; width: 100%; }
.site-main.narrow { max-width: 760px; }
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 20px; }
.site-footer .inner { max-width: 1140px; margin: 0 auto; padding: 18px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.site-footer img { height: 28px; width: auto; vertical-align: middle; margin-right: 8px; background: #fff; }
.site-footer .copyright { display: flex; align-items: center; }

.hero { background: linear-gradient(135deg, var(--brand-darker) 0%, var(--brand) 55%, var(--brand-light) 100%); color: #fff; border-radius: var(--radius); padding: 36px 24px; margin-bottom: 24px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -80px; top: -80px; width: 280px; height: 280px; border-radius: 50%; background: rgba(255, 255, 255, .08); pointer-events: none; }
.hero h1 { color: #fff; font-size: 1.9rem; margin-bottom: 8px; }
.hero p { max-width: 640px; font-size: 1.02rem; opacity: .95; margin-bottom: 0; position: relative; }
@media (min-width: 768px) { .hero { padding: 52px 40px; } .hero h1 { font-size: 2.3rem; } }

.action-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 28px; }
@media (min-width: 640px) { .action-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .action-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }
.action-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
.action-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--brand-light); color: inherit; }
.action-card .icon { width: 52px; height: 52px; border-radius: 12px; background: var(--brand-50); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.action-card .icon svg { width: 28px; height: 28px; }
.action-card h2 { font-size: 1.15rem; margin: 4px 0 0; }
.action-card p { color: var(--muted); margin: 0; font-size: .93rem; }
.action-card .text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.action-card .link { margin-top: auto; color: var(--brand); font-weight: 700; font-size: .9rem; }

.faq-list { list-style: none; margin: 0; padding: 0; }
.faq-list li { border-bottom: 1px solid var(--border); }
.faq-list li:last-child { border-bottom: 0; }
.faq-list a { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 4px; color: var(--text); font-weight: 600; }
.faq-list a:hover { color: var(--brand); text-decoration: none; }
.faq-list .meta { color: var(--muted); font-size: .82rem; font-weight: 400; white-space: nowrap; }
.faq-answer { font-size: 1rem; line-height: 1.7; }
.kb-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .kb-grid { grid-template-columns: 1fr 1fr; } }

/* Pagine di autenticazione */
.auth-body { background: linear-gradient(160deg, var(--brand-50) 0%, var(--bg) 60%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-wrap { width: 100%; max-width: 440px; }
.auth-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 32px 28px; border: 1px solid var(--border); }
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo img { height: 56px; width: auto; }
.auth-title { font-size: 1.3rem; text-align: center; margin-bottom: 6px; }
.auth-subtitle { text-align: center; color: var(--muted); font-size: .92rem; margin-bottom: 22px; }
.auth-footer { text-align: center; color: var(--muted); font-size: .84rem; margin-top: 18px; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: .9rem; margin-top: 16px; }
.check-list { list-style: none; padding: 0; margin: 0 0 16px; }
.check-list li { padding: 8px 10px 8px 34px; position: relative; border-bottom: 1px solid var(--border); font-size: .92rem; }
.check-list li::before { content: "✓"; position: absolute; left: 10px; font-weight: 700; color: var(--success); }
.check-list li.fail::before { content: "✗"; color: var(--danger); }
.check-list li.warn::before { content: "!"; color: var(--warning); }

/* -----------------------------------------------------------------------------
   Layout PANNELLO STAFF
   -------------------------------------------------------------------------- */
.scp { min-height: 100vh; }
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); background: linear-gradient(180deg, #04506d 0%, #0a6f93 100%); color: #e6f3f8; display: flex; flex-direction: column; z-index: 60; transform: translateX(-100%); transition: transform .22s ease; overflow-y: auto; }
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
.sidebar-brand { background: #fff; padding: 12px 16px; min-height: var(--header-h); display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar-brand a { display: block; }
.sidebar-brand img { height: 40px; width: auto; display: block; }
.sidebar-close { background: none; border: 0; color: var(--brand-dark); cursor: pointer; width: 34px; height: 34px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-close:hover { background: var(--brand-50); color: var(--brand-darker); }
.sidebar-nav { padding: 12px 10px; flex: 1; }
.sidebar-nav .section { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: rgba(255, 255, 255, .6); padding: 14px 10px 6px; font-weight: 700; }
.sidebar-nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 7px; color: rgba(255, 255, 255, .9); font-size: .92rem; font-weight: 500; margin-bottom: 2px; }
.sidebar-nav a svg { width: 19px; height: 19px; flex: none; opacity: .85; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: #fff; color: var(--brand-dark); box-shadow: 0 2px 8px rgba(0, 40, 60, .2); }
.sidebar-nav a .count-badge { margin-left: auto; background: rgba(255, 255, 255, .22); }
.sidebar-nav a.active .count-badge { background: var(--brand); color: #fff; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, .14); font-size: .76rem; color: rgba(255, 255, 255, .65); }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(4, 50, 70, .5); z-index: 55; display: none; }
.sidebar-overlay.open { display: block; }
.scp-main { min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 16px; position: sticky; top: 0; z-index: 40; }
.topbar .page-title { font-size: 1.05rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-search { display: none; flex: 0 1 360px; }
.topbar-search .form-control { min-height: 38px; padding: 7px 12px 7px 36px; background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b7680' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center; border-color: transparent; }
.topbar-search .form-control:focus { background-color: var(--surface); border-color: var(--brand); }
.topbar .user-btn { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; font: inherit; padding: 4px; border-radius: 999px; color: var(--text); }
.topbar .user-btn:hover { background: var(--brand-50); }
.topbar .user-name { display: none; font-weight: 600; font-size: .9rem; }
.scp-content { padding: 20px 16px 40px; flex: 1; max-width: 1400px; width: 100%; min-width: 0; }
.scp-footer { padding: 14px 16px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--border); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
@media (min-width: 1024px) {
  .sidebar { transform: none; box-shadow: none; }
  .sidebar-close, .sidebar-overlay { display: none !important; }
  .scp-main { margin-left: var(--sidebar-w); }
  .topbar .nav-toggle { display: none; }
  .topbar-search { display: block; }
  .topbar .user-name { display: inline; }
  .scp-content { padding: 28px 28px 48px; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 1.45rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin: 2px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 22px; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .stat-grid { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); color: inherit; display: block; position: relative; overflow: hidden; }
.stat:hover { text-decoration: none; border-color: var(--brand-light); color: inherit; }
.stat .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 1.9rem; font-weight: 800; color: var(--slate-dark); line-height: 1.1; margin-top: 4px; }
.stat.accent-danger .value { color: var(--danger); }
.stat.accent-warning .value { color: var(--warning); }
.stat.accent-success .value { color: var(--success); }
.stat.accent-brand .value { color: var(--brand); }
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); opacity: .7; }
.stat.accent-danger::after { background: var(--danger); }
.stat.accent-warning::after { background: var(--warning); }
.stat.accent-success::after { background: var(--success); }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 1100px) { .dash-grid { grid-template-columns: 2fr 1fr; } }
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { margin-bottom: 12px; }
.bar-list .bar-head { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: 4px; }
.bar-list .bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-list .bar span { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: 10px; width: 100%; max-width: 100%; overflow: hidden; contain: inline-size; }
.chart .col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 2px; position: relative; min-width: 0; overflow: hidden; }
.chart .col .bars { display: flex; align-items: flex-end; gap: 2px; height: 100%; width: 100%; justify-content: center; }
.chart .col .bars span { display: block; width: 45%; max-width: 16px; border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .col .bars .created { background: var(--brand); }
.chart .col .bars .closed { background: #9fd4e8; }
.chart .col .lbl { font-size: .62rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; min-width: 0; width: 100%; text-align: center; }
.chart .col:hover .tip { display: block; }
.chart .tip { display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--brand-dark); color: #fff; font-size: .72rem; padding: 4px 8px; border-radius: 4px; white-space: nowrap; z-index: 5; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* Filtri lista ticket */
.filter-bar { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 768px) { .filter-bar { grid-template-columns: 2fr 1fr 1fr 1fr auto; align-items: end; } }
.filter-bar .form-group { margin: 0; }
.filter-bar label { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
.bulk-bar { display: none; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: var(--radius-sm); margin-bottom: 12px; font-size: .9rem; }
.bulk-bar.open { display: flex; }
.bulk-bar .form-select { width: auto; min-width: 180px; min-height: 36px; padding: 6px 30px 6px 10px; }

/* Vista ticket */
.ticket-layout { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 1100px) { .ticket-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } }
.ticket-side { position: static; }
@media (min-width: 1100px) { .ticket-side { position: sticky; top: calc(var(--header-h) + 16px); } }
.ticket-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.ticket-head h1 { font-size: 1.3rem; margin: 0; word-break: break-word; }
.ticket-head .number { color: var(--muted); font-weight: 600; font-size: .95rem; }
.ticket-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thread { display: flex; flex-direction: column; gap: 14px; }
.entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.entry-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: #f6fafc; flex-wrap: wrap; }
.entry-head .who { font-weight: 700; font-size: .92rem; }
.entry-head .when { color: var(--muted); font-size: .82rem; margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.entry-head .when .btn-sm { padding: 3px 6px; }
.entry-body { padding: 14px 16px; font-size: .95rem; line-height: 1.65; word-wrap: break-word; overflow-wrap: anywhere; }
.entry-response { border-color: var(--brand-100); }
.entry-response .entry-head { background: var(--brand-50); }
.entry-note { border: 1px dashed var(--brand-light); }
.entry-note .entry-head { background: #e3f1f7; }
.entry-note .entry-body { background: #f7fbfd; }
.entry-attachments { padding: 0 16px 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachment-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: .84rem; color: var(--text); max-width: 100%; }
.attachment-chip:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.attachment-chip svg { width: 15px; height: 15px; flex: none; }
.attachment-chip .size { color: var(--muted); }
.attachment-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.reply-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.reply-tabs { display: flex; border-bottom: 1px solid var(--border); }
.reply-tabs button { flex: 1; padding: 12px; background: none; border: 0; border-bottom: 3px solid transparent; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; }
.reply-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.reply-tabs button.note.active { color: var(--brand-dark); border-bottom-color: var(--brand-light); }
.reply-pane { display: none; padding: 16px; }
.reply-pane.active { display: block; }
.reply-options { display: grid; grid-template-columns: 1fr; gap: 10px 14px; }
@media (min-width: 640px) { .reply-options { grid-template-columns: 1fr 1fr; } }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-light); border: 2px solid #fff; }
.timeline .when { color: var(--muted); font-size: .78rem; display: block; }
.priority-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .86rem; }
.priority-pill i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.ticket-side .card-body { padding: 14px 16px; }
.side-form .form-group { margin-bottom: 10px; }
.side-form .form-select, .side-form .form-control { min-height: 36px; padding: 6px 30px 6px 10px; font-size: .9rem; }
.quick-list { list-style: none; margin: 0; padding: 0; }
.quick-list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.quick-list li:last-child { border: 0; }
.quick-list a { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-list a:hover { color: var(--brand); }

/* Varie */
.icon { width: 18px; height: 18px; vertical-align: -3px; }
.inline-form { display: inline; }
.sortable::after { content: " ↕"; opacity: .4; font-size: .8em; }
.sortable.asc::after { content: " ↑"; opacity: 1; }
.sortable.desc::after { content: " ↓"; opacity: 1; }
.settings-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.settings-nav a { padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .88rem; font-weight: 600; color: var(--slate); }
.settings-nav a.active, .settings-nav a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .admin-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .admin-grid { grid-template-columns: 1fr 1fr 1fr; } }
.two-col { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }
.color-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0, 0, 0, .1); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--brand-dark); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .9rem; box-shadow: var(--shadow-lg); z-index: 100; }
.var-list { display: flex; flex-wrap: wrap; gap: 6px; }
.var-list code { background: var(--bg); border: 1px solid var(--border); padding: 2px 7px; border-radius: 4px; cursor: pointer; }
.var-list code:hover { border-color: var(--brand); color: var(--brand); }
details summary { cursor: pointer; font-weight: 600; color: var(--brand); }


/* -----------------------------------------------------------------------------
   Smartphone e tablet: rifiniture touch
   -------------------------------------------------------------------------- */
.topbar .search-link { display: none; }
@media (max-width: 1023px) { .topbar .search-link { display: inline-flex; } }

@media (max-width: 767px) {
  /* Evita lo zoom automatico di iOS sui campi (font minimo 16px) */
  .form-control, .form-select, textarea.form-control, .input-group .form-control { font-size: 16px; }
  .form-control-sm { font-size: 16px; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .btn-icon { min-height: 36px; }
  .site-main { padding-left: 12px; padding-right: 12px; }
  .scp-content { padding-left: 12px; padding-right: 12px; }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 1.3rem; }
  .page-head .sub { font-size: .86rem; }
  .page-actions { width: 100%; }
  .page-actions > * { flex: 1 1 calc(50% - 8px); }
  .page-actions form .btn, .page-actions .btn { width: 100%; }
  .ticket-head h1 { font-size: 1.15rem; }
  .hero { padding: 26px 18px; border-radius: 12px; }
  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: .95rem; }
  .action-grid { gap: 12px; }
  .action-card { flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; }
  .action-card .icon { width: 44px; height: 44px; border-radius: 10px; flex: none; }
  .action-card .icon svg { width: 24px; height: 24px; }
  .action-card h2 { font-size: 1rem; margin: 0; }
  .action-card p { font-size: .84rem; }
  .action-card .link { display: none; }
  .action-card .text { min-width: 0; }
  .stat-grid { gap: 10px; }
  .stat { padding: 12px 12px 12px 16px; }
  .stat .label { font-size: .68rem; }
  .stat .value { font-size: 1.5rem; }
  .chart { height: 120px; }
  .chart .col:nth-child(even) .lbl { visibility: hidden; }
  .tabs a { padding: 6px 11px; font-size: .84rem; }
  .filter-bar .btn { width: 100%; }
  .kv { grid-template-columns: 104px 1fr; font-size: .9rem; }
  .entry-body { padding: 12px 14px; font-size: .94rem; }
  .entry-attachments { padding: 0 14px 12px; }
  .attachment-chip .name { max-width: 150px; }
  .reply-pane { padding: 14px; }
  .reply-tabs button { font-size: .9rem; padding: 11px 6px; }
  .pagination a, .pagination span { min-width: 40px; height: 40px; }
  .site-footer .inner { flex-direction: column; align-items: flex-start; gap: 6px; }
  .scp-footer { flex-direction: column; }
  .auth-card { padding: 24px 18px; }
  .dropdown-menu { position: fixed; left: 12px; right: 12px; top: calc(var(--header-h) + 4px); min-width: 0; }
  .table-wrap { margin: 0 -2px; }
}

/* Aree sicure dei dispositivi con notch */
.site-header .inner, .topbar, .site-footer .inner { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* Dispositivi touch (anche tablet e telefoni in orizzontale): campi a 16px e niente effetti hover */
@media (hover: none) and (pointer: coarse) {
  .form-control, .form-select, textarea.form-control, .form-control-sm { font-size: 16px; }
}
@media (hover: none) {
  .card-link:hover, .action-card:hover { transform: none; }
  .chart .col:active .tip, .chart .col:focus .tip { display: block; }
}

/* Stampa */
@media print {
  .sidebar, .topbar, .site-header, .site-footer, .scp-footer, .reply-box, .btn, .page-actions, .ticket-side form { display: none !important; }
  .scp-main { margin: 0; }
  body { background: #fff; }
  .entry { break-inside: avoid; }
}

/* Tema scuro di sistema (solo per accenti del browser) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
