/* AutoRevisioni internal UI — plain CSS, no framework/build step on purpose
   (matches the "boring and small" backend philosophy: this file is served
   as-is by express.static, nothing compiles it). */

/* ING-28 Phase 2 — self-hosted Inter (SIL Open Font License). The .woff2 live
   in public/fonts/ and are served by express.static under font-src 'self':
   no Google Fonts, no CDN, nothing external at runtime. font-display: swap
   shows the system fallback immediately and swaps Inter in when it loads, so
   there's never a flash of invisible text. --font-sans (see :root) lists Inter
   first and degrades to the previous system stack if a file ever fails. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/inter-latin-700-normal.woff2") format("woff2");
}

:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-border: #dde1e6;
  --color-text: #1c2530;
  --color-text-muted: #5b6675;
  --color-primary: #1f5fbf;
  --color-primary-dark: #164a96;
  --color-danger: #b3261e;
  --color-danger-bg: #fdecea;
  --color-warning: #8a5a00;
  --color-warning-bg: #fff4e0;
  --color-success: #1e7a34;
  --color-success-bg: #e8f6ea;
  --radius: 6px;

  /* ---- ING-28 Phase 2: additive design tokens (extend, don't replace) ----
     The colour tokens above are unchanged. Everything below is new: a coherent
     type/spacing scale, softer radii + elevation, a couple of neutral surfaces,
     and an explicit minimum touch target. Existing rules keep working because
     they reference only the tokens they already used. */
  --color-bg-subtle: #eef1f5;
  --color-surface-2: #f8fafc;
  --color-primary-bg: #eaf1fc;
  --color-focus-ring: rgba(31, 95, 191, 0.35);

  /* Self-hosted font (see @font-face below); degrades to the system stack the
     app used before, so nothing breaks if the .woff2 fails to load. */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* type scale (1.20 minor-third), rem-based */
  --fs-xs: 0.78rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.35rem;
  --fs-xl: 1.7rem;
  --fs-2xl: 2.1rem;
  --lh-tight: 1.2;
  --lh-base: 1.5;

  /* spacing scale (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  /* radii + elevation */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 26, 40, 0.06), 0 1px 3px rgba(16, 26, 40, 0.08);
  --shadow-md: 0 4px 12px rgba(16, 26, 40, 0.10);

  --tap-target: 44px; /* minimum touch target, per ING-28 */

  /* ---- Dark palette bundle (values only; mapped onto the live --color-*
     tokens by the two blocks below). Declared once so "explicit Scuro" and
     "Auto + OS is dark" share exactly the same values with no duplication. */
  --dark-bg: #0f141b;
  --dark-surface: #171e27;
  --dark-surface-2: #1d2734;
  --dark-bg-subtle: #212c39;
  --dark-border: #2c3a49;
  --dark-text: #e7ecf3;
  --dark-text-muted: #9aa8b8;
  --dark-primary: #5b9bff;
  --dark-primary-dark: #3f82ee;
  --dark-primary-bg: #16273c;
  --dark-focus-ring: rgba(91, 155, 255, 0.5);
  --dark-danger: #ff6b61;
  --dark-danger-bg: #3a1c1a;
  --dark-warning: #e0a53a;
  --dark-warning-bg: #382a12;
  --dark-success: #4fce6c;
  --dark-success-bg: #14301c;
  --dark-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  --dark-shadow-md: 0 6px 18px rgba(0, 0, 0, 0.55);
}

/* ---- Theme = a user preference (ING-28) --------------------------------
   The end user decides, we don't impose:
     • no [data-theme] / [data-theme="auto"] → "Auto": follow the OS via
       prefers-color-scheme (no JS involved, so no flash on first paint);
     • [data-theme="dark"] / ="light" → explicit override, set by
       /js/theme.js from the user's remembered choice (localStorage).
   Only the colour + shadow tokens are remapped; every component reads those
   same variables, so the whole app themes consistently from these blocks. */
