/* ============================================================
  HR-Plus - Stylesheet
  ============================================================ */

:root {
  /* COLORS */
  --primary: #E8724A;
  --primary-light: #F4956E;
  --primary-dark: #C85A35;
  --bg: #F0F2F5; /* Softer gray background */
  --sidebar-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --text: #2D3748; /* Darker main text */
  --text-muted: #718096;
  --border: #EDF2F7; /* Very light border */
  --border-focus: #E8724A;

  /* STATUS COLORS */
  --scaduto-bg: #FFF5F5;
  --scaduto-text: #E53E3E;
  --urgente-bg: #FEEBC8;
  --urgente-text: #DD6B20;
  --inscad-bg: #FFFFF0;
  --inscad-text: #D69E2E;
  --ok-bg: #F0FFF4;
  --ok-text: #38A169;

  /* SHADOWS & RADIUS */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
  --radius: 16px; /* Increased radius */
  --radius-sm: 8px;

  /* TRANSITIONS */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme opzionale (default resta light) */
html.dark-theme {
  --bg: #0F1623;
  --sidebar-bg: #111A2A;
  --card-bg: #162238;
  --text: #E6EDF7;
  --text-muted: #9BAAC2;
  --border: #22314A;
  --border-focus: #F08B67;

  --scaduto-bg: #3B1E24;
  --scaduto-text: #F3A7B1;
  --urgente-bg: #3B2D1D;
  --urgente-text: #F2BE7B;
  --inscad-bg: #3A3619;
  --inscad-text: #E7D46E;
  --ok-bg: #1D3528;
  --ok-text: #9BD3AE;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
  --shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 12px 20px -8px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 250px;
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  overflow: hidden;
}

.sidebar-logo {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-logo .logo-text {
  font-weight: 800;
  color: var(--primary);
  font-size: 0.95rem;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-logo .logo-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 1.25rem 0.75rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  margin-bottom: 0.2rem;
  transition: var(--transition);
  position: relative;
}

.nav-item:hover {
  background: #FFF5F0;
  color: var(--primary);
}

.nav-item.active {
  background: #FFF5F0;
  color: var(--primary);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  opacity: 0.8;
}

.nav-item.active svg {
  opacity: 1;
}

.nav-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  margin-left: auto;
}

.sidebar-footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: #FAFAFA;
  flex-shrink: 0;
}

/* ---- Sidebar compatta per schermi con altezza ridotta ---- */
@media (max-height: 720px) {
  .sidebar-logo          { padding: 0.65rem 1rem; }
  .sidebar-logo .logo-text { font-size: 1rem; }
  .sidebar-nav           { padding: 0.5rem 0.5rem; }
  .nav-item              { padding: 0.4rem 0.65rem; font-size: 0.82rem; margin-bottom: 0.05rem; }
  .nav-item svg          { width: 15px; height: 15px; }
  .sidebar-footer        { padding: 0.65rem 1rem; font-size: 0.7rem; }
  .sidebar-footer .sidebar-logout { margin-bottom: 0.3rem; }
}
@media (max-height: 580px) {
  .sidebar-logo          { padding: 0.4rem 0.75rem; }
  .sidebar-nav           { padding: 0.3rem 0.4rem; }
  .nav-item              { padding: 0.28rem 0.5rem; font-size: 0.78rem; margin-bottom: 0; }
  .sidebar-footer        { padding: 0.4rem 0.75rem; font-size: 0.68rem; }
}

.theme-toggle {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  padding: 0.45rem 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
  cursor: pointer;
  transition: var(--transition);
}

.theme-toggle:hover {
  border-color: var(--border-focus);
}

.theme-toggle-icon {
  font-size: 0.95rem;
}

.theme-toggle.theme-toggle-compact {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  margin: 0;
  border-radius: 9px;
  flex-shrink: 0;
}

.theme-toggle.theme-toggle-compact .theme-toggle-icon {
  font-size: 1rem;
  line-height: 1;
}

/* ---- MAIN ---- */
.main {
  flex: 1;
  padding: 2rem;
  min-width: 0;
  margin-left: 250px;
  transition: margin-left 0.3s ease;
}
/* Ensure main content can scroll vertically when content overflows viewport */
.main { overflow: auto; }

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: var(--transition);
  line-height: 1.2;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 6px -1px rgba(232, 114, 74, 0.2);
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 8px -1px rgba(232, 114, 74, 0.3);
}

.btn-secondary, .btn-outline-secondary {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover, .btn-outline-secondary:hover {
  background: color-mix(in srgb, var(--card-bg) 86%, var(--text) 14%);
  border-color: color-mix(in srgb, var(--border) 70%, var(--text) 30%);
}

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border) 55%);
}

.btn-outline-primary:hover {
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  border-color: var(--primary);
  color: var(--primary-light);
}

.btn-danger, .btn-outline-danger {
  background: var(--scaduto-bg);
  color: var(--scaduto-text);
  border-color: transparent;
}

.btn-danger:hover, .btn-outline-danger:hover {
  background: #FEB2B2;
}

.btn-success, .btn-outline-success {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: transparent;
}

.btn-success:hover, .btn-outline-success:hover {
  background: #C6F6D5;
}

.btn-warning, .btn-outline-warning {
  background: var(--urgente-bg);
  color: var(--urgente-text);
  border-color: transparent;
}

.btn-warning:hover, .btn-outline-warning:hover {
  background: #FAD08A;
}

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

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
  border-color: #CBD5E0;
}

.btn-icon.danger:hover {
    color: var(--scaduto-text);
    background: var(--scaduto-bg);
    border-color: var(--scaduto-bg);
}

/* ---- STAT CARDS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.red { background: #FFF5F5; color: #E53E3E; }
.stat-icon.orange { background: #FFFAF0; color: #DD6B20; }
.stat-icon.blue { background: #EBF8FF; color: #3182CE; }

/* ---- CALENDARIO ---- */
.calendar-card {
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.5rem;
  margin-top: 1.5rem;
  overflow: hidden;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.calendar-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .9rem;
}

.calendar-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1.5rem;
  padding: 0 1.5rem 1rem;
}

/* ---- SCHEDULING GRID ---- */
.schedule-grid {
  display: grid;
  grid-template-columns: 220px repeat(7, minmax(160px, 1fr));
  gap: 0;
  align-items: stretch;
  font-size: 13px;
}

