:root {
  --bg: #0a0e14;
  --surface: #151c28;
  --surface-2: #1c2535;
  --border: #2a3548;
  --text: #f0f4fa;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-pressed: #2563eb;
  --danger: #ef4444;
  --danger-pressed: #dc2626;
  --ok: #22c55e;
  --ok-pressed: #16a34a;
  --radius: 16px;
  --touch: 52px;
  --page-pad: clamp(10px, 3.2vw, 20px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bar-h: calc(60px + var(--safe-bottom));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  min-height: -webkit-fill-available;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
  padding: calc(10px + var(--safe-top)) var(--page-pad) 10px;
  padding-left: max(var(--page-pad), var(--safe-left));
  padding-right: max(var(--page-pad), var(--safe-right));
  background: rgba(10, 14, 20, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  width: 100%;
}

.header-inner h1 {
  margin: 0;
  font-size: clamp(1.4rem, 5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}

.app-brand:active {
  opacity: 0.85;
}

.app-brand--static {
  cursor: default;
  justify-content: center;
  margin-bottom: 8px;
}

.app-brand--static:active {
  opacity: 1;
}

.app-brand-icon {
  flex-shrink: 0;
  display: block;
  border-radius: 22%;
  object-fit: cover;
}

.app-brand-text {
  margin: 0;
  font-size: clamp(1.4rem, 5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.login-card .app-brand-text {
  font-size: 1.75rem;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 3.5vw, 1.05rem);
}

.home-summary {
  margin: 6px 0 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.home-summary::-webkit-scrollbar {
  display: none;
}

.home-summary__line {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.68rem, 2.4vw, 0.82rem);
  line-height: 1.35;
  white-space: nowrap;
  flex-shrink: 0;
}

.home-summary__line:not(:last-child)::after {
  content: '·';
  margin-left: 8px;
  color: var(--border);
  font-weight: 400;
}

.home-summary__line strong {
  color: var(--text);
  font-weight: 600;
}

.home-changelog {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(59, 130, 246, 0.45);
  background: rgba(59, 130, 246, 0.12);
  position: relative;
}

.home-changelog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.home-changelog__titles {
  flex: 1;
  min-width: 0;
}

.home-changelog__title {
  margin: 0;
  font-size: clamp(0.95rem, 3.5vw, 1.05rem);
  font-weight: 700;
  color: var(--text);
}

.home-changelog__version {
  margin: 2px 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.home-changelog__close {
  width: 34px;
  height: 34px;
  font-size: 1.35rem;
  line-height: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  flex-shrink: 0;
}

.home-changelog__close:hover,
.home-changelog__close:focus-visible {
  color: var(--text);
  border-color: var(--accent);
}

.home-changelog__list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: clamp(0.85rem, 3vw, 0.92rem);
  line-height: 1.45;
  color: var(--text);
}

.home-changelog__list li {
  margin-bottom: 4px;
}

.home-changelog__list li::marker {
  color: var(--accent);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: var(--page-pad);
  padding-left: max(var(--page-pad), var(--safe-left));
  padding-right: max(var(--page-pad), var(--safe-right));
  padding-bottom: var(--bar-h);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel {
  width: 100%;
}

.panel.hidden { display: none; }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: clamp(1rem, 4vw, 1.15rem);
  line-height: 1.5;
  padding: 3rem 0.5rem;
}

.locale-header {
  width: 100%;
  margin-bottom: clamp(16px, 4vw, 24px);
  padding: 4px 2px;
}

.locale-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.locale-header h2 {
  margin: 0;
  font-size: clamp(1.75rem, 7vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.btn-locale-edit {
  width: 40px;
  height: 40px;
  font-size: 1.15rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.btn-locale-edit:hover,
.btn-locale-edit:focus-visible {
  color: var(--text);
  border-color: var(--accent);
}

.locale-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 4vw, 1.2rem);
}

.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.5vw, 14px);
}

.locale-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: clamp(72px, 18vw, 84px);
  height: clamp(72px, 18vw, 84px);
  box-sizing: border-box;
  padding: 0 clamp(18px, 4.5vw, 24px);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
}

.locale-card:active,
.locale-card--pressing {
  background: var(--surface-2);
  transform: scale(0.99);
}

.locale-card-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
  flex: 1;
}

.locale-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  flex: 1;
  min-width: 0;
}

