/* ===== Variables & Base ===== */
:root {
  --bg-primary: #0f1419;
  --bg-secondary: #1a2332;
  --bg-tertiary: #243447;
  --bg-card: #1e2d3d;
  --text-primary: #e7e9ea;
  --text-secondary: #8b98a5;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --success: #00ba7c;
  --warning: #ffad1f;
  --danger: #f4212e;
  --border: #38444d;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  /* Layout responsive (vedi anche classi su html: .layout-narrow, .layout-touch) */
  --layout-break-mobile: 900px;
  --touch-min-target: 44px;
  --main-padding: 1.5rem;
  --main-padding-mobile: 0.75rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== Layout ===== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: linear-gradient(rgba(15, 20, 25, 0.7), rgba(15, 20, 25, 0.7)), url('../assets/login-bg.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.env-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(255, 173, 31, 0.2);
  color: var(--warning);
  border: 1px solid rgba(255, 173, 31, 0.5);
  vertical-align: middle;
}

.env-badge.hidden {
  display: none;
}

/* Homepage login: stesso badge Beta dell’header per riconoscere l’ambiente */
.login-page-brand {
  text-align: center;
  margin-bottom: 1rem;
}

.login-page-title {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.35;
  color: var(--text-primary);
  margin: 0 0 0.4rem 0;
}

.env-badge--login {
  vertical-align: baseline;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
}
.header-right #user-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}
.header-right #app-version {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.nav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.main {
  flex: 1;
  padding: 1.5rem;
  overflow: visible;
}

/* ===== Cards & Panels ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Opzioni disabilitate nelle tendine assegnazione turni (medici non idonei) */
select.slot-assign-select option:disabled {
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

/* ===== Buttons ===== */
.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card);
}

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

/** Esportazione PDF (Assenze, Piano turni) */
.btn-pdf {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--danger);
  color: white;
}
.btn-pdf .btn-pdf-icon {
  display: inline-flex;
  line-height: 0;
  flex-shrink: 0;
}
.btn-pdf .btn-pdf-icon svg {
  display: block;
  width: 1.1em;
  height: 1.1em;
}
.btn-pdf:hover:not(:disabled) {
  filter: brightness(0.92);
}
.btn-pdf:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

