*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --sidebar-bg: #1e2a3a;
  --sidebar-text: #c8d3e0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --unread-bg: #eff6ff;
  --danger: #ef4444;
  --radius: 8px;
}

body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; }

/* ── SCREENS ──────────────────────────────────────────────── */
.screen { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* ── LOGIN ────────────────────────────────────────────────── */
#login-screen { align-items: center; justify-content: center; background: var(--sidebar-bg); }
.login-box {
  background: var(--surface); border-radius: var(--radius);
  padding: 2.5rem; width: 340px; max-width: 90vw; display: flex; flex-direction: column; gap: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-logo { display: block; max-width: 200px; max-height: 90px; width: auto; height: auto; margin: 0 auto .5rem; object-fit: contain; }
.login-box h1 { text-align: center; font-size: 1.6rem; }
.login-box input, .login-box button {
  padding: .65rem .9rem; border-radius: var(--radius); font-size: 1rem; width: 100%;
}
.login-box input { border: 1px solid var(--border); }
.login-box button { background: var(--accent); color: #fff; border: none; cursor: pointer; font-weight: 600; }
.login-box button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: .9rem; text-align: center; }
.status { margin-top: .5rem; font-size: .9rem; color: var(--muted); }

/* ── SIDEBAR ──────────────────────────────────────────────── */
#sidebar {
  width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 1.5rem 1rem; gap: 1rem; flex-shrink: 0;
}
.logo {
  font-size: 1.2rem; font-weight: 700; color: #fff; padding: .5rem 0;
  display: flex; align-items: center; gap: .6rem;
}
.sidebar-logo {
  max-width: 100%; max-height: 40px; width: auto; height: auto;
  background: #fff; border-radius: 4px; padding: .25rem .4rem; object-fit: contain;
}
nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.nav-btn {
  background: transparent; border: none; color: var(--sidebar-text);
  text-align: left; padding: .6rem .8rem; border-radius: var(--radius);
  cursor: pointer; font-size: .95rem; display: flex; align-items: center; gap: .5rem;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-separator { height: 1px; background: rgba(255,255,255,.1); margin: .4rem .8rem; }
.badge {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .72rem; padding: .1rem .45rem; font-weight: 700; margin-left: auto;
}
#user-info { font-size: .85rem; color: var(--sidebar-text); padding: .4rem .8rem; }
#logout-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.2);
  color: var(--sidebar-text); border-radius: var(--radius); padding: .5rem; cursor: pointer; font-size: .9rem;
}
#logout-btn:hover { background: rgba(255,255,255,.1); }

/* ── MAIN ─────────────────────────────────────────────────── */
#content { flex: 1; overflow-y: auto; padding: 2rem; }
.view h2 { margin-bottom: 1.25rem; font-size: 1.3rem; }

/* ── MESSAGE LIST ─────────────────────────────────────────── */
.message-list { display: flex; flex-direction: column; gap: .5rem; }
.message-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem 1.1rem; cursor: pointer; transition: box-shadow .15s;
  display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem;
}
.message-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.message-item.unread { background: var(--unread-bg); border-color: var(--accent); }
.message-item.unread .msg-subject { font-weight: 700; }
.msg-subject { font-size: 1rem; }
.msg-meta { font-size: .82rem; color: var(--muted); }
.msg-date { font-size: .8rem; color: var(--muted); text-align: right; }
.msg-clip { font-size: .8rem; color: var(--muted); }

/* ── COMPOSE ──────────────────────────────────────────────── */
#compose-form { display: flex; flex-direction: column; gap: 1rem; max-width: 680px; }
#compose-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 600; }
.compose-field-label { font-size: .9rem; font-weight: 600; }
#compose-form input[type=text],
#compose-form textarea {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .8rem; font-size: .95rem; font-family: inherit;
}
#compose-form button[type=submit] {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .65rem 1.5rem; font-size: 1rem; font-weight: 600; cursor: pointer; align-self: flex-start;
}
#compose-form button[type=submit]:hover { background: var(--accent-hover); }