.locale-name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: clamp(1.25rem, 5.5vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  word-break: break-word;
}

.locale-device-stars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  line-height: 1;
}

.locale-device-star {
  display: inline-block;
  font-size: clamp(1rem, 4.2vw, 1.15rem);
  line-height: 1;
  transition: color 0.2s ease, -webkit-text-stroke 0.2s ease;
}

.locale-device-star--on {
  color: #facc15;
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.45);
  -webkit-text-stroke: 0 transparent;
}

.locale-device-star--off {
  color: transparent;
  -webkit-text-stroke: 1.5px #ca8a04;
  paint-order: stroke fill;
  opacity: 0.95;
}

.locale-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: clamp(0.85rem, 3.2vw, 1rem);
  font-weight: 500;
  white-space: nowrap;
}

.chevron {
  font-size: clamp(1.4rem, 5vw, 1.75rem);
  line-height: 1;
  opacity: 0.45;
  font-weight: 300;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 3vw, 16px);
  width: 100%;
}

.device-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 4vw, 20px);
}

.device-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.device-card h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: clamp(1.15rem, 4.5vw, 1.35rem);
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 20px;
  font-size: clamp(0.8rem, 3vw, 0.9rem);
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  flex-shrink: 0;
}

.status-pill.online { color: var(--ok); }
.status-pill.offline { color: var(--danger); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--touch);
  padding: 14px 18px;
  border: none;
  border-radius: 14px;
  font-size: clamp(1rem, 4vw, 1.1rem);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:active { background: var(--accent-pressed); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-toggle.on {
  background: var(--ok);
  color: #fff;
}
.btn-toggle.on:active { background: var(--ok-pressed); }

.btn-toggle.off {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  min-height: 56px;
  font-size: clamp(1.05rem, 4.2vw, 1.15rem);
}
.btn-danger:active { background: var(--danger-pressed); }

.btn-block { width: 100%; }

.move-select {
  width: 100%;
  min-height: var(--touch);
  margin-top: 12px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: clamp(1rem, 4vw, 1.05rem);
  appearance: none;
  -webkit-appearance: none;
}

.app-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  gap: clamp(8px, 2.5vw, 12px);
  width: 100%;
  min-height: var(--bar-h);
  padding: 8px var(--page-pad) calc(8px + var(--safe-bottom));
  padding-left: max(var(--page-pad), var(--safe-left));
  padding-right: max(var(--page-pad), var(--safe-right));
  background: rgba(10, 14, 20, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

.app-bar--solo .bar-btn-primary {
  flex: 1;
  width: 100%;
}

.bar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 0 clamp(16px, 4vw, 24px);
  border: none;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: clamp(1rem, 4vw, 1.125rem);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.bar-btn:active { transform: scale(0.98); }

.bar-btn-back {
  flex-shrink: 0;
  min-width: clamp(88px, 24vw, 110px);
}

.bar-btn-primary {
  flex: 1;
  min-width: 0;
  background: var(--accent);
  color: #fff;
}
.bar-btn-primary:active { background: var(--accent-pressed); }

.bar-btn-text {
  white-space: nowrap;
}

.bar-icon {
  font-size: clamp(1.4rem, 5vw, 1.6rem);
  line-height: 1;
  font-weight: 400;
}

dialog {
  margin: auto;
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100%;
  width: 100%;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog[open] {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  max-height: 100dvh;
  width: 100%;
}

.sheet-form {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 8px var(--page-pad) calc(20px + var(--safe-bottom));
  padding-left: max(var(--page-pad), var(--safe-left));
  padding-right: max(var(--page-pad), var(--safe-right));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  margin: 4px auto 16px;
  border-radius: 2px;
  background: var(--border);
}

.sheet-form h3 {
  margin: 0 0 20px;
  font-size: clamp(1.25rem, 5vw, 1.5rem);
  font-weight: 700;
}

.field {
  display: block;
  margin-bottom: 16px;
  width: 100%;
}

.field span {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(0.9rem, 3.5vw, 1rem);
  color: var(--muted);
  font-weight: 500;
}

.field input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.hint {
  font-size: clamp(0.85rem, 3.2vw, 0.95rem);
  color: var(--muted);
  margin: -8px 0 16px;
  line-height: 1.4;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.toast {
  position: fixed;
  left: max(var(--page-pad), var(--safe-left));
  right: max(var(--page-pad), var(--safe-right));
  bottom: calc(var(--bar-h) + 12px);
  z-index: 30;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: clamp(0.95rem, 3.8vw, 1.05rem);
  line-height: 1.4;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.toast:not(.hidden) {
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Navigazione a passi --- */
.screen-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.device-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  overflow: hidden;
}

.device-view-header .status-pill {
  flex-shrink: 0;
  max-width: min(140px, 40%);
}

.device-view-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 6vw, 2rem);
  font-weight: 700;
  flex: 1;
  word-break: break-word;
}

.device-gestione-dates {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: grid;
  gap: 8px;
}

.device-gestione-date-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 12px;
}

.device-gestione-date-row dt {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

.device-gestione-date-row dd {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

.device-view-id {
  margin: 0 0 20px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.95rem;
  color: var(--muted);
  word-break: break-all;
}

.btn-program-main {
  min-height: 56px;
  font-size: 1.1rem;
  margin: 16px 0 8px;
}

.hint-center {
  text-align: center;
  margin-bottom: 20px;
}

/* --- Lista dispositivi nel locale --- */
.device-rows {
  gap: 10px;
}

.device-card-btn {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 72px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.device-card-btn:active {
  transform: scale(0.99);
  background: var(--surface-2);
}

.device-card-btn__accent {
  width: 4px;
  flex-shrink: 0;
  background: var(--muted);
  transition: background 0.2s ease;
}

.device-card-btn--online .device-card-btn__accent {
  background: var(--ok);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.5);
}

.device-card-btn--offline .device-card-btn__accent {
  background: var(--danger);
  opacity: 0.85;
}

.device-card-btn__content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 14px 12px 14px 14px;
}

.device-card-btn__name {
  font-size: clamp(1.05rem, 4.2vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  word-break: break-word;
}

.device-card-btn__chevron {
  display: flex;
  align-items: center;
  padding-right: 16px;
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--muted);
  opacity: 0.5;
  flex-shrink: 0;
}

.device-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  box-sizing: border-box;
}

.device-status-chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.device-status-chip--online {
  color: #86efac;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.device-status-chip--online .device-status-chip__dot {
  background: var(--ok);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
}

.device-status-chip--offline {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.28);
}

.device-status-chip--offline .device-status-chip__dot {
  background: var(--danger);
}

/* --- Controlli dispositivo (scheda) --- */
.device-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin: 16px 0 20px;
}