/* ---- Day / Employee headers ---- */
.calendar-day-header {
  padding: .55rem .75rem;
  font-weight: 700;
  font-size: .82rem;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  background: transparent;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.calendar-day-header:first-child { border-right: 2px solid var(--border); }
.calendar-day-header.weekend { color: #9AA7B2; background: rgba(0,0,0,0.025); }

/* ---- Employee column ---- */
.employee-cell {
  padding: .6rem .65rem;
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  border-right: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.employee-avatar {
  width: 36px; height: 36px; min-width: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 12px;
}
.employee-meta { display: flex; flex-direction: column; gap: 1px; }
.employee-meta .name { font-weight: 700; font-size: .86rem; line-height: 1.2; }
.employee-meta .role { color: var(--text-muted); font-size: .76rem; }
.employee-meta .stats { color: var(--text-muted); font-size: .72rem; margin-top: 1px; }
.employee-cell.left-accent { position: relative; padding-left: 1rem; }
.employee-cell.left-accent::before {
  content: '';
  position: absolute; left: 4px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 4px;
  background: linear-gradient(180deg, #F49A6E, #2FB27B);
}

/* ---- Publish button ---- */
.btn-publish {
  background: #E03030; color: #fff; border: none;
  padding: .5rem .9rem; border-radius: 10px;
  font-weight: 700; font-size: .85rem;
  box-shadow: 0 4px 10px rgba(224,48,48,0.15);
  cursor: pointer;
}
.btn-publish:hover { background: #c12727; }

/* ---- Day cell ---- */
.calendar-day {
  padding: .4rem .4rem .3rem;
  min-height: 110px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .25rem;
  vertical-align: top;
}
.calendar-day.weekend { background: rgba(0,0,0,0.025); }

/* empty placeholder */
.day-empty { color: var(--text-muted); font-size: .75rem; opacity: .5; }

/* ---- Shift pill (compact horizontal) ---- */
.shift-pill {
  display: flex;
  align-items: center;
  gap: .3rem;
  background: #EBF8F2;
  border: 1px solid rgba(45,178,123,0.5);
  border-radius: 8px;
  padding: .22rem .4rem;
  font-size: .78rem;
  line-height: 1.3;
  min-height: 26px;
  transition: background .15s;
}
.shift-pill:hover { background: #D6F4E8; }

/* ---- Code badge (P / T / F / M / R / C) ---- */
.pill-code {
  font-weight: 800;
  font-size: .72rem;
  min-width: 16px;
  text-align: center;
  color: #2DB27B;
  flex-shrink: 0;
}

/* ---- Tipo color variants ---- */
.shift-pill.tipo-trasferta    { background:#FFF3E0; border-color:rgba(245,158,11,.5); }
.shift-pill.tipo-trasferta    .pill-code { color:#D97706; }
.shift-pill.tipo-trasferta    .pill-site { color:#92400E; }
.shift-pill.tipo-trasferta:hover { background:#FFE8C0; }

.shift-pill.tipo-ferie        { background:#D1FAE5; border-color:rgba(16,185,129,.5); }
.shift-pill.tipo-ferie        .pill-code { color:#059669; }
.shift-pill.tipo-ferie        .pill-site { color:#065F46; }
.shift-pill.tipo-ferie:hover  { background:#A7F3D0; }

.shift-pill.tipo-malattia     { background:#FEE2E2; border-color:rgba(220,38,38,.5); }
.shift-pill.tipo-malattia     .pill-code { color:#DC2626; }
.shift-pill.tipo-malattia     .pill-site { color:#991B1B; }
.shift-pill.tipo-malattia:hover { background:#FECACA; }

.shift-pill.tipo-reperibilita { background:#DBEAFE; border-color:rgba(59,130,246,.5); }
.shift-pill.tipo-reperibilita .pill-code { color:#1D4ED8; }
.shift-pill.tipo-reperibilita .pill-site { color:#1E3A8A; }
.shift-pill.tipo-reperibilita:hover { background:#BFDBFE; }

.shift-pill.tipo-corso        { background:#FEF9C3; border-color:rgba(202,138,4,.5); }
.shift-pill.tipo-corso        .pill-code { color:#A16207; }
.shift-pill.tipo-corso        .pill-site { color:#78350F; }
.shift-pill.tipo-corso:hover  { background:#FEF08A; }

.shift-pill .pill-body {
  flex: 1; display: flex; flex-wrap: wrap;
  align-items: center; gap: .2rem; overflow: hidden;
}
.shift-pill .pill-site {
  font-weight: 700; color: #0f6f45;
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.shift-pill .pill-time {
  color: var(--text-muted); font-size: .72rem; white-space: nowrap;
}
.shift-pill .pill-mezzo,
.shift-pill .pill-trasferta,
.shift-pill .pill-note { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }
.shift-pill .pill-actions {
  display: flex; gap: .15rem; flex-shrink: 0;
  opacity: 0; transition: opacity .15s;
}
.shift-pill:hover .pill-actions { opacity: 1; }
.pill-btn {
  background: none; border: none; cursor: pointer;
  padding: 0 .15rem; font-size: .8rem; line-height: 1; border-radius: 4px;
}
.pill-btn:hover { background: rgba(0,0,0,0.07); }
.pill-btn-del:hover { background: rgba(220,38,38,0.1); }
.pill-btn-copy { opacity: .7; }
.pill-btn-copy:hover { background: rgba(59,130,246,0.12); color: var(--primary); opacity: 1; }

/* ---- Bottone invio Telegram giornata nell'header colonna ---- */
.btn-send-day {
  display: inline-block;
  background: none;
  border: none;
  font-size: .75rem;
  cursor: pointer;
  opacity: .45;
  padding: 1px 3px;
  margin-left: 2px;
  vertical-align: middle;
  transition: opacity .15s;
}
.btn-send-day:hover { opacity: 1; }

/* ---- Pill assenza (dalla tabella assenze, sola lettura) ---- */
.shift-pill-assenza {
  opacity: .88;
  cursor: default;
  border-style: dashed !important;
}
.shift-pill-assenza .pill-body { font-style: italic; }
.pill-conflict-warn {
  font-size: .68rem; font-weight: 700;
  color: #b45309;
  background: #f59e0b22;
  border: 1px solid #f59e0b66;
  border-radius: 4px;
  padding: .05rem .35rem;
  margin-top: .15rem;
}
.btn-add-shift-locked {
  opacity: .45;
  cursor: not-allowed;
  font-size: .7rem;
}

/* ---- Ripeti Turno modal ---- */
.ripeti-riepilogo {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .85rem;
  margin-bottom: 1rem;
  font-size: .9rem;
  line-height: 1.6;
}
.giorni-settimana-selector {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem;
}
.giorno-chk { display: inline-flex; cursor: pointer; user-select: none; }
.giorno-chk input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }
.giorno-chk span {
  display: inline-block;
  padding: .25rem .6rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--card-bg);
  color: var(--text-muted);
  transition: background .15s, color .15s, border-color .15s;
}
.giorno-chk input:checked + span {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.ripeti-conflitti-box {
  background: color-mix(in srgb, #f59e0b 12%, var(--card-bg));
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: .65rem .9rem;
  font-size: .85rem;
}

/* ---- Tipo giornata selector ---- */
.tipo-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .3rem;
  margin-top: .35rem;
}
.tipo-btn {
  padding: .45rem .35rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  transition: border-color .15s, background .15s, color .15s;
  white-space: nowrap;
}
.tipo-btn.active              { border-color:#6B7280; background:#F3F4F6; color:#111; }
.tipo-btn.tipo-ferie.active   { border-color:#059669; background:#D1FAE5; color:#065F46; }
.tipo-btn.tipo-malattia.active{ border-color:#DC2626; background:#FEE2E2; color:#991B1B; }
.tipo-btn.tipo-reperibilita.active { border-color:#1D4ED8; background:#DBEAFE; color:#1E3A8A; }
.tipo-btn.tipo-corso.active   { border-color:#A16207; background:#FEF9C3; color:#78350F; }
.tipo-btn:hover:not(.active)  { border-color:#9CA3AF; background:color-mix(in srgb, var(--card-bg) 84%, var(--text) 16%); }

/* ---- Trasferta toggle ---- */
.trasferta-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  padding: .4rem .5rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  transition: border-color .15s, background .15s;
}
.trasferta-label:has(input:checked) {
  border-color: #D97706;
  background: color-mix(in srgb, #D97706 18%, var(--card-bg) 82%);
  color: #92400E;
}
.trasferta-label input { accent-color: #D97706; width: 16px; height: 16px; }

/* ---- Dipendenti dinamici (modale cronoprogramma) ---- */
.dip-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .3rem;
}
.dip-row .form-control {
  flex: 1;
}
.dip-row-remove {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  color: #9CA3AF;
  font-size: .9rem;
  padding: .3rem .5rem;
  cursor: pointer;
  line-height: 1;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.dip-row-remove:hover { background: #FEE2E2; color: #DC2626; border-color: #FCA5A5; }

.btn-add-dip {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-top: .3rem;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--primary);
  font-size: .82rem;
  font-weight: 600;
  padding: .3rem .6rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-add-dip:hover { background: rgba(232,114,74,0.06); border-color: var(--primary); }

/* ---- Categorie dipendenti ---- */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
  margin-top: .2rem;
}
.cat-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
/* filtro pill */
.cat-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .28rem .75rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.cat-filter-btn:hover { border-color: var(--cat-color, var(--primary)); color: var(--cat-color, var(--primary)); }
.cat-filter-btn.active { background: var(--cat-color, var(--primary)); border-color: var(--cat-color, var(--primary)); color: #fff; }
.cat-filter-btn.active .cat-dot { background: #fff !important; }

/* pannello gestione categorie */
.cat-badge-manage {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .65rem;
  border-radius: 999px;
  border: 1.5px solid var(--cat-color, #6B7280);
  font-size: .82rem;
  font-weight: 600;
  color: var(--cat-color, #6B7280);
  background: color-mix(in srgb, var(--cat-color, #6B7280) 10%, transparent);
}
.cat-edit-btn {
  background: none; border: none; cursor: pointer; font-size: .8rem; padding: 0 .15rem; opacity: .7; line-height: 1;
}
.cat-edit-btn:hover { opacity: 1; }
.cat-del-btn:hover { color: #DC2626; }

/* color presets */
.cat-color-presets { display: flex; gap: .35rem; flex-wrap: wrap; }
.cat-color-preset {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform .1s, border-color .1s;
}
.cat-color-preset:hover { transform: scale(1.2); border-color: #fff; }

/* ---- Fascia oraria selector ---- */
.fascia-selector {
  display: flex;
  gap: .45rem;
  margin-top: .35rem;
}
.fascia-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: .55rem .3rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  transition: border-color .15s, background .15s, color .15s;
}
.fascia-btn span {
  display: block;
  font-size: .68rem;
  font-weight: 400;
  color: var(--text-muted);
}
.fascia-btn.active {
  border-color: var(--primary);
  background: rgba(232,114,74,0.08);
  color: var(--primary);
}
.fascia-btn.active span { color: var(--primary); }
.fascia-btn:hover:not(.active) {
  border-color: #aaa;
  background: color-mix(in srgb, var(--card-bg) 84%, var(--text) 16%);
}

/* ---- Add-shift button ---- */
.btn-add-shift {
  display: block; width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--text-muted);
  font-size: .75rem;
  padding: .2rem 0;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, color .15s, background .15s;
  margin-top: auto;
}
.btn-add-shift:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(232,114,74,0.05);
}

/* responsive tweaks */
@media (max-width: 900px) {
  .schedule-grid { grid-template-columns: 180px repeat(7, minmax(130px, 1fr)); }
}


/* Mini year calendar used in employee profile */
.abs-calendar {
  padding: 1rem;
}
.abs-calendar .calendar-top {
  margin-bottom: .75rem;
  display:flex;
  align-items:center;
  gap: .5rem;
}
.abs-calendar .mini-months {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .4rem;
  max-height: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .25rem 0.25rem .25rem .25rem;
}

/* Compact cards on the left of Assenze tab */
.assenze-left .card {
  padding: .75rem;
  border-radius: 12px;
}
.assenze-left .card h4 {
  margin: 0 0 .25rem 0;
  font-size: 1rem;
}
.assenze-left .card .text-muted,
.assenze-left .card .small,
.assenze-left .card div.text-muted.small {
  font-size: .85rem;
}
.assenze-left .card p.text-muted { margin-bottom: .5rem; }
.assenze-left .card + .card { margin-top: .5rem; }

.abs-calendar .mini-month {
  border: 1px solid var(--border);
  padding: .35rem;
  border-radius: 12px;
  background: #fff;
  font-size: 12px;
  min-width: 0;
}
.abs-calendar .day-cell{ padding:4px 2px; border-radius:6px; min-width:0; }
/* Give left column a max width so calendar gets more space */
.assenze-left { max-width: 40%; }

/* Ensure mini-months grid items don't force horizontal scroll */
.abs-calendar .mini-month, .abs-calendar .days-grid { box-sizing: border-box; }
.abs-calendar .month-name {
  font-weight: 700;
  margin-bottom: .25rem;
  font-size: .95rem;
}
.abs-calendar .days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.abs-calendar .wd {
  text-align:center;
  color:var(--text-muted);
  font-size:10px;
}
.abs-calendar .day-cell{
  text-align:center;
  color:var(--text-muted);
  padding:4px 2px;
  border-radius:6px;
}
.abs-calendar .day-cell.marked{
  background:#FFECEF;
  color:#C53030;
  font-weight:700;
}
.abs-calendar .day-cell.holiday{
  background:#FCEAEA;
  color:#C53030;
  font-weight:700;
  border:1px solid rgba(197,40,62,0.12);
}
.abs-calendar .mini-months::-webkit-scrollbar{
  width:8px;
}
.abs-calendar .mini-months::-webkit-scrollbar-thumb{
  background:var(--border);
  border-radius:8px;
}

.calendar-page .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
  min-width: 650px;
}

.calendar-page .calendar-day-header {
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: .5rem;
  border-bottom: 1px solid var(--border);
}

.calendar-page .calendar-day {
  text-align: left;
  padding: .8rem;
  border-radius: 16px;
  font-size: .95rem;
  cursor: pointer;
  min-height: 100px;
  background: #fdfdfd;
  border: 1px solid #f0f0f0;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
}

.calendar-page .day-num {
  font-weight: 600;
  margin-bottom: 0.5rem;
  display: block;
}

.calendar-page .calendar-day:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .05);
  background: #fff;
  z-index: 1;
}

.calendar-page .calendar-day.today {
  background: #FFF5F0;
  border-color: var(--primary);
}

.calendar-page .calendar-day.today .day-num {
  color: var(--primary);
}

.calendar-page .calendar-day.has-event {
  border-left: 3px solid var(--primary);
}

.calendar-page .calendar-day.other-month {
  opacity: .3;
  cursor: default;
  pointer-events: none;
  background: #FAFAFA;
}

/* Weekends: make Saturday and Sunday visually muted */
.calendar-page .calendar-day.weekend {
  background: #FBFBFB;
  color: var(--text-muted);
  opacity: 0.95;
}
.calendar-page .calendar-day-header.weekend {
  color: var(--text-muted);
  opacity: 0.9;
}

.calendar-page .calendar-day.scaduto {
  border-left: 3px solid var(--scaduto-text);
  background: #FFF5F5;
}

.calendar-page .calendar-dots {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 0.5rem;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.dot-dipendente { background: #3182CE; }
.dot-mezzo { background: #E8724A; }
.dot-documento { background: #38A169; }
.dot-contratto { background: #805AD5; }
.dot-utenza { background: #805AD5; }

/* Modal details */
.cal-detail-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-radius: 8px;
  background: #f9f9f9;
  margin-bottom: .8rem;
  border: 1px solid var(--border);
}

.cal-detail-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
}

.cal-detail-info {
  flex: 1;
}

.cal-detail-type {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.cal-detail-name {
  font-weight: 600;
  font-size: .92rem;
  margin: .1rem 0;
}

.cal-detail-sub {
  font-size: .78rem;
  color: var(--text-muted);
}

/* ---- TABLE & LISTS ---- */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.section-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

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

.section-card-title {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-card-body {
  padding: 0;
  flex: 1;
}

.scad-row {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.15s;
}

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  display: flex;
  transition: all 0.25s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body {
  padding: 1.3rem 1.5rem;
}

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


/* ---- LOGIN ---- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-page {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
}

.login-card {
  background: var(--card-bg);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  border: 1px solid var(--border);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---- ALERTS ---- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.alert-error, .alert-danger {
  background: var(--scaduto-bg);
  color: var(--scaduto-text);
}

.alert-success {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.alert-warning {
  background: var(--urgente-bg);
  color: var(--urgente-text);
}

/* ============================================================
   BOOTSTRAP-LIKE GRID & UTILITIES (ADDED)
   ============================================================ */

/* -- GRID -- */
.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -0.75rem;
  margin-left: -0.75rem;
}

.row > * {
  padding-right: 0.75rem;
  padding-left: 0.75rem;
  width: 100%;
  max-width: 100%;
}

.col-12 { flex: 0 0 100%; max-width: 100%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }

@media (min-width: 768px) {
  .col-md-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
  .col-md-6 { flex: 0 0 50%; max-width: 50%; }
  .col-md-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
  .col-md-12 { flex: 0 0 100%; max-width: 100%; }
}

@media (min-width: 992px) {
  .col-lg-6 { flex: 0 0 50%; max-width: 50%; }
}

.g-2 { gap: 0.5rem; }
.g-3 { gap: 1rem; }

/* -- CARDS -- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-color: var(--card-bg);
  background-clip: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-body {
  flex: 1 1 auto;
  padding: 1.5rem;
}

.card-header {
  padding: 1rem 1.5rem;
  margin-bottom: 0;
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  margin-bottom: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* -- LIST GROUP -- */
.list-group {
  display: flex;
  flex-direction: column;
  padding-left: 0;
  margin-bottom: 0;
  border-radius: var(--radius-sm);
}

.list-group-item {
  position: relative;
  display: block;
  padding: 0.75rem 1.25rem;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
}

.list-group-item:first-child {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
}

.list-group-item:last-child {
  border-bottom-right-radius: inherit;
  border-bottom-left-radius: inherit;
}

.list-group-item + .list-group-item {
  border-top-width: 0;
}

.list-group-flush {
  border-radius: 0;
}

.list-group-flush .list-group-item {
  border-width: 0 0 1px;
}

.list-group-flush .list-group-item:last-child {
  border-bottom-width: 0;
}

/* -- BADGES -- */
.badge {
  display: inline-block;
  padding: 0.35em 0.65em;
  font-size: 0.75em;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  vertical-align: baseline;
  border-radius: 0.25rem;
}

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

.badge-warning, .badge-in-scadenza {
  color: var(--inscad-text);
  background-color: var(--inscad-bg);
}

.badge-danger, .badge-scaduto, .badge-urgente {
  color: var(--scaduto-text);
  background-color: var(--scaduto-bg);
}

.badge-secondary {
  color: var(--text-muted);
  background-color: var(--border);
}

.badge-outline {
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: transparent;
}

/* -- FORMS -- */
.form-control {
  display: block;
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}

.form-control:focus {
  color: var(--text);
  background-color: #fff;
  border-color: var(--border-focus);
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(232, 114, 74, 0.25);
}

.form-label {
  display: inline-block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 1rem;
}

.input-group {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;
}

.input-group .form-control {
  position: relative;
  flex: 1 1 auto;
  width: 1%;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  background-color: #e9ecef;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}

/* -- TABLES -- */
.table-responsive {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  margin-bottom: 1rem;
  color: var(--text);
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.75rem;
  vertical-align: middle;
  border-top: 1px solid var(--border);
}

.table thead th {
  vertical-align: bottom;
  border-bottom: 2px solid var(--border);
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.8rem;
}

.table-hover tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* -- UTILITIES -- */
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.p-0 { padding: 0 !important; }
.p-3 { padding: 1rem !important; }
.p-4 { padding: 1.5rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.py-4 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
.py-5 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
.px-3 { padding-right: 1rem !important; padding-left: 1rem !important; }
.px-4 { padding-right: 1.5rem !important; padding-left: 1.5rem !important; }

.d-flex { display: flex !important; }
.d-none { display: none !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-end { align-items: flex-end !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-end { justify-content: flex-end !important; }
.flex-grow-1 { flex-grow: 1 !important; }

.w-100 { width: 100% !important; }
.h-100 { height: 100% !important; }

.text-center { text-align: center !important; }
.text-end { text-align: right !important; }
.text-start { text-align: left !important; }
.text-muted { color: var(--text-muted) !important; }
.text-success { color: var(--ok-text) !important; }
.text-danger { color: var(--scaduto-text) !important; }
.text-white { color: #fff !important; }
.text-decoration-none { text-decoration: none !important; }

.fw-bold { font-weight: 700 !important; }
.fs-5 { font-size: 1.25rem !important; }
.fs-6 { font-size: 1rem !important; }
.small { font-size: 0.875em !important; }

.bg-light { background-color: var(--bg) !important; }
.bg-white { background-color: #fff !important; }
.bg-secondary { background-color: var(--text-muted) !important; }

/* Colori scadenze calendario */
.bg-primary { background-color: #3b82f6 !important; }
.bg-warning { background-color: #f59e0b !important; }
.bg-success { background-color: #10b981 !important; }
.bg-info { background-color: #06b6d4 !important; }
.bg-danger { background-color: #ef4444 !important; }

.border { border: 1px solid var(--border) !important; }
.border-0 { border: 0 !important; }
.rounded { border-radius: var(--radius) !important; }
.rounded-circle { border-radius: 50% !important; }

.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }

/* -- AVATAR -- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }
  
  .sidebar.active {
    transform: translateX(0);
  }
  
  .main {
    margin-left: 0;
    padding: 1.5rem;
  }
  
  .sidebar-toggle {
    display: block;
  }
}

@media (min-width: 1025px) {
  .sidebar {
    transform: none;
  }
  
  .main {
    margin-left: 260px;
  }
  
  .sidebar-toggle {
    display: none;
  }
}

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  background: var(--primary);
  color: white;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  box-shadow: 0 4px 12px rgba(232, 114, 74, 0.4);
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: white;
  margin: 4px auto;
  transition: 0.3s;
}

/* ============================================================
   MISSING ENTITY COMPONENTS (Added for Fix)
   ============================================================ */

/* -- ENTITY GRID -- */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

/* -- ENTITY CARD -- */
.entity-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  overflow: hidden;
  height: 100%;
}

.entity-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary-light);
}

.entity-card.has-scaduto {
  border-left: 4px solid var(--scaduto-text);
}

.entity-card.has-in-scadenza {
  border-left: 4px solid var(--inscad-text);
}

.entity-card-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--card-bg);
}

/* -- DIPENDENTE SPECIFIC -- */
.dipendente-info {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.dipendente-avatar {
  width: 42px;
  height: 42px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.dipendente-contacts {
  padding: 0.65rem 1rem;
  background: color-mix(in srgb, var(--card-bg) 86%, var(--text) 14%);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.dipendente-contacts span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* -- ENTITY SCADENZE LIST -- */
.entity-scad-list {
  padding: 0.85rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.entity-scad-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  border: 1px solid transparent;
  transition: background 0.2s;
}

.entity-scad-item:hover {
  background: color-mix(in srgb, var(--card-bg) 84%, var(--text) 16%);
  border-color: var(--border);
}

.entity-scad-item-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.entity-scad-item-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.entity-scad-item-data {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.5rem;
}

/* -- SEARCH BAR -- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #fff;
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  max-width: 600px;
  transition: box-shadow 0.2s;
}

.search-bar:focus-within {
  box-shadow: 0 0 0 3px rgba(232, 114, 74, 0.1);
  border-color: var(--primary);
}

.search-bar input {
  border: none;
  outline: none;
  font-size: 1rem;
  width: 100%;
  color: var(--text);
}

.search-bar svg {
  color: var(--text-muted);
}

/* -- FORM ROW -- */
.form-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .form-row .form-group {
    margin-bottom: 1rem;
  }
}

/* -- EXTRAS -- */
.entity-card-sub {
  padding: 0 1rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.fornitori-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: #EDF2F7;
  color: var(--text-muted);
  border-radius: 4px;
  margin-left: 0.5rem;
  font-weight: 500;
  vertical-align: middle;
}

/* -- EMPTY STATE -- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  margin-bottom: 1rem;
  color: #CBD5E0;
  width: 64px;
  height: 64px;
}

.empty-icon svg {
  width: 100%;
  height: 100%;
}

/* -- NOTIFICHE EXTRAS -- */
.dashed-border {
  border-style: dashed !important;
}

.list-group-item {
  display: flex;
  align-items: center;
}

.list-group-item.unread {
  background-color: color-mix(in srgb, var(--primary) 14%, var(--card-bg) 86%);
}

.unread-dot {
  width: 8px;
  height: 8px;
  background-color: var(--primary);
  border-radius: 50%;
  margin-right: 0.75rem;
  flex-shrink: 0;
}

.item-text {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   MOBILE & TABLET OPTIMIZATION
   ============================================================ */

/* -- GLOBAL RESPONSIVE TWEAKS -- */
@media (max-width: 767.98px) {
  /* Layout */
  .main {
    padding: 1rem;
    margin-left: 0;
  }

  /* Typography */
  body {
    font-size: 14px;
  }

  .page-title {
    font-size: 1.5rem;
  }

  /* Grid System - Force single column on mobile */
  .entity-grid, 
  .cards-row, 
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Touch Targets (min 44px) */
  .btn, 
  .form-control, 
  .nav-item,
  .sidebar-toggle,
  .btn-icon {
    min-height: 44px;
    touch-action: manipulation;
  }

  .btn-sm {
    min-height: 32px; /* Small buttons exception but still clickable */
    padding: 0.5rem 1rem;
  }

  /* Components */
  .stat-card {
    padding: 1rem;
  }

  .stat-value {
    font-size: 1.75rem;
  }

  .search-bar {
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
  }

  /* Tables */
  .table th, .table td {
    padding: 0.5rem;
    font-size: 0.85rem;
  }
  
  .table-responsive {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }

  /* Calendar Specific */
  .calendar-wrapper {
    margin: 0 -1rem; /* Negative margin to edge */
    padding: 0 1rem 1rem;
  }
  
  .calendar-grid {
    min-width: 100%;
    /* On mobile, month grid might need horizontal scroll or stack. 
       Current .calendar-wrapper has overflow-x: auto. 
       Let's keep it scrollable for month view validity. */
  }
}

/* -- TABLET (768px - 1024px) -- */
@media (min-width: 768px) and (max-width: 1024px) {
  .main {
    padding: 1.5rem;
    margin-left: 0; /* Sidebar hidden by default on tablet too in previous rules */
  }

  .entity-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* -- DESKTOP (> 1024px) -- */
@media (min-width: 1025px) {
  /* Sidebar is visible, main has margin */
  .main {
    margin-left: 250px;
  }
}

/* ---- CARD STYLES REFINED ---- */
.card, .section-card, .calendar-card, .entity-card {
  border: 1px solid rgba(0,0,0,0.03);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
  border-radius: var(--radius);
  background: var(--card-bg);
}

.section-card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
}

.section-card-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
}

.scad-row {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

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

/* Badge Refinements */
.badge {
  padding: 0.4em 0.8em;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 6px;
}

/* Calendar Grid Refinements */
.calendar-month-wrapper {
  border: none;
  box-shadow: none;
  background: transparent;
}

.calendar-grid-header {
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: none;
  padding-bottom: 1rem;
}

.cal-cell {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: 120px;
  margin-bottom: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.cal-cell.today {
  background: color-mix(in srgb, var(--primary) 10%, var(--card-bg) 90%);
  border: 2px solid var(--primary);
  position: relative;
  z-index: 2;
}

.cal-cell:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0,0,0,0.04);
  z-index: 3;
}

/* Ensure buttons in calendar are rounded */
.calendar-controls .btn-icon {
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

/* Modal rounding */
.modal {
    border-radius: 24px;
}

.layout {
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  overflow: hidden;
}

.sidebar-logo {
  padding: 1rem 1rem 0.85rem;
}

.sidebar-logo .logo-text {
  font-size: 1rem;
}

.sidebar-logo .logo-sub {
  font-size: 0.64rem;
}

.sidebar-nav {
  padding: 0.75rem 0.5rem;
}

.nav-item {
  padding: 0.5rem 0.7rem;
  gap: 0.55rem;
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
}

.nav-item svg {
  width: 16px;
  height: 16px;
}

.sidebar-footer {
  padding: 0.8rem;
  display: grid;
  gap: 0.55rem;
  background: #fff;
}

.sidebar-logout {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--scaduto-text);
  background: var(--scaduto-bg);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}

.sidebar-logout svg {
  width: 16px;
  height: 16px;
}

.main {
  margin-left: 232px;
  padding: 1.35rem;
}

.page-header {
  margin-bottom: 1.25rem;
  gap: 0.7rem;
}

.page-title {
  font-size: 1.4rem;
  gap: 0.5rem;
}

.page-subtitle {
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
}

.btn-sm {
  padding: 0.34rem 0.62rem;
  font-size: 0.75rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
}

.stats-grid {
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  padding: 0.95rem 1rem;
}

.stat-label {
  margin-bottom: 0.15rem;
}

.stat-value {
  font-size: 1.45rem;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 1rem;
}

.cards-row,
.entity-grid {
  gap: 1rem;
  margin-bottom: 1.25rem;
  margin-top: 1rem;
}

.section-card-header,
.card-header {
  padding: 0.8rem 1rem;
}

.section-card-title,
.card-title {
  font-size: 0.95rem;
}

.scad-row {
  padding: 0.65rem 1rem;
}

.scad-meta {
  min-width: 108px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  text-align: right;
  gap: 0.08rem;
  line-height: 1;
  flex-shrink: 0;
}

.scad-meta .badge {
  width: 94px;
  min-height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  line-height: 1;
}

.scad-date {
  font-size: 0.83rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  line-height: 1.05;
}

.scad-days {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--scaduto-text);
  white-space: nowrap;
  line-height: 1.05;
}

.card-body {
  padding: 1rem;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-label {
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.form-control {
  padding: 0.5rem 0.62rem;
  font-size: 0.88rem;
}

.search-bar {
  padding: 0.55rem 0.8rem;
  margin-bottom: 1rem;
}

.table th,
.table td {
  padding: 0.55rem 0.62rem;
}

.table thead th {
  font-size: 0.72rem;
}

.table td {
  font-size: 0.84rem;
}

@media (max-width: 1024px) {
  .sidebar {
    width: 232px;
    transform: translateX(-100%);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: 1rem;
  }
}

@media (min-width: 1025px) {
  .sidebar {
    transform: none;
  }

  .main {
    margin-left: 232px;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 767.98px) {
  .sidebar-toggle {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(8px);
  }

  .sidebar-toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 3px;
  }

  .sidebar-toggle-inner {
    width: 20px;
    height: 16px;
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }

  .sidebar-toggle-line {
    width: 100%;
    height: 1.5px;
    background: #6b7280;
    border-radius: 999px;
    transform-origin: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease, width 0.2s ease, background 0.2s ease;
  }

  .sidebar-toggle-line:nth-child(2) {
    width: 86%;
  }
  
  .sidebar-toggle:hover .sidebar-toggle-line {
    background: #374151;
  }
  
  .sidebar-toggle:hover .sidebar-toggle-line:nth-child(2) {
    width: 100%;
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(2) {
    opacity: 0;
    width: 100%;
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }
  
  .sidebar-toggle.open .sidebar-toggle-line {
    background: #1f2937;
  }

  .sidebar-overlay {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
  }

  .sidebar {
    width: min(88vw, 340px);
    border-left: 1px solid rgba(148, 163, 184, 0.35);
    box-shadow: -14px 0 36px rgba(2, 6, 23, 0.34);
    transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
    background: linear-gradient(180deg, #FFFFFF 0%, #FAFCFF 100%);
  }

  .sidebar-logo {
    padding: 1rem 1rem 0.8rem;
  }

  .sidebar-nav {
    padding: 0.7rem 0.55rem 1rem;
  }

  .nav-item {
    border: 1px solid transparent;
    border-radius: 12px;
  }

  .nav-item:hover,
  .nav-item:focus-visible {
    border-color: rgba(232, 114, 74, 0.22);
    background: #FFF7F4;
    outline: none;
  }

  .nav-item.active {
    border-color: rgba(232, 114, 74, 0.25);
    box-shadow: 0 4px 10px rgba(232, 114, 74, 0.1);
  }

  .sidebar-logout {
    border-radius: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-toggle-line,
  .sidebar,
  .sidebar-overlay,
  .sidebar-toggle {
    transition: none !important;
  }
}

@media (max-width: 767.98px) {
  body {
    font-size: 15px;
  }

  .page-title {
    font-size: 1.2rem;
  }

  .btn,
  .form-control,
  .nav-item,
  .sidebar-logout,
  .sidebar-toggle {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 36px;
    min-height: 36px;
  }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

.sidebar-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0.7rem;
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 0.78rem;
}

.btn-icon-sm {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
}

.form-hint {
  display: block;
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.m-0 { margin: 0 !important; }
.mr-3 { margin-right: 0.75rem !important; }
.me-2 { margin-right: 0.5rem !important; }
.ms-2 { margin-left: 0.5rem !important; }
.pl-4 { padding-left: 1rem !important; }
.pr-4 { padding-right: 1rem !important; }
.fw-normal { font-weight: 400 !important; }
.text-dark { color: var(--text) !important; }
.text-sm { font-size: 0.84rem !important; }
.text-xs { font-size: 0.72rem !important; }
.uppercase { text-transform: uppercase !important; }
.block { display: block !important; }
.flex-1 { flex: 1 1 0% !important; }
.border-bottom { border-bottom: 1px solid var(--border) !important; }

.stat-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.section-card-count {
  min-width: 24px;
  height: 24px;
  padding: 0 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: #fff;
}

.btn-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.btn-group .btn {
  border-radius: 0;
  border: 0;
}

.btn-group .btn + .btn {
  border-left: 1px solid var(--border);
}

.calendar-page .page-header {
  margin-bottom: 0.9rem;
}

.calendar-controls {
  border-radius: 12px !important;
  padding: 0.55rem 0.7rem !important;
  margin-bottom: 0.9rem !important;
}

.calendar-controls h2 {
  font-size: 1rem !important;
  line-height: 1.1;
}

.calendar-month-wrapper {
  padding: 0.3rem;
}

.calendar-grid-header {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.day-header {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  padding: 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 0.25rem;
}

.day-header.weekend {
  color: #ef4444;
  font-weight: 700;
}

.day-header.today {
  color: #3b82f6;
  font-weight: 700;
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-radius: 6px;
  position: relative;
}

.day-header.today::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: #3b82f6;
  border-radius: 50%;
}

@media (max-width: 767.98px) {
  .day-header {
    font-size: 0.65rem;
    padding: 0.35rem 0;
    letter-spacing: 0.03em;
  }
  
  .day-header .day-full {
    display: none;
  }
  
  .day-header .day-abbr {
    display: inline;
  }
  
  .day-header.today {
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
  }
}

@media (min-width: 768px) {
  .day-header .day-full {
    display: inline;
  }
  
  .day-header .day-abbr {
    display: none;
  }
}

.calendar-grid-header > div {
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.3rem 0;
}

.calendar-grid-body {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
}

.cal-cell {
  padding: 0.45rem;
}

.cal-cell.empty {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.cal-date {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text);
}

.cal-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 0.3rem;
}

.cal-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 0.3rem;
}

.cal-item {
  font-size: 0.62rem;
  line-height: 1.15;
  padding: 0.16rem 0.28rem;
  border-radius: 6px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-item strong {
  font-weight: 700;
  margin-right: 0.12rem;
}

.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.18);
}

.cal-more {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 700;
  line-height: 1;
}

.cal-presence-badge {
  position: absolute;
  right: 0.4rem;
  bottom: 0.35rem;
  font-size: 0.66rem;
  line-height: 1;
  padding: 0.22rem 0.35rem;
  border-radius: 999px;
  background: color-mix(in srgb, #3b82f6 16%, var(--card-bg) 84%);
  color: #93c5fd;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

@media (max-width: 1024px) {
  .calendar-grid-body {
    gap: 0.3rem;
  }

  .cal-cell {
    min-height: 96px;
  }
}

@media (max-width: 767.98px) {
  .sidebar-nav {
    padding: 0.7rem 0.55rem 1rem;
  }

  .sidebar-footer {
    padding: 0.8rem;
  }

  .calendar-controls {
    margin-bottom: 0.7rem !important;
  }

  .calendar-grid-header {
    display: none;
  }

  .calendar-grid-body {
    grid-template-columns: repeat(7, 1fr);
    gap: 0.2rem;
  }

  .cal-cell {
    min-height: 68px;
    padding: 0.35rem;
  }

  .cal-date {
    font-size: 0.7rem;
  }

  .cal-dot {
    width: 5px;
    height: 5px;
  }

  .cal-list {
    display: none;
  }

  .cal-presence-badge {
    font-size: 0.6rem;
    padding: 0.18rem 0.28rem;
    right: 0.25rem;
    bottom: 0.2rem;
  }

  .scad-meta {
    min-width: 98px;
  }

  .scad-meta .badge {
    width: 90px;
  }
}

body.menu-open {
  overflow: hidden;
}

@media (max-width: 767.98px) {
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 18px;
    right: 18px;
    bottom: auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #ffffff;
    color: #374151;
    z-index: 1300;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(0);
    touch-action: manipulation;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .sidebar-toggle:hover {
     transform: translateY(-1px);
     box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15), 0 3px 8px rgba(0, 0, 0, 0.1);
   }
   
   .sidebar-toggle:active {
      transform: translateY(0) scale(0.96);
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
    }
    
   .sidebar-toggle.open {
       transform: scale(1.05) rotate(90deg);
       box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.12);
     }

  .sidebar-toggle-inner {
    width: 22px;
    height: 18px;
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }

  .sidebar-toggle-line {
    width: 100%;
    height: 2px;
    background: #F8FAFC;
    border-radius: 999px;
    transform-origin: center;
    transition: transform 0.28s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.2s ease, width 0.2s ease;
  }

  .sidebar-toggle-line:nth-child(2) {
    width: 86%;
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(2) {
    opacity: 0;
    width: 100%;
  }

  .sidebar-toggle.open .sidebar-toggle-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
  }

  .sidebar-toggle:focus-visible {
    outline: 3px solid #93C5FD;
    outline-offset: 2px;
  }

  .sidebar-overlay {
    z-index: 1190;
    background: rgba(2, 6, 23, 0.64);
    backdrop-filter: blur(2px);
  }

  .sidebar {
    width: min(88vw, 340px);
    height: 100vh;
    left: auto;
    right: 0;
    border-right: 0;
    border-left: 1px solid rgba(148, 163, 184, 0.35);
    transform: translateX(100%);
    z-index: 1200;
    box-shadow: -14px 0 36px rgba(2, 6, 23, 0.34);
    transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
    background: linear-gradient(180deg, #FFFFFF 0%, #FAFCFF 100%);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .sidebar-nav {
    padding-bottom: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item,
  .sidebar-logout {
    min-height: 44px;
  }
}

/* ============================================================
   AI CHAT WIDGET
   ============================================================ */
.ai-chat-bubble {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 1200;
  transition: transform .15s, box-shadow .15s;
  user-select: none;
}
.ai-chat-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.ai-bubble-icon { font-size: 1.5rem; line-height: 1; }
.ai-bubble-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fc3; color: #fc3;
  font-size: .5rem;
  border: 2px solid var(--primary);
}

.ai-chat-panel {
  position: fixed;
  bottom: 5rem;
  right: 1.5rem;
  width: 340px;
  max-height: 480px;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  z-index: 1200;
  flex-direction: column;
  overflow: hidden;
}
@media (max-width: 480px) {
  .ai-chat-panel { width: calc(100vw - 1.5rem); right: .75rem; bottom: 4.5rem; }
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 1rem;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  flex-shrink: 0;
}
.ai-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: .2rem .4rem;
  border-radius: 4px;
  opacity: .85;
}
.ai-chat-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  background: var(--bg);
}

.ai-msg {
  max-width: 85%;
  padding: .45rem .7rem;
  border-radius: 12px;
  font-size: .82rem;
  line-height: 1.45;
  word-break: break-word;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-bot {
  align-self: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.ai-msg-error { border-color: #fc8; background: #fffbea; color: #7a4f00; }
html.dark-theme .ai-msg-error { background: #3a3010; color: #f5d87a; border-color: #7a6000; }

/* Typing indicator */
.ai-msg-typing { display: flex; align-items: center; gap: 4px; padding: .5rem .7rem; }
.ai-msg-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--primary);
  opacity: .6;
  animation: aiTypingDot 1.2s infinite ease-in-out;
}
.ai-msg-typing span:nth-child(2) { animation-delay: .2s; }
.ai-msg-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aiTypingDot {
  0%,80%,100% { transform: scale(.65); opacity:.4; }
  40%         { transform: scale(1.1);  opacity:1;  }
}

.ai-chat-footer {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  padding: .5rem .65rem;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .45rem .6rem;
  font-size: .82rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
}
.ai-chat-input:focus { border-color: var(--primary); }
.ai-chat-send {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.ai-chat-send:hover { background: var(--primary-dark); }

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

  .sidebar-overlay {
    display: none !important;
  }

  .tab-bar-ibrida,
  .sheet-overlay,
  .bottom-sheet {
    display: none !important;
  }

  .sidebar {
    left: 0;
    right: auto;
    width: 232px;
    border-left: 0;
    border-right: 1px solid var(--border);
    transform: none !important;
    box-shadow: none;
    z-index: 100;
  }

  .sidebar.active {
    transform: none;
  }

  .main {
    margin-left: 232px;
  }
}

@media (max-width: 767.98px) {
  .tab-bar-ibrida {
    display: flex;
  }

  .sheet-overlay,
  .bottom-sheet {
    display: block;
  }

  body.has-tab-bar .sidebar-toggle {
    display: none !important;
  }

  .tab-bar-ibrida {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 64px;
    padding: 0 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    z-index: 1250;
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: #6b7280;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    position: relative;
  }

  .tab-item:hover {
    background: #f3f4f6;
    color: #374151;
  }

  .tab-item.active {
    background: #eff6ff;
    color: #3b82f6;
  }

  .tab-icon {
    font-size: 20px;
    margin-bottom: 2px;
    line-height: 1;
  }

  .tab-label {
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
  }

  .tab-badge {
    position: absolute;
    top: 2px;
    right: 8px;
    min-width: 16px;
    padding: 2px 4px;
    border-radius: 8px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    text-align: center;
  }

  .sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1290;
  }

  .sheet-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: -100%;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1300;
  }

  .bottom-sheet.show {
    bottom: 0;
  }

  .sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
  }

  .sheet-title {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
  }

  .sheet-close {
    border: 0;
    background: none;
    color: #6b7280;
    font-size: 24px;
    line-height: 1;
    padding: 4px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease;
  }

  .sheet-close:hover {
    background: #f3f4f6;
  }

  .sheet-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-radius: 8px;
    color: #374151;
    text-decoration: none;
    transition: background 0.2s ease;
  }

  .sheet-item:hover {
    background: #f9fafb;
  }

  .sheet-icon {
    width: 24px;
    margin-right: 12px;
    font-size: 20px;
    line-height: 1;
    text-align: center;
  }

  body.has-tab-bar {
    padding-bottom: 64px;
  }
}

@media (max-width: 767px) {
  .tab-bar-ibrida {
    height: 56px;
    padding: 0 4px;
  }

  .tab-item {
    min-width: 50px;
    padding: 6px 8px;
  }

  .tab-icon {
    font-size: 18px;
  }

  .tab-label {
    font-size: 10px;
  }

  body.has-tab-bar {
    padding-bottom: 56px;
  }
}

/* ============================================================
   DARK THEME HARDENING (legacy/light hardcoded overrides)
   ============================================================ */
html.dark-theme,
html.dark-theme body {
  background: var(--bg);
  color: var(--text);
}

html.dark-theme .sidebar-footer,
html.dark-theme .sidebar-logo,
html.dark-theme .card,
html.dark-theme .calendar-card,
html.dark-theme .stat-card,
html.dark-theme .entity-card,
html.dark-theme .modal,
html.dark-theme .bottom-sheet,
html.dark-theme .search-bar,
html.dark-theme .table-responsive,
html.dark-theme .tab-bar-ibrida {
  background: var(--card-bg) !important;
  color: var(--text);
  border-color: var(--border) !important;
}

html.dark-theme .calendar-wrapper,
html.dark-theme .schedule-grid,
html.dark-theme .calendar-day,
html.dark-theme .calendar-day-header,
html.dark-theme .employee-cell {
  background: transparent !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html.dark-theme .calendar-day.weekend,
html.dark-theme .calendar-day-header.weekend {
  background: rgba(255, 255, 255, 0.03) !important;
  color: var(--text-muted) !important;
}

html.dark-theme .day-empty,
html.dark-theme .employee-meta .role,
html.dark-theme .employee-meta .stats {
  color: var(--text-muted) !important;
}

html.dark-theme .table,
html.dark-theme .table thead,
html.dark-theme .table tbody,
html.dark-theme .table tr,
html.dark-theme .table th,
html.dark-theme .table td {
  background: transparent !important;
  color: var(--text);
  border-color: var(--border) !important;
}

html.dark-theme .form-control,
html.dark-theme input,
html.dark-theme textarea,
html.dark-theme select {
  background: #0f1b2d !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html.dark-theme .btn-secondary,
html.dark-theme .btn-outline-secondary,
html.dark-theme .btn-icon,
html.dark-theme .sheet-close,
html.dark-theme .sheet-item,
html.dark-theme .tab-item {
  background: #122036 !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html.dark-theme .btn-secondary:hover,
html.dark-theme .btn-outline-secondary:hover,
html.dark-theme .btn-icon:hover,
html.dark-theme .sheet-close:hover,
html.dark-theme .sheet-item:hover,
html.dark-theme .tab-item:hover {
  background: #1a2a42 !important;
}

html.dark-theme .tab-item.active {
  background: #1d3452 !important;
  color: #8ec5ff !important;
}

html.dark-theme .sheet-title,
html.dark-theme .sheet-icon,
html.dark-theme .tab-label,
html.dark-theme .tab-icon {
  color: var(--text) !important;
}

html.dark-theme .nav-item:hover,
html.dark-theme .nav-item.active {
  background: rgba(232, 114, 74, 0.18) !important;
}

html.dark-theme .sheet-header,
html.dark-theme .sidebar-divider {
  border-color: var(--border) !important;
}

/* Utility classes often forcing light UI */
html.dark-theme .bg-white,
html.dark-theme .text-dark {
  background-color: var(--card-bg) !important;
  color: var(--text) !important;
}

/* Inline-style hotspots */
html.dark-theme #c_dip_edit_name {
  background: #122036 !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html.dark-theme .sidebar-logo > div > div:first-child {
  background: #223a56 !important;
  color: #b8d7ff !important;
}

html.dark-theme tr[style*="background:#fafafa"] {
  background: rgba(255, 255, 255, 0.04) !important;
}

html.dark-theme [style*="background:#f8f9fa"] {
  background: #122036 !important;
  color: var(--text) !important;
}

html.dark-theme [style*="background:#fff"],
html.dark-theme [style*="background:#ffffff"],
html.dark-theme [style*="background: #fff"],
html.dark-theme [style*="background:#f3f4f6"],
html.dark-theme [style*="background:#f9fafb"],
html.dark-theme [style*="background:#fafafa"],
html.dark-theme [style*="background: white"] {
  background: #122036 !important;
  color: var(--text) !important;
}

html.dark-theme [style*="color:#1f2937"],
html.dark-theme [style*="color: #1f2937"],
html.dark-theme [style*="color:#666"] {
  color: var(--text) !important;
}

/* Calendar page specific dark refinements */
html.dark-theme .calendar-page .calendar-month-wrapper {
  background: transparent !important;
}

html.dark-theme .calendar-page .day-header {
  color: var(--text-muted) !important;
  border-bottom-color: var(--border) !important;
}

html.dark-theme .calendar-page .day-header.weekend {
  color: #ff8f8f !important;
}

html.dark-theme .calendar-page .day-header.today {
  color: #8ec5ff !important;
  background: color-mix(in srgb, #3b82f6 20%, transparent) !important;
}

html.dark-theme .calendar-page .day-header.today::after {
  background: #60a5fa !important;
}

html.dark-theme .calendar-page .cal-cell {
  background: #122036 !important;
  border-color: var(--border) !important;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

html.dark-theme .calendar-page .cal-cell.today {
  background: color-mix(in srgb, var(--primary) 14%, #122036 86%) !important;
  border-color: var(--primary) !important;
}

html.dark-theme .calendar-page .cal-dot {
  box-shadow: 0 0 0 1px rgba(15, 22, 35, 0.8), 0 0 0 2px rgba(255,255,255,0.08);
}

html.dark-theme .calendar-page .cal-dot.bg-primary { background-color: #60a5fa !important; }
html.dark-theme .calendar-page .cal-dot.bg-warning { background-color: #fbbf24 !important; }
html.dark-theme .calendar-page .cal-dot.bg-success { background-color: #34d399 !important; }
html.dark-theme .calendar-page .cal-dot.bg-info { background-color: #22d3ee !important; }
html.dark-theme .calendar-page .cal-dot.bg-danger { background-color: #fb7185 !important; }

html.dark-theme .calendar-page .cal-presence-badge {
  background: color-mix(in srgb, #3b82f6 24%, #122036 76%) !important;
  color: #bfdbfe !important;
  border: 1px solid rgba(96,165,250,0.35);
}

html.dark-theme pre {
  background: #0f1b2d !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
}

/* =====================================================
   CRONOPROGRAMMA — RESPONSIVE MOBILE
   ===================================================== */

/* ---- Page header: wrap buttons on small screens ---- */
@media (max-width: 767.98px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: .75rem;
  }
  .page-header > .d-flex {
    flex-wrap: wrap;
    gap: .4rem;
    width: 100%;
  }
  /* Nascondi bottoni export meno urgenti su mobile */
  .page-header .btn-sm.btn-success,
  .page-header .btn-sm.btn-outline-secondary:last-child {
    display: none;
  }
}

/* ---- Schedule grid: colonna dipendente sticky + colonne più compatte ---- */
@media (max-width: 1024px) {
  .schedule-grid {
    grid-template-columns: 160px repeat(7, minmax(120px, 1fr));
    font-size: 12px;
  }
}

@media (max-width: 767.98px) {
  /* Colonne più strette per minimizzare lo scroll orizzontale */
  .schedule-grid {
    grid-template-columns: 130px repeat(7, minmax(100px, 1fr));
    font-size: 11px;
  }

  /* Wrapper: scroll orizzontale touch-friendly */
  .calendar-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 0 1rem;
    /* Indicatore visivo che c'è scroll */
    background-image: linear-gradient(to right, var(--card-bg) 30%, transparent),
                      linear-gradient(to right, transparent, var(--card-bg) 70%);
    background-position: left center, right center;
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%;
    background-attachment: local, local;
  }

  /* Colonna dipendente: resta visibile durante lo scroll orizzontale */
  .employee-cell {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--card-bg);
    box-shadow: 2px 0 6px rgba(0,0,0,.08);
    padding: .5rem .4rem;
    gap: .4rem;
    min-width: 130px;
  }

  /* Prima intestazione (Dipendente / Ore sett.) anch'essa sticky */
  .calendar-day-header:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--card-bg);
    box-shadow: 2px 0 6px rgba(0,0,0,.08);
    min-width: 130px;
  }

  /* Avatar più piccolo su mobile */
  .employee-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 10px;
  }

  .employee-meta .name   { font-size: .78rem; }
  .employee-meta .role   { font-size: .68rem; }
  .employee-meta .stats  { font-size: .65rem; }

  /* Intestazioni giorni: compatte */
  .calendar-day-header {
    padding: .4rem .35rem;
    font-size: .72rem;
    white-space: nowrap;
  }

  /* Celle giorno */
  .calendar-day {
    padding: .3rem .25rem;
    min-height: 80px;
    gap: .2rem;
  }

  /* Pill turno: più stretta */
  .shift-pill {
    padding: .18rem .28rem;
    gap: .2rem;
    font-size: .7rem;
    min-height: 22px;
  }

  .pill-code {
    font-size: .65rem;
    min-width: 14px;
  }

  .pill-site {
    font-size: .7rem;
    white-space: normal;
    word-break: break-word;
  }

  .pill-time,
  .pill-mezzo {
    font-size: .65rem;
    white-space: normal;   /* permette il wrap della targa */
    word-break: break-all;
  }

  /* pill-body: va a capo invece di tagliare */
  .shift-pill .pill-body {
    overflow: visible;
    flex-wrap: wrap;
  }

  /* Azioni pill: sempre visibili su touch (non c'è hover) */
  .shift-pill .pill-actions {
    opacity: 1;
  }

  /* Azioni pill su mobile: bottoni più grandi */
  .pill-actions {
    display: flex;
    gap: .15rem;
    margin-top: .2rem;
  }

  .pill-btn {
    min-width: 28px;
    min-height: 28px;
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Bottone aggiungi: occupa tutta la larghezza */
  .btn-add-shift {
    width: 100%;
    font-size: .7rem;
    padding: .2rem .25rem;
    min-height: 28px;
  }

  /* Bottoni invio telegram/whatsapp nella header colonna */
  .btn-send-day {
    font-size: .65rem;
    padding: .1rem .2rem;
  }

  /* Badge categorie */
  .cat-badge {
    font-size: .65rem;
    padding: .1rem .3rem;
  }
}

/* Dark theme: sfondo sticky colonna dipendente corretto */
html.dark-theme .employee-cell,
html.dark-theme .calendar-day-header:first-child {
  background: var(--card-bg) !important;
}
