/* === Variables === */
:root, [data-theme="midnight"] {
  --bg-primary: #0F1923;
  --bg-secondary: #1A2733;
  --bg-tertiary: #243442;
  --accent: #1E88E5;
  --accent-hover: #1976D2;
  --accent-light: rgba(30, 136, 229, 0.15);
  --text-primary: #E0E0E0;
  --text-secondary: #90A4AE;
  --text-muted: #607D8B;
  --border: #2A3A4A;
  --success: #4CAF50;
  --warning: #FF9800;
  --danger: #EF5350;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --theme-dot: #1E88E5;
}

/* Cyber Violet - electric purple, cyberpunk */
[data-theme="violet"] {
  --bg-primary: #0C0A1D;
  --bg-secondary: #14112B;
  --bg-tertiary: #1E1A3A;
  --accent: #8B5CF6;
  --accent-hover: #7C3AED;
  --accent-light: rgba(139, 92, 246, 0.15);
  --text-primary: #EDE9FE;
  --text-secondary: #A5A0C8;
  --text-muted: #6E6994;
  --border: #2E2955;
  --success: #34D399;
  --warning: #FBBF24;
  --danger: #F87171;
  --shadow: 0 2px 12px rgba(139, 92, 246, 0.1);
  --theme-dot: #8B5CF6;
}

/* Ocean Abyss - deep sea, cyan/teal */
[data-theme="ocean"] {
  --bg-primary: #06121B;
  --bg-secondary: #0C1E2E;
  --bg-tertiary: #142D42;
  --accent: #22D3EE;
  --accent-hover: #06B6D4;
  --accent-light: rgba(34, 211, 238, 0.12);
  --text-primary: #E0F7FA;
  --text-secondary: #80CBC4;
  --text-muted: #4D8A84;
  --border: #1A3A50;
  --success: #4ADE80;
  --warning: #FCD34D;
  --danger: #FB7185;
  --shadow: 0 2px 12px rgba(34, 211, 238, 0.08);
  --theme-dot: #22D3EE;
}

/* Ember Gold - warm luxury, amber/gold */
[data-theme="ember"] {
  --bg-primary: #110E08;
  --bg-secondary: #1C1710;
  --bg-tertiary: #29221A;
  --accent: #F59E0B;
  --accent-hover: #D97706;
  --accent-light: rgba(245, 158, 11, 0.12);
  --text-primary: #FEF3C7;
  --text-secondary: #BFB094;
  --text-muted: #887A62;
  --border: #3A3020;
  --success: #4ADE80;
  --warning: #FB923C;
  --danger: #EF4444;
  --shadow: 0 2px 12px rgba(245, 158, 11, 0.08);
  --theme-dot: #F59E0B;
}

/* Windows 11 - clean, light, Fluent Design */
[data-theme="windows"] {
  color-scheme: light;
  --bg-primary: #F0F0F0;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #E5E5E5;
  --accent: #005FB8;
  --accent-hover: #004C95;
  --accent-light: rgba(0, 95, 184, 0.08);
  --text-primary: #1A1A1A;
  --text-secondary: #5C5C5C;
  --text-muted: #9A9A9A;
  --border: #D4D4D4;
  --success: #107C10;
  --warning: #FFB900;
  --danger: #C42B1C;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --theme-dot: #005FB8;
}

/* Corporate - formal, professional, navy */
[data-theme="corporate"] {
  color-scheme: light;
  --bg-primary: #EBEEF2;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #D8DDE5;
  --accent: #1B3A5C;
  --accent-hover: #152E4A;
  --accent-light: rgba(27, 58, 92, 0.07);
  --text-primary: #1C2331;
  --text-secondary: #4A5568;
  --text-muted: #8896A6;
  --border: #CBD2DA;
  --success: #0D7C3D;
  --warning: #B8860B;
  --danger: #B91C1C;
  --shadow: 0 1px 4px rgba(0,0,0,0.05);
  --theme-dot: #1B3A5C;
}