/* ===== Sliders ===== */
.slider-group {
  margin-bottom: 1rem;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.slider-group .slots-info {
  font-size: 0.8rem;
  color: var(--accent);
  font-family: var(--font-mono);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  background: var(--bg-tertiary);
  border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

/* ===== Checkboxes ===== */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

tr:hover td {
  background: rgba(29, 155, 240, 0.05);
}

/* ===== Grid / Calendar ===== */
.calendar-grid {
  display: grid;
  gap: 2px;
  font-size: 0.75rem;
}

.calendar-cell {
  padding: 0.35rem;
  min-height: 32px;
  min-width: 28px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.calendar-cell:hover {
  background: var(--bg-tertiary);
}

.calendar-cell.blocked,
.calendar-cell.libera-professione,
.calendar-cell.formazione,
.calendar-cell.desiderata {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.7rem;
  text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}

.calendar-cell.blocked,
.calendar-cell.libera-professione,
.calendar-cell.formazione {
  color: #fff;
}

.calendar-cell.blocked {
  background: var(--danger);
  opacity: 0.7;
}

.calendar-cell.desiderata {
  background: var(--warning);
  opacity: 0.6;
  color: #1a1a1a;
}

.calendar-cell.libera-professione {
  background: #0d9488;
  opacity: 0.8;
}

.calendar-cell.formazione {
  background: #7c3aed;
  opacity: 0.8;
}

.calendar-cell.available {
  background: transparent;
}

.calendar-cell.selecting {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.calendar-table {
  -webkit-user-select: none;
  user-select: none;
}
/* Calendario assenze: scroll verticale con intestazione fissa */
.absences-table-wrapper {
  overflow-y: auto;
  max-height: 70vh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.absences-table-wrapper th,
.absences-table-wrapper td {
  -webkit-user-select: none;
  user-select: none;
}
.absences-table-wrapper .calendar-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-card);
  box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.2);
}
.absences-table-wrapper .calendar-table thead th {
  background: var(--bg-tertiary);
}

/* Assenze su telefono: bersagli touch ~44px, scroll orizzontale fluido; pointer capture in JS per la selezione periodi */
@media (max-width: 900px), (pointer: coarse) {
  .absences-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .absences-table-wrapper .calendar-table thead th:not(.calendar-col-medico) {
    min-width: 3rem;
    padding: 0.5rem 0.35rem;
    font-size: 0.82rem;
    line-height: 1.25;
  }
  .absences-table-wrapper .calendar-table td.calendar-cell-wrapper {
    min-width: 3rem;
    padding: 3px;
    vertical-align: middle;
  }
  .absences-table-wrapper .calendar-cell {
    min-width: 44px;
    min-height: 44px;
    padding: 0.45rem 0.35rem;
    touch-action: manipulation;
    box-sizing: border-box;
    font-size: 0.82rem;
  }
  .absences-table-wrapper .calendar-cell.blocked,
  .absences-table-wrapper .calendar-cell.libera-professione,
  .absences-table-wrapper .calendar-cell.formazione,
  .absences-table-wrapper .calendar-cell.desiderata {
    font-size: 0.8rem;
  }
  .absences-table-wrapper .calendar-table .calendar-col-medico {
    min-width: 6.75rem;
    max-width: 40vw;
    font-size: 0.9rem;
    padding: 0.5rem 0.45rem;
    white-space: normal;
    word-break: break-word;
  }

  /* Piano turni — vista a tabella: celle e header più grandi al touch */
  .shift-table-grid th,
  .shift-table-grid td {
    font-size: 0.85rem;
  }
  .shift-table-grid .grid-row-head {
    font-size: 0.85rem;
    max-width: 42vw;
    white-space: normal;
    width: auto;
    min-width: 7rem;
  }
  .shift-table-grid .grid-row-cat { font-size: 0.8rem; }
  .shift-table-grid .grid-row-time { font-size: 0.8rem; }
  .shift-table-grid .grid-day-head {
    width: auto;
    min-width: 48px;
    padding: 6px 4px;
  }
  .shift-table-grid .grid-day-letter { font-size: 0.9rem; }
  .shift-table-grid .grid-day-date { font-size: 0.75rem; }
  .shift-table-grid .grid-cell {
    height: auto;
    min-height: 2.85rem;
    min-width: 48px;
    padding: 4px;
    touch-action: manipulation;
  }
  .shift-table-grid .slot-cell-inner.view-table .grid-sigla {
    font-size: 0.88rem;
    padding: 0.2rem 0.45rem;
  }
}

/* Balance indicator (carico vs disponibilità) */
.balance-indicator,
.balance-indicator-section {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--border);
}
.balance-indicator.balance-ok,
.balance-indicator-row.balance-ok {
  background: rgba(0, 186, 124, 0.12);
  border-left-color: var(--success);
}
.balance-indicator.balance-deficit,
.balance-indicator-row.balance-deficit {
  background: rgba(244, 33, 46, 0.12);
  border-left-color: var(--danger);
}
.balance-indicator-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.balance-indicator-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.balance-indicator-row {
  padding: 0.35rem 0;
  border-radius: 4px;
  margin-bottom: 0.25rem;
  padding-left: 0.5rem;
  border-left: 3px solid transparent;
}
.balance-indicator-row:last-child {
  margin-bottom: 0;
}

.calendar-table th,
.calendar-table td {
  border-right: 1px solid var(--border);
}

/* Prima colonna (medico) fissa durante lo scroll orizzontale */
.calendar-table .calendar-col-medico {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-card);
  box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.15);
}
.calendar-table thead .calendar-col-medico {
  background: var(--bg-tertiary);
  z-index: 2;
}
.calendar-table tbody tr:hover .calendar-col-medico {
  background: rgba(29, 155, 240, 0.05);
}

