/*!
 * iFix Gestionale Web - stili "gestionale" identici al client PyQt
 * Copyright (c) 2024-2026 Fix Solutions S.r.l.s.
 */

:root {
  --bg:       #F1F5F9;
  --panel:    #FFFFFF;
  --text:     #0F172A;
  --muted:    #64748B;
  --border:   #E2E8F0;
  --border-2: #CBD5E1;
  --input-bg: #FFFFFF;
  --input-readonly: #F1F5F9;
  --nav:      #1E3A8A;
  --nav-text: #FFFFFF;
  --nav-hover:#1E40AF;
  --nav-muted:#93C5FD;
  --BG: #2563EB;
  --GR: #16A34A;
  --RD: #DC2626;
  --OR: #D97706;
  --SL: #64748B;
  --row-alt: #F8FAFC;
  --row-hover:#EFF6FF;
  --row-sel: #DBEAFE;
  /* Dedicati a form/label/title: chiari in dark, navy in light */
  --label:    #1E3A8A;
  --section-title: #1E3A8A;
  --card-bg:  #F0F9FF;
  --card-border: #BAE6FD;
  --card-hl-yellow-bg: #FEF9C3;
  --card-hl-yellow-border: #FACC15;
  --card-hl-orange-bg: #FFEDD5;
  --card-hl-orange-border: #F59E0B;
}
html.dark {
  --bg:       #000000;
  --panel:    #111827;
  --text:     #F1F5F9;
  --muted:    #CBD5E1;
  --border:   #334155;
  --border-2: #64748B;
  --input-bg: #0B1220;
  --input-readonly: #1E293B;
  --nav:      #0B1F4D;
  --nav-hover:#1E3A8A;
  --row-alt:  #0B1220;
  --row-hover:#1E3A5F;
  --row-sel:  #1E3A8A;
  --label:    #93C5FD;
  --section-title: #93C5FD;
  --card-bg:  #1E3A5F;
  --card-border: #3B82F6;
  --card-hl-yellow-bg: #713F12;
  --card-hl-yellow-border: #EAB308;
  --card-hl-orange-bg: #7C2D12;
  --card-hl-orange-border: #F97316;
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  font-size: 13px; line-height: 1.35;
  /* Scala UI globale: applicata via la variabile --ui-scale (default 1.5).
     Ogni px del progetto viene scalato proporzionalmente — niente bisogno
     dello zoom del browser. Il valore è impostato in <head> da uno script
     che legge localStorage.ifix_ui_scale, e modificato con il bottone 🔍
     della navbar. La proprietà `zoom` (a differenza di transform:scale)
     ricalcola anche il layout, quindi posizionamento e click restano
     perfettamente allineati. */
  zoom: var(--ui-scale, 1.5);
}
a { color: var(--BG); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ══════════════ NAVBAR ══════════════ */
.navbar {
  background: var(--nav); color: var(--nav-text);
  height: 54px;
  display: flex; align-items: center;
  padding: 0 14px; gap: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  position: sticky; top: 0; z-index: 40;
}
.navbar .brand {
  font-size: 15pt; font-weight: bold; padding-right: 10px;
  border-right: 1px solid rgba(255,255,255,.2);
  display: flex; align-items: center; gap: 6px;
}
.navbar .nav-btn {
  background: transparent; color: var(--nav-text);
  border: 1px solid transparent;
  padding: 7px 14px; font-size: 12px; font-weight: 600;
  border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.navbar .nav-btn:hover { background: var(--nav-hover); }
.navbar .nav-btn.active { background: rgba(255,255,255,0.15); }
.navbar .spacer { flex: 1; }
.navbar .user-info {
  color: var(--nav-muted); font-size: 12px;
  display: inline-flex; align-items: center; gap: 8px; padding: 0 8px;
}
.navbar .user-info b { color: #FFF; }
.navbar select.sede-sel, .navbar .sede-badge {
  background: rgba(255,255,255,0.18); color: #FFF;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 5px 26px 5px 10px; border-radius: 5px;
  font-size: 12px; font-weight: 600;
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M1,3 L5,7 L9,3' fill='none' stroke='white' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat; background-position: right 8px center;
  cursor: pointer;
}
.navbar select.sede-sel:hover { background-color: rgba(255,255,255,0.28); }
/* Dropdown aperto — forzati leggibili con !important (altrimenti il browser fa quel che vuole) */
.navbar select.sede-sel option {
  background: #1E3A8A !important; color: #FFFFFF !important;
  padding: 6px 10px; font-weight: 600;
}
.navbar .icon-btn {
  background: transparent; color: #FFF; border: none;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 16px;
  position: relative;
}
.navbar .icon-btn:hover { background: var(--nav-hover); }
.navbar .badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--RD); color: #FFF; font-size: 10px; font-weight: bold;
  border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-hamburger { display: none; background: transparent; color:#FFF; border:none; font-size:20px; padding:4px 8px; cursor:pointer; }
.mobile-menu { display: none; background: var(--nav-hover); padding: 8px; gap: 4px; flex-direction: column; }
.mobile-menu a { color: #FFF; padding: 10px 14px; border-radius: 6px; }
.mobile-menu a:hover { background: rgba(255,255,255,0.1); text-decoration: none; }
@media (max-width: 900px) {
  .navbar .nav-btn.nav-page { display: none; }
  .btn-hamburger { display: inline-block; }
  .mobile-menu.open { display: flex; }
  .navbar .user-info { font-size: 11px; }
  .navbar .user-info .role-pill { display: none; }
}

/* ══════════════ LAYOUT ══════════════ */
.container {
  max-width: 1400px; margin: 0 auto; padding: 16px;
}
h1.page-title {
  margin: 0 0 14px 0; font-size: 18px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}

/* ══════════════ PANEL / GROUPBOX ══════════════ */
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; margin-bottom: 14px;
}
.groupbox {
  border: 1px solid var(--border-2); border-radius: 6px; padding: 10px 12px 12px;
  margin-bottom: 12px; position: relative; background: var(--panel);
}
.groupbox > .gb-title {
  display: inline-block; background: var(--panel); padding: 0 6px;
  position: relative; top: -18px; left: 6px; font-weight: 700; font-size: 11px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--section-title);
}
.groupbox > .gb-title + * { margin-top: -10px; }

/* ══════════════ FORM CONTROL ══════════════ */
label.fld, .fld {
  display: block; font-size: 11px; font-weight: 600; color: var(--label);
  margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.04em;
}
/* IMPORTANTE: cattura anche gli <input> senza attributo type (default = text).
   Il selettore [type="text"] NON matcha gli input senza type esplicito,
   perciò aggiungiamo input:not([type]). */
input:not([type]),
input[type="text"], input[type="password"], input[type="email"], input[type="tel"],
input[type="number"], input[type="date"], input[type="search"], input[type="url"],
input[type="time"], input[type="datetime-local"], input[type="month"], input[type="week"],
select, textarea {
  width: 100%; padding: 7px 10px; font-size: 13px; font-family: inherit;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 5px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--BG); box-shadow: 0 0 0 2px rgba(37,99,235,0.25); }
textarea { min-height: 60px; resize: vertical; }
input[readonly], input[disabled], textarea[readonly], textarea[disabled], select[disabled] {
  background: var(--input-readonly); color: var(--muted); cursor: not-allowed;
}
/* Placeholder leggibile in entrambi i temi */
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
/* Date input con calendario in dark mode (Chrome/Edge) */
html.dark input[type="date"], html.dark input[type="time"],
html.dark input[type="datetime-local"], html.dark input[type="month"], html.dark input[type="week"] {
  color-scheme: dark;
}
/* Override autofill di Chrome (di default forza sfondo giallo/bianco) */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text) !important;
  transition: background-color 5000s ease-in-out 0s;
}
/* Select dropdown options leggibili in dark (browsers usano nativo) */
option { background: var(--input-bg); color: var(--text); }
.input-upper { text-transform: uppercase; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 700px) { .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }

