@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f1f2f5;
  --surface-sunken: #e8e9ed;
  --border: #e3e4e9;
  --border-strong: #d3d5dc;

  --ink: #16181d;
  --ink-soft: #33353c;
  --text: #191b20;
  --text-muted: #5c5f68;
  --text-faint: #9497a1;

  --accent: #2454e8;
  --accent-soft: #eaf0fe;

  --success: #157a4a;
  --success-soft: #e9f6ef;
  --warning: #a45a09;
  --warning-soft: #fbf1e3;
  --danger: #b3261e;
  --danger-soft: #fbeceb;

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;

  --shadow-card: 0 1px 2px rgba(20, 21, 26, 0.04);
  --shadow-pop: 0 12px 32px rgba(20, 21, 26, 0.14);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--accent); }
svg { display: block; }
button { font-family: var(--font); }

/* ---------- Logo mark ---------- */
.logo-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--ink); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-mark svg { width: 17px; height: 17px; color: #fff; }
.logo-mark.sm { width: 30px; height: 30px; }
.logo-mark.sm svg { width: 15px; height: 15px; }

/* ---------- Auth screen ---------- */
.auth-screen { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.remember-me-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-muted); margin: -8px 0 18px; cursor: pointer; }
.remember-me-row input { width: 16px; height: 16px; accent-color: var(--ink); }
html.scroll-locked, html.scroll-locked body {
  overscroll-behavior: none; height: 100%; margin: 0;
}
html.scroll-locked .auth-screen { min-height: 100dvh; }

/* ---------- Schermata di avvio: nasconde il contenuto finché i dati reali non sono
   pronti (crediti, ordine del menu, ecc.), evitando qualsiasi lampeggio di dati errati ---------- */
html.app-loading .app-shell, html.app-loading .mobile-topbar { visibility: hidden; }
.app-boot-spinner { display: none; }
html.app-loading .app-boot-spinner {
  display: flex; position: fixed; inset: 0; z-index: 999; align-items: center; justify-content: center;
  background: var(--bg);
}
.app-boot-spinner-ring {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border-strong);
  border-top-color: var(--ink); animation: app-boot-spin .7s linear infinite;
}
@keyframes app-boot-spin { to { transform: rotate(360deg); } }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 32px; }
.auth-card .brand-row { display: flex; align-items: center; gap: 11px; margin-bottom: 30px; }
.brand-name { font-size: 16px; font-weight: 700; }
.auth-card h1 { font-size: 19px; margin-bottom: 6px; }
.auth-card .subtitle-lead { color: var(--text-muted); font-size: 13.5px; margin: 0 0 26px; }