/* Colonne giorni festivi (sabato, domenica, festivi infrasettimanali) */
.calendar-table th.day-festivo,
.calendar-table td.day-festivo {
  background: rgba(120, 86, 255, 0.12);
}

/* Card Riepilogo Assenze: font ridotto e tabella compatta */
.summary-absences-card {
  font-size: 0.9rem;
}
.summary-absences-card .card-title {
  font-size: 1rem;
}
.summary-absences-card .table-wrapper {
  display: inline-block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
}
.summary-absences-card .table-wrapper .summary-absences-table {
  table-layout: auto;
  width: max-content;
}
.summary-absences-table th,
.summary-absences-table td {
  padding: 0.35rem 0.5rem;
}
.summary-absences-table .summary-cell {
  white-space: nowrap;
  text-align: center;
}
.summary-absences-table .calendar-col-medico {
  white-space: nowrap;
  text-align: left;
}
/* Valori oltre il massimo in rosso */
.summary-absences-table .summary-cell.summary-over {
  background: rgba(244, 33, 46, 0.12);
}
.summary-absences-table .summary-cell.summary-over .summary-val-over,
.summary-absences-table .summary-cell.summary-over {
  color: var(--danger);
  font-weight: 600;
}

.calendar-summary .week-cell {
  cursor: pointer;
  min-height: 2.5rem;
  vertical-align: top;
}
.calendar-summary .week-cell:hover {
  background: rgba(29, 155, 240, 0.08);
}
.calendar-summary .week-slot-badge:hover {
  opacity: 0.9;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 4px;
  font-weight: 500;
}