/* ══════════════ BOTTONI ══════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  border: 1px solid transparent; border-radius: 5px; cursor: pointer;
  background: var(--SL); color: #FFF; transition: filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(0.92); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-bg { background: var(--BG); }
.btn-gr { background: var(--GR); }
.btn-rd { background: var(--RD); }
.btn-or { background: var(--OR); }
.btn-sl { background: var(--SL); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border-2);
}
.btn-ghost:hover { background: var(--row-alt); }

/* ══════════════ TABELLE ══════════════ */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); font-size: 12.5px;
}
table.data thead th {
  background: var(--BG); padding: 9px 10px; text-align: left;
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  color: #FFFFFF; border-bottom: 2px solid var(--BG);
  position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none;
}
table.data thead th .col-resizer:hover::after,
table.data thead th .col-resizer.active::after { background: #FFFFFF; }
table.data tbody td { padding: 7px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
table.data tbody tr:nth-child(even) { background: var(--row-alt); }
table.data tbody tr:hover { background: var(--row-hover); cursor: pointer; }
/* Riga selezionata: mantieni leggibile sia in light che in dark.
   La regola usa la classe .row-selected applicata da JS al click. */
table.data tbody tr.row-selected,
table.data tbody tr.row-selected:hover {
  background: var(--row-sel) !important;
}
table.data tbody tr.row-selected td { color: var(--text); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.ctr { text-align: center; }
table.data td.mono { font-family: "Consolas", "Monaco", monospace; font-size: 11.5px; }
.th-sort::after { content: ' ⇅'; opacity: 0.3; }
.th-sort.asc::after { content: ' ▲'; opacity: 1; color: var(--BG); }
.th-sort.desc::after { content: ' ▼'; opacity: 1; color: var(--BG); }

/* ═══════════════════════════════════════════════════════════════════
   RESIZE COLONNE STILE EXCEL
   Tabella con <colgroup>, table-layout:fixed: il colgroup comanda le
   larghezze, ogni <col> ha style="width: Xpx". Nessun min-width -> si
   puo' ridurre finche' si vede solo una lettera (limite duro 12px per
   tenere l'handle cliccabile).
═══════════════════════════════════════════════════════════════════ */
table.data.resizable {
  table-layout: fixed;
  /* La width viene settata dinamicamente da JS come somma delle <col>.
     table-layout:fixed + width esplicita + overflow:hidden sulle celle
     fa funzionare correttamente text-overflow:ellipsis. */
  border-collapse: collapse;
}
table.data.resizable th,
table.data.resizable td {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}
table.data.resizable thead th {
  border-right: 1px solid rgba(255,255,255,0.25);
  padding: 9px 10px;
  position: relative;
}
table.data.resizable tbody td { padding: 6px 10px; }
table.data.resizable th:last-child,
table.data.resizable td:last-child { border-right: none; }

.col-resizer {
  position: absolute; top: 0; right: 0;
  width: 7px; height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 10;
}
.col-resizer::after {
  content: "";
  position: absolute; top: 0; right: 0;
  width: 2px; height: 100%;
  background: transparent;
  transition: background 0.12s;
}
.col-resizer:hover::after,
.col-resizer.active::after {
  background: #FFFFFF;
  box-shadow: 0 0 5px rgba(255,255,255,0.7);
}
body.col-resizing,
body.col-resizing * { cursor: col-resize !important; user-select: none !important; }

/* Pallino stato (colonna ●) */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* ══════════════ PILL STATO / MACRO ══════════════ */
.pill-stato, .pill-macro {
  display: inline-block; padding: 3px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
/* Lampeggio quando una notifica e' arrivata per quella commessa
   (si ferma quando l'utente apre la riparazione e poi la chiude). */
@keyframes ifix-pill-blink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.95), inset 0 0 0 2px #DC2626; filter: brightness(1); }
  50%      { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0),  inset 0 0 0 2px #DC2626; filter: brightness(1.2); }
}
.pill-macro.blink {
  animation: ifix-pill-blink 1.0s ease-in-out infinite;
  outline: none;
  font-weight: 800;
}
.pill-macro.blink::before {
  content: "● ";
  color: #DC2626;
  animation: ifix-pill-blink-dot 0.7s ease-in-out infinite;
  margin-right: 2px;
}
@keyframes ifix-pill-blink-dot {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}
/* Stato neutro: solo testo, niente sfondo (solo le macro fasi hanno colore) */
.pill-stato-neutro {
  display: inline-block; padding: 2px 6px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--text);
}

/* ══════════════ TAB ══════════════ */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  background: var(--panel); margin-bottom: 0; overflow-x: auto;
}
.tab-btn {
  padding: 10px 16px; background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 12.5px; border-bottom: 3px solid transparent;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); background: var(--row-alt); }
