/* Supporto Simone Branca — UI */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e6e9f2;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --violet: #8b5cf6;
  --green: #16a34a;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 41, 59, .05), 0 4px 16px rgba(30, 41, 59, .06);
  --shadow-lg: 0 4px 12px rgba(30, 41, 59, .08), 0 12px 40px rgba(79, 70, 229, .10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand-name { font-size: 15px; line-height: 1.2; }
.brand-name strong { font-weight: 700; }
.nav { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.nav-link {
  color: var(--muted); font-weight: 500; padding: 7px 12px; border-radius: 9px;
}
.nav-link:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }
.nav-new { margin-left: 6px; }
.nav-user { display: flex; align-items: center; gap: 6px; margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--border); }
.nav-logout { font-size: 13px; }

/* ---- Layout ---- */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0 36px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-card, .section-card { padding: 24px; margin-bottom: 20px; }
.empty { padding: 48px 24px; text-align: center; }
.empty p { margin: 6px 0; }
.empty-icon { font-size: 34px; }
.empty .btn { margin-top: 14px; }

/* ---- Bottoni ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 9px 18px; transition: all .15s ease; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #7c5cf6);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, .35);
}
.btn-primary:hover { filter: brightness(1.07); box-shadow: 0 4px 14px rgba(99, 102, 241, .45); }
.btn-outline { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: #c7cbe0; background: var(--bg); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---- Form ---- */
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 13px; transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.textarea { resize: vertical; min-height: 90px; }
select.input { appearance: auto; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid-form .form-actions { grid-column: 1 / -1; justify-content: flex-start; }
.inline-form { display: inline-flex; }

/* ---- Flash ---- */
.flash {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-radius: 10px; padding: 11px 14px; margin-bottom: 14px; font-size: 14px;
}
.flash-success { background: var(--green-soft); color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: var(--red-soft); color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: var(--accent-soft); color: #3730a3; border: 1px solid #e0e7ff; }
.flash-x {
  background: none; border: none; font-size: 18px; line-height: 1;
  cursor: pointer; color: inherit; opacity: .6; padding: 0 2px;
}
.flash-x:hover { opacity: 1; }

/* ---- Badge e priorità ---- */
.badge {
  display: inline-flex; align-items: center;
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  border-radius: 99px; padding: 3px 10px; vertical-align: middle;
}
.badge-open { background: var(--accent-soft); color: #4338ca; }
.badge-answered { background: var(--green-soft); color: #15803d; }
.badge-closed { background: #f1f5f9; color: var(--muted); }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.badge-active { background: var(--green-soft); color: #15803d; }
.badge-disabled { background: #f1f5f9; color: var(--muted); }
.badge-staff { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }

.prio { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.prio-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.prio-low .prio-dot { background: #94a3b8; }
.prio-normal .prio-dot { background: #6366f1; }
.prio-high { color: var(--red); }
.prio-high .prio-dot { background: var(--red); }

.prio-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.prio-option {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 16px;
  font-weight: 600; font-size: 14px; transition: all .15s;
}
.prio-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.prio-option input { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--muted);
  background: var(--bg); border-radius: 99px; padding: 3px 9px;
}
.count-pill {
  display: inline-flex; min-width: 22px; height: 22px; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border-radius: 99px;
  font-size: 12px; font-weight: 700; padding: 0 7px; margin-left: 6px;
}

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; display: flex; flex-direction: column; gap: 2px;
  color: var(--text); transition: all .15s; box-shadow: var(--shadow);
}
.stat:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.stat-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stat-num { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat-open { color: var(--accent); }
.stat-answered { color: var(--green); }
.stat-closed { color: var(--muted); }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ---- Filtri ---- */
.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.input-search { flex: 1; min-width: 200px; }
.input-select { width: auto; }

/* ---- Lista ticket ---- */
.ticket-list { overflow: hidden; }
.ticket-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 15px 20px; color: var(--text);
  border-bottom: 1px solid var(--border); transition: background .12s;
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: #f8faff; text-decoration: none; }
.ticket-main { min-width: 0; }
.ticket-subject { display: block; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-meta { font-size: 12.5px; color: var(--muted); }
.ticket-side { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: wrap; justify-content: flex-end; }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; }
.page-link {
  min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 9px; background: var(--card);
  color: var(--text); font-weight: 600; font-size: 13.5px;
}
.page-link:hover { text-decoration: none; border-color: var(--accent); }
.page-link.current { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Testata ticket ---- */
.ticket-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.back-link { font-size: 13.5px; color: var(--muted); display: inline-block; margin-bottom: 6px; }
.ticket-title { font-size: 22px; margin-bottom: 6px; }
.ticket-title-meta { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ticket-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- Thread ---- */
.thread { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.msg {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
}
.msg-staff { background: #fbfaff; border-color: #e4e2f7; border-left: 3px solid var(--accent); }
.msg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.msg-author { font-weight: 700; }
.msg-date { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.msg-body { white-space: normal; overflow-wrap: break-word; }
.msg-body a { word-break: break-all; }

.avatar {
  width: 34px; height: 34px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #e2e8f0; color: #475569;
  font-size: 13px; font-weight: 700;
}
.avatar-staff { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.avatar-lg { width: 48px; height: 48px; font-size: 17px; }
a.avatar:hover { text-decoration: none; filter: brightness(1.05); }

.msg-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.att {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; color: var(--text); max-width: 100%;
}
.att:hover { border-color: var(--accent); text-decoration: none; background: var(--accent-soft); }
.att-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.att-size { color: var(--muted); flex: none; }

.closed-note { padding: 16px 20px; background: var(--amber-soft); border-color: #fde68a; }
.closed-note p { margin: 0; }

/* ---- Risposta ---- */
.reply-card { padding: 20px; }
.reply-title { margin-bottom: 10px; }
.reply-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

/* ---- Dropzone ---- */
.dropzone {
  display: block; cursor: pointer;
  border: 2px dashed #c7cbe0; border-radius: 12px;
  padding: 18px; text-align: center; color: var(--muted);
  transition: all .15s; background: #fafbff;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone input[type="file"] { display: none; }
.dropzone-slim { padding: 9px 16px; display: inline-block; text-align: left; border-radius: 10px; }
.dropzone-text { font-weight: 600; font-size: 14px; }
.dropzone-list { display: block; font-size: 12.5px; margin-top: 4px; color: var(--muted); }
.dropzone-list:empty { display: none; }

/* ---- Righe admin ---- */
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.row-item:last-child { border-bottom: none; }
.row-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 12.5px; color: var(--muted); }
.row-actions { display: flex; gap: 8px; flex: none; }
.section-title { display: flex; align-items: center; font-size: 16px; }
.pending-card { border-left: 3px solid var(--amber); }

.company { border-bottom: 1px solid var(--border); }
.company:last-of-type { border-bottom: none; }
.company-summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 4px; cursor: pointer; list-style: none; font-weight: 600;
}
.company-summary::-webkit-details-marker { display: none; }
.company-summary::before { content: "\25B8"; color: var(--muted); transition: transform .15s; }
.company[open] .company-summary::before { transform: rotate(90deg); }
.company-name { font-size: 15px; }
.company-meta { font-weight: 400; margin-left: auto; }
.company-users { padding: 0 4px 12px 24px; }

.profile-info { display: flex; align-items: center; gap: 14px; }
.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ---- Pagine auth ---- */
.auth-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(60% 50% at 15% 0%, rgba(99, 102, 241, .14), transparent),
    radial-gradient(50% 40% at 90% 100%, rgba(139, 92, 246, .12), transparent),
    var(--bg);
  padding: 24px 16px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 44px; height: 44px; }
.auth-brand-text { font-size: 17px; line-height: 1.25; }
.auth-card { padding: 30px 28px; box-shadow: var(--shadow-lg); }
.auth-title { font-size: 21px; margin-bottom: 6px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.auth-links {
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  margin-top: 18px; font-size: 13.5px; color: var(--muted);
}
.auth-done { text-align: center; }
.auth-done .auth-sub { margin-bottom: 22px; }
.done-icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 24px;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-form { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; gap: 10px; }
  .container { padding: 20px 14px 48px; }
  .ticket-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .ticket-side { justify-content: flex-start; }
  .ticket-subject { white-space: normal; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .msg-date { margin-left: 0; width: 100%; }
  .brand-name { display: none; }
}