.badge-ti { background: #1d9bf033; color: #1d9bf0; }
.badge-so { background: #00ba7c33; color: #00ba7c; }
.badge-nora { background: #34d39933; color: #34d399; }
.badge-md { background: #ffad1f33; color: #ffad1f; }
.badge-cp { background: #fb923c33; color: #fb923c; }
.badge-formazione { background: #818cf833; color: #a5b4fc; }
.badge-dir { background: #7856ff33; color: #a78bfa; }

.calendar-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 1rem 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.calendar-tab {
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
}
.calendar-tab:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}
.calendar-tab.is-active {
  color: var(--text-primary);
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.calendar-tab-panel {
  display: none;
  padding-top: 0.25rem;
}
.calendar-tab-panel.is-active {
  display: block;
}

.template-wd-row .template-wd-label {
  cursor: pointer;
  user-select: none;
}

.badge-draggable {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.badge-draggable:active { cursor: grabbing; }

/* Piano turni: blocca selezione testo sul documento durante drag-and-drop */
body.planner-dnd-active {
  user-select: none;
  -webkit-user-select: none;
}

.slot-lock-icon {
  cursor: pointer;
  font-size: 1.2rem;
  margin-left: 5px;
  padding: 2px;
  border-radius: 4px;
  transition: all 0.2s;
}
.slot-lock-icon.locked {
  color: #ef4444; /* Red */
  opacity: 1;
  background: rgba(239, 68, 68, 0.1);
}
.slot-lock-icon.unlocked {
  color: #9ca3af; /* Grey */
  opacity: 0.5;
  filter: grayscale(100%);
}
.slot-lock-icon.unlocked:hover {
  opacity: 1;
  color: #22c55e; /* Green on hover */
  background: rgba(34, 197, 94, 0.1);
}
.badge-draggable.dragging { opacity: 0.5; }
.slot-cell-inner {
  min-height: 2.5rem;
}
.slot-cell-inner.drag-over {
  background: rgba(29, 155, 240, 0.2);
  outline: 2px dashed var(--accent);
}

.slot-cell-inner.slot-uncovered {
  background: rgba(244, 33, 46, 0.15);
  border: 1px dashed var(--danger);
  border-radius: var(--radius);
}

/* Piano Turni layout con sidebar */
.shift-planner-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}
.shift-planner-main { flex: 1; min-width: 0; }
.shift-planner-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.shift-planner-sidebar .sidebar-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}
.shift-planner-sidebar .sidebar-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.shift-planner-sidebar .sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.shift-planner-sidebar .sidebar-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.shift-planner-sidebar .sidebar-list li:last-child { border-bottom: none; }
.week-badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.15rem 0.4rem;
  background: var(--warning);
  color: var(--bg-primary);
  border-radius: 4px;
  font-size: 0.75rem;
}
.week-badge-sotto { background: var(--warning); color: var(--bg-primary); }
.week-badge-ok { background: #22c55e; color: #fff; }
.week-badge-sopra { background: #f97316; color: #fff; }
.week-badge-empty { background: var(--bg-secondary); color: var(--text-secondary); opacity: 0.7; }
.week-badge-over { background: #f97316; color: #fff; }

.shift-planner-sidebar-stable { min-width: 220px; max-width: 320px; }
.sidebar-status-table-wrapper { overflow-x: auto; max-height: 88vh; overflow-y: auto; }
.sidebar-status-table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
}
.sidebar-status-table th,
.sidebar-status-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.sidebar-status-table th { font-weight: 600; color: var(--text-secondary); text-align: center; }
.sidebar-status-table td:first-child { white-space: normal; }
.sidebar-status-table .week-badge { margin: 0; display: block; text-align: center; }

/* Piano Turni: sticky intestazioni e card stato settimana */
.week-block {
  margin-bottom: 2rem;
  padding: 1rem;
  overflow: visible;
}
.week-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.45rem 0.25rem 0.6rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.week-title-iso {
  font-weight: 600;
}
.week-title-range {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
}
.week-lock-btn {
  cursor: pointer;
  font-size: 1.2rem;
  margin-left: 0.25rem;
}
.week-archived-badge {
  font-size: 0.75rem;
}
.week-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}
.week-shifts {
  flex: 1;
  min-width: 300px;
  overflow: visible;
}
.week-shifts .shift-table {
  border-collapse: separate;
  border-spacing: 0;
}
.week-shifts .shift-table thead th {
  position: sticky;
  top: var(--week-sticky-offset, 3.6rem);
  z-index: 24;
  background: var(--bg-tertiary);
  box-shadow: 0 1px 0 var(--border);
}
.week-stats {
  width: 300px;
  flex-shrink: 0;
  align-self: flex-start;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.5rem;
  position: sticky;
  top: var(--week-sticky-offset, 3.6rem);
  max-height: calc(100vh - 4rem);
  overflow: auto;
}
.week-stats-title {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}
.week-stats-content .sidebar-status-table {
  font-size: 0.8rem;
}

/* Squadre weekend */
.weekend-teams-section {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.weekend-teams-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 0.5rem;
}
.weekend-teams-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
}
.weekend-team-card {
  padding: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.weekend-team-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.weekend-team-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.weekend-team-slots select {
  flex: 1 1 85px;
  min-width: 70px;
  max-width: 110px;
}

@media (max-width: 1100px) {
  .week-shifts .shift-table thead th {
    top: 0;
  }
  .week-stats {
    position: static;
    max-height: none;
  }
}

/* ===== Vista a tabella (posti = righe, giorni = colonne) ===== */
.shift-table-grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
.shift-table-grid th,
.shift-table-grid td {
  border: 1px solid var(--border);
  padding: 0;
  vertical-align: middle;
  font-size: 0.78rem;
}
.shift-table-grid thead th {
  position: sticky;
  top: var(--week-sticky-offset, 3.6rem);
  z-index: 24;
  background: var(--bg-tertiary);
  box-shadow: 0 1px 0 var(--border);
  padding: 4px 2px;
  text-align: center;
  font-weight: 600;
}
.shift-table-grid .grid-row-head {
  text-align: left;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 3px 6px;
  width: 14ch;
  max-width: 180px;
  background: var(--bg-tertiary);
  white-space: nowrap;
}
.shift-table-grid tbody .grid-row-head {
  position: sticky;
  left: 0;
  z-index: 5;
}
.shift-table-grid .grid-row-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.shift-table-grid .grid-row-cat { font-size: 0.72rem; padding: 1px 5px; }
.shift-table-grid .grid-row-time {
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.shift-table-grid .grid-day-head {
  width: 60px;
  min-width: 40px;
}
.shift-table-grid .grid-day-letter { font-weight: 700; font-size: 0.82rem; }
.shift-table-grid .grid-day-date { font-size: 0.7rem; color: var(--text-secondary); }
.shift-table-grid .grid-day-weekend {
  background: rgba(249, 115, 22, 0.12);
}
.shift-table-grid .grid-cell {
  height: 2.2rem;
  padding: 2px;
  text-align: center;
  position: relative;
}
/* Vista tabella: turni diurni = pastello chiaro (tinte per categoria); TI notte e reper = traslucido scuro come i vecchi diurni TI */

.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #e0f2fe 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #d1fae5 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #a7f3d0 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #fef3c7 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #ffedd5 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #e0e7ff 82%, var(--bg-primary) 18%);
}
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) {
  background: color-mix(in srgb, #ede9fe 82%, var(--bg-primary) 18%);
}

/* TI notte: stesso schema scuro che avevano i diurni TI */
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte {
  background: #1d9bf028;
  color: var(--text-primary);
}
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-cell-inner.view-table .grid-sigla {
  color: inherit;
}
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-cell-inner.view-table .grid-empty-mark {
  color: var(--text-secondary);
  opacity: 0.65;
}
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-lock-icon.unlocked {
  color: #94a3b8;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-lock-icon.locked {
  color: #fca5a5;
}

/* Reperibilità: verde traslucido scuro (come contrasto coi diurni a pastello) */
.shift-table-grid .grid-cell.cat-bg-rep-slot {
  background: #00ba7c28;
  color: var(--text-primary);
}
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-cell-inner.view-table .grid-sigla {
  color: inherit;
}
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-cell-inner.view-table .grid-empty-mark {
  color: var(--text-secondary);
  opacity: 0.65;
}
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-lock-icon.unlocked {
  color: #86efac;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-lock-icon.locked {
  color: #fca5a5;
}

/* Pastelli: testo scuro per contrasto sulle celle chiare */
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) {
  color: #0c4a6e;
}
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #075985;
}
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #0c4a6e;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #64748b;
  opacity: 0.85;
}
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) {
  color: #14532d;
}
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #166534;
}
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #14532d;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #4d7c4f;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) {
  color: #064e3b;
}
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #047857;
}
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #064e3b;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #0f766e;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) {
  color: #78350f;
}
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #b45309;
}
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #78350f;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #a16207;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) {
  color: #7c2d12;
}
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #c2410c;
}
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #7c2d12;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #9a3412;
  opacity: 0.9;
}
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) {
  color: #312e81;
}
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #4338ca;
}
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #312e81;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #6366f1;
  opacity: 0.85;
}
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) {
  color: #4c1d95;
}
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-sigla {
  color: #6d28d9;
}
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-cell-inner.view-table .grid-empty-mark {
  color: #4c1d95;
  opacity: 0.55;
}
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-lock-icon.unlocked {
  color: #7c3aed;
  opacity: 0.85;
}
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-lock-icon.locked {
  color: #b91c1c;
}