/* ── TAG INPUT ────────────────────────────────────────────── */
.tag-input-wrap {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: .4rem .5rem; display: flex; flex-direction: column; gap: .35rem;
  transition: border-color .15s;
}
.tag-input-wrap:focus-within { border-color: var(--accent); }
.tag-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: #e0edff; color: var(--accent); border-radius: 999px;
  padding: .2rem .65rem; font-size: .82rem; font-weight: 600;
}
.tag-chip button {
  background: none; border: none; cursor: pointer; color: var(--accent);
  font-size: .9rem; padding: 0; line-height: 1; display: flex; align-items: center;
}
.tag-chip button:hover { color: var(--danger); }
.tag-input-row { display: flex; align-items: center; gap: .4rem; }
.tag-input-row input {
  flex: 1; border: none; outline: none; font-size: .9rem;
  background: transparent; padding: .2rem .3rem; font-family: inherit;
}
.tag-show-all {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: .78rem; padding: .2rem .55rem; cursor: pointer; white-space: nowrap;
}
.tag-show-all:hover { background: var(--bg); color: var(--text); border-color: var(--accent); }
.tag-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.1); max-height: 220px; overflow-y: auto;
  margin-top: .25rem; padding: .25rem 0; list-style: none;
}
.tag-dropdown li {
  padding: .5rem .9rem; cursor: pointer; font-size: .9rem; display: flex; align-items: center; gap: .5rem;
}
.tag-dropdown li:hover, .tag-dropdown li.focused { background: var(--bg); }
.tag-dropdown li.selected { color: var(--muted); }
.tag-dropdown li .dd-check { color: var(--accent); font-size: .8rem; margin-left: auto; }
.tag-dropdown-empty { padding: .6rem .9rem; font-size: .85rem; color: var(--muted); }

/* ── MESSAGE DETAIL ───────────────────────────────────────── */
#back-btn {
  background: transparent; border: none; color: var(--accent); cursor: pointer;
  font-size: .95rem; margin-bottom: 1rem; padding: 0;
}
#message-detail { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; border: 1px solid var(--border); }
.msg-detail-header { margin-bottom: 1rem; }
.msg-detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.msg-detail-header h3 { font-size: 1.2rem; margin-bottom: .3rem; }
.msg-detail-header p { font-size: .85rem; color: var(--muted); }
.btn-reply {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .5rem 1.1rem; font-size: .9rem; font-weight: 600; cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.btn-reply:hover { background: var(--accent-hover); }
.msg-detail-body { white-space: pre-wrap; font-size: .95rem; line-height: 1.6; margin: 1rem 0; }
.attachments-section { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.attachments-section h4 { font-size: .9rem; margin-bottom: .5rem; }
.att-link {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .35rem .7rem; font-size: .85rem; text-decoration: none; color: var(--text);
  margin: .2rem; transition: background .15s;
}
.att-link:hover { background: var(--border); }

/* ── TOAST ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--sidebar-bg); color: #fff;
  padding: .85rem 1.2rem; border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.3); font-size: .9rem;
  max-width: 320px; z-index: 9999; cursor: pointer;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── ONLINE USERS ─────────────────────────────────────────── */
.online-grid { display: flex; flex-wrap: wrap; gap: .75rem; }
.online-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem 1.1rem; min-width: 200px; display: flex; align-items: center; gap: .75rem;
}
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; flex-shrink: 0; }
.online-card-info { flex: 1; }
.online-card .card-name { font-weight: 600; font-size: .95rem; }
.online-card .card-dept { font-size: .78rem; color: var(--muted); margin-top: .1rem; }
.btn-msg-online {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .3rem .5rem; cursor: pointer; font-size: .9rem; color: var(--muted); flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.btn-msg-online:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── SEGNALAZIONI (TICKET) ────────────────────────────────── */
.ticket-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; border-bottom: 2px solid var(--border); padding-bottom: 0; flex-wrap: wrap; align-items: flex-end; }
.ticket-tabs .ttab-archived-btn { margin-left: auto; margin-bottom: .25rem; }
.ttab-btn {
  background: transparent; border: none; padding: .6rem 1.2rem; cursor: pointer;
  font-size: .95rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.ttab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.ttab-btn:hover:not(.active) { color: var(--text); }
.ttab-content.hidden { display: none; }

#ticket-form { display: flex; flex-direction: column; gap: 1rem; max-width: 680px; }
#ticket-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 600; }
#ticket-form input[type=text],
#ticket-form select,
#ticket-form textarea {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .8rem; font-size: .95rem; font-family: inherit;
}
#ticket-form button[type=submit] {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .65rem 1.5rem; font-size: 1rem; font-weight: 600; cursor: pointer; align-self: flex-start;
}
#ticket-form button[type=submit]:hover { background: var(--accent-hover); }
.ticket-form-row { display: flex; gap: 1rem; }
.ticket-form-row label { flex: 1; }