.device-ctrl {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  min-height: 72px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.device-ctrl:active {
  transform: scale(0.98);
}

.device-ctrl__label {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.device-ctrl__state {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
}

.device-ctrl__hint {
  font-size: 0.75rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  margin-top: 2px;
}

.device-ctrl--toggle.device-ctrl--off {
  background: var(--surface-2);
  border-color: var(--border);
}

.device-ctrl--toggle.device-ctrl--off .device-ctrl__state {
  color: var(--muted);
}

.device-ctrl--toggle.device-ctrl--on {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.45);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.device-ctrl--toggle.device-ctrl--on .device-ctrl__state {
  color: #4ade80;
}

.device-ctrl--emergenza {
  grid-column: 1 / -1;
  align-items: center;
  text-align: center;
  min-height: 56px;
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.18) 0%, rgba(239, 68, 68, 0.08) 100%);
  border-color: rgba(239, 68, 68, 0.45);
}

.device-ctrl--emergenza .device-ctrl__label {
  font-size: 1.05rem;
  color: #fca5a5;
  width: 100%;
  text-align: center;
}

.device-ctrl--emergenza:active {
  background: var(--danger);
  border-color: var(--danger);
}

.device-ctrl--emergenza:active .device-ctrl__label,
.device-ctrl--emergenza:active .device-ctrl__hint {
  color: #fff;
}

.device-ctrl:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Menu opzioni dispositivo */
.device-menu-list {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.device-menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease;
}

.device-menu-item:last-child {
  border-bottom: none;
}

.device-menu-item:active {
  background: var(--surface-2);
}

.device-menu-item__icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
}

.device-menu-item__label {
  flex: 1;
  min-width: 0;
}

.device-menu-item__chevron {
  flex-shrink: 0;
  font-size: 1.25rem;
  color: var(--muted);
  opacity: 0.45;
  font-weight: 300;
}