:root[data-theme="dark"] {
  --color-bg: var(--dark-bg);
  --color-surface: var(--dark-surface);
  --color-surface-2: var(--dark-surface-2);
  --color-bg-subtle: var(--dark-bg-subtle);
  --color-border: var(--dark-border);
  --color-text: var(--dark-text);
  --color-text-muted: var(--dark-text-muted);
  --color-primary: var(--dark-primary);
  --color-primary-dark: var(--dark-primary-dark);
  --color-primary-bg: var(--dark-primary-bg);
  --color-focus-ring: var(--dark-focus-ring);
  --color-danger: var(--dark-danger);
  --color-danger-bg: var(--dark-danger-bg);
  --color-warning: var(--dark-warning);
  --color-warning-bg: var(--dark-warning-bg);
  --color-success: var(--dark-success);
  --color-success-bg: var(--dark-success-bg);
  --shadow-sm: var(--dark-shadow-sm);
  --shadow-md: var(--dark-shadow-md);
}

@media (prefers-color-scheme: dark) {
  /* "Auto": absent or ="auto". An explicit light/dark override opts out. */
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --color-bg: var(--dark-bg);
    --color-surface: var(--dark-surface);
    --color-surface-2: var(--dark-surface-2);
    --color-bg-subtle: var(--dark-bg-subtle);
    --color-border: var(--dark-border);
    --color-text: var(--dark-text);
    --color-text-muted: var(--dark-text-muted);
    --color-primary: var(--dark-primary);
    --color-primary-dark: var(--dark-primary-dark);
    --color-primary-bg: var(--dark-primary-bg);
    --color-focus-ring: var(--dark-focus-ring);
    --color-danger: var(--dark-danger);
    --color-danger-bg: var(--dark-danger-bg);
    --color-warning: var(--dark-warning);
    --color-warning-bg: var(--dark-warning-bg);
    --color-success: var(--dark-success);
    --color-success-bg: var(--dark-success-bg);
    --shadow-sm: var(--dark-shadow-sm);
    --shadow-md: var(--dark-shadow-md);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* Accessible, always-visible focus ring on keyboard focus (ING-28). Applied
   with :focus-visible so it never shows on mouse clicks — it replaces the old
   input outline only where the browser reports keyboard intent. */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
  border-radius: var(--radius);
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem 2rem;
  flex-wrap: wrap; /* ING-28: header wraps instead of overflowing on mobile */
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
}

