@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ─── RESET & BASE ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --sidebar-w: 260px;
  --header-h: 60px;
  --primary:   #3b82f6;
  --primary-d: #2563eb;
  --primary-l: #eff6ff;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
  /* Light */
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #0f172a;
  --text-2:    #64748b;
  --text-3:    #94a3b8;
  --sidebar-bg:    #0f172a;
  --sidebar-text:  #94a3b8;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active:#3b82f6;
}
[data-theme="dark"] {
  --bg:      #0f172a;
  --surface: #1e293b;
  --border:  #334155;
  --text:    #f1f5f9;
  --text-2:  #94a3b8;
  --text-3:  #475569;
}

html, body { height: 100%; font-family: 'Inter', sans-serif; font-size: 14px; }

/* ─── LAYOUT ────────────────────────────────────────────────────────────────── */
.app-body { display: flex; height: 100vh; overflow: hidden; background: var(--bg); color: var(--text); transition: background .3s, color .3s; }

/* ─── SIDEBAR ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 50;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo { flex-shrink: 0; }
.logo-placeholder {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.logo-placeholder svg { width: 22px; height: 22px; color: #fff; }
.logo-img-sidebar { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }

.sidebar-brand { flex: 1; min-width: 0; }
.brand-name {
  display: block;
  font-size: 13px; font-weight: 700;
  color: #f8fafc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: 11px; color: #475569; font-weight: 400; }

.sidebar-close {
  display: none;
  padding: 6px; border-radius: 8px; color: #64748b;
  background: transparent; border: none; cursor: pointer;
}
.sidebar-close svg { width: 18px; height: 18px; }
.sidebar-close:hover { color: #f1f5f9; background: rgba(255,255,255,0.08); }

/* Nav items */
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: #334155;
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 13.5px; font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
  text-decoration: none;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-item.active {
  background: rgba(59,130,246,0.15);
  color: #60a5fa;
}
.nav-item.active svg { color: var(--primary); }