/* Light theme overrides - ensure proper contrast for badges and buttons */
[data-theme="windows"] .badge-success,
[data-theme="corporate"] .badge-success { background: rgba(16,124,16,0.12); }
[data-theme="windows"] .badge-warning,
[data-theme="corporate"] .badge-warning { background: rgba(180,130,0,0.12); }
[data-theme="windows"] .badge-danger,
[data-theme="corporate"] .badge-danger { background: rgba(185,28,28,0.12); }
[data-theme="windows"] .badge-info,
[data-theme="corporate"] .badge-info { background: rgba(0,95,184,0.08); }
[data-theme="corporate"] .badge-info { background: rgba(27,58,92,0.08); }

[data-theme="windows"] .sidebar,
[data-theme="corporate"] .sidebar {
  background: var(--bg-secondary);
  box-shadow: 1px 0 0 var(--border);
}

[data-theme="windows"] .modal-overlay,
[data-theme="corporate"] .modal-overlay {
  background: rgba(0,0,0,0.3);
}

[data-theme="windows"] .lightbox,
[data-theme="corporate"] .lightbox {
  background: rgba(0,0,0,0.75);
}

[data-theme="windows"] ::-webkit-scrollbar-thumb,
[data-theme="corporate"] ::-webkit-scrollbar-thumb {
  background: #C0C0C0;
}

[data-theme="windows"] .toast,
[data-theme="corporate"] .toast {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Login === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .material-icons {
  font-size: 48px;
  color: var(--accent);
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 600;
  margin-top: 8px;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Radio e checkbox NON devono ereditare width:100%/padding dalla regola
   generica sugli input: nelle righe flex (editor quiz formazione,
   compilazione test, elenco ruoli) si allargavano a tutta la riga
   schiacciando il testo della risposta fino a renderlo invisibile. */
input[type="radio"], input[type="checkbox"] {
  width: auto;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

select {
  cursor: pointer;
  appearance: auto;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #d32f2f; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #388E3C; }

.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover:not(:disabled) { background: #F57C00; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-block { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.btn-icon:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* === App Shell === */
#app-shell {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .material-icons {
  color: var(--accent);
  font-size: 28px;
}

.sidebar-title {
  font-weight: 700;
  font-size: 16px;
}

.sidebar-close-btn { display: none; }

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--accent-light);
  color: var(--text-primary);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-light);
  border-right: 3px solid var(--accent);
}

.nav-item .material-icons { font-size: 20px; }

/* === Nav Accordion (collapsible groups) === */
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.nav-group-toggle:hover {
  background: var(--accent-light);
  color: var(--text-primary);
}
.nav-group-toggle .material-icons:first-child { font-size: 20px; }
.nav-group-toggle .nav-arrow {
  margin-left: auto;
  font-size: 18px;
  transition: transform 0.2s;
}
.nav-group.open > .nav-group-toggle .nav-arrow {
  transform: rotate(180deg);
}
.nav-group.open > .nav-group-toggle {
  color: var(--accent);
}

.nav-group-items {
  display: none;
  padding-left: 0;
}
.nav-group.open > .nav-group-items {
  display: block;
}

.nav-item.nav-sub {
  padding-left: 44px;
  font-size: 13px;
  gap: 8px;
}
.nav-item.nav-sub-2 {
  padding-left: 56px;
  font-size: 13px;
}

.nav-group-nested > .nav-group-toggle {
  padding-left: 44px;
}
.nav-group-nested .nav-group-items {
  padding-left: 0;
}

.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--warning);
  border-radius: 10px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
}

.user-info .material-icons { font-size: 20px; }

/* === Main Content === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar h2 {
  font-size: 16px;
  font-weight: 600;
}

.topbar-spacer { flex: 1; }

#menu-toggle { display: none; }

.page-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* === Cards === */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Stat Cards === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon .material-icons { font-size: 24px; color: #fff; }

.stat-icon.blue { background: var(--accent); }
.stat-icon.red { background: var(--danger); }
.stat-icon.green { background: var(--success); }
.stat-icon.orange { background: var(--warning); }

.stat-info h3 {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.stat-info p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
}

.table-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.table-toolbar .search-input {
  max-width: 300px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text-secondary); }