.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-cell-inner.view-table.slot-uncovered {
  color: #fecaca;
}
.shift-table-grid .grid-cell.cat-bg-ti.cat-bg-ti-notte .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-rep-slot .slot-cell-inner.view-table.slot-uncovered .grid-sigla {
  color: #fecaca;
}

.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered,
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered {
  color: #991b1b;
}
.shift-table-grid .grid-cell.cat-bg-ti:not(.cat-bg-ti-notte):not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-so:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-nora:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-md:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-cp:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-formazione:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla,
.shift-table-grid .grid-cell.cat-bg-dir:not(.cat-bg-rep-slot) .slot-cell-inner.view-table.slot-uncovered .grid-sigla {
  color: #991b1b;
}

/* Toolbar Piano Turni: filtri su prima riga, tutti i bottoni su seconda riga in linea */
.planner-toolbar {
  margin-bottom: 1rem;
}
.planner-toolbar-filters {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.planner-toolbar-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem 0.65rem;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.planner-toolbar-actions .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.shift-table-grid .grid-cell-na {
  background: repeating-linear-gradient(45deg, var(--bg-secondary) 0 4px, var(--bg-tertiary) 4px 8px);
  color: var(--text-secondary);
  opacity: 0.5;
  cursor: not-allowed;
  font-size: 0.7rem;
}
.shift-table-grid .grid-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}