/* ---------- Form fields ---------- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); padding: 10.5px 12px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; outline: none; transition: border-color .12s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); }
.field textarea { resize: vertical; min-height: 96px; }
.field-hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.field input[type="datetime-local"] { font-size: 13.5px; padding: 10px 8px; }

.profile-info-row { display: flex; gap: 32px; flex-wrap: wrap; }
.profile-info-row > div { font-size: 15px; font-weight: 600; }

.checkbox-list { max-height: 220px; overflow-y: auto; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; }
.checkbox-list label { display: flex; align-items: center; gap: 9px; padding: 8px 9px; font-size: 13.5px; border-radius: 6px; cursor: pointer; }
.checkbox-list label:hover { background: var(--surface); }
.checkbox-list input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--ink); }
.checkbox-list .empty-state { padding: 10px; }

.deleted-tag {
  display: flex; align-items: center; gap: 4px; font-size: 10.5px; color: var(--text-faint);
  margin-top: 5px; cursor: help;
}
.deleted-tag svg { width: 11px; height: 11px; flex-shrink: 0; }

/* Riga con matita: modifica diretta in-place (niente form sotto) */
.inline-edit-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.inline-edit-row:last-child { border-bottom: none; }
.inline-edit-row .label { font-size: 12.5px; color: var(--text-faint); margin-bottom: 2px; }
.inline-edit-row .value { font-size: 14.5px; font-weight: 600; word-break: break-all; }
.inline-edit-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.inline-edit-actions .icon-btn.success { background: var(--success-soft); border-color: transparent; }
.inline-edit-actions .icon-btn.success:hover { background: var(--success); color: #fff; }
.inline-edit-actions .icon-btn.danger { background: var(--danger-soft); border-color: transparent; }
.inline-edit-actions .icon-btn.danger:hover { background: var(--danger); color: #fff; }
.icon-btn { width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.icon-btn.success { color: var(--success); }
.icon-btn.success:hover { background: var(--success-soft); border-color: var(--success-soft); }
.icon-btn svg { width: 15px; height: 15px; }
.inline-edit-value-input {
  width: 100%; font-size: 14.5px; font-weight: 600; font-family: var(--font); color: var(--text);
  background: var(--surface-alt); border: 1px solid var(--ink); border-radius: var(--radius-sm);
  padding: 6px 9px; outline: none;
}

/* ---------- Timeline (storico crediti) ---------- */
.timeline { display: flex; flex-direction: column; }
.timeline-item { display: flex; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.timeline-dot.positive { background: var(--success); }
.timeline-dot.negative { background: var(--danger); }
.timeline-content { flex: 1; min-width: 0; }
.timeline-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.timeline-amount { font-size: 15px; font-weight: 700; }
.timeline-amount.positive { color: var(--success); }
.timeline-amount.negative { color: var(--danger); }
.timeline-date { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.timeline-reason { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Buttons (niente pillole, niente animazioni "bounce") ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10.5px 16px;
  font-family: var(--font); font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--ink-soft); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-alt); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.error-text { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ==================== APP SHELL ==================== */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

/* --- Sidebar (desktop) --- */
.sidebar {
  width: 264px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.sidebar .brand-row, .drawer-panel .brand-row { display: flex; align-items: center; gap: 10px; padding: 4px 8px 0; }

/* Scheda utente nel menu (tra logo e nav) */
.nav-user-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 13px;
}
.nav-user-card .identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-user-card .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13.5px; font-weight: 700; flex-shrink: 0;
}
.nav-user-card .identity-text { min-width: 0; }
.nav-user-card .identity-name { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-card .identity-email { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-card .divider-thin { height: 1px; background: var(--border); }
.nav-user-card .credits-row { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-muted); }
.nav-user-card .credits-row strong { color: var(--text); font-size: 14px; }
.nav-user-card .role-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); background: var(--accent-soft); padding: 3px 8px; border-radius: 5px; width: fit-content;
}

.nav-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 11px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; border-left: 2px solid transparent;
  transition: background-color .12s, color .12s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active { background: var(--surface-alt); color: var(--text); font-weight: 600; border-left-color: var(--ink); }

.sidebar-footer { margin-top: auto; }

/* --- Mobile top app bar (hamburger a sinistra) --- */
.mobile-topbar {
  display: none; position: sticky; top: 0; z-index: 80;
  align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.mobile-topbar .brand-row { display: flex; align-items: center; gap: 9px; }
.menu-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.menu-btn svg { width: 18px; height: 18px; }

/* --- Drawer (mobile) --- */
.drawer-overlay {
  display: none; position: fixed; inset: 0; z-index: 150; background: rgba(15,16,20,.4);
  opacity: 0; transition: opacity .18s ease;
}
.drawer-overlay.open { display: block; }
.drawer-overlay.visible { opacity: 1; }
.drawer-panel {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(82vw, 300px);
  background: var(--surface); z-index: 151; border-right: 1px solid var(--border);
  padding: calc(18px + env(safe-area-inset-top)) 14px 18px;
  display: flex; flex-direction: column; gap: 16px;
  transform: translateX(-100%); transition: transform .2s ease;
}
.drawer-overlay.open .drawer-panel { transform: translateX(0); }
.drawer-panel .brand-row { justify-content: space-between; }
.drawer-close-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.drawer-close-btn svg { width: 15px; height: 15px; }

.main { flex: 1; min-width: 0; padding: 30px 36px 56px; max-width: 980px; width: 100%; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 14px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; }
.topbar .subtitle { color: var(--text-muted); font-size: 13.5px; margin-top: 3px; }

.credit-pill {
  background: var(--surface-alt); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 14px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.credit-pill svg { width: 14px; height: 14px; color: var(--text-muted); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; margin-bottom: 16px; box-shadow: var(--shadow-card); }
.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 18px; }
.card-header-row h2 { margin: 0; }
.card h2 .card-subtitle { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 400; margin-top: 4px; }

.search-box { position: relative; width: 230px; max-width: 100%; flex-shrink: 0; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }
.search-box input {
  width: 100%; background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 999px; padding: 8.5px 14px 8.5px 33px; font-size: 13px; font-family: var(--font);
  outline: none; transition: border-color .12s, background-color .12s;
}
.search-box input:focus { border-color: var(--ink); background: var(--surface); }
@media (max-width: 900px) {
  .card-header-row { flex-direction: column; align-items: stretch; }
  .card-header-row.collapsible-header { flex-direction: row; align-items: center; }
  .search-box { width: 100%; }
}

.row { display: flex; gap: 14px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Switch ---------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.flag-list .switch-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.flag-list .switch-row:last-child { border-bottom: none; padding-bottom: 0; }
.flag-list .switch-row:first-child { padding-top: 0; }
.switch-label { font-size: 14px; font-weight: 600; }
.switch-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.switch-inline-label { font-size: 13px; font-weight: 600; color: var(--text); }
.switch { position: relative; width: 40px; height: 23px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; cursor: pointer; transition: background-color .12s; }
.switch .slider::before { content: ''; position: absolute; width: 17px; height: 17px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .12s; }
.switch input:checked + .slider { background: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(17px); }

/* ---------- Segmented control (niente pillole: rettangolare) ---------- */
.segmented { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 14px; }
.segmented button {
  flex: 1; padding: 9px; border: none; background: var(--surface);
  color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font);
  border-right: 1px solid var(--border-strong); transition: background-color .12s, color .12s;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--ink); color: #fff; }

.prefix-sender-row { display: flex; gap: 8px; }
.prefix-sender-row select { flex: 0 0 128px; }
.prefix-sender-row.alias-mode select { display: none; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 480px; }
thead th { text-align: left; color: var(--text-faint); font-weight: 700; padding: 9px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
tbody td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-alt); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.badge-delivered { background: var(--success-soft); color: var(--success); }
.badge-sent { background: var(--warning-soft); color: var(--warning); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }
.badge-queued { background: var(--surface-alt); color: var(--text-muted); }
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-banned { background: var(--danger-soft); color: var(--danger); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,16,20,.4); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 420px; padding: 24px; box-shadow: var(--shadow-pop); max-height: 86vh; overflow-y: auto; }
.modal h3 { font-size: 16px; margin-bottom: 15px; }
.modal-actions { display: flex; gap: 9px; margin-top: 18px; justify-content: flex-end; }

.message-readonly {
  font-size: 14.5px; line-height: 1.6; color: var(--text); margin: 0; padding: 14px;
  background: var(--surface-alt); border-radius: var(--radius-sm); border-left: 2px solid var(--ink);
  white-space: pre-wrap; word-break: break-word;
}
.message-editable {
  width: 100%; min-height: 130px; resize: vertical; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 12px;
  font-size: 14px; font-family: var(--font); line-height: 1.55; outline: none;
}
.message-editable:focus { border-color: var(--ink); }

/* Popup toast (nessuna animazione elastica) */
.popup-toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; z-index: 200; box-shadow: var(--shadow-pop);
  display: none; max-width: 90vw;
}
.popup-toast.success { background: var(--success); }
.popup-toast.error { background: var(--danger); }
.popup-toast.show { display: block; }

.empty-state { color: var(--text-faint); font-size: 13px; padding: 26px 0; text-align: center; }

.bulk-list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 7px; font-size: 13px;
}
.bulk-list-item .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bulk-list-item .meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-list-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

.section-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ---------- Ricerca utenti con suggerimenti + tag rimovibili ---------- */
.autocomplete-list {
  border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 6px;
  max-height: 180px; overflow-y: auto; background: var(--surface);
}
.autocomplete-item { padding: 9px 12px; font-size: 13.5px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.autocomplete-item:hover { background: var(--surface-alt); }
.autocomplete-item .ac-username { font-weight: 700; }
.autocomplete-item .ac-meta { font-size: 11.5px; color: var(--text-faint); }
.tag-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 12.5px; font-weight: 600;
}
.tag-chip button {
  border: none; background: var(--border-strong); color: var(--text); width: 17px; height: 17px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 11px; line-height: 1; padding: 0;
}
.tag-chip button:hover { background: var(--danger); color: #fff; }

/* ---------- Liste entità (utenti, admin, paesi bloccati): schede uniformi ---------- */
.entity-list { display: flex; flex-direction: column; gap: 10px; }
.entity-card { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.entity-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.entity-row .entity-label { color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.entity-row .entity-value { font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-actions {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--surface-alt);
}
.entity-actions .btn-secondary.btn-sm { flex-shrink: 0; }

/* ---------- Selettore data/ora personalizzato (niente picker di sistema) ---------- */
.dt-picker { position: relative; }
.dt-picker-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10.5px 12px; font-size: 14px; font-family: var(--font); color: var(--text); cursor: pointer;
  text-align: left;
}
.dt-picker-trigger.placeholder { color: var(--text-faint); }
.dt-picker-trigger svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.dt-picker-panel {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 130;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop); padding: 14px; width: 272px; max-width: min(272px, 82vw);
}
.dt-picker.open .dt-picker-panel { display: block; }
.dt-cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dt-cal-header button {
  width: 26px; height: 26px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.dt-cal-header button svg { width: 13px; height: 13px; }
.dt-cal-title { font-size: 13px; font-weight: 700; text-transform: capitalize; }
.dt-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 12px; }
.dt-cal-dow { font-size: 10px; color: var(--text-faint); text-align: center; font-weight: 700; padding: 3px 0; }
.dt-cal-day {
  font-size: 12.5px; text-align: center; padding: 7px 0; border-radius: 7px; cursor: pointer;
  background: none; border: none; font-family: var(--font); color: var(--text);
}
.dt-cal-day:hover { background: var(--surface-alt); }
.dt-cal-day.selected { background: var(--ink); color: #fff; font-weight: 700; }
.dt-cal-day.today:not(.selected) { box-shadow: inset 0 0 0 1px var(--border-strong); }
.dt-cal-day.disabled { color: var(--text-faint); opacity: .35; pointer-events: none; }
.dt-cal-day.empty { visibility: hidden; pointer-events: none; }
.dt-time-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 12px;
}
.dt-time-row .dt-time-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-right: 2px; }
.dt-time-input {
  width: 48px; text-align: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 2px; font-size: 15px; font-family: var(--font); color: var(--text);
}
.dt-time-sep { font-weight: 700; color: var(--text-muted); }
.dt-picker-confirm { width: 100%; }

/* ---------- Sezioni comprimibili (freccetta giù = chiusa, su = aperta) ---------- */
.collapsible-header { }
.collapsible-toggle {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm); flex-shrink: 0;
}
.collapsible-toggle:hover { background: var(--surface-alt); }
.collapsible-toggle svg { width: 16px; height: 16px; transition: transform .15s ease; }
.collapsible-toggle.open svg { transform: rotate(180deg); }
.collapsible-body.collapsed { display: none; }
.section-flag-checkbox {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.section-flag-checkbox input { width: 15px; height: 15px; accent-color: var(--ink); }

/* ---------- Elenco attività (card-list, niente overlap su mobile) ---------- */
.activity-item { padding: 12px 2px; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-item .top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.activity-item .action { font-size: 13.5px; font-weight: 600; }
.activity-item .date { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.activity-item .details { font-size: 13px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; }
/* ---------- Elenco attività v2: icona + testo, più curato (usato ovunque) ---------- */
.activity-item-v2 {
  display: flex; gap: 12px; padding: 13px 14px; margin-bottom: 8px;
  background: var(--surface-alt); border-radius: var(--radius-md);
}
.activity-item-v2:last-child { margin-bottom: 0; }
.activity-icon {
  width: 36px; height: 36px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-card);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--ink);
}
.activity-icon svg { width: 16px; height: 16px; }
.activity-content { flex: 1; min-width: 0; }
.activity-content .top-row { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.activity-content .action { font-size: 13.5px; font-weight: 700; }
.activity-content .date { font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.activity-content .details { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; word-break: break-word; }
@media (max-width: 480px) {
  .activity-item-v2 { padding: 12px; }
  .activity-content .top-row { flex-direction: column; align-items: flex-start; gap: 2px; }
}
.load-more-row { display: flex; justify-content: center; margin-top: 14px; }

/* ---------- Selezione multipla nello storico SMS ---------- */
.history-toolbar { margin-bottom: 14px; }
.history-toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.history-toolbar .search-box { flex: 1; min-width: 160px; max-width: 280px; margin-bottom: 0; }
.select-all-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; }
.select-all-row input { width: 16px; height: 16px; accent-color: var(--ink); }
.history-toolbar-select-actions { display: flex; gap: 8px; flex-shrink: 0; }
.entity-select-row { display: none; cursor: pointer; }
.entity-select-row input { width: 17px; height: 17px; accent-color: var(--ink); cursor: pointer; }
#historyBody.select-mode .entity-select-row { display: flex; }

/* ---------- Ordine e nomi del menu (pannello master) ---------- */
.nav-config-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.nav-config-item {
  display: flex; align-items: center; gap: 10px; background: var(--surface-alt);
  border-radius: var(--radius-sm); padding: 8px 10px; transition: box-shadow .1s;
}
.nav-config-item.dragging { box-shadow: var(--shadow-pop); background: var(--surface); z-index: 5; position: relative; }
.nav-config-item input {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 7px 9px; font-size: 13.5px; font-family: var(--font); color: var(--text);
}
.nav-config-grip {
  width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: grab; flex-shrink: 0; touch-action: none;
}
.nav-config-grip:active { cursor: grabbing; }
.nav-config-grip svg { width: 16px; height: 16px; }
.nav-config-home-btn {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; color: var(--text-faint);
}
.nav-config-home-btn:hover { color: var(--text-muted); }
.nav-config-home-btn svg { width: 15px; height: 15px; }
.nav-config-home-btn.active { color: var(--ink); background: var(--surface-sunken); border-color: var(--border-strong); }
.nav-config-home-btn.active svg { fill: var(--ink); }

/* ---------- Galleria icone (pannello master) ---------- */
.icon-gallery-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.icon-gallery-select-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.icon-gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px;
}
.icon-gallery-item {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.icon-gallery-checkbox { display: none; position: absolute; top: 8px; left: 8px; z-index: 2; }
.icon-gallery-grid.select-mode .icon-gallery-checkbox { display: block; }
.icon-gallery-checkbox input { width: 19px; height: 19px; accent-color: var(--ink); cursor: pointer; }
.icon-gallery-thumb {
  width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); background: var(--surface-alt);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.icon-gallery-thumb img { width: 100%; height: 100%; object-fit: contain; }
.icon-gallery-badges { display: flex; gap: 4px; flex-wrap: wrap; min-height: 18px; }
.icon-gallery-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface-sunken); color: var(--text); padding: 2.5px 7px; border-radius: 999px;
}
.icon-gallery-assign { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
.icon-gallery-assign button {
  font-size: 11px; font-weight: 600; padding: 7px 4px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.icon-gallery-assign button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.icon-gallery-delete {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--danger);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-gallery-delete svg { width: 14px; height: 14px; }

@media (max-width: 480px) {
  .icon-gallery-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
  .icon-gallery-toolbar { justify-content: space-between; }
  .icon-gallery-toolbar #iconUploadBtn { flex: 1; }
}



/* ---------- Storico crediti: riga con accento colorato + importo in evidenza ---------- */
.credit-entry {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 14px 14px 16px; border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
}
.credit-entry.positive { border-left-color: var(--success); }
.credit-entry.negative { border-left-color: var(--danger); }
.credit-entry:last-child { border-bottom: none; }
.credit-entry .info { flex: 1; min-width: 0; }
.credit-entry .info .reason { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credit-entry .info .date { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.credit-entry .info .date svg { width: 11px; height: 11px; }
.credit-entry .amount-chip {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 7px 15px; border-radius: var(--radius-md); min-width: 62px; flex-shrink: 0;
}
.credit-entry .amount-chip.positive { background: var(--success-soft); }
.credit-entry .amount-chip.negative { background: var(--danger-soft); }
.credit-entry .amount-chip .value { font-size: 17px; font-weight: 800; line-height: 1.1; }
.credit-entry .amount-chip.positive .value { color: var(--success); }
.credit-entry .amount-chip.negative .value { color: var(--danger); }
.credit-entry .amount-chip .label {
  font-size: 9px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; opacity: .65; margin-top: 1px;
}
.credit-entry .amount-chip.positive .label { color: var(--success); }
.credit-entry .amount-chip.negative .label { color: var(--danger); }

/* ---------- Scheda utente / admin: intestazione profilo + griglia statistiche ---------- */
.detail-header { display: flex; align-items: center; gap: 14px; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.detail-header .avatar-lg {
  width: 50px; height: 50px; border-radius: 50%; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 19px; font-weight: 700; flex-shrink: 0;
}
.detail-header-text { min-width: 0; }
.detail-header-text h2 { margin: 0; font-size: 17px; }
.detail-header-text .muted { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 18px; }
.stat-item .stat-label { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; font-weight: 600; }
.stat-item .stat-value { font-size: 16.5px; font-weight: 700; }
.stat-item.subtle .stat-value { font-size: 13px; font-weight: 500; color: var(--text-muted); }

/* ==================== MOBILE ==================== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobile-topbar { display: flex; }

  .main { padding: 18px 16px 44px; max-width: none; }
  .row { flex-direction: column; }
  .prefix-sender-row select { flex: 0 0 112px; }

  .table-wrap { overflow-x: visible; }
  table { min-width: 0; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 9px; padding: 4px 0; }
  tr:last-child { margin-bottom: 0; }
  td { padding: 9px 13px; padding-left: 44%; position: relative; text-align: right; min-height: 20px; border-bottom: none; }
  td::before { content: attr(data-label); position: absolute; left: 13px; font-weight: 600; color: var(--text-muted); text-align: left; }
  td.cell-actions { text-align: left; padding-left: 13px; justify-content: flex-start; }
  td.cell-actions::before { content: none; }

  .card { padding: 17px; border-radius: var(--radius-md); }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 90vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); width: 100%; max-width: none; }

  .topbar { align-items: stretch; }
  .credit-pill { align-self: flex-start; }
}