thead th.sort-asc::after { content: ' \u25B2'; font-size: 10px; }
thead th.sort-desc::after { content: ' \u25BC'; font-size: 10px; }

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tbody tr:hover { background: var(--accent-light); }

tbody tr:last-child td { border-bottom: none; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: rgba(76,175,80,0.15); color: var(--success); }
.badge-warning { background: rgba(255,152,0,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,83,80,0.15); color: var(--danger); }
.badge-info { background: var(--accent-light); color: var(--accent); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-muted); }

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* === Photo thumbnails === */
.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.photo-thumb:hover { border-color: var(--accent); }

/* === Sanification SSOP === */
.ssop-chip {
  display: inline-block;
  padding: 4px 8px;
  background: rgba(0, 137, 123, 0.08);
  border-radius: 6px;
  font-size: 12px;
  color: #00695C;
}
.ssop-chip .ssop-title {
  font-size: 11px;
  color: #666;
  margin-top: 2px;
  font-weight: normal;
}
.btn-link {
  background: none;
  border: none;
  color: #00897B;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-link:hover { text-decoration: underline; }
.san-details-row td {
  background: #fafafa;
  padding: 0 !important;
}
.san-details-box {
  padding: 12px 16px;
  border-left: 3px solid #00897B;
  margin: 6px 8px;
  background: #fff;
  border-radius: 4px;
}
.san-details-title {
  font-size: 12px;
  font-weight: 700;
  color: #00695C;
  margin-bottom: 6px;
  margin-top: 8px;
}
.san-details-title:first-child { margin-top: 0; }
.san-steps-list {
  margin: 4px 0 8px 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.6;
}
.san-steps-list li { color: #333; }
.san-notes {
  font-size: 13px;
  font-style: italic;
  color: #555;
}

/* === Pulizie Perfetti === */
.cln-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.cln-dot-green  { background: #2e7d32; }
.cln-dot-orange { background: #e65100; }
.cln-dot-grey   { background: #bdbdbd; }

.cln-area-header {
  padding: 10px 12px;
  background: #f3e5f5;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #4a148c;
}
.cln-area-count {
  background: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  color: #6a1b9a;
  border: 1px solid #e0e0e0;
}

.cln-task-row {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  align-items: center;
  transition: background 0.15s;
}
.cln-task-row:hover { background: #fafafa; }

.cln-task-body { flex: 1; min-width: 0; }
.cln-task-loc {
  font-size: 11px;
  color: #666;
  font-weight: 500;
  margin-bottom: 2px;
}
.cln-task-azione {
  font-size: 13.5px;
  line-height: 1.3;
  color: #222;
}
.cln-task-azione.cln-done {
  text-decoration: line-through;
  color: #999;
}
.cln-task-meta {
  margin-top: 4px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.cln-freq-chip {
  display: inline-block;
  padding: 2px 8px;
  background: #f3e5f5;
  color: #4a148c;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.cln-done-chip {
  display: inline-block;
  padding: 2px 8px;
  background: #e8f5e9;
  color: #1b5e20;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.cln-chev { color: #bdbdbd; }

.cln-task-summary {
  padding: 12px;
  background: #f3e5f5;
  border-radius: 6px;
  margin-bottom: 12px;
  border-left: 3px solid #6a1b9a;
}

/* === Tap-to-toggle UI === */
.cln-big-check {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2.5px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  margin-left: 10px;
}
.cln-big-check-todo {
  border-color: #e65100;
  background: transparent;
}
.cln-big-check-done {
  border-color: #2e7d32;
  background: #2e7d32;
  color: white;
}
.cln-big-check-done .material-icons { font-size: 22px; }
.cln-big-check-pending {
  border-color: #9e9e9e;
  background: transparent;
}
.cln-spin {
  font-size: 22px;
  animation: cln-spin 1s linear infinite;
  color: #9e9e9e;
}
@keyframes cln-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.cln-row-done {
  background: rgba(67, 160, 71, 0.06);
}
.cln-row-pending {
  opacity: 0.6;
}

.cln-photo-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: rgba(21, 101, 192, 0.1);
  color: #0d47a1;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* Lightweight toast */
#cln-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 6px;
  color: white;
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 2000;
  max-width: 480px;
}
.cln-toast-success { background: #2e7d32; }
.cln-toast-neutral { background: #455a64; }
#cln-toast button {
  background: none;
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
#cln-toast button:hover { background: rgba(255,255,255,0.15); }

/* === Vista Programma (overview grid) === */
.ov-legend {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}
.ov-leg-cell {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 3px;
  font-size: 11px;
  color: white;
  font-weight: 600;
  border: 1px solid rgba(0,0,0,0.1);
}

.ov-grid {
  border-collapse: collapse;
  font-size: 11px;
  table-layout: fixed;
  transition: transform 0.15s ease;
}
.ov-grid th, .ov-grid td {
  border: 1px solid #e0e0e0;
  padding: 0;
  text-align: center;
  height: 22px;
  width: 26px;
  min-width: 26px;
}
.ov-grid th {
  background: #f5f5f5;
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 600;
  color: #444;
}
.ov-grid th.ov-label-col {
  width: 220px;
  min-width: 220px;
  text-align: left;
  padding-left: 8px;
  z-index: 3;
  left: 0;
}
.ov-grid td.ov-label-col {
  width: 220px;
  min-width: 220px;
  text-align: left;
  padding: 2px 6px;
  background: white;
  position: sticky;
  left: 0;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ov-label-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.ov-week-col.ov-week-current {
  background: rgba(106, 27, 154, 0.18);
}

.ov-area-row td {
  background: rgba(106, 27, 154, 0.12);
  font-weight: 700;
  text-align: left;
  padding: 4px 8px;
  font-size: 12px;
  color: #4a148c;
  position: sticky;
  left: 0;
}

.ov-cell {
  cursor: pointer;
  transition: filter 0.1s;
}
.ov-cell:hover { filter: brightness(0.9); }

.ov-cell-done   { background: #43a047; color: white; font-weight: bold; }
.ov-cell-due    { background: #fb8c00; color: white; }
.ov-cell-missed { background: #ef9a9a; color: #b71c1c; }
.ov-cell-future { background: #90caf9; color: #0d47a1; }

/* === SSOP Editor === */
.ssops-table {
  width: 100%;
  border-collapse: collapse;
}
.ssops-table th, .ssops-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ssops-table th {
  background: #fafafa;
  text-align: left;
  font-weight: 600;
  color: #555;
}
.ssops-table tr:hover td { background: #fafafa; }

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.status-green { background: #e8f5e9; color: #2e7d32; }
.status-grey { background: #eee; color: #888; }

#ssop-editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}

.ssop-editor-modal {
  background: white;
  border-radius: 12px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.ssop-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.ssop-editor-header h3 {
  margin: 0;
  font-size: 18px;
  color: #00695C;
}

.ssop-editor-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.ssop-editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  border-radius: 0 0 12px 12px;
}

.ssop-field {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
}
.ssop-field label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
}
.ssop-field input[type="text"],
.ssop-field input[type="number"],
.ssop-field textarea,
.ssop-field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
}
.ssop-field textarea {
  resize: vertical;
  font-family: inherit;
}
.ssop-field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}
.ssop-field-row .ssop-field { margin-bottom: 0; }

.ssop-hint {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  font-style: italic;
}

.ssop-active-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 8px 0;
  cursor: pointer;
}

.ssop-cc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  align-items: center;
  padding: 4px;
}
.cc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 137, 123, 0.12);
  color: #00695C;
  padding: 4px 4px 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.cc-chip-x {
  background: none;
  border: none;
  color: #00695C;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 6px;
  font-weight: bold;
}
.cc-chip-x:hover { color: #d32f2f; }

.ssop-section-title {
  font-size: 13px;
  font-weight: 700;
  color: #00695C;
  margin: 18px 0 8px 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ssop-step-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #eee;
}
.ssop-step-controls {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ssop-step-text {
  flex: 1;
  padding: 6px 10px !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  font-size: 13px !important;
}
.ssop-step-required {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #666;
  white-space: nowrap;
}
.btn-icon-sm {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  color: #777;
  line-height: 1;
}
.btn-icon-sm:hover { background: #eee; }
.btn-icon-sm .material-icons { font-size: 16px; }
.btn-icon-sm.btn-danger:hover { background: #ffebee; color: #d32f2f; }

/* === Lightbox === */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: pointer;
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
}

/* === Toast === */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-success { border-left: 3px solid var(--success); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === Detail panel === */
.detail-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-item label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-item p {
  font-size: 14px;
  margin-top: 2px;
}

/* === Inline detail row (expandable table rows) === */
.inline-detail-row {
  background: var(--bg-primary);
}

.inline-detail-row > td {
  padding: 0 !important;
  border-bottom: 2px solid var(--accent) !important;
}

.inline-detail-content {
  padding: 20px;
  animation: expandIn 0.2s ease;
}

@keyframes expandIn {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 2000px; }
}

.inline-detail-row:hover {
  background: var(--bg-primary) !important;
}

.inline-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

tr.row-expanded {
  background: var(--accent-light) !important;
}

.inline-detail-content .table-wrapper {
  margin-bottom: 8px;
}

.inline-detail-content .detail-panel {
  margin-bottom: 8px;
}

.inline-detail-content .empty-state {
  padding: 16px 12px;
}

/* Dashboard UTA links */
.dash-uta-link {
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s;
  white-space: nowrap;
}
.dash-uta-link:hover {
  background: var(--accent-light);
  text-decoration: underline;
}

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .material-icons { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* === Chart container === */
.chart-container {
  position: relative;
  height: 300px;
  margin-top: 16px;
}

/* === Theme Picker === */
.theme-picker-wrap {
  position: relative;
}

.theme-picker-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.theme-picker-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.theme-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 300;
  min-width: 180px;
}
.theme-dropdown.open { display: block; }

.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
}
.theme-option:hover { background: var(--bg-tertiary); }
.theme-option.active { background: var(--accent-light); }

.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.theme-option.active .theme-dot {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0;
    width: 280px;
    transform: translateX(-100%);
    z-index: 200;
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-close-btn { display: inline-flex; margin-left: auto; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 150;
    display: none;
  }

  .sidebar-overlay.active { display: block; }

  #menu-toggle { display: inline-flex; }

  .page-container { padding: 10px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .detail-panel { grid-template-columns: 1fr; }

  .modal { margin: 8px; max-width: calc(100% - 16px); max-height: 90vh; }
  .modal-body { max-height: 70vh; overflow-y: auto; }

  .table-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .table-toolbar .search-input { max-width: none; }
  .table-toolbar input[type="date"],
  .table-toolbar select { width: 100%; }

  /* Card header impilato su mobile */
  .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .card-header .btn-group { width: 100%; }

  /* Tabelle: font piu piccolo, celle compatte */
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  /* Bottoni piu grandi per touch */
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn-sm { min-height: 36px; }
  .btn-icon { min-width: 40px; min-height: 40px; }

  /* Topbar compatta */
  .topbar { padding: 8px 12px; }
  #page-title { font-size: 16px; }

  /* Form inputs piu grandi per touch */
  input, select, textarea { font-size: 16px !important; }

  /* Floor map: bottoni piano piu grandi */
  .floor-btn { padding: 8px 14px; font-size: 13px; }
  .floor-map-mode-btn { padding: 8px 12px; }

  /* Ticket badge riassuntivi */
  .tk-badge { padding: 3px 8px; font-size: 11px; }

  /* Training tabs scrollabili */
  .tr-tab { padding: 8px 12px; font-size: 12px; white-space: nowrap; }

  /* Nasconde colonne meno importanti nelle tabelle su mobile */
  .hide-mobile { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 12px; gap: 10px; }
  .stat-info h3 { font-size: 20px; }

  table { font-size: 11px; }
  th, td { padding: 5px 6px; }

  .modal { margin: 4px; max-width: calc(100% - 8px); }

  /* Mappa: altezza minima per visualizzare */
  .floor-map-page { height: auto; min-height: 60vh; }
  .map-container { min-height: 300px; }

  /* Legenda compatta */
  .map-legend { gap: 10px; font-size: 11px; flex-wrap: wrap; justify-content: center; }
}

/* === Floor Map === */
.floor-map-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-height) - 32px);
  gap: 8px;
}

.floor-selector {
  display: flex;
  gap: 8px;
  padding: 8px 0;
}

.floor-btn {
  padding: 8px 20px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.floor-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.floor-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.placing-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--warning);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
}

.map-container {
  flex: 1;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  cursor: grab;
  position: relative;
  touch-action: none;
}

.map-viewport {
  position: relative;
  transform-origin: 0 0;
  transition: none;
}

.floor-svg {
  width: 100%;
  height: 100%;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.markers-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.uta-marker-wrap {
  position: absolute;
  transform: translate(-11px, -11px);
  transform-origin: 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  pointer-events: all;
  z-index: 1;
  white-space: nowrap;
}

.uta-marker-wrap:hover {
  z-index: 10;
}

.uta-marker-wrap:hover .uta-marker {
  transform: scale(1.3);
}

.uta-marker-wrap.marker-dragging {
  z-index: 100;
  opacity: 0.8;
}
.uta-marker-wrap.marker-dragging .uta-marker {
  transform: scale(1.5);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.uta-marker {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}

.uta-marker-label {
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.75);
  border-radius: 4px;
  padding: 2px 5px;
  line-height: 1.2;
}

.marker-code {
  font-size: 10px;
  font-weight: 700;
  color: #000;
}

.marker-desc {
  font-size: 8px;
  color: #000;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.marker-ok      { background: #4CAF50; }
.marker-warning { background: #FDD835; }
.marker-danger  { background: #FF9800; }

.map-legend {
  display: flex;
  gap: 20px;
  padding: 8px 0;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.3);
}

.legend-ok      { background: #4CAF50; }
.legend-warning { background: #FDD835; }
.legend-danger  { background: #FF9800; }

.map-controls {
  position: absolute;
  bottom: 60px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.map-controls .btn-icon {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.uta-popup-info p {
  margin: 4px 0;
  color: var(--text-primary);
}

.uta-popup-info strong {
  color: var(--text-secondary);
}

/* Editor modifica sanificazione */
.san-photos-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 80px;
  background: #fafafa;
}
.san-photo-edit-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
}
.san-photo-edit-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  display: block;
}
.san-photo-new {
  background: #e8f5e9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.san-photo-new-label {
  font-size: 10px;
  text-align: center;
  color: #2e7d32;
  padding: 4px;
  word-break: break-all;
  line-height: 1.2;
}
.san-photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(220, 53, 69, 0.95);
  color: white;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.san-photo-remove:hover {
  background: #b71c1c;
}
.san-steps-edit {
  max-height: 280px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
}
.san-step-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  font-size: 13px;
  cursor: pointer;
}
.san-step-item:last-child {
  border-bottom: none;
}
.san-step-item input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
}

/* Floor map mode toggle */
.floor-map-mode-btn {
  opacity: 0.5;
  border: 1px solid var(--border);
}
.floor-map-mode-btn.active {
  opacity: 1;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Training tabs */
.tr-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tr-tab:hover { color: var(--text); }
.tr-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Training matrix cells */
.tr-cell-ok { background: rgba(76,175,80,0.2); color: #4CAF50; }
.tr-cell-expiring { background: rgba(253,216,53,0.2); color: #F9A825; }
.tr-cell-expired { background: rgba(255,152,0,0.2); color: #FF9800; }
.tr-cell-fail { background: rgba(244,67,54,0.15); color: #F44336; }
.tr-cell-none { color: var(--text-muted); }

.tr-legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 4px;
}