.tab-btn.active { color: var(--BG); border-bottom-color: var(--BG); background: var(--panel); }
.tab-pane { display: none; background: var(--panel); border: 1px solid var(--border); border-top: none; padding: 16px; }
.tab-pane.active { display: block; }
/* Quando un tab-pane e' mostrato SENZA la barra .tabs sopra (es. archivio
   di un centro non-IFIX con un solo tab), ripristina il bordo superiore. */
.tab-pane.no-tabs-above { border-top: 1px solid var(--border); border-radius: 6px; }

/* ══════════════ HEADER COMMESSA (colorato) ══════════════ */
.head-commessa {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-radius: 8px 8px 0 0;
}
.head-commessa .numero { font-size: 13px; font-weight: 600; color: var(--muted); }
.head-commessa .head-btns { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.pill-macro-xl {
  font-size: 22px !important;
  padding: 8px 22px !important;
  border-radius: 20px !important;
  letter-spacing: 0.3px;
}

/* Card row Riepilogo */
.cards-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr));
  gap: 10px; margin-bottom: 14px;
}
/* Layout split del riepilogo dettaglio: sinistra contenuti, destra codice+pattern */
.riep-split {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
}
.riep-right {
  border-left: 1px solid var(--border);
  padding-left: 20px;
}
@media (max-width: 720px) {
  .riep-split { grid-template-columns: 1fr; }
  .riep-right { border-left: none; border-top: 1px solid var(--border); padding-left: 0; padding-top: 14px; }
}
.card-mini {
  border: 1px solid var(--card-border); border-radius: 8px; padding: 10px 14px;
  background: var(--card-bg); color: var(--text);
}
.card-mini .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--label); font-weight: 700; }
.card-mini .val { margin-top: 4px; font-weight: 700; font-size: 14px; color: var(--text); }
.card-mini.hl-yellow { background: var(--card-hl-yellow-bg); border-color: var(--card-hl-yellow-border); }
.card-mini.hl-orange { background: var(--card-hl-orange-bg); border-color: var(--card-hl-orange-border); }