/* Cella slot compatta in vista tabella */
.slot-cell-inner.view-table {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 1.8rem;
  padding: 2px 4px;
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}
.slot-cell-inner.view-table .slot-assign-select {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  width: 100%;
  max-width: 260px;
  font-size: 0.8rem;
}
/* Cella con tendina aperta sopra intestazione settimana sticky e thead della tabella */
.slot-cell-inner.view-table[data-open="1"] {
  z-index: 50;
}
.slot-cell-inner.view-table[data-open="1"] .slot-assign-select {
  display: block;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 51;
  width: max-content;
  min-width: 220px;
  max-height: min(55vh, 320px);
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
}
.slot-cell-inner.view-table .badge-draggable.grid-sigla.table-drag-armed {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  cursor: grab;
}
.slot-cell-inner.view-table .grid-sigla {
  font-weight: 700;
  font-size: 0.82rem;
  padding: 2px 6px;
  letter-spacing: 0.3px;
  cursor: grab;
}
.slot-cell-inner.view-table .grid-sigla:active { cursor: grabbing; }
.slot-cell-inner.view-table .grid-empty-mark {
  color: var(--text-secondary);
  font-size: 0.9rem;
  opacity: 0.5;
}
.slot-cell-inner.view-table .slot-lock-icon {
  font-size: 0.9rem;
  margin-left: 2px;
  padding: 0;
}
.slot-cell-inner.view-table.slot-uncovered {
  background: rgba(244, 33, 46, 0.12);
  border: 1px dashed var(--danger);
}
.slot-cell-inner.view-table.drag-over {
  background: rgba(29, 155, 240, 0.22);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  box-sizing: border-box;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: min(90vh, 100dvh - 2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ===== Desiderata selector ===== */
.desiderata-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.desiderata-option {
  padding: 0.35rem 0.65rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.desiderata-option:hover,
.desiderata-option.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.slot-absence-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.slot-absence-option {
  padding: 0.35rem 0.65rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.slot-absence-option:hover,
.slot-absence-option.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ===== Workload / Carichi ===== */
.workload-section {
  margin-top: 1.5rem;
}
.workload-section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}
.workload-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.workload-table th,
.workload-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.workload-table th { color: var(--text-secondary); font-weight: 500; }
.workload-table .negative { color: var(--warning); }
.workload-table .over { color: var(--danger); }
.workload-table .under { color: var(--warning); }
.workload-table-small { font-size: 0.85rem; }
.workload-table-small th, .workload-table-small td { padding: 0.35rem 0.5rem; }
.workload-history-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.workload-history-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-width: 180px;
}
.workload-history-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.workload-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* ===== Layout mobile / touch (html.layout-* da js/device.js) ===== */
html.layout-narrow .main {
  padding: var(--main-padding-mobile);
  padding-bottom: calc(var(--main-padding-mobile) + var(--safe-bottom));
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.header-brand h1 {
  font-size: clamp(0.85rem, 3.5vw, 1.25rem);
  line-height: 1.25;
  margin: 0;
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min-target);
  min-height: var(--touch-min-target);
  padding: 0.35rem 0.65rem;
  flex-shrink: 0;
}

.nav-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .nav-toggle {
    display: inline-flex;
  }

  .header:not(.header--nav-open) #main-nav {
    display: none !important;
  }

  .header.header--nav-open #main-nav {
    display: flex !important;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(320px, calc(100vw - 2rem));
    max-height: min(480px, 72vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1001;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding: 0.75rem;
    margin: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
  }

  .header.header--nav-open .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.55);
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }

  .header-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-left: 0 !important;
    row-gap: 0.5rem;
  }

  .header-right .btn-sm {
    min-height: var(--touch-min-target);
    padding: 0.45rem 0.75rem;
  }

  .header-right #app-version {
    width: 100%;
    white-space: normal;
    font-size: 0.7rem;
  }

  .nav-btn {
    min-height: var(--touch-min-target);
    justify-content: center;
    text-align: center;
  }

  .modal-overlay {
    padding: 0.65rem;
    padding-bottom: calc(0.65rem + var(--safe-bottom));
  }

  .modal-overlay .modal {
    max-height: min(88vh, 100dvh - 1.5rem);
  }

  .planner-toolbar-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .planner-toolbar-actions .btn {
    min-height: var(--touch-min-target);
  }

  .shift-planner-layout {
    flex-direction: column;
  }

  .shift-planner-sidebar,
  .shift-planner-sidebar-stable {
    width: 100%;
    max-width: none;
  }

  .week-layout {
    flex-direction: column;
  }

  .week-shifts {
    min-width: 0;
    width: 100%;
  }

  .calendar-tab {
    min-height: var(--touch-min-target);
    padding: 0.5rem 0.75rem;
  }

  .calendar-summary th,
  .calendar-summary td {
    padding: 0.45rem 0.35rem;
    font-size: 0.82rem;
  }

  .doctor-profile .form-group input,
  .doctor-profile .form-group select {
    min-height: var(--touch-min-target);
  }

  .manual-view .manual-section-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .workload-table {
    font-size: 0.88rem;
  }

  .workload-table th,
  .workload-table td {
    padding: 0.45rem 0.4rem;
  }

  .workload-history-grid {
    flex-direction: column;
  }

  .workload-history-card {
    min-width: 0;
    width: 100%;
  }

  .users-backup-card input#backup-label {
    width: 100% !important;
    max-width: 100%;
  }

  .manual-view-page {
    overflow-x: hidden;
  }

  .calendar-planner-root select[id="calendar-jump-week"] {
    max-width: 100%;
    min-width: 0;
  }

  .shift-planner-page .planner-toolbar select,
  .shift-planner-page .planner-toolbar input {
    max-width: 100%;
  }
}