.ticket-toolbar { display: flex; justify-content: flex-end; margin-bottom: .75rem; }

.ticket-filters { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.ticket-filters select, .ticket-filters input {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .45rem .7rem; font-size: .85rem; font-family: inherit; background: var(--surface);
}
.tf-search { flex: 1; min-width: 200px; }
.ticket-filters .btn-secondary { margin-left: auto; }

/* ── KANBAN ──────────────────────────────────────────────── */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
  align-items: start;
  overflow-x: auto;
}
.kanban-col {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 120px;
}
.kanban-col-header {
  font-size: .8rem;
  font-weight: 700;
  padding: .55rem .85rem;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  align-items: center;
  gap: .4rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.kanban-count {
  font-size: .72rem;
  background: rgba(0,0,0,.12);
  border-radius: 999px;
  padding: .05rem .45rem;
  font-weight: 700;
}
.kanban-cards {
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  flex: 1;
}
.kc-loading, .kc-empty {
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
  padding: .75rem 0;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem .8rem;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.tk-urgency-border-alta  { border-left-color: var(--danger); }
.tk-urgency-border-media { border-left-color: #f59e0b; }
.tk-urgency-border-bassa { border-left-color: var(--border); }
.kc-id-title {
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: .25rem;
  word-break: break-word;
}
.kc-id { color: var(--muted); font-weight: 400; margin-right: .2rem; }
.kc-reporter { font-size: .78rem; color: var(--muted); margin-bottom: .3rem; }
.kc-behalf { font-size: .75rem; color: var(--muted); font-style: italic; display: block; margin-bottom: .25rem; }
.kc-badges { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; margin-top: .2rem; }
.kc-comments { font-size: .75rem; color: var(--muted); }
.kc-worked { font-size: .75rem; color: var(--muted); font-weight: 600; }
.kc-archived-badge { font-size: .72rem; color: var(--muted); font-style: italic; }

.btn-archive {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: .75rem; padding: .1rem .35rem; margin-left: auto;
  color: var(--muted); transition: background .15s;
}
.btn-archive:hover { background: #fef3c7; border-color: #f59e0b; }

/* ── SEZIONE ARCHIVIATI ──────────────────────────────── */
.archive-section { margin-top: 1.25rem; }
.btn-archive-toggle {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .45rem .9rem; font-size: .85rem; cursor: pointer; color: var(--muted);
  font-weight: 600; transition: background .15s;
}
.btn-archive-toggle:hover { background: var(--bg); }
.archived-panel { margin-top: .6rem; }
.archived-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .45rem;
}
.archived-panel .kanban-card { opacity: .75; }
.archived-panel .kanban-card:hover { opacity: 1; }

.ticket-item-title { font-size: 1rem; font-weight: 600; }
.ticket-item-id { color: var(--muted); font-weight: 400; margin-right: .35rem; }
.ticket-item-badges { display: flex; gap: .35rem; margin-top: .25rem; }

.tk-badge { display: inline-block; border-radius: 999px; padding: .12rem .6rem; font-size: .72rem; font-weight: 700; }
.tk-status-aperto { background: #dbeafe; color: #1d4ed8; }
.tk-status-in_corso { background: #fef3c7; color: #b45309; }
.tk-status-sospeso { background: #ede9fe; color: #6d28d9; }
.tk-status-chiuso { background: #dcfce7; color: #15803d; }
.tk-urgency-alta { background: #fee2e2; color: var(--danger); }
.tk-urgency-media { background: #fef3c7; color: #b45309; }
.tk-urgency-bassa { background: #e2e8f0; color: var(--muted); }
.tk-category { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.tk-worked { background: var(--bg); color: var(--text); border: 1px solid var(--border); font-weight: 600; }

/* Dettaglio segnalazione */
#ticket-detail { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; border: 1px solid var(--border); }
.ticket-detail-header { margin-bottom: 1rem; }
.ticket-detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.ticket-detail-title-row h3 { font-size: 1.2rem; margin-bottom: .3rem; }
.ticket-detail-meta { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.ticket-detail-badges { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.ticket-status-control { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; }
.ticket-status-control select {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem .7rem; font-size: .85rem; font-family: inherit; background: var(--surface);
}
.ticket-worked-time {
  font-size: .85rem; font-weight: 600; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .35rem .7rem;
}
.ticket-detail-body { white-space: pre-wrap; font-size: .95rem; line-height: 1.6; margin: 1rem 0; }

.ticket-comments { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; display: flex; flex-direction: column; gap: .85rem; }
.ticket-comments h4 { font-size: .9rem; }
.ticket-comment {
  background: var(--bg); border-radius: var(--radius); padding: .75rem 1rem; font-size: .9rem;
}
.ticket-comment.from-admin { background: var(--unread-bg); }
.ticket-comment-meta { font-size: .78rem; color: var(--muted); margin-bottom: .3rem; }
.ticket-comment-body { white-space: pre-wrap; line-height: 1.5; }

.ticket-reply-form { margin-top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.ticket-reply-form textarea {
  border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; font-size: .9rem; font-family: inherit; resize: vertical;
}
.ticket-reply-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.ticket-reply-actions button {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .5rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.ticket-reply-actions button:hover { background: var(--accent-hover); }
.ticket-reply-actions input[type=file] { font-size: .82rem; }
.btn-reopen {
  background: transparent; color: var(--accent); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: .4rem .9rem; font-size: .85rem; font-weight: 600; cursor: pointer; margin-top: .75rem;
}
.btn-reopen:hover { background: var(--accent); color: #fff; }

/* ── ADMIN PANEL ──────────────────────────────────────────── */
.admin-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.tab-btn {
  background: transparent; border: none; padding: .6rem 1.2rem; cursor: pointer;
  font-size: .95rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-btn:hover:not(.active) { color: var(--text); }

.admin-toolbar { margin-bottom: 1rem; }
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: .55rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger {
  background: transparent; color: var(--danger); border: 1px solid var(--danger);
  border-radius: var(--radius); padding: .3rem .7rem; font-size: .82rem; cursor: pointer;
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-secondary {
  background: transparent; color: var(--accent); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: .3rem .7rem; font-size: .82rem; cursor: pointer;
}
.btn-secondary:hover { background: var(--accent); color: #fff; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.admin-table th { background: var(--bg); text-align: left; padding: .75rem 1rem; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); }
.admin-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg); }

.tag { display: inline-block; background: #e0edff; color: var(--accent); border-radius: 999px; padding: .1rem .55rem; font-size: .75rem; margin: .1rem; }
.tag-inactive { background: #fee2e2; color: var(--danger); }
.tag-admin { background: #fef3c7; color: #b45309; }

/* ── GIACENZA IT ──────────────────────────────────────────── */
.inv-tab-btn {
  background: transparent; border: none; padding: .6rem 1.2rem; cursor: pointer;
  font-size: .95rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.inv-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.inv-tab-btn:hover:not(.active) { color: var(--text); }
.inv-tab-content.hidden { display: none; }
.inv-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.inv-lowstock-toggle { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.inv-qty-low { color: var(--danger); font-weight: 700; }
.inv-status-in_giacenza { background: #dcfce7; color: #15803d; }
.inv-status-assegnato { background: #dbeafe; color: #1d4ed8; }
.inv-status-guasto { background: #fef3c7; color: #b45309; }
.inv-status-dismesso { background: #f1f5f9; color: var(--muted); }

.inv-cat-columns { display: flex; gap: 2.5rem; flex-wrap: wrap; }
.inv-cat-col { flex: 1; min-width: 260px; }
.inv-cat-col h3 { font-size: 1rem; margin-bottom: .75rem; }
.inv-cat-form { display: flex; gap: .5rem; margin-bottom: 1rem; }
.inv-cat-form input {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .75rem; font-size: .9rem; font-family: inherit;
}
.inv-cat-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .6rem 0; border-bottom: 1px solid var(--border);
}
.inv-cat-row:last-child { border-bottom: none; }

/* ── RUBRICA AZIENDALE ────────────────────────────────────── */
#dir-search {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .55rem .8rem; font-size: .9rem; font-family: inherit; min-width: 260px;
}
.dir-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.imp-error-list { margin: .4rem 0 0 1.2rem; color: var(--danger); font-size: .85rem; }
.imp-error-list li { margin-bottom: .2rem; }
.dir-zone-header td {
  background: var(--bg); color: var(--muted); font-weight: 700; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .04em; padding: .5rem 1rem;
  border-bottom: 1px solid var(--border);
}

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface); border-radius: var(--radius); width: 480px; max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h3 { font-size: 1.05rem; }
#modal-close { background: transparent; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
#modal-close:hover { color: var(--text); }
#modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: .9rem; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-field { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 600; }
.modal-field input, .modal-field select, .modal-field textarea {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .75rem; font-size: .95rem; font-family: inherit;
}
.modal-field select[multiple] { height: 100px; }
.modal-row { display: flex; gap: .75rem; align-items: center; font-size: .9rem; font-weight: 400; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: .25rem; }
.modal-actions button { padding: .55rem 1.2rem; border-radius: var(--radius); font-size: .95rem; font-weight: 600; cursor: pointer; border: none; }
.modal-actions .btn-save { background: var(--accent); color: #fff; }
.modal-actions .btn-save:hover { background: var(--accent-hover); }
.modal-actions .btn-cancel { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.modal-actions .btn-cancel:hover { background: var(--border); }

/* ── MENU MOBILE (hamburger + drawer) ────────────────────────
   Nascosti di default: diventano attivi solo sotto i 640px (vedi
   media query in fondo al file). Su desktop/tablet la sidebar
   resta quella "classica" affiancata al contenuto. */
.mobile-menu-btn {
  display: none;
  position: fixed; top: .75rem; left: .75rem; z-index: 1001;
  width: 42px; height: 42px; align-items: center; justify-content: center;
  background: var(--sidebar-bg); color: #fff; border: none; border-radius: var(--radius);
  font-size: 1.3rem; line-height: 1; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.mobile-menu-btn.hidden { display: none !important; }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 999;
}
/* Pulsante di chiusura dentro l'header della sidebar: visibile solo su
   mobile (drawer aperto), posizionato di fianco al logo e non sopra. */
.sidebar-close-btn {
  display: none;
  margin-left: auto; flex-shrink: 0;
  width: 32px; height: 32px; align-items: center; justify-content: center;
  background: rgba(255,255,255,.08); color: #fff; border: none; border-radius: var(--radius);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,.18); }

/* ── RESPONSIVE (smartphone) ──────────────────────────────────
   Breakpoint scelto per coprire i telefoni in verticale (~360-430px
   di larghezza tipica) senza intercettare i tablet: da 641px in su
   il layout desktop resta identico a oggi, invariato. */
@media (max-width: 640px) {
  .mobile-menu-btn { display: flex; }
  .sidebar-overlay:not(.hidden) { display: block; }
  .sidebar-close-btn { display: flex; }

  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000;
    width: 260px; max-width: 80vw;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.3);
  }
  #sidebar.open { transform: translateX(0); }

  #content { padding: 1rem; padding-top: 4rem; }
  .view h2 { font-size: 1.15rem; }

  /* Tabelle: restano identiche, ma scorrono lateralmente dentro il loro riquadro
     invece di far scrollare l'intera pagina o di schiacciarsi illeggibili. */
  .table-scroll-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-table { min-width: 640px; }

  /* Kanban segnalazioni: da 4 colonne schiacciate a colonne a piena
     larghezza (quasi) che scorrono in orizzontale una alla volta. */
  .kanban-board { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 84vw; }

  /* Form e filtri: impilati a piena larghezza invece che affiancati */
  .ticket-form-row { flex-direction: column; gap: .85rem; }
  .ticket-filters { flex-direction: column; align-items: stretch; }
  .ticket-filters .tf-search { min-width: 0; }
  .ticket-filters .btn-secondary { margin-left: 0; align-self: flex-end; }
  .inv-toolbar { flex-direction: column; align-items: stretch; }
  .inv-toolbar select, .inv-toolbar input { width: 100%; }
  .online-grid { flex-direction: column; }
  .online-card { min-width: 0; }

  #message-detail, #ticket-detail { padding: 1rem; }
  .msg-detail-title-row, .ticket-detail-title-row { flex-direction: column; align-items: stretch; }

  .modal { max-height: 85vh; }
}