.topbar nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.topbar nav a {
  color: var(--color-text-muted);
  font-weight: 500;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.topbar nav a.active,
.topbar nav a:hover {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-left: auto;
}

.admin-console-link {
  color: var(--color-text-muted);
  font-weight: 500;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.admin-console-link.active,
.admin-console-link:hover {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  text-decoration: none;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-user-email {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.nav-logout-form {
  margin: 0;
}

.nav-logout-form .btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.login-page {
  display: flex;
  justify-content: center;
  padding-top: 3rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem;
}

.footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 1.5rem;
}

/* Admin Console (board request 2026-07-24): shared lateral sidebar layout
   for the three admin-only screens (/app/users, /app/permessi,
   /app/impostazioni-collaudo), presented as one named interface. */
.admin-console {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
}

/* The default 1000px container leaves the admin content area only
   ~720px once the 200px sidebar + gap are subtracted, while the Utenti
   table alone is ~980px wide — so the Azioni column always sat half
   clipped behind the table-wrap scroll edge. Widen the container on
   admin-console pages so the full table fits on ≥1366px viewports;
   .table-wrap's horizontal scroll remains the fallback below that. */
.container:has(> .admin-console) {
  max-width: 1360px;
}

.admin-sidebar {
  width: 200px;
  flex-shrink: 0;
}

.admin-sidebar-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-text);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.admin-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.admin-sidebar-nav a {
  color: var(--color-text-muted);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
}

.admin-sidebar-nav a.active,
.admin-sidebar-nav a:hover {
  background: var(--color-bg);
  color: var(--color-primary);
  text-decoration: none;
}

.admin-content {
  flex: 1;
  min-width: 0;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}

.subtitle {
  color: var(--color-text-muted);
  margin: 0 0 1.5rem;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card-link {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--color-text);
}

.card-link:hover {
  border-color: var(--color-primary);
  text-decoration: none;
}

.card-link h2 {
  color: var(--color-primary);
}

[role="button"].card-link {
  cursor: pointer;
}

.card-featured {
  grid-column: 1 / -1;
  background: var(--color-primary);
  border-color: var(--color-primary-dark);
  box-shadow: 0 2px 8px rgba(31, 95, 191, 0.35);
}

.card-featured h2,
.card-featured p {
  color: #ffffff;
}

.card-featured:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 37, 48, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

body.modal-open {
  overflow: hidden;
}

.modal-dialog {
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  padding: 1.25rem 1.5rem 1.5rem;
  box-sizing: border-box;
}

/* ING-53 (3.a): keep long modal bodies scrollable inside the popup instead of
   letting the message block push past the dialog's edges. */
.modal-body {
  max-height: 70vh;
  overflow-y: auto;
}

/* ING-53 (3.a): the "Invia SMS" riepilogo renders the saved template inside a
   <pre>. Its browser default (white-space: pre) never wraps, so long lines or
   unbroken strings (URLs, targhe) spilled outside the popup. Honour the
   template's own line breaks AND wrap long text, breaking unbreakable runs. */
.sms-preview {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  box-sizing: border-box;
}

/* ING-54: schematic layout for the read-only "Invia SMS" riepilogo. Each row is
   a clearly separated label (title) + value (paragraph) pair, so operators can
   tell the recipient apart from the message body at a glance. */
.sms-summary {
  margin: 0 0 var(--space-4);
}

.sms-summary-row {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.sms-summary-row:last-child {
  border-bottom: 1px solid var(--color-border);
}

.sms-summary-label {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.sms-summary-value {
  margin: 0;
  color: var(--color-text);
}

.sms-summary-value .sms-preview {
  margin: 0;
}

.sms-summary-value .field-hint {
  margin: var(--space-2) 0 0;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal-header h2 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--color-text);
  background: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
}

th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td {
  border-bottom: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.table-wrap table {
  border: none;
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-neutral {
  background: #eef0f3;
  color: var(--color-text-muted);
}

form.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.9rem;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.field:has(> input[required]) label,
.field:has(> select[required]) label,
.field:has(> textarea[required]) label {
  color: var(--color-text);
}

.field:has(> input[required]) label::after,
.field:has(> select[required]) label::after,
.field:has(> textarea[required]) label::after {
  content: " *";
  color: var(--color-danger);
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0;
  min-height: 1.1em;
}

.field-hint.found {
  color: var(--color-success);
}

.field-hint.error {
  color: var(--color-danger);
}

/* WhatsApp reachability: a required Sì/No radio group (no default) so staff
   must make an explicit choice — an unchecked checkbox couldn't tell "no"
   apart from "not answered yet". Board request, 2026-07-27 (ING-1). */
.field-radio-group .field-label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--color-text);
}

.field-radio-group .radio-options {
  display: flex;
  gap: 1.5rem;
}

.field-radio-group .radio-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  color: var(--color-text);
  cursor: pointer;
}

.field-radio-group input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
}

input,
select,
textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Reminder-message editor (/app/impostazioni-messaggio). */
textarea#template {
  width: 100%;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  line-height: 1.4;
}

.placeholder-legend {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
  color: var(--color-text-muted, inherit);
  font-size: 0.9rem;
}

.placeholder-legend li {
  margin: 0.15rem 0;
}

.message-preview {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  font-family: inherit;
}

button,
.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
}

button:hover,
.btn:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  text-decoration: none;
}

.card.card-cta {
  border: 1px solid var(--color-primary);
  background: #eef3fb;
}