/* Toggle notifiche per dispositivo (gestione) */
.notify-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 0 8px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.notify-setting__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.notify-setting__title {
  font-size: 0.95rem;
  font-weight: 600;
}

.notify-setting__hint {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.toggle-switch {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 32px;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.toggle-switch__track {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.toggle-switch__track::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.toggle-switch input:checked + .toggle-switch__track {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.35);
}

.toggle-switch input:checked + .toggle-switch__track::after {
  transform: translateX(20px);
}

.toggle-switch input:disabled + .toggle-switch__track {
  opacity: 0.45;
  cursor: not-allowed;
}

.toggle-switch input:focus-visible + .toggle-switch__track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Programmazione --- */
#program-panel h2 {
  margin: 0 0 16px;
  font-size: clamp(1.35rem, 5vw, 1.6rem);
}

.workflow-box {
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.5;
}

.workflow-box p {
  margin: 0 0 8px;
}

.workflow-box--new {
  margin-top: 16px;
  border-color: var(--accent);
}

.workflow-box--new .section-title {
  margin-top: 0;
  color: var(--text);
}

.hint-box {
  padding: 10px 12px;
  margin: 10px 0;
  background: rgba(59, 130, 246, 0.12);
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.steps-list--tight {
  margin-bottom: 0;
}

.id-highlight {
  display: block;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1rem;
  color: var(--ok);
  word-break: break-all;
}

.steps-list {
  margin: 0 0 20px;
  padding-left: 1.25rem;
  line-height: 1.6;
  color: var(--muted);
}

.steps-list li {
  margin-bottom: 8px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.section-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.btn-file {
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
}

.btn-file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.ota-status-label {
  margin: 12px 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.details-advanced {
  margin-top: 20px;
}

.details-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.build-status {
  margin: 8px 0 12px;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}

.firmware-profile-pick {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.firmware-profile-pick .section-title {
  margin: 0 0 4px;
  padding: 0;
}

.firmware-profile-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.firmware-profile-option input {
  margin-top: 4px;
  flex-shrink: 0;
}

.firmware-profile-option__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.firmware-profile-option__text .hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: normal;
}

.flash-progress {
  margin: 10px 0 14px;
}

.flash-progress.hidden {
  display: none;
}

.flash-progress__track {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.flash-progress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.flash-progress__fill--indeterminate {
  width: 40% !important;
  animation: flash-progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes flash-progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

.flash-progress__label {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.usb-log {
  margin: 12px 0 0;
  padding: 12px;
  max-height: 160px;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
}

#firmware-code {
  width: 100%;
  min-height: 180px;
  max-height: 35vh;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
}

/* Tablet / desktop: contenuto centrato ma ancora ampio */
@media (min-width: 600px) {
  :root {
    --page-pad: clamp(16px, 3vw, 28px);
  }

  .app-main {
    max-width: min(100%, 680px);
    margin: 0 auto;
  }

  .app-header .header-inner {
    max-width: min(100%, 680px);
    margin: 0 auto;
  }

  .app-bar {
    max-width: min(100%, 680px);
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}

@media (min-width: 900px) {
  .app-main,
  .app-header .header-inner {
    max-width: 800px;
  }

  .app-bar {
    max-width: 800px;
  }

  dialog[open] {
    align-items: center;
  }

  .sheet-form {
    max-width: 520px;
    border-radius: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
  }
}

/* --- Login --- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--page-pad);
  padding-top: calc(var(--page-pad) + var(--safe-top));
  padding-bottom: calc(var(--page-pad) + var(--safe-bottom));
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.75rem;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-form .field {
  margin-bottom: 14px;
}

.login-error {
  min-height: 1.25em;
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 0.9rem;
}

.header-inner--toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.header-titles {
  flex: 1;
  min-width: 0;
}

.btn-hamburger {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  margin-top: 2px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn-hamburger span {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

body.side-menu-open .btn-hamburger span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.side-menu-open .btn-hamburger span:nth-child(2) {
  opacity: 0;
}

body.side-menu-open .btn-hamburger span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* --- Side menu --- */
.side-menu {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  visibility: hidden;
}

.device-sheet {
  z-index: 210;
}

.side-menu--open {
  pointer-events: auto;
  visibility: visible;
}

.side-menu-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.25s ease;
  cursor: pointer;
}

.side-menu--open .side-menu-backdrop {
  opacity: 1;
}

.side-menu-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 90vw);
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-right: var(--safe-right);
}

.side-menu--open .side-menu-panel {
  transform: translateX(0);
}

.side-menu-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.side-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.side-menu-header--sub {
  padding-left: 12px;
}

.side-menu-user {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.side-menu-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

.btn-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.side-menu-back {
  font-size: 1.75rem;
}

.side-menu-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.app-build-hint {
  margin: 0 18px 8px;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

.side-menu-footer {
  border-top: 1px solid var(--border);
  padding: 8px 0 12px;
}

.side-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--touch);
  padding: 14px 18px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.side-menu-item:active {
  background: var(--surface-2);
}

.side-menu-item-label {
  flex: 1;
}

.side-menu-chevron {
  color: var(--muted);
  font-size: 1.25rem;
}

.side-menu-item--danger {
  color: var(--danger);
}

.side-menu-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px 24px;
}

body.side-menu-open {
  overflow: hidden;
}

.btn-sm {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.9rem;
}

.operator-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.operatori-status {
  margin: 0 0 8px;
}

.anomaly-filter-field {
  margin-bottom: 12px;
}

.anomaly-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.anomaly-empty {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  padding: 8px 0;
}

.anomaly-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 44px 12px 12px;
  margin-bottom: 10px;
  position: relative;
  border-radius: 12px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.12);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.08);
}

.anomaly-row__badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #78350f;
  background: #fbbf24;
}