.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px;
  padding: 0 6px; border-radius: 10px;
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 8px;
}
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.user-details { min-width: 0; }
.user-name  { display: block; font-size: 12.5px; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { display: block; font-size: 11px; color: #475569; text-transform: capitalize; }

.logout-btn {
  flex-shrink: 0;
  height: 34px;
  padding: 0 10px;
  gap: 6px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  transition: all .15s;
}
.logout-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.logout-btn:hover { background: rgba(239,68,68,0.15); color: #f87171; }

/* ─── SIDEBAR OVERLAY (mobile) ──────────────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
}

/* ─── MAIN WRAPPER ───────────────────────────────────────────────────────────── */
.main-wrapper {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  height: 100vh;
  transition: margin-left .3s;
}

/* ─── HEADER ─────────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 30;
}
.header-left  { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.menu-toggle {
  display: none;
  padding: 8px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-2);
}
.menu-toggle svg { width: 20px; height: 20px; }
.menu-toggle:hover { background: var(--bg); }

.page-title { font-size: 17px; font-weight: 700; color: var(--text); }

.theme-toggle {
  padding: 8px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-2); transition: all .15s;
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle:hover { background: var(--bg); color: var(--text); }

.header-user { display: flex; align-items: center; gap: 8px; }
.header-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
#headerUserName { font-size: 13px; font-weight: 500; color: var(--text-2); }

.header-logout-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.header-logout-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.header-logout-btn:hover {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.35);
  color: #dc2626;
}

/* ─── PAGE CONTENT ───────────────────────────────────────────────────────────── */
.page-content { flex: 1; overflow-y: auto; padding: 24px; }
.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── LOADING SPINNER ───────────────────────────────────────────────────────── */
.loading-spinner { display: flex; justify-content: center; align-items: center; height: 200px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── CARDS ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 700; color: var(--text); }
.card-body  { padding: 20px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ─── TABLE ──────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 11px 16px; text-align: left;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--bg); }
.td-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all .15s; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); box-shadow: 0 4px 12px rgba(59,130,246,.35); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger  { background: #fee2e2; color: #dc2626; }
.btn-danger:hover  { background: #fca5a5; }
.btn-success { background: #dcfce7; color: #16a34a; }
.btn-success:hover { background: #bbf7d0; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon svg { width: 16px; height: 16px; }

/* ─── FORM ────────────────────────────────────────────────────────────────────── */
.form-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1/-1; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.form-label .req { color: #dc2626; font-weight: 700; margin-left: 2px; }
.form-control {
  padding: 9px 12px; border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-control::placeholder { color: var(--text-3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ─── BADGE ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
}
.badge-blue    { background: #dbeafe; color: #1d4ed8; }
.badge-green   { background: #dcfce7; color: #16a34a; }
.badge-yellow  { background: #fef9c3; color: #a16207; }
.badge-red     { background: #fee2e2; color: #dc2626; }
.badge-gray    { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.badge-orange  { background: #ffedd5; color: #c2410c; }
[data-theme="dark"] .badge-blue   { background: rgba(59,130,246,.2);  color: #93c5fd; }
[data-theme="dark"] .badge-green  { background: rgba(34,197,94,.2);   color: #86efac; }
[data-theme="dark"] .badge-yellow { background: rgba(234,179,8,.2);   color: #fde047; }
[data-theme="dark"] .badge-red    { background: rgba(239,68,68,.2);   color: #fca5a5; }
[data-theme="dark"] .badge-orange { background: rgba(249,115,22,.2);  color: #fdba74; }

/* ─── SEARCH + FILTERS ───────────────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-3); pointer-events: none;
}
.search-input {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-family: inherit;
  transition: border-color .15s;
}
.search-input:focus { outline: none; border-color: var(--primary); }

/* ─── MODAL ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 680px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: modalIn .2s ease;
}
.modal-box.modal-lg { max-width: 900px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-3); display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.modal-close svg { width: 18px; height: 18px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body    { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer  {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ─── TOAST ──────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 280px; max-width: 380px;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s ease;
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast-msg  { font-size: 13.5px; color: var(--text); }
.toast.success { border-left-color: #22c55e; }
.toast.success svg { color: #22c55e; }
.toast.error   { border-left-color: #ef4444; }
.toast.error   svg { color: #ef4444; }
.toast.warning { border-left-color: #f59e0b; }
.toast.warning svg { color: #f59e0b; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  to   { opacity: 0; transform: translateX(20px); }
}
.toast.out { animation: toastOut .3s ease forwards; }

/* ─── EMPTY STATE ─────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; text-align: center;
}
.empty-state svg { width: 56px; height: 56px; color: var(--text-3); margin-bottom: 14px; }
.empty-state h3  { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.empty-state p   { font-size: 13px; color: var(--text-3); }

/* ─── CONTATTI EXTRA (cliente) ────────────────────────────────────────────────── */
.contatti-list { display: flex; flex-direction: column; gap: 8px; }
.contatto-row  { display: grid; grid-template-columns: 1fr 1fr 1fr 32px; gap: 8px; align-items: center; }

/* ─── SEZIONE "COMING SOON" ───────────────────────────────────────────────────── */
.coming-soon {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 300px; text-align: center;
  color: var(--text-2);
}
.coming-soon svg { width: 64px; height: 64px; color: var(--text-3); margin-bottom: 16px; }
.coming-soon h2  { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.coming-soon p   { font-size: 14px; max-width: 400px; }
.coming-soon .badge-coming { background: var(--primary); color: #fff; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 16px; display: inline-block; }

/* Firma digitale */
.sig-wrap { border: 2px dashed var(--border); border-radius: 10px; background: #fff; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; max-width: 400px; height: 120px; cursor: crosshair; }
.contatori-box { padding: 14px; background: var(--bg); border-radius: 8px; margin-bottom: 12px; }
.contatori-box h4 { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--text-2); }
.riga-ricambio { display: grid; grid-template-columns: 1fr 2fr 80px 36px; gap: 8px; align-items: end; margin-bottom: 8px; }
.riga-ricambio-suggest { position: relative; }
.suggest-list { position: absolute; z-index: 50; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; max-height: 180px; overflow-y: auto; box-shadow: var(--shadow-lg); }
.suggest-item { padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.suggest-item:hover { background: var(--bg); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 20px; }
.cal-day { min-height: 100px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--surface); }
.cal-day-head { font-size: 11px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.cal-event { font-size: 11px; padding: 4px 6px; border-radius: 4px; margin-bottom: 4px; color: #fff; cursor: pointer; }

/* ─── LOGO UPLOAD (config) ────────────────────────────────────────────────────── */
.logo-upload-area {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.logo-upload-area:hover { border-color: var(--primary); background: var(--primary-l); }
.logo-preview { max-height: 80px; max-width: 240px; object-fit: contain; margin: 0 auto 12px; display: block; }

/* ─── TABS ────────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s;
}
.tab-btn:hover   { color: var(--text); }
.tab-btn.active  { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel.hidden { display: none; }

/* ─── CALENDARIO ───────────────────────────────────────────────────────────── */
.cal-card .card-header.cal-toolbar {
  flex-wrap: wrap;
  gap: 12px;
}
.cal-toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.cal-view-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.cal-view-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.cal-view-btn:hover { color: var(--text); background: var(--surface); }
.cal-view-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  font-weight: 600;
}
.cal-nav { display: flex; gap: 6px; flex-shrink: 0; }
.cal-period-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}
.cal-body { padding-top: 12px !important; }
.cal-filter { margin-bottom: 12px !important; }
.cal-main-view { overflow-x: auto; }
.cal-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-3);
}

/* Vista mensile */
.cal-month-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
}
.cal-month-head-cell {
  padding: 8px 4px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-2);
}
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-left: 1px solid var(--border);
}
.cal-month-cell {
  min-height: 100px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  transition: background .12s;
}
.cal-month-cell:hover { background: var(--bg); }
.cal-month-cell.other-month { background: var(--bg); opacity: .65; }
.cal-month-cell.today {
  background: var(--primary-l);
  box-shadow: inset 0 0 0 2px var(--primary);
}
[data-theme="dark"] .cal-month-cell.today { background: rgba(59,130,246,.15); }
.cal-month-day {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  width: 26px;
  height: 26px;
  line-height: 26px;
  text-align: center;
  border-radius: 50%;
}
.cal-month-cell.today .cal-month-day {
  background: var(--primary);
  color: #fff;
}
.cal-month-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
.cal-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  background: color-mix(in srgb, var(--ev-color, #3b82f6) 18%, transparent);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
}
.cal-chip:hover { filter: brightness(.95); }
.cal-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ev-color, #3b82f6);
  flex-shrink: 0;
}
.cal-chip-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-month-more {
  font-size: 10px;
  color: var(--text-2);
  padding: 2px 4px;
}
.cal-month-add {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.cal-month-cell:hover .cal-month-add { opacity: 1; }
.cal-month-add:hover {
  background: var(--primary);
  color: #fff;
}

/* Vista settimanale */
.cal-week-wrap {
  display: grid;
  grid-template-columns: 52px repeat(7, minmax(90px, 1fr));
  grid-template-rows: auto 1fr;
  min-width: 720px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.cal-week-corner {
  grid-column: 1;
  grid-row: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.cal-week-head {
  padding: 10px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.cal-week-head.today {
  background: var(--primary-l);
  color: var(--primary-d);
}
.cal-week-dow {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-2);
}
.cal-week-date {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.cal-week-wrap > .cal-week-hours {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.cal-week-wrap > .cal-week-col { grid-row: 2; }
.cal-week-hour {
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  padding: 0 6px 0 0;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
  line-height: 1;
  transform: translateY(-6px);
}
.cal-week-col {
  grid-row: 2;
  border-right: 1px solid var(--border);
  position: relative;
}
.cal-week-col.today { background: rgba(59,130,246,.04); }
.cal-week-col-body {
  position: relative;
  overflow: hidden;
}
.cal-week-slots { position: absolute; inset: 0; }
.cal-week-slot {
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
  cursor: pointer;
}
.cal-week-slot:hover { background: rgba(59,130,246,.06); }
.cal-week-events-layer {
  position: absolute;
  inset: 0 2px;
  pointer-events: none;
}
.cal-week-event {
  position: absolute;
  left: 0;
  right: 0;
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  pointer-events: auto;
  cursor: pointer;
  background: color-mix(in srgb, var(--ev-color, #3b82f6) 22%, var(--surface));
  border-left: 3px solid var(--ev-color, #3b82f6);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.cal-week-event:hover { filter: brightness(.97); z-index: 2; }
.cal-week-event strong {
  display: block;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-week-event span,
.cal-week-event em {
  display: block;
  font-size: 10px;
  color: var(--text-2);
  font-style: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 900px) {
  .cal-week-wrap { min-width: 600px; }
  .cal-month-cell { min-height: 72px; }
  .page-content [style*="minmax(280px"] {
    display: flex !important;
    flex-direction: column;
  }
}

/* Colori tecnici */
.tec-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.tec-color-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.tec-color-swatch {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,.08);
}
.tec-color-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tec-color-pick input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.tec-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.tec-palette-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  padding: 0;
}

/* Firme rapportino */
.sig-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
.sig-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg);
}
.sig-panel h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.sig-panel canvas {
  width: 100%;
  max-width: 100%;
  height: 140px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}
.sig-preview {
  width: 100%;
  height: 140px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.sig-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.sig-preview-empty {
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  padding: 8px;
}
@media (max-width: 640px) {
  .sig-dual { grid-template-columns: 1fr; }
}

/* ─── MOBILE RESPONSIVE ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-close { display: flex; }
  .sidebar-overlay.open { display: block; }
  .main-wrapper { margin-left: 0 !important; }
  .menu-toggle  { display: flex; }
  .page-content { padding: 16px; }
  .stat-grid    { grid-template-columns: 1fr 1fr; }
  .form-grid    { grid-template-columns: 1fr; }
  .contatto-row { grid-template-columns: 1fr 32px; }
  .toolbar      { flex-direction: column; align-items: stretch; }
  table thead   { display: none; }
  tbody tr {
    display: block; margin-bottom: 8px;
    border: 1px solid var(--border); border-radius: var(--radius);
  }
  tbody td { display: flex; justify-content: space-between; align-items: center; border: none; padding: 10px 14px; }
  tbody td::before { content: attr(data-label); font-weight: 600; color: var(--text-2); font-size: 11px; text-transform: uppercase; margin-right: 8px; }
}