.btn.btn-cta {
  font-size: 1.05rem;
  padding: 0.75rem 1.4rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

button.secondary,
.btn.secondary {
  background: var(--color-surface);
  color: var(--color-primary);
}

button.secondary:hover,
.btn.secondary:hover {
  background: #eef3fb;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-msg {
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  display: none;
}

.form-msg.error {
  display: block;
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.form-msg.success {
  display: block;
  background: var(--color-success-bg);
  color: var(--color-success);
}

.empty-state {
  color: var(--color-text-muted);
  padding: 1.5rem;
  text-align: center;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}

/* Only the free-text search grows; nested date-range inputs keep their
   natural width (see .date-filter below). */
.search-form > input {
  flex: 1;
  min-width: 12rem;
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.breadcrumb {
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

/* Row action cell. The generic .actions rule above turns this into a
   flex container, which pulls the <td> out of table layout so the
   table-wrap can no longer contain it (the column clips on the right).
   Keep it a real table cell: the inner forms are block/flex rows that
   stack naturally, and .table-wrap { overflow-x: auto } handles width. */
td.actions {
  display: table-cell;
  vertical-align: top;
  margin: 0;
  white-space: nowrap;
}

td.actions .inline-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.4rem;
}

td.actions .inline-form:last-child {
  margin-bottom: 0;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

.inline-form input,
.inline-form select {
  padding: 0.35rem 0.5rem;
}

.inline-form .btn {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.wa-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #25d366;
  border-color: #1da851;
  color: #fff;
}

.wa-link:hover {
  background: #1da851;
  border-color: #178c43;
}

.wa-link.is-sent {
  pointer-events: none;
  opacity: 0.6;
  cursor: not-allowed;
}

/* ING-20: disabled "Invia WhatsApp" placeholder shown for WhatsApp = No (or
   phone-less) rows in the "Invia avvisi" list — visible but not clickable,
   sitting next to the "Segna come contattato" button. */
.btn.is-disabled {
  display: inline-block;
  pointer-events: none;
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: -0.75rem 0 1.5rem;
}

.pagination-status {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.pagination [aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.pagination-size {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem 1.5rem;
  margin-bottom: 0.5rem;
}

.detail-grid dt {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin: 0;
}

.detail-grid dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
}

.form-msg.warning {
  display: block;
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

/* ING-12 §Case C: phone/name-conflict panel on the vehicle registration form,
   shown when POST /vehicles/register returns 409 owner_phone_name_conflict. */
.owner-conflict {
  border: 1px solid var(--color-warning);
  background: var(--color-warning-bg);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.owner-conflict[hidden] {
  display: none;
}

.owner-conflict-title {
  margin-top: 0;
  font-weight: 600;
  color: var(--color-warning);
}

.owner-conflict-details {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin: 0.6rem 0;
}

.owner-conflict-details dt {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.owner-conflict-details dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
}

.owner-conflict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

/* ING-73 §6.4: scheda-completion banner — informational, primary palette */
.scheda-completion-banner {
  border: 1px solid var(--color-primary);
  background: var(--color-primary-bg);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.scheda-completion-banner[hidden] {
  display: none;
}

.scheda-completion-banner-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--color-primary-dark);
}

/* KPI dashboard (board request 2026-07-24, /app/kpi) — this codebase's
   first chart. Colors follow the `dataviz` skill's method: text/border/
   surface reuse this file's existing tokens (already accessible and
   consistent with the rest of the app), and only the data-mark colors
   below (bar fills) come from the skill's validated categorical/sequential
   palette, since there was no prior chart convention to match. Scoped as
   custom properties under .kpi-viz per the skill's guidance (this project
   has one global stylesheet and no per-page <style> blocks, so "local" here
   means class-scoped rather than inline). No dark-mode variant: this app
   has no dark mode anywhere (no prefers-color-scheme / data-theme usage
   exists in this file), so a chart-only dark mode would be inconsistent
   with the rest of the UI rather than an accessibility win — revisit if/
   when the app gets a real dark mode. */
.kpi-viz {
  --kpi-bar-base: #5598e7; /* sequential blue, step 350 — context bars */
  --kpi-bar-full: #2a78d6; /* categorical slot 1 — "fullest month" accent */
  --kpi-bar-empty: #eb6834; /* categorical slot 2 — "emptiest month" accent */
}

.kpi-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.kpi-stat-tile.kpi-stat-fullest {
  border-left-color: var(--kpi-bar-full);
}

.kpi-stat-tile.kpi-stat-emptiest {
  border-left-color: var(--kpi-bar-empty);
}

.kpi-stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin: 0 0 0.35rem;
}

.kpi-stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.15;
}

.kpi-stat-sub {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
}

.kpi-stat-note {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--color-warning);
  background: var(--color-warning-bg);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.kpi-section {
  margin-bottom: 1.75rem;
}

.kpi-chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 0.75rem;
  margin-bottom: 1.5rem;
}

.kpi-chart-legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
}

.kpi-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.kpi-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.kpi-swatch-full {
  background: var(--kpi-bar-full);
}

.kpi-swatch-empty {
  background: var(--kpi-bar-empty);
}

.kpi-chart-scroll {
  overflow-x: auto;
}

.kpi-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 200px;
  padding-top: 1.5rem; /* headroom for direct value labels above the tallest bars */
  border-bottom: 1px solid var(--color-border);
}

.kpi-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 22px;
  flex: 1 0 22px;
}

.kpi-bar-value {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  margin-bottom: 0.15rem;
}

.kpi-bar {
  width: 100%;
  max-width: 24px;
  background: var(--kpi-bar-base);
  border-radius: 4px 4px 0 0;
}

