/* Stili di base comuni alle app (reception, officina, prenota, platform). */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
img { max-width: 100%; display: block; }
a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0 0 var(--sp-3); line-height: 1.2; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Layout */
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-3); }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--mono); }
.plate {
  font-family: var(--mono); font-weight: 700; letter-spacing: 0.04em;
  border: 1.5px solid var(--text); border-radius: 4px; padding: 0 6px; background: var(--surface);
  white-space: nowrap;
}
.plate.provisional { border-style: dashed; color: var(--text-muted); border-color: var(--text-muted); }

/* App shell: barra laterale + contenuto */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: var(--sp-3); gap: var(--sp-1);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2); margin-bottom: var(--sp-3); font-weight: 700; }
.sidebar .brand img { max-height: 32px; width: auto; }
.nav-link {
  display: flex; align-items: center; gap: var(--sp-2); padding: 9px var(--sp-3);
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); }
.nav-link .count { margin-left: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5); background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.content { padding: var(--sp-5); min-width: 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.page-header h1 { margin: 0; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; }
  .sidebar .brand { display: none; }
  .content { padding: var(--sp-3); }
}

.banner { padding: var(--sp-2) var(--sp-4); font-weight: 600; text-align: center; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-danger { background: var(--danger-soft); color: var(--danger); }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4); box-shadow: var(--shadow-sm); }
.card-tight { padding: var(--sp-3); }
.card h2, .card h3 { margin-bottom: var(--sp-2); }

/* Pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 36px; padding: 0 var(--sp-4); border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, black); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 28px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-lg { min-height: 56px; padding: 0 var(--sp-5); font-size: var(--fs-lg); border-radius: var(--radius); }
.btn-block { width: 100%; }

/* Form */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
}
textarea.input { min-height: 80px; resize: vertical; }
.input.invalid { border-color: var(--danger); }
.field .hint { font-size: var(--fs-xs); color: var(--text-faint); }
.field .error { font-size: var(--fs-xs); color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input { width: 18px; height: 18px; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* Tabelle */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-weight: 600; color: var(--text-muted); background: var(--surface-2); padding: 8px 12px; white-space: nowrap; }
.table td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }

/* Overlay: modale e pannello laterale */
.overlay { position: fixed; inset: 0; background: rgb(15 20 27 / 0.45); z-index: 100; display: flex; }
.modal {
  margin: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal-head, .drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-head h2, .drawer-head h2 { margin: 0; }
.modal-body, .drawer-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot, .drawer-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); }
.drawer {
  margin-left: auto; height: 100%; width: min(520px, 100vw); background: var(--surface);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide-in 0.16s ease-out;
}
.drawer-body { flex: 1; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Toast */
.toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; }
.toast {
  min-width: 260px; max-width: 420px; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-weight: 500;
}
.toast-ok { background: var(--ok); color: #fff; }
.toast-danger { background: var(--danger); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }

/* Varie */
.empty { text-align: center; color: var(--text-muted); padding: var(--sp-6) var(--sp-4); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand);
  animation: spin 0.8s linear infinite; display: inline-block;
}
.loading { display: flex; justify-content: center; padding: var(--sp-6); }
@keyframes spin { to { transform: rotate(360deg); } }
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); overflow-x: auto; }
.tab { padding: var(--sp-2) var(--sp-3); border: 0; background: none; font: inherit; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }
.note-alert { background: var(--warn-soft); color: var(--warn); border-left: 4px solid var(--warn); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); font-weight: 600; }

/* Pagine di accesso */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4); }
.auth-card { width: min(400px, 100%); }
.auth-card .logo { max-height: 56px; margin: 0 auto var(--sp-4); }
