/* ============================================================
   byebyte Ticket - tema chiaro, minimal, moderno
   ============================================================ */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #0c0d10;
  --muted: #6b7280;
  --line: #edeef1;
  --accent: #635bff;
  --accent-2: #8b5cf6;
  --green-bg: #dcfce7; --green-fg: #15803d;
  --amber-bg: #fef9c3; --amber-fg: #a16207;
  --blue-bg: #ede9fe;  --blue-fg: #5b21b6;
  --grey-bg: #f1f5f9;  --grey-fg: #475569;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(16,18,33,.04), 0 1px 3px rgba(16,18,33,.03);
  --shadow: 0 2px 6px rgba(16,18,33,.05), 0 12px 32px rgba(16,18,33,.06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
h1, h2, h3 { letter-spacing: -.02em; }

/* Buttons */
.btn-primary { border: none; background: var(--text); color: #fff; padding: 11px 20px;
  border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600; font-family: inherit;
  transition: transform .08s ease, opacity .15s ease; }
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.98); }
.btn-ghost { border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 500;
  font-family: inherit; transition: background .15s ease, border-color .15s; }
.btn-ghost:hover { background: var(--surface-2); border-color: #e2e3e8; text-decoration: none; }

/* App shell: sidebar sinistra + contenuto */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: 0 0 240px; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; padding: 4px 6px 0; }
.brand:hover { opacity: .85; text-decoration: none; }
.brand-txt { white-space: nowrap; }
.logo { width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; letter-spacing: -.5px; flex: 0 0 32px; }
.logo-img { height: 32px; width: auto; max-width: 160px; object-fit: contain; display: block; }

/* switch profilo azienda */
.company-switch { margin: 20px 0 18px; }
.cs-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; margin: 0 6px 7px; }
.cs-box { position: relative; display: flex; align-items: center; gap: 10px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; transition: border-color .15s, box-shadow .15s; }
.cs-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.cs-ava { width: 28px; height: 28px; border-radius: 8px; flex: 0 0 28px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700; font-size: 13px; }
.cs-box select { appearance: none; -webkit-appearance: none; border: 0; background: transparent; flex: 1; min-width: 0;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; padding-right: 14px; }
.cs-box select:focus { outline: none; }
.cs-caret { position: absolute; right: 10px; color: var(--muted); font-size: 11px; pointer-events: none; }

.sidenav { display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-size: 14px; font-weight: 600; transition: background .15s, color .15s; }
.sidenav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidenav a.on { background: var(--blue-bg); color: var(--accent); }
.sidenav svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: #e11d48; margin-left: auto; flex: 0 0 8px;
  box-shadow: 0 0 0 3px rgba(225,29,72,.15); }

.side-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; border-top: 1px solid var(--line); padding-top: 14px; }
.su-ava { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 13px; }
.su-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.su-logout { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); }
.su-logout:hover { background: var(--surface-2); color: var(--text); }
.su-logout svg { width: 17px; height: 17px; }

.content { flex: 1; min-width: 0; padding: 26px 32px 40px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px; }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; align-items: center;
    gap: 14px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .company-switch { margin: 0; flex: 1; min-width: 180px; }
  .cs-label { display: none; }
  .sidenav { flex-direction: row; }
  .side-foot { margin: 0; border-top: 0; padding-top: 10px; }
  .content { padding: 20px 16px; }
}

/* Pick brand (scelta azienda dopo login) */
.pick-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px; }
.pick-box { width: 100%; max-width: 460px; text-align: center; }
.pick-box .login-logo { margin: 0 auto 18px; }
.pick-box h1 { margin: 0; font-size: 22px; font-weight: 800; }
.pick-box .sub { color: var(--muted); font-size: 14px; margin: 6px 0 28px; }

.brand-cards { display: flex; flex-direction: column; gap: 12px; }
.brand-card { display: flex; align-items: center; gap: 16px; width: 100%;
  background: var(--surface); border: 1px solid #ebebeb; border-radius: 16px;
  padding: 16px 20px; cursor: pointer; text-align: left; font-family: inherit;
  transition: box-shadow .15s, border-color .15s, transform .05s; }