.kpi-bar.kpi-bar-full {
  background: var(--kpi-bar-full);
}

.kpi-bar.kpi-bar-empty {
  background: var(--kpi-bar-empty);
}

.kpi-bar-axis-labels {
  display: flex;
  gap: 2px;
  margin-top: 0.35rem;
}

.kpi-bar-axis-label {
  flex: 1 0 22px;
  min-width: 22px;
  font-size: 0.65rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  text-align: center;
  transform: rotate(-40deg);
  transform-origin: top center;
}

.kpi-empty-state-icon {
  font-size: 1.4rem;
}

/* ING-21 — camera plate scan */
.targa-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.targa-input-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.plate-scan-trigger {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Sits above the "Registra collaudo" modal (.modal-overlay, z-index 100)
   from which it can be opened on the home page. Keep the base modal's
   top-anchored alignment (align-items:flex-start): if it were centered, the
   dialog would re-center — visibly shifting the image — the moment the
   recognised-plate field and Riprova/Usa buttons appear after a capture. */
.plate-scan-overlay {
  z-index: 1000;
}

.plate-scan-dialog {
  max-width: 520px;
}

.plate-scan-status {
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
  /* Reserve two lines so the status text changing length between states
     (live → recognising → result/error) doesn't reflow and shove the camera
     stage up or down under it. */
  min-height: 2.6em;
}

/* The stage is locked to the LIVE camera frame's aspect ratio (set from
   video.videoWidth/Height in plate-scan.js on loadedmetadata; the 4/3 here is
   just a sane default until then). With the box matching the frame, object-fit
   :contain fills it edge to edge — no black bars, nothing "cut" — the centered
   .plate-scan-guide maps linearly onto the frame (so the crop is exactly what
   the operator framed), and the <video> and the captured <canvas> occupy the
   identical box, so swapping them on capture no longer shifts the image. */
.plate-scan-stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  margin: 0 auto;
}

/* :not([hidden]) is load-bearing — an unqualified `display:block` here is an
   author rule that overrides the UA `[hidden]{display:none}`, so the JS toggling
   video.hidden / canvas.hidden would have NO effect and the captured <canvas>
   would render stacked below the still-shown <video> (the image "shifting"
   down). Only the currently-visible element fills the stage. */
.plate-scan-stage video:not([hidden]),
.plate-scan-stage canvas:not([hidden]) {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Centered framing guide: the operator lines the plate up inside this box, and
   capture crops to exactly this region before OCR. The box is taller than a car
   plate (~4.7:1) on purpose so a roughly-square MOTORCYCLE plate (2 letters over
   5 digits) also fits; trimToPlate() in plate-scan.js then tightens the crop to
   the real plate rectangle for either shape before recognition. */
.plate-scan-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 86%;
  aspect-ratio: 1.9 / 1;
  border: 2px dashed rgba(120, 200, 255, 0.95);
  border-radius: 6px;
  pointer-events: none;
}

.plate-scan-guide::after {
  content: "Inquadra la targa qui (auto o moto)";
  position: absolute;
  left: 0;
  bottom: -1.4rem;
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  color: rgba(120, 200, 255, 0.95);
}

.plate-scan-guess {
  margin-top: 1rem;
}

.plate-scan-guess label {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
}

.plate-scan-guess input {
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

.plate-scan-hint {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--color-text-muted);
}

.plate-scan-hint strong {
  color: var(--color-text);
}

.plate-scan-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* =====================================================================
   ING-28 Phase 2 — touch targets, loading state, responsive tables.
   Appended (not interleaved) so the rules above are untouched; these
   only extend existing components via the new tokens declared in :root.
   ===================================================================== */

/* Comfortable primary tap targets (>=44px, ING-28). Buttons become flex so
   text + optional icon centre cleanly. Dense/desktop contexts (table row
   actions, nav, pagination) keep a smaller 36px control — they are keyboard-
   and mouse-driven on wide screens and collapse into full-width cards on
   mobile, where the row itself is the large target. */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  line-height: 1.15;
}

.btn.small,
.nav-logout-form .btn,
.inline-form .btn,
td.actions .btn,
.pagination .btn,
.modal-close {
  min-height: 36px;
}

/* Loading state: an inline CSS-only spinner (no JS dependency, no asset,
   CSP-safe). Add .is-loading to a .btn while its form/action is in flight. */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ing-spin 0.6s linear infinite;
}