@media (min-width: 901px) {
  .nav-toggle {
    display: none !important;
  }

  /* Prima riga: titolo + badge + azioni; seconda riga: voci menu (niente sovrapposizioni a finestra stretta) */
  .header-brand {
    order: 1;
    flex: 1 1 auto;
    min-width: min(100%, 12rem);
  }

  .header-right {
    order: 2;
    margin-left: auto;
    flex-shrink: 0;
    width: auto;
  }

  #main-nav {
    order: 3;
    display: flex !important;
    position: static !important;
    transform: none !important;
    flex: 1 1 100%;
    width: 100% !important;
    max-height: none !important;
    justify-content: flex-start;
    flex-wrap: wrap;
    row-gap: 0.5rem;
    column-gap: 0.5rem;
    padding: 0.5rem 0 0 0;
    margin: 0.15rem 0 0 0;
    background: transparent;
    border: none;
    border-top: 1px solid var(--border);
    box-shadow: none;
    overflow: visible;
  }

  .nav-backdrop {
    display: none !important;
  }
}

@media (pointer: coarse) {
  .btn:not(.btn-sm),
  .nav-btn {
    min-height: 42px;
  }

  .table-wrapper th,
  .table-wrapper td {
    padding: 0.55rem 0.5rem;
  }
}