.anomaly-row__main {
  min-width: 0;
  flex: 1;
}

.anomaly-row__title {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
}

.anomaly-row__detail {
  margin: 0 0 2px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.35;
}

.anomaly-row__detail strong {
  color: #fbbf24;
}

.anomaly-row__when {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.anomaly-row--long-offline {
  border-color: rgba(96, 165, 250, 0.45);
  background: rgba(96, 165, 250, 0.1);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.08);
}

.anomaly-row--long-offline .anomaly-row__badge {
  color: #1e3a8a;
  background: #93c5fd;
  font-size: 0.85rem;
}

.anomaly-row--long-offline .anomaly-row__detail strong {
  color: #93c5fd;
}

.anomaly-row__repeat {
  margin: 4px 0 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fbbf24;
}

.anomaly-row__dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  font-size: 1.35rem;
  line-height: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.anomaly-row__dismiss:hover,
.anomaly-row__dismiss:focus-visible {
  color: var(--danger, #ef4444);
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.1);
}

.operator-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.operator-row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.operator-row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.operator-username {
  font-weight: 600;
}

.operator-self-tag {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.operator-dates {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
}

.operator-date-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.operator-date-row--login .operator-date-value {
  font-weight: 600;
  color: var(--text);
}

.operator-date-label {
  color: var(--muted);
  min-width: 9.5rem;
}

.operator-date-value {
  color: var(--muted);
}

.operator-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.operator-row-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.btn-sm-danger {
  color: var(--danger);
}

.btn-disabled,
button:disabled.btn-danger {
  opacity: 0.45;
  cursor: not-allowed;
}

.role-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  width: fit-content;
}

.role-badge--admin {
  background: rgba(59, 130, 246, 0.15);
  color: #2563eb;
}

.role-badge--operatore {
  background: rgba(34, 197, 94, 0.15);
  color: #15803d;
}

.operator-row:last-child {
  border-bottom: none;
}

.empty-operators {
  color: var(--muted);
  padding: 8px 0;
}

.operator-form {
  margin-bottom: 12px;
}

#device-panel {
  padding-bottom: 8px;
}

.device-sheet .side-menu-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.device-sheet-pane.hidden {
  display: none !important;
}

.device-sheet-pane:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.device-sheet-pane .move-select {
  margin-top: 0;
}

.device-sheet-pane .event-filter-field {
  margin-top: 0;
}

.device-sheet-pane .event-list {
  flex: 1;
  min-height: 120px;
}

.device-sheet .side-menu-title {
  margin: 0;
  font-size: 1.1rem;
}

.device-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

body.device-sheet-open {
  overflow: hidden;
}

.event-filter-field {
  margin: 12px 0 4px;
}

.event-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 280px;
  overflow-y: auto;
}

.event-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.event-row:last-child {
  border-bottom: none;
}

.event-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.event-row--on .event-dot {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.event-row--off .event-dot {
  background: var(--muted);
}

.event-row--on .event-label {
  color: var(--ok);
}

.event-time {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}