.btn.secondary.is-loading::after {
  border-color: var(--color-primary-bg);
  border-top-color: var(--color-primary);
}

@keyframes ing-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .btn.is-loading::after { animation-duration: 1.6s; }
}

/* Self-hosted SVG sprite icons (public/img/sprite.svg). Sized in em so an icon
   scales with the surrounding text, and inherits the current text colour via
   stroke: currentColor — so the same symbol works on a button, a link, etc. */
.ico {
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
}

/* Theme switcher: a pure segmented pill in the top bar. The buttons opt out
   of the primary-button base styling so they read as a toggle, not 3 CTAs. */
.theme-switch {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--color-surface);
}

.theme-switch-btn {
  min-height: 32px;
  padding: 0.25rem 0.7rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
}

.theme-switch-btn:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.theme-switch-btn.is-active,
.theme-switch-btn[aria-pressed="true"] {
  background: var(--color-primary);
  color: #fff;
}

/* ---- The headline fix: admin data tables collapse into cards < 768px ----
   Scoped to .table-wrap so it only touches the scrollable data tables (the
   veicoli/proprietari/utenti/permessi/KPI lists), never detail layouts. The
   header row is visually hidden and each cell prints its column name from
   data-label="…" (added to every <td> in the list views). Above 768px the
   normal table + horizontal-scroll fallback is unchanged. */
@media (max-width: 767px) {
  /* Admin Console (Utenti/Permessi/Parametri/KPI): the 200px lateral sidebar
     would otherwise crush the content into a ~150px column on phones. Stack
     it — sidebar becomes a horizontal chip row above the content. */
  .admin-console {
    flex-direction: column;
    gap: var(--space-4);
  }

  .admin-sidebar {
    width: 100%;
  }

  .admin-sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .table-wrap {
    border: none;
    overflow: visible;
    background: transparent;
    margin-bottom: var(--space-4);
  }

  .table-wrap table {
    background: transparent;
  }

  /* Hide the header row without removing it from the accessibility tree. */
  .table-wrap thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    background: var(--color-surface);
    margin-bottom: var(--space-3);
    padding: var(--space-2) var(--space-3);
  }

  .table-wrap tr:last-child td {
    border-bottom: 1px dashed var(--color-border);
  }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px dashed var(--color-border);
    text-align: right;
    font-size: var(--fs-sm);
  }

  .table-wrap tr td:last-child {
    border-bottom: none;
  }

  /* Column label, taken from the cell's data-label attribute. */
  .table-wrap td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: var(--fs-xs);
    letter-spacing: 0.03em;
    text-align: left;
  }

  /* Cells with no label (or empty) shouldn't render a stray divider row. */
  .table-wrap td:not([data-label])::before,
  .table-wrap td[data-label=""]::before {
    content: none;
  }

  /* Actions cell: give it the full card width, left-aligned, label on top. */
  .table-wrap td.actions {
    display: block;
    text-align: left;
    white-space: normal;
  }

  .table-wrap td.actions::before {
    display: block;
    margin-bottom: var(--space-1);
  }

  .table-wrap td.actions .inline-form {
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
  }

  /* Empty-state row ("Nessun risultato") spanning all columns: keep it a
     single centred block, no column label. */
  .table-wrap td.empty-state {
    display: block;
    text-align: center;
  }

  .table-wrap td.empty-state::before {
    content: none;
  }
}

/* ING-66 (T4): collapsible message boxes on /app/impostazioni-messaggio.
   Native <details>/<summary> — no JS, keyboard-accessible, survives reload. */
.msg-box {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  margin-bottom: var(--space-5);
}

.msg-box-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
  list-style: none;
  border-radius: var(--radius);
}

.msg-box-summary::-webkit-details-marker {
  display: none;
}

.msg-box-summary::before {
  content: "▶";
  font-size: 0.65em;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.msg-box[open] > .msg-box-summary::before {
  transform: rotate(90deg);
}

.msg-box[open] > .msg-box-summary {
  border-bottom: 1px solid var(--color-border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.msg-box-summary:hover {
  background: var(--color-bg-subtle);
}

.msg-box-body {
  padding: var(--space-5);
}

.section-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-5) 0;
}

.form-hint {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
  border-left: 3px solid var(--color-primary);
  padding: var(--space-2) var(--space-3);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: var(--space-4);
}