/* Varianti colorate per le card statistiche.
   In light mode: sfondo tenue colorato; in dark mode: tonalita' scura
   contrastata, testo bianco sempre leggibile. */
.card-mini.stat-blue   { background: #EFF6FF; border-color: #BFDBFE; }
.card-mini.stat-yellow { background: #FFFBEB; border-color: #FDE68A; }
.card-mini.stat-green  { background: #F0FDF4; border-color: #BBF7D0; }
.card-mini.stat-red    { background: #FEF2F2; border-color: #FECACA; }
.card-mini.stat-purple { background: #FAF5FF; border-color: #E9D5FF; }
.card-mini.stat-orange { background: #FFF7ED; border-color: #FED7AA; }
html.dark .card-mini.stat-blue   { background: #172554; border-color: #1E3A8A; }
html.dark .card-mini.stat-yellow { background: #422006; border-color: #713F12; }
html.dark .card-mini.stat-green  { background: #052E16; border-color: #14532D; }
html.dark .card-mini.stat-red    { background: #450A0A; border-color: #7F1D1D; }
html.dark .card-mini.stat-purple { background: #2E1065; border-color: #4C1D95; }
html.dark .card-mini.stat-orange { background: #431407; border-color: #7C2D12; }

/* ══════════════ PATTERN LOCK ══════════════ */
.pattern-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 14px; width: 200px; padding: 14px;
  background: #F1F5F9; border: 1px solid var(--border-2); border-radius: 8px;
}
html.dark .pattern-grid { background: #1F2937; }
.pattern-dot {
  width: 44px; height: 44px; border-radius: 50%; background: #CBD5E1;
  border: 2px solid #94A3B8; cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #334155; font-size: 12px; user-select: none;
}
.pattern-dot.on { background: #FF7A3C; border-color: #E65100; color: #FFF; }
.pattern-dot.on.first { background: #DC2626; border-color: #991B1B; }

/* ══════════════ CHAT ══════════════ */
.chat-box {
  height: 400px; max-height: 55vh; overflow-y: auto;
  padding: 12px; background: #FAFAFA; border: 1px solid var(--border); border-radius: 6px;
  display: flex; flex-direction: column; gap: 8px;
}
html.dark .chat-box { background: #0F172A; }
.chat-bubble {
  max-width: 75%; padding: 8px 12px; border-radius: 12px; font-size: 13px;
  word-wrap: break-word; white-space: pre-wrap;
}
.chat-bubble .hdr { font-size: 10px; font-weight: 700; margin-bottom: 3px; opacity: 0.85; }
.chat-bubble .ts  { font-size: 9.5px; opacity: 0.7; margin-top: 2px; text-align: right; }

/* ══════════════ NOTIFICATION CENTER DROPDOWN ══════════════ */
.notif-wrap { position: relative; }
#notifDropdown {
  position: absolute; right: 0; top: 44px;
  width: 340px; max-width: 92vw; max-height: 70vh;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.22);
  display: flex; flex-direction: column; z-index: 50;
}
#notifDropdown.hidden { display: none; }
#notifDropdown header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
#notifDropdown header h3 { margin: 0; font-size: 13px; }
#notifList { flex: 1; overflow-y: auto; padding: 6px; }
#notifList .empty { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 12px; }
.notif-item {
  display: flex; gap: 8px; padding: 8px 10px; border-radius: 6px;
  color: var(--text); margin-bottom: 2px;
}
.notif-item:hover { background: var(--row-alt); text-decoration: none; }
.notif-item.unread { background: #EFF6FF; border-left: 3px solid var(--BG); }
html.dark .notif-item.unread { background: #1E293B; }
.notif-item .ni-ico { font-size: 18px; line-height: 1; }
.notif-item .ni-body { flex: 1; min-width: 0; }
.notif-item .ni-title { font-weight: 700; font-size: 12.5px; }
.notif-item .ni-text  { font-size: 11.5px; color: var(--muted); white-space: pre-wrap; max-height: 34px; overflow: hidden; }
.notif-item .ni-date  { font-size: 10px; color: var(--muted); margin-top: 2px; }
#notifDropdown footer { padding: 8px; text-align: center; border-top: 1px solid var(--border); font-size: 11px; }

/* ══════════════ TOAST ══════════════ */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; padding: 10px 14px; border-radius: 6px;
  font-size: 13px; min-width: 240px; box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  animation: slideIn 0.2s ease-out;
}
.toast-ok { background: var(--GR); color: #FFF; }
.toast-err{ background: var(--RD); color: #FFF; }
.toast-info{ background: var(--BG); color: #FFF; }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ══════════════ MODAL ══════════════ */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.65);
  z-index: 100; align-items: center; justify-content: center; padding: 16px;
}
.modal.show { display: flex; }
.modal-box {
  background: var(--panel); color: var(--text);
  border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  max-width: 760px; width: 100%; max-height: 92vh; overflow-y: auto;
}
.modal-box.sm { max-width: 460px; }
.modal-box.lg { max-width: 1000px; }
.modal-hdr { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-hdr h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px; }
.modal-ftr { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close-x { background: transparent; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* Img modal */
#imgModal { position: fixed; inset: 0; background: rgba(0,0,0,0.88); z-index: 120; align-items: center; justify-content: center; padding: 16px; }
#imgModal.hidden { display: none !important; }
#imgModal img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ══════════════ UTIL ══════════════ */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.mono  { font-family: Consolas, Monaco, monospace; font-size: 12px; }
.txt-r { text-align: right; }
.flex  { display: flex; }
.gap-8 { gap: 8px; }
.nowrap { white-space: nowrap; }
.sep { border-top: 1px solid var(--border); margin: 12px 0; }

/* Radio / checkbox custom */
.tipo-options { display: flex; gap: 16px; flex-wrap: wrap; }
.tipo-options label { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; }

/* Foto grid */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 10px; }
.foto-grid .foto-it { position: relative; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #000; }
.foto-grid img { width: 100%; height: 160px; object-fit: cover; display: block; cursor: zoom-in; }
.foto-grid .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.6); color: #FFF; border: none; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1; }
.foto-grid .del:hover { background: var(--RD); }

/* Autocomplete list */
.ac-list {
  position: absolute; z-index: 5; background: var(--panel);
  border: 1px solid var(--border-2); border-radius: 5px;
  max-height: 220px; overflow-y: auto; min-width: 100%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.ac-list .ac-item { padding: 6px 10px; cursor: pointer; font-size: 12.5px; }
.ac-list .ac-item:hover, .ac-list .ac-item.sel { background: var(--row-alt); }

/* Storia note append-only (tab Tecnico): note precedenti bloccate.
   NB: NIENTE white-space:pre-wrap sul container — quello sul container farebbe
   apparire i newline/indentazioni del template literal come grossi spazi vuoti
   tra le entry. Il pre-wrap va solo sul corpo testo della singola nota. */
.note-history {
  background: var(--row-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  min-height: 40px;
  max-height: 280px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}
.note-history:empty::before, .note-history.empty::before {
  content: "(nessuna nota)";
  color: var(--muted);
  font-style: italic;
}
.note-history .note-entry {
  padding: 4px 0;
  margin: 0;
  border-bottom: 1px dashed var(--border);
}
.note-history .note-entry:first-child { padding-top: 0; }
.note-history .note-entry:last-child { border-bottom: none; padding-bottom: 0; }
.note-history .note-head {
  font-weight: 700;
  color: var(--label);
  font-size: 11.5px;
  margin: 0 0 2px 0;
}
/* Solo il corpo testo della nota preserva i newline dell'utente. */
.note-history .note-body { white-space: pre-wrap; margin: 0; }
/* Riga header della nota: titolo a sinistra, azioni (★ pin / 🗑️ delete) a destra. */
.note-history .note-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 3px;
}
.note-history .note-actions { display: inline-flex; gap: 4px; flex-shrink: 0; }
.note-pin-btn, .note-del-btn {
  background: transparent; border: 1px solid var(--border-2);
  color: var(--muted); cursor: pointer;
  padding: 2px 8px; border-radius: 4px; font-size: 13px; line-height: 1;
}
.note-pin-btn:hover, .note-del-btn:hover { background: var(--row-hover); color: var(--text); }
.note-pin-btn.pinned { color: #D97706; border-color: #F59E0B; background: #FEF3C7; }
html.dark .note-pin-btn.pinned { background: #78350F; color: #FBBF24; border-color: #F59E0B; }
.note-del-btn:hover { color: var(--RD); border-color: var(--RD); }
/* Nota pinnata = sfondo evidenziato */
.note-history .note-entry.is-pinned,
#rNotePinnate .note-entry.is-pinned {
  background: #FFFBEB;
  border-left: 3px solid #F59E0B;
  padding-left: 8px;
}
html.dark .note-history .note-entry.is-pinned,
html.dark #rNotePinnate .note-entry.is-pinned {
  background: #44320B;
  border-left-color: #F59E0B;
}
#rNotePinnate .fld { color: #B45309; font-weight: 700; margin-bottom: 8px; }
html.dark #rNotePinnate .fld { color: #FBBF24; }
#rNotePinnate .note-entry { padding: 8px 10px; border-bottom: none; margin-bottom: 6px; border-radius: 4px; }

/* Firma canvas */
.firma-box { border: 1px solid var(--border-2); border-radius: 6px; background: #FFF; }
.firma-box canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }

/* ══════════════ FORM LAYOUT PyQt-style (label sinistra fissa) ══════════════ */
.form-section {
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 10px 14px 14px;
  margin: 14px 0;
  position: relative;
  background: var(--panel);
}
.form-section > .fs-title {
  position: absolute;
  top: -10px; left: 12px;
  background: var(--panel);
  padding: 0 8px;
  font-size: 12px; font-weight: 700;
  color: var(--section-title);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.form-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  min-height: 34px;
}
.form-row > label {
  color: var(--label);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-row > label .req { color: var(--RD); }
.form-row .multi { display: flex; gap: 8px; align-items: center; }
.form-row .multi > * { flex: 1; }
.form-row .input-with-btn { display: flex; gap: 6px; align-items: stretch; }
.form-row .input-with-btn input,
.form-row .input-with-btn select { flex: 1; }
.btn-plus-blue {
  background: var(--BG); color: #FFF; border: none;
  width: 40px; font-size: 18px; font-weight: 700;
  border-radius: 5px; cursor: pointer;
}
.btn-plus-blue:hover { filter: brightness(0.92); }
.form-checkbox-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.form-checkbox-row label { font-weight: 600; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.tipo-cliente-row {
  display: flex; gap: 20px; padding: 8px 0; margin-bottom: 6px;
}
.tipo-cliente-row label {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 13px; cursor: pointer;
}
.btn-fullwidth { width: 100%; justify-content: center; padding: 12px; font-size: 13px; }
.btn-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
/* Badge firma in modalità modifica (read-only) */
.firma-badge {
  display: flex; align-items: center; justify-content: center;
  padding: 12px; border-radius: 5px;
  font-size: 13px; font-weight: 600;
  background: var(--row-alt);
  border: 1px solid var(--border-2);
  color: var(--muted);
}
.firma-badge.ok { background: #D1FAE5; border-color: #10B981; color: #065F46; }
.firma-badge.ko { background: #FEE2E2; border-color: #EF4444; color: #991B1B; }
html.dark .firma-badge.ok { background: #064E3B; border-color: #10B981; color: #D1FAE5; }
html.dark .firma-badge.ko { background: #7F1D1D; border-color: #EF4444; color: #FEE2E2; }

/* Firma / Termini / Privacy Modal contenitori */
.legal-text {
  max-height: 280px; overflow-y: auto;
  border: 1px solid var(--border-2); border-radius: 5px;
  padding: 12px 16px; background: #FFFFFF !important;
  color: #111827 !important;
  font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word;
  font-family: "Segoe UI", Arial, sans-serif;
}
html.dark .legal-text { background: #1F2937 !important; color: #F3F4F6 !important; }
.firma-label { display: flex; align-items: center; gap: 6px; font-weight: 700; margin-top: 12px; margin-bottom: 6px; }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #94A3B8; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #64748B; }
html.dark ::-webkit-scrollbar-thumb { background: #475569; }