.brand-card:hover { box-shadow: var(--shadow); border-color: #d0d2d9; }
.brand-card:active { transform: scale(.99); }
.bc-ava { width: 44px; height: 44px; border-radius: 14px; flex: 0 0 44px; display: grid;
  place-items: center; font-size: 18px; font-weight: 800; color: #fff; }
.bc-ava-all { background: var(--surface-2); color: var(--muted); }
.bc-ava-all svg { width: 20px; height: 20px; }
.bc-label { font-size: 15px; font-weight: 700; color: var(--text); flex: 1; }
.bc-email { font-size: 12.5px; color: var(--muted); }
.brand-card-all .bc-label { color: var(--muted); }

/* Login / Setup / errori */
.login-box { max-width: 400px; margin: 9vh auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 38px 34px; text-align: center; box-shadow: var(--shadow); }
.login-logo { margin: 0 auto 22px; display: flex; align-items: center; justify-content: center; }
.login-logo img { height: 52px; width: auto; max-width: 200px; object-fit: contain; display: block; }
.login-box h1 { margin: 0; font-size: 22px; font-weight: 700; }
.login-box .sub { color: var(--muted); margin: 6px 0 24px; font-size: 14px; }
.login-box label { display: block; text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 14px; }
.login-box input { width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color .15s, background .15s, box-shadow .15s; }
.login-box input:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.12); }
.login-box .btn-primary { width: 100%; margin-top: 8px; padding: 13px; }
.alert { background: #fdeef0; color: #c0344b; border: 1px solid #f7d4da; padding: 11px 14px;
  border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; text-align: left; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

/* Lista ticket - stile helpdesk moderno */
.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.btn-new { background: var(--accent); color: #fff !important; font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 12px; white-space: nowrap; transition: filter .15s, transform .08s; }
.btn-new:hover { filter: brightness(.96); text-decoration: none; }
.btn-new:active { transform: scale(.98); }
.tk-search { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.tk-searchbox { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 14px; transition: border-color .15s, box-shadow .15s; }
.tk-searchbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.tk-searchbox .ic { color: var(--muted); font-size: 14px; }
.tk-searchbox input { border: 0; background: transparent; padding: 11px 0; font-size: 14px; font-family: inherit; min-width: 240px; color: var(--text); }
.tk-searchbox input:focus { outline: none; }
.tk-search select { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit; cursor: pointer; }
.tk-search select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }

/* ===== Dashboard ticket (intestazione + statistiche) ===== */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.dash-head h1 { margin: 0; font-size: 24px; font-weight: 800; }
.dash-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px; }
.stat-label::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 7px; }
.stat-open .stat-label::before { background: #16a34a; }
.stat-pending .stat-label::before { background: #eab308; }
.stat-active .stat-label::before { background: var(--accent); }
.stat-solved .stat-label::before { background: #16a34a; }
.stat-num { font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }

/* barra filtri */
.filter-bar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.fl { display: flex; flex-direction: column; gap: 6px; }
.fl > span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.fl select, .fl input { border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 12px; font-family: inherit; font-size: 13.5px; color: var(--text); cursor: pointer; min-width: 150px; }
.fl input { cursor: text; }
.fl select:focus, .fl input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,91,255,.12); }
.fl-search { flex: 1; min-width: 200px; }
.fl-search input { width: 100%; min-width: 0; }
.reset-filters { margin-left: auto; align-self: flex-end; margin-bottom: 1px; color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); }
.reset-filters:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ===== Lista ticket a card ===== */
.tlist { display: flex; flex-direction: column; gap: 10px; }
.tlist-head, .trow { display: grid; gap: 14px; align-items: center;
  grid-template-columns: 34px minmax(260px, 1fr) 150px 140px 150px 120px 100px; }
.tlist-head { padding: 2px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }

.trow { background: #fff; border: 1px solid #ebebeb; border-radius: 14px; padding: 18px 22px;
  cursor: pointer; transition: box-shadow .15s, border-color .15s, transform .05s; }
.trow:hover { box-shadow: var(--shadow); }
.trow:active { transform: scale(.998); }
.trow.read .t-subj { color: var(--text); font-weight: 600; }
.trow.unread { border-color: #673ab7; }
.trow.unread .t-subj { font-weight: 800; color: var(--text); }

.tck { display: grid; place-items: center; }
.tck input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

.t-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.t-ava { width: 42px; height: 42px; border-radius: 50%; flex: 0 0 42px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 16px; }
.t-main-txt { min-width: 0; }
.t-title { display: flex; align-items: center; gap: 8px; }
.t-subj { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }
.t-id { color: var(--muted); font-weight: 700; font-size: 13px; flex: 0 0 auto; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: #673ab7; flex: 0 0 8px; }
.t-prev { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 460px; }
.t-meta-row { display: flex; align-items: center; gap: 9px; margin-top: 7px; }
.t-req { color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.prod-tag { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 8px; background: var(--grey-bg); color: var(--grey-fg); }
.prod-tag.purebliss { background: #fce7f3; color: #be185d; }
.prod-tag.cartook { background: #e0f2fe; color: #0369a1; }
.ch-mini { font-size: 11px; color: var(--muted); text-transform: capitalize; }

/* controlli inline (stato / priorita / assegnatario) - senza box, in stile pulito */
.t-col { min-width: 0; }
.ictl { display: flex; align-items: center; gap: 8px; width: 100%; border-radius: 8px;
  padding: 4px 6px; transition: background .15s; }
.ictl:hover { background: var(--surface-2); }
.ictl select { appearance: none; -webkit-appearance: none; border: 0; background: transparent; font-family: inherit;
  font-size: 13.5px; font-weight: 600; color: var(--text); cursor: pointer; min-width: 0;
  text-overflow: ellipsis; white-space: nowrap; padding: 0; }
.ictl select:focus { outline: none; }
.ictl .sep { width: 1px; height: 15px; background: var(--line); flex: 0 0 1px; margin-left: auto; }
.ictl .caret { color: var(--muted); font-size: 12px; line-height: 1; pointer-events: none; }
.ictl .ic-act { width: 15px; height: 15px; flex: 0 0 15px; color: var(--muted); }
.ictl .sq { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 14px; background: var(--muted); }
.ictl-prio.prio-low .sq { background: #16a34a; }
.ictl-prio.prio-medium .sq { background: #eab308; }
.ictl-prio.prio-high .sq { background: #f97316; }
.ictl-prio.prio-critical .sq { background: #dc2626; }
.mini-ava { width: 24px; height: 24px; border-radius: 50%; flex: 0 0 24px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text); font-size: 11px; font-weight: 700; }
.mini-ava.empty { display: none; }

.t-time { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.t-ic { width: 14px; height: 14px; flex: 0 0 14px; opacity: .65; }

/* lista Pixart: avatar + oggetto + stato + aggiornato + creato */
.tlist-pixart .tlist-head, .tlist-pixart .trow { grid-template-columns: 44px minmax(240px, 1fr) 130px 120px 100px; align-items: center; }
.t-ava-pix { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
@media (max-width: 720px) {
  .tlist-pixart .tlist-head, .tlist-pixart .trow { grid-template-columns: 44px 1fr; }
}

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .tlist-head, .trow { grid-template-columns: 30px 1fr 140px 130px; }
  .tlist-head span:nth-child(5), .tlist-head span:nth-child(6), .tlist-head span:nth-child(7),
  .trow > .t-col:nth-child(5), .trow > .t-col:nth-child(6), .trow > .t-col:nth-child(7) { display: none; }
}
@media (max-width: 720px) {
  .tlist-head { display: none; }
  .trow { grid-template-columns: 30px 1fr; }
  .trow > .t-col { display: none; }
}

.tk-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.tk-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 700; padding: 11px 14px; background: var(--surface-2);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.tk-table th:first-child { border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 18px; }
.tk-table th:last-child { border-top-right-radius: 10px; border-bottom-right-radius: 10px; }
.tk-table td { padding: 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.tk-table td:first-child { padding-left: 18px; }
.tk-table tbody tr { cursor: pointer; transition: background .12s; box-shadow: inset 3px 0 0 transparent; }
.tk-table tbody tr:hover { background: #f8f9fb; box-shadow: inset 3px 0 0 var(--accent); }
.c-id { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }
.c-menu { width: 44px; text-align: center; }
.row-menu { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  color: var(--muted); font-size: 18px; line-height: 1; }
.row-menu:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.req { display: flex; align-items: center; gap: 11px; }
.tk-ava { width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px; }
.req-txt { min-width: 0; }
.r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.r-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.c-subj { max-width: 280px; }
.msgc { display: inline-block; min-width: 18px; text-align: center; margin-left: 6px; padding: 1px 7px;
  background: var(--surface-2); color: var(--muted); border-radius: 999px; font-size: 11px; font-weight: 600; }
.muted { color: var(--muted); }

.brand-tag { font-size: 11px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
  background: var(--grey-bg); color: var(--grey-fg); }
.brand-tag.purebliss { background: #fce7f3; color: #be185d; }
.brand-tag.cartook { background: #e0f2fe; color: #0369a1; }
.ch { font-size: 12.5px; color: var(--muted); text-transform: capitalize; }
.ch-pill { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: capitalize; }

/* pill di stato in stile outline (lista) */
.pill-st { font-size: 11.5px; font-weight: 600; padding: 4px 12px; border-radius: 999px; white-space: nowrap; border: 1px solid; background: #fff; }
.pst-open    { color: var(--green-fg); border-color: #86efac; background: var(--green-bg); }
.pst-pending  { color: var(--amber-fg); border-color: #fde047; background: var(--amber-bg); }
.pst-solved   { color: var(--blue-fg);  border-color: #c4b5fd; background: var(--blue-bg); }
.pst-closed   { color: var(--grey-fg);  border-color: #cbd5e1; background: var(--grey-bg); }

/* Status badge con pallino colorato */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; padding: 4px 11px;
  border-radius: 999px; white-space: nowrap; letter-spacing: .2px;
}
.status::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none;
}
.st-open    { background: var(--green-bg); color: var(--green-fg); }
.st-open::before { background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,.5);
  animation: stpulse 2s infinite; }
@keyframes stpulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.st-pending  { background: var(--amber-bg); color: var(--amber-fg); }
.st-pending::before  { background: #eab308; }
.st-solved   { background: var(--blue-bg);  color: var(--blue-fg);  }
.st-solved::before   { background: #7c3aed; }
.st-closed   { background: var(--grey-bg);  color: var(--grey-fg);  }
.st-closed::before   { background: #94a3b8; }

.empty { text-align: center; color: var(--muted); padding: 56px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); }

/* Dettaglio ticket - conversazione in stile chat */
.ticket-grid { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
@media (max-width: 880px) { .ticket-grid { grid-template-columns: 1fr; } }

.thread { display: flex; flex-direction: column; height: calc(100vh - 56px); min-height: 460px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.th-title { flex: 1; min-width: 0; }
.th-title h2 { margin: 0; font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-sub { font-size: 12px; color: var(--muted); }
.back { color: var(--muted); font-size: 20px; font-weight: 600; line-height: 1; padding: 2px 6px; border-radius: 8px; }
.back:hover { color: var(--text); background: var(--surface-2); }

.timeline { flex: 1 1 auto; padding: 18px 24px; display: flex; flex-direction: column; gap: 16px;
  overflow-y: auto; background: var(--surface); scroll-behavior: smooth; }
.empty-chat { margin: auto; color: var(--muted); font-size: 14px; }

.day-sep { text-align: center; margin: 6px 0; }
.day-sep span { color: var(--muted); font-size: 12px; font-weight: 600; }

/* messaggio: bolla classica con avatar piccolo accanto */
.msg { display: flex; align-items: flex-end; gap: 9px; max-width: 74%; }
.msg-in { align-self: flex-start; }
.msg-out { align-self: flex-end; flex-direction: row-reverse; }
.msg-note { align-self: center; max-width: 82%; }

.m-ava { width: 28px; height: 28px; aspect-ratio: 1; border-radius: 50%; flex: 0 0 28px; display: grid;
  place-items: center; font-size: 11px; font-weight: 700; color: #fff; margin-bottom: 2px; }
.m-ava-in { background: linear-gradient(135deg,#9aa0ff,#c4a6ff); }
.m-ava-out { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.m-ava-note { background: #d8b15a; }

.m-body { display: flex; flex-direction: column; min-width: 0; }
.m-meta { display: flex; align-items: center; gap: 7px; margin: 0 4px 4px; font-size: 11px; color: var(--muted); }
.msg-out .m-meta { flex-direction: row-reverse; }
.msg-note .m-meta { justify-content: center; }
.m-who { font-weight: 700; color: var(--text); }
.m-ch { text-transform: uppercase; letter-spacing: .3px; font-size: 9.5px; }

.bubble { padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.45; word-break: break-word; }
.msg-in .bubble { background: var(--surface-2); color: var(--text); border-bottom-left-radius: 5px; }
.msg-out .bubble { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 5px; }
.msg-note .bubble { background: var(--amber-bg); border: 1px solid #f6e2bf; color: #7a5a16; }
.b-text { white-space: pre-wrap; word-break: break-word; }

/* chip allegato nelle bolle */
.att { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 7px 11px;
  background: rgba(0,0,0,.05); border-radius: 12px; font-size: 13px; font-weight: 500; color: inherit; max-width: 100%; }
.att:hover { background: rgba(0,0,0,.09); text-decoration: none; }
.msg-out .att { background: rgba(255,255,255,.22); color: #fff; }
.msg-out .att:hover { background: rgba(255,255,255,.32); }
.att-ic { font-size: 14px; }

/* Composer chat */
.composer { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 12px 16px 14px; background: var(--surface); }
.composer-tabs { display: inline-flex; gap: 2px; margin-bottom: 10px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.composer-tabs .tab { display: inline-flex; align-items: center; cursor: pointer; font-size: 12.5px;
  font-weight: 600; color: var(--muted); padding: 6px 14px; border-radius: 999px; transition: all .15s; }
.composer-tabs .tab:has(input:checked) { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); }
.composer-tabs .tab:has(input:disabled) { opacity: .4; cursor: not-allowed; }
.composer-tabs .tab input { display: none; }

.composer-bar { display: flex; align-items: flex-end; gap: 6px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 28px; padding: 6px 6px 6px 8px;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.composer-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.chat-input { flex: 1; border: none; background: transparent; resize: none; font-family: inherit; font-size: 14px;
  line-height: 1.45; padding: 10px 4px; max-height: 160px; color: var(--text); }
.chat-input:focus { outline: none; }
.attach-btn { flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  cursor: pointer; color: var(--muted); font-size: 24px; font-weight: 300; line-height: 1;
  transition: background .15s, color .15s; }
.attach-btn:hover { background: var(--surface-2); color: var(--text); }
.attach-btn input { display: none; }
.send-btn { flex: 0 0 auto; width: 40px; height: 40px; border: none; border-radius: 50%; cursor: pointer;
  background: #1f2430; color: #fff; font-size: 18px; display: grid; place-items: center;
  transition: transform .08s, opacity .15s; }
.send-btn:hover { opacity: .9; }
.send-btn:active { transform: scale(.94); }
.file-name { font-size: 12px; color: var(--muted); margin: 8px 6px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* footer allegati riusato dalla pagina "Nuova email" */
.composer-foot { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.composer-foot .btn-primary { margin-left: auto; }
.file-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px;
  font-weight: 500; color: var(--muted); padding: 8px 14px; border-radius: 999px; background: var(--surface-2);
  transition: background .15s, color .15s; }
.file-btn:hover { background: #e9eaef; color: var(--text); }
.file-btn input { display: none; }

/* scheda cliente arricchita */
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { margin: 0; }
.refresh { font-size: 18px; line-height: 1; text-decoration: none; color: var(--muted); border-radius: 8px; padding: 2px 6px; }
.refresh:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.enrich .kv { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.enrich .kv > span:first-child { color: var(--muted); }
.enrich .kv.ord { font-size: 12.5px; }
.enrich .kv.ord span:first-child { color: var(--text); }
.enrich .sep { margin: 12px 0 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.pill { display: inline-block; margin-bottom: 8px; padding: 3px 10px; border-radius: 999px; background: #e6f7ed; color: #137a43; font-size: 11.5px; font-weight: 600; }
.ord-st { padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.ord-st.st-completed { background: #e6f7ed; color: #137a43; }
.ord-st.st-processing { background: #e8f0fe; color: #1a56db; }
.ord-st.st-pending { background: #fef3e2; color: #b25e09; }
.ord-st.st-cancelled, .ord-st.st-refunded { background: #fdeaea; color: #c0392b; }
.enrich-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.enrich-links a { font-size: 13px; font-weight: 500; }
.muted-note { color: var(--muted); font-size: 13px; }

/* skeleton di caricamento (box cliente) */
.skeleton { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.sk { display: block; border-radius: 8px; background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 37%, #eef0f3 63%);
  background-size: 400% 100%; animation: sk-shimmer 1.3s ease infinite; }
.sk-pill { width: 110px; height: 22px; border-radius: 999px; }
.sk-line { width: 100%; height: 13px; }
.sk-line.short { width: 55%; }
@keyframes sk-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* voce di menu "Nuova email" */
.nav-cta { background: var(--accent); color: #fff !important; padding: 7px 14px; border-radius: 999px; font-weight: 600; }
.nav-cta:hover { filter: brightness(.95); text-decoration: none; }

/* pagina composizione email */
.compose-wrap { max-width: 1080px; margin: 0 auto; }
.compose-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.compose-head h2 { margin: 0; font-size: 19px; font-weight: 700; flex: 1; }
.compose-head .back { color: var(--muted); font-size: 22px; line-height: 1; padding: 2px 8px; border-radius: 8px; }
.compose-head .back:hover { color: var(--text); background: var(--surface-2); }

.compose-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: stretch; }
.compose-side { display: flex; flex-direction: column; gap: 14px; }
.compose-body { display: flex; flex-direction: column; }
.compose-body .fld-grow { flex: 1; }
.compose-body textarea { flex: 1; min-height: 460px; resize: none; }
.attach-row { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.fld-hint { margin: -4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
@media (max-width: 900px) {
  .compose-grid { grid-template-columns: 1fr; }
  .compose-body textarea { min-height: 300px; }
}

.fld { display: flex; flex-direction: column; gap: 6px; position: relative; }
.fld > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.fld input, .fld select, .fld textarea { width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; }
.fld textarea { resize: vertical; line-height: 1.5; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.fld-row { display: flex; gap: 16px; }
.fld-row .fld { flex: 1; }
.results { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; margin-top: 4px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); max-height: 280px; overflow: auto; }
.res-item { padding: 10px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.res-item:hover { background: var(--surface-2); }
.res-item .r-name { font-size: 14px; font-weight: 500; }
.res-item .r-sub { font-size: 12px; color: var(--muted); }
.res-empty { padding: 12px 14px; font-size: 13px; color: var(--muted); }
.compose-form .composer-foot { margin-top: 4px; }
@media (max-width: 640px) { .fld-row { flex-direction: column; gap: 16px; } }

.side { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); }
.card h3 { margin: 0 0 14px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.contact { text-align: center; }
.contact .ava { width: 60px; height: 60px; border-radius: 20px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center;
  font-size: 24px; font-weight: 700; color: #fff; box-shadow: 0 8px 20px rgba(99,91,255,.25); }
.contact .c-name { font-size: 17px; font-weight: 700; }
.c-row { font-size: 13.5px; color: var(--muted); margin-top: 9px; }
.c-row b { color: var(--text); }
.actions label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 14px; }

/* ===== Pagina Operatori ===== */
.users-grid { display: grid; grid-template-columns: 1fr 340px; gap: 22px; align-items: start; }
@media (max-width: 860px) { .users-grid { grid-template-columns: 1fr; } }

.users-list { display: flex; flex-direction: column; gap: 10px; }
.user-row { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid #ebebeb;
  border-radius: 14px; padding: 14px 18px; }
.u-ava { width: 40px; height: 40px; aspect-ratio: 1; border-radius: 50%; flex: 0 0 40px; display: grid;
  place-items: center; font-size: 15px; font-weight: 700; color: #fff; }
.u-info { flex: 1; min-width: 0; }
.u-name { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.u-email { font-size: 13px; color: var(--muted); margin-top: 2px; }
.u-badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.u-you { background: var(--surface-2); color: var(--muted); }
.u-admin { background: var(--blue-bg); color: var(--accent); }
.u-status { font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.u-active { background: var(--green-bg); color: var(--green-fg); }
.u-inactive { background: var(--grey-bg); color: var(--grey-fg); }
.u-del { flex: 0 0 32px; width: 32px; }
.u-del-btn { width: 32px; height: 32px; border: none; background: transparent; border-radius: 8px;
  cursor: pointer; display: grid; place-items: center; color: var(--muted); transition: background .15s, color .15s; }
.u-del-btn:hover { background: #fdeef0; color: #c0344b; }
.u-del-btn svg { width: 16px; height: 16px; }

.users-form { padding: 22px; }
.users-form h3 { margin: 0 0 18px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 700; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.actions select, .actions input { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit;
  transition: border-color .15s, background .15s, box-shadow .15s; }
.actions select:focus, .actions input:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(99,91,255,.1); }
.actions .btn-ghost, .actions .btn-primary { width: 100%; }

/* Pulsante distruttivo */
.btn-ghost.danger { color: #c0344b; border-color: #f1d2d8; }
.btn-ghost.danger:hover { background: #fdeef0; border-color: #efbcc5; }

/* Flash / messaggi */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 14px; }
.flash.ok { background: var(--green-bg); color: var(--green-fg); }
.flash.err { background: #fdeef0; color: #c0344b; }

/* Azione pericolosa nel dettaglio ticket */
.danger-zone { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 16px; }
.danger-zone .btn-ghost { width: 100%; }

/* ===================== Impostazioni ===================== */
.settings-card { max-width: 720px; margin-bottom: 18px; }
.set-help { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 8px 0 0; }
.set-help code, .set-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.set-help code { background: var(--grey-bg); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.set-code { display: block; background: #0c0d10; color: #e6e6ea; padding: 12px 14px; border-radius: 10px;
  font-size: 12px; overflow-x: auto; white-space: pre; }
.set-toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; }
.set-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.set-toggle.set-danger { color: #c0344b; }
.set-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ===================== Statistiche ===================== */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.sc-num { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.sc-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
@media (max-width: 860px) { .stat-grid, .stat-cards { grid-template-columns: 1fr; } }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 46px; align-items: center; gap: 14px; }
.bar-lbl { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.bl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--grey-bg); height: 22px; border-radius: 8px; overflow: hidden; }
.bar-fill { display: flex; align-items: center; justify-content: flex-end; height: 100%; border-radius: 8px;
  min-width: 22px; transition: width .3s ease; }
.bar-fill b { color: #fff; font-size: 12px; font-weight: 700; padding-right: 8px; }
.bf-cust { background: var(--accent); }
.bf-pix { background: #8b5cf6; }
.sb-positivo { background: #16a34a; }
.sb-neutro { background: #94a3b8; }
.sb-negativo { background: #e0556e; }
.bar-val { font-size: 13px; color: var(--text); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

.senti-bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; background: var(--grey-bg); }
.senti-bar .seg { height: 100%; transition: width .3s ease; }
.senti-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; color: var(--muted); }
.senti-legend span { display: inline-flex; align-items: center; gap: 7px; }
.senti-legend b { color: var(--text); }

.recent-list { display: flex; flex-direction: column; }
.recent-row { display: flex; flex-direction: column; gap: 5px;
  padding: 12px 6px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.recent-row:last-child { border-bottom: none; }
.recent-row:hover { background: var(--bg); }
.rr-top { display: flex; align-items: center; gap: 12px; }
.rr-cat { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; flex: none;
  background: var(--grey-bg); color: var(--grey-fg); }
.rr-cat.tag-negativo { background: #fdeef0; color: #c0344b; }
.rr-cat.tag-positivo { background: var(--green-bg); color: var(--green-fg); }
.rr-subj { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.rr-reason { color: var(--muted); font-size: 13px; padding-left: 2px; }
.rr-meta { color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
@media (max-width: 860px) {
  .bar-row { grid-template-columns: 120px 1fr 44px; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d9dbe1; border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #c4c7d0; }
