/* ============================================================
   ENGY IMPIANTI — Portal Styles
   ============================================================ */
:root {
  --navy: #1B3A6B;
  --ink: #1B3A6B;        /* colore TESTO "navy" — diventa chiaro in dark mode */
  --navy-dark: #122850;
  --navy-light: #24508f;
  --sky: #4A90C4;
  --sky-light: #e8f2fa;
  --green: #27ae60;
  --green-light: #eafaf1;
  --red: #e53935;
  --red-light: #fff5f5;
  --orange: #f39c12;
  --orange-light: #fff8e1;
  --bg: #f0f4fa;
  --white: #ffffff;
  --sidebar-w: 260px;
  --header-h: 64px;
  --text: #1a2640;
  --text-muted: #6b7a99;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(27,58,107,0.08);
  --shadow-md: 0 4px 24px rgba(27,58,107,0.12);

  /* Semantic aliases — used throughout app.js */
  --danger:  #e53935;
  --success: #27ae60;
  --warning: #f39c12;
  --primary: #1B3A6B;
  --muted:   #6b7a99;
  --info:    #4A90C4;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform 0.3s;
  overflow: hidden;
}

.sidebar-brand {
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-icon {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand-icon svg { width: 20px; height: 20px; }

.sidebar-brand-text .name {
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.5px;
}
.sidebar-brand-text .sub {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.nav-group-label {
  font-size: 9.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 12px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 1px;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: var(--sky); color: white; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 34px; height: 34px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: white; }
.user-role { font-size: 10px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 1px; }
.btn-logout {
  width: 100%;
  padding: 9px;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-logout:hover { background: var(--red); color: white; }

.btn-site-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.1);
  transition: all 0.15s;
  letter-spacing: 0.3px;
}
.btn-site-link:hover { background: rgba(74,144,196,0.15); color: var(--sky); border-color: var(--sky); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--navy); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content {
  padding: 28px;
  flex: 1;
}

/* ============================================================
   CARDS & STATS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--sky-light); color: var(--sky); }
.stat-icon.green { background: var(--green-light); color: var(--green); }
.stat-icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.red { background: var(--red-light); color: var(--red); }
.stat-icon.navy { background: rgba(27,58,107,0.08); color: var(--ink); }

.stat-value { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ============================================================
   TABLES
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  flex: 1;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  background: #f8fafd;
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #f0f4fa;
  color: var(--text);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafd; }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-blue { background: var(--sky-light); color: var(--sky); }
.badge-gray { background: #f0f4fa; color: var(--text-muted); }
.badge-navy { background: rgba(27,58,107,0.08); color: var(--ink); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}
.btn-primary { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--navy-light); }
.btn-sky { background: var(--sky); color: white; }
.btn-sky:hover { background: #3a80b4; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #219150; }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #c62828; }
.btn-outline {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--sky); color: var(--sky); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}
.btn-ghost:hover { color: var(--navy); background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 6px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-1 { grid-template-columns: 1fr; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

label.fld {
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"], input[type="email"], input[type="number"],
input[type="date"], input[type="password"], input[type="tel"],
select, textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  background: white;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--sky); }
textarea { resize: vertical; min-height: 80px; }
/* Bootstrap-compatible alias used in JS */
.form-control { width: 100%; }
.form-label { font-size: 12px; font-weight: 600; color: #4a5568; text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-bottom: 5px; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  width: 280px;
}
.search-bar input {
  border: none;
  background: transparent;
  font-size: 13px;
  width: 100%;
  outline: none;
  padding: 0;
}
.search-bar .icon { color: var(--text-muted); font-size: 14px; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,20,50,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: slideUp 0.2s ease;
}
.modal.modal-lg { max-width: 820px; }
.modal.modal-sm { max-width: 420px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--navy); flex: 1; }
.modal-close {
  width: 30px; height: 30px;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}
.modal-close:hover { background: var(--red-light); color: var(--red); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #fafbff;
  border-radius: 0 0 16px 16px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  min-width: 280px;
  max-width: 380px;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
.toast.info { background: var(--navy); color: white; }
.toast.warning { background: var(--orange); color: white; }

/* ============================================================
   DETAIL PAGE
   ============================================================ */
.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.detail-avatar {
  width: 64px; height: 64px;
  background: var(--navy);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.detail-name { font-size: 22px; font-weight: 700; color: var(--navy); }
.detail-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
  width: fit-content;
}
.tab {
  padding: 8px 18px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
}
.tab.active { background: white; color: var(--navy); box-shadow: var(--shadow); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-warning { background: var(--orange-light); color: #7a4f00; border: 1px solid #ffe082; }
.alert-danger { background: var(--red-light); color: #7a0000; border: 1px solid #ffcdd2; }
.alert-info { background: var(--sky-light); color: #1a4a7a; border: 1px solid #b3d4f0; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; }

/* ============================================================
   LOADING
   ============================================================ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-muted);
  gap: 12px;
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--sky);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   ALERT EXPIRY INDICATORS
   ============================================================ */
.expiry-ok { color: var(--green); font-weight: 600; }
.expiry-soon { color: var(--orange); font-weight: 600; }
.expiry-expired { color: var(--red); font-weight: 600; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--navy);
}

@media (max-width: 900px) {
  /* ── Sidebar: full width slide-in on mobile ── */
  .sidebar {
    transform: translateX(-100%);
    width: min(300px, 85vw);   /* wider but capped */
    z-index: 300;              /* above topbar */
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 32px rgba(0,0,0,.4); }

  /* ── Overlay: covers everything including topbar ── */
  /* z-index already set globally to 250 */

  /* ── Main: no left margin, slight top padding for topbar ── */
  .main { margin-left: 0; }

  /* ── Topbar ── */
  .mobile-menu-btn { display: block; }
  .topbar { padding: 0 10px; gap: 6px; height: 52px; position: sticky; top: 0; z-index: 200; }
  .topbar-title { font-size: 15px; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Hide lang switcher & search on small screens — show compact version */
  .lang-switcher { display: none !important; }
  .topbar-search-btn { display: none !important; }
  #topbarPermanent { gap: 4px !important; }

  /* ── Topbar actions: compact + scrollable on mobile ── */
  .topbar-actions {
    overflow-x: auto;
    flex-shrink: 1;
    min-width: 0;
    max-width: 50vw;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    display: flex;
    gap: 4px;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions .btn {
    font-size: 11px !important;
    padding: 5px 8px !important;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Forms ── */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr; }

  /* ── Stats grid: 2 cols ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* ── Content padding ── */
  .content { padding: 10px; }

  /* ── Inline style grids → collapse to 1 col on mobile ── */
  [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:1fr 1fr 1fr"] { grid-template-columns: 1fr 1fr !important; }
  [style*="grid-template-columns:repeat(4,1fr)"] { grid-template-columns: 1fr 1fr !important; }
  .search-bar { width: 100%; }

  /* ── Tables: scroll horizontally ── */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 500px; }

  /* ── Cards ── */
  .card { border-radius: 10px; }
  .card-header { flex-wrap: wrap; gap: 8px; }

  /* ── Stat cards ── */
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }

  /* ── Quick action buttons: horizontal scroll row ── */
  .quick-actions-bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    gap: 8px !important;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .quick-actions-bar::-webkit-scrollbar { display: none; }
  .quick-actions-bar .btn { flex-shrink: 0; font-size: 12px !important; padding: 7px 12px !important; white-space: nowrap; }

  /* ── Modal ── */
  .modal, .modal-box { width: 96vw !important; max-width: 96vw !important; margin: 8px auto; max-height: 92vh; overflow-y: auto; }
  .modal-footer { flex-wrap: wrap; gap: 8px; }

  /* ── Week sheet table ── */
  .week-table th, .week-table td { min-width: 60px !important; font-size: 11px; padding: 4px 2px !important; }
}

@media (max-width: 500px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 8px; }
  .topbar { padding: 0 8px; }
  .stat-card { padding: 10px; }
  .stat-value { font-size: 20px; }
  .modal, .modal-box { width: 100vw !important; max-width: 100vw !important; margin: 0; border-radius: 16px 16px 0 0; position: fixed; bottom: 0; top: auto; }
  .modal-body { max-height: 60vh; overflow-y: auto; }
}

/* ============================================================
   MISC
   ============================================================ */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); font-size: 12px; }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.w-full { width: 100%; }

.divider { height: 1px; background: var(--border); margin: 20px 0; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.info-item label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 4px;
}
.info-item span {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ============================================================
   FILE UPLOAD
   ============================================================ */
.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--bg);
}
.file-upload-area:hover {
  border-color: var(--sky);
  background: var(--sky-light);
}
.file-upload-text {
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ============================================================
   DARK MODE
   ============================================================ */
body.dark {
  --bg: #121a28;
  --white: #1c2536;
  --text: #eef2fb;
  --text-muted: #9fb0d0;
  --ink: #dbe6fb;          /* il testo "navy" diventa azzurro chiaro/bianco */
  --border: #2a3a5a;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.4);
  --sky-light: rgba(74,144,196,0.15);
  --green-light: rgba(39,174,96,0.15);
  --red-light: rgba(229,57,53,0.15);
  --orange-light: rgba(243,156,18,0.15);
  /* alias overrides for dark mode */
  --bg-alt:     #1e2d45;
  --bg-light:   #1e2d45;
  --bg-card:    #1a2235;
  --surface:    #1a2235;
  --muted:      #8899bb;
  --light:      #1e2d45;
  /* Semantic aliases in dark mode */
  --danger:  #fc8181;
  --success: #68d391;
  --warning: #fbd38d;
  --primary: #4a9eff;
  --info:    #7dc3f5;
}
body.dark .topbar { background: #1a2235; border-color: #2a3a5a; }
body.dark .sidebar { background: #0d1525; }
body.dark thead th { background: #1e2d45; }
body.dark tbody tr:hover td { background: #1e2d45; }
body.dark .modal { background: #1a2235; }
body.dark .modal-footer { background: #162030; }
body.dark .modal-close { background: #2a3a5a; }
body.dark input[type="text"], body.dark input[type="email"],
body.dark input[type="number"], body.dark input[type="date"],
body.dark input[type="password"], body.dark input[type="tel"],
body.dark select, body.dark textarea {
  background: #1e2d45; color: var(--text); border-color: #2a3a5a;
}
body.dark .search-bar { background: #1e2d45; border-color: #2a3a5a; }
body.dark .search-bar input { color: var(--text); }
body.dark .tabs { background: #1e2d45; }
body.dark .tab.active { background: #2a3a5a; }
body.dark .file-upload-area { background: #1e2d45; border-color: #2a3a5a; }
body.dark .btn-outline { color: var(--text); border-color: #2a3a5a; }
body.dark .btn-ghost { color: var(--text-muted); }
body.dark .btn-ghost:hover { background: #2a3a5a; color: var(--text); }
body.dark .badge-gray { background: #2a3a5a; color: var(--text-muted); }
body.dark .alert-info { background: rgba(74,144,196,0.12); color: #7dc3f5; border-color: #2a5a8a; }
body.dark .alert-warning { background: rgba(243,156,18,0.12); color: #fbd38d; border-color: #7a5000; }
body.dark .alert-danger { background: rgba(229,57,53,0.12); color: #fc8181; border-color: #7a0000; }
/* Icone/badge "navy" leggibili anche in dark mode */
body.dark .stat-icon.navy { background: rgba(147,197,253,0.16); color: var(--ink); }
body.dark .badge-navy     { background: rgba(147,197,253,0.16); color: var(--ink); }

/* ── WORK HOURS — Weekly Grid ───────────────────────────── */
.hours-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
@media (max-width: 900px) {
  .hours-week-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 600px) {
  .hours-week-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Caposquadra Excel sheet — scrollable on mobile */
.capo-sheet-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.capo-sheet-wrap table { min-width: 700px; }
.capo-sheet-wrap td, .capo-sheet-wrap th {
  border: 1px solid var(--border);
  padding: 6px 4px;
  font-size: 12px;
}
.capo-sheet-wrap tr:hover td { background: rgba(74,144,196,0.04); }

/* mb-16 utility */
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* ── Monthly hours grid — cell add button ─────────────────── */
.cell-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: transparent;
  color: var(--border);
  font-size: 18px;
  font-weight: 300;
  cursor: pointer;
  border: 1px dashed transparent;
  transition: all 0.15s;
  line-height: 1;
  user-select: none;
}
.cell-add-btn:hover {
  background: var(--sky-light);
  color: var(--sky);
  border-color: var(--sky);
  font-weight: 600;
}

body.dark .capo-sheet-wrap td,
body.dark .capo-sheet-wrap th { border-color: #2a3a5a; }

/* Dark mode toggle button */
.dark-toggle {
  width: 36px; height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--text-muted);
}
.dark-toggle:hover { background: var(--bg); color: var(--text); }

/* ============================================================
   GLOBAL SEARCH OVERLAY
   ============================================================ */
.gsearch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,20,50,0.6);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  animation: fadeIn 0.15s ease;
}
.gsearch-box {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 580px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}
.gsearch-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.gsearch-input-wrap input {
  flex: 1;
  border: none;
  font-size: 16px;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 0;
}
.gsearch-results { max-height: 400px; overflow-y: auto; }
.gsearch-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.1s;
}
.gsearch-item:hover { background: var(--bg); }
.gsearch-item .avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--navy);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.gsearch-item .info { flex: 1; }
.gsearch-item .name { font-weight: 600; font-size: 14px; color: var(--text); }
.gsearch-item .meta { font-size: 12px; color: var(--text-muted); }
.gsearch-empty { padding: 32px; text-align: center; color: var(--text-muted); font-size: 14px; }
.gsearch-shortcut {
  font-size: 11px;
  color: var(--text-muted);
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 16px;
}
.gsearch-shortcut kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: monospace;
}

/* ============================================================
   SCADENZE ALERT WIDGET
   ============================================================ */
.expiry-widget {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
}
.expiry-widget-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.expiry-widget-title { font-size: 15px; font-weight: 700; color: var(--navy); flex: 1; }
.expiry-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 3px;
  border-radius: 8px;
}
.expiry-tab {
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
}
.expiry-tab.active { background: white; color: var(--navy); box-shadow: var(--shadow); }
.expiry-list { padding: 4px 0; max-height: 280px; overflow-y: auto; }
.expiry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: pointer;
}
.expiry-row:last-child { border-bottom: none; }
.expiry-row:hover { background: var(--bg); }
.expiry-row .emp-name { font-weight: 600; font-size: 13px; flex: 1; }
.expiry-row .doc-name { font-size: 12px; color: var(--text-muted); }
.expiry-row .days-badge { flex-shrink: 0; }

/* ============================================================
   EMPLOYEE FILTER TABS
   ============================================================ */
.emp-filter-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.emp-filter-btn {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}
.emp-filter-btn.active {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}
.emp-filter-btn:hover:not(.active) { border-color: var(--sky); color: var(--sky); }

/* ============================================================
   PERSONAL DOCUMENTS — Employee upload cards
   ============================================================ */
.doc-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: border-color 0.2s, background 0.2s;
}
.doc-card:hover { box-shadow: var(--shadow); }
.doc-card .doc-icon { font-size: 36px; line-height: 1; flex-shrink: 0; }
.doc-card .doc-info { flex: 1; min-width: 200px; }
.doc-card .doc-name { font-weight: 700; font-size: 15px; color: var(--navy); }
.doc-card .doc-note { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.doc-card .doc-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

body.dark .doc-card { border-color: #2a3a5a; }
body.dark .doc-name { color: var(--text); }

/* ============================================================
   LANGUAGE SWITCHER
   ============================================================ */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 5px;
}
.lang-btn {
  padding: 3px 9px;
  border: none;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
  line-height: 1.5;
}
.lang-btn:hover { background: rgba(27,58,107,0.08); color: var(--navy); }
.lang-btn.lang-btn-active {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 4px rgba(27,58,107,0.18);
}
body.dark .lang-switcher { background: #1e2d48; border-color: #2a3a5a; }
body.dark .lang-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* Compact lang button — mobile only */
.mobile-lang-btn { display: none; }
@media (max-width: 900px) {
  .mobile-lang-btn { display: inline-flex !important; align-items: center; justify-content: center; min-width: 36px; }
}

/* ============================================================
   RTL — Arabic layout overrides  [dir="rtl"]
   ============================================================ */

/* Arabic font */
html[dir="rtl"] body {
  font-family: 'Cairo', 'Tajawal', 'Inter', sans-serif;
}

/* ── Sidebar: anchored to RIGHT on desktop ─────────────────── */
[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
  /* NO transform here — sidebar is always visible on desktop */
}

/* ── Main content: leave space on the RIGHT for the sidebar ── */
[dir="rtl"] .main {
  margin-left: 0;
  margin-right: var(--sidebar-w);
}

/* ── Navigation items ──────────────────────────────────────── */
[dir="rtl"] .nav-item          { text-align: right; flex-direction: row-reverse; }
[dir="rtl"] .nav-badge         { margin-left: 0; margin-right: auto; }
[dir="rtl"] .nav-group-label   { text-align: right; letter-spacing: 0; }

/* Sidebar footer user row */
[dir="rtl"] .user-info         { flex-direction: row-reverse; }

/* Sidebar brand */
[dir="rtl"] .sidebar-brand     { flex-direction: row-reverse; }
[dir="rtl"] .sidebar-brand-text{ text-align: right; }

/* ── Topbar ────────────────────────────────────────────────── */
/* Keep LTR flex order — just right-align the title text.
   The lang/dark/search cluster stays at the right edge, which
   is perfectly natural for Arabic portals too. */
[dir="rtl"] .topbar-title      { text-align: right; }

/* ── Content area ─────────────────────────────────────────── */
[dir="rtl"] .card              { text-align: right; }
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
[dir="rtl"] .stat-card         { flex-direction: row-reverse; text-align: right; }

/* Tables */
[dir="rtl"] table              { direction: rtl; }

/* Forms */
[dir="rtl"] .form-group label,
[dir="rtl"] .fld               { display: block; text-align: right; }
[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea           { text-align: right; direction: rtl; }

/* Alerts */
[dir="rtl"] .alert             { text-align: right; }

/* Page-header rows */
[dir="rtl"] .page-header       { flex-direction: row-reverse; text-align: right; }
[dir="rtl"] .btn-group         { flex-direction: row-reverse; }

/* Modals */
[dir="rtl"] .modal-header      { flex-direction: row-reverse; }
[dir="rtl"] .modal-body        { text-align: right; direction: rtl; }

/* Toast: slide in from the LEFT in RTL */
[dir="rtl"] .toast-container   { right: auto; left: 24px; }
[dir="rtl"] .toast             { flex-direction: row-reverse; text-align: right; }

/* ── Arabic font throughout ─────────────────────────────────── */
html[dir="rtl"] body,
html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea,
html[dir="rtl"] button {
  font-family: 'Cairo', 'Tajawal', 'Inter', sans-serif;
}

/* ── Numbers & codes stay LTR inside RTL ────────────────────── */
[dir="rtl"] .stat-value,
[dir="rtl"] td[style*="text-align:right"],
[dir="rtl"] .badge             { direction: ltr; unicode-bidi: embed; }

/* ── Card header flex rows ───────────────────────────────────── */
[dir="rtl"] .card-header       { flex-direction: row-reverse; }
[dir="rtl"] .card-title        { text-align: right; }

/* ── Flex rows with gap (action bars, filter bars) ───────────── */
[dir="rtl"] .page-header,
[dir="rtl"] [style*="display:flex"][style*="align-items:center"] { direction: rtl; }

/* ── Empty state centered text ──────────────────────────────── */
[dir="rtl"] .empty-state       { direction: rtl; }

/* ── Table header ────────────────────────────────────────────── */
[dir="rtl"] thead th           { text-align: right; }

/* ── Progress bar stays LTR so it fills left→right ─────────── */
[dir="rtl"] [style*="border-radius:4px"][style*="height:"] { direction: ltr; }

/* ── Topbar action cluster stays as-is (already right-aligned) */
[dir="rtl"] .topbar-actions    { flex-direction: row-reverse; }

/* ── Nav icon spacing ────────────────────────────────────────── */
[dir="rtl"] .nav-icon          { margin-right: 0; margin-left: 10px; }

/* ── Modal footer buttons ────────────────────────────────────── */
[dir="rtl"] .modal-footer      { flex-direction: row-reverse; }

/* ── Tab buttons ─────────────────────────────────────────────── */
[dir="rtl"] .tab-bar           { flex-direction: row-reverse; }

/* ── Stats grid ──────────────────────────────────────────────── */
[dir="rtl"] .stats-grid        { direction: rtl; }
[dir="rtl"] .stat-label        { text-align: right; }

/* ── ── Mobile RTL (≤ 900 px) ─────────────────────────────────── */
@media (max-width: 900px) {
  /* Sidebar slides in from the RIGHT on mobile */
  [dir="rtl"] .sidebar          { transform: translateX(100%); }
  [dir="rtl"] .sidebar.open     { transform: translateX(0); }
  /* No sidebar offset on mobile */
  [dir="rtl"] .main             { margin-right: 0; }
  /* Move the hamburger button visually to the right */
  [dir="rtl"] .mobile-menu-btn  { order: 10; margin-left: auto; }
  [dir="rtl"] .topbar-title     { order: 0; }
}

/* ── Additional CSS variables (used in app.js) ─────────────── */
:root {
  --danger:       #e53935;
  --bg-alt:       #f4f7fc;
  --bg-soft:      #f8fafd;
  --bg-secondary: #f0f4fa;
  /* Aliases for variables used across JS-generated HTML */
  --primary:      #1B3A6B;    /* = --navy */
  --bg-light:     #f0f4fa;    /* = --bg */
  --bg-card:      #ffffff;    /* = --white */
  --surface:      #ffffff;    /* = --white */
  --light:        #f0f4fa;    /* = --bg */
  --muted:        #6b7a99;    /* = --text-muted */
  --warning:      #f39c12;    /* = --orange */
  --success:      #27ae60;    /* = --green */
  --info:         #4A90C4;    /* = --sky */
}

/* ── Extra modal sizes ─────────────────────────────────────── */
.modal.modal-xl { max-width: 1100px; }

/* ── Tab bar (siteContent section) ────────────────────────── */
.tab-bar { display:flex; gap:4px; margin-bottom:16px; border-bottom:2px solid var(--border); flex-wrap:wrap; }
.tab-btn { padding:8px 16px; border:none; background:none; cursor:pointer; font-size:13px; font-weight:600; color:var(--text-muted); border-bottom:2px solid transparent; margin-bottom:-2px; transition:all 0.15s; }
.tab-btn:hover { color:var(--navy); }
.tab-btn.active { color:var(--navy); border-bottom-color:var(--navy); }
body.dark .tab-btn { color:rgba(255,255,255,0.5); }
body.dark .tab-btn.active { color:#fff; border-bottom-color:var(--sky); }

/* ============================================================
   MOBILE BOTTOM NAV BAR
   ============================================================ */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--navy);
  z-index: 200;
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -2px 16px rgba(0,0,0,.2);
}
.mobile-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  padding: 6px 4px;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  transition: color .15s;
  min-height: 44px;
}
.mobile-bottom-nav button.active { color: white; }
.mobile-bottom-nav button .bn-icon { font-size: 20px; line-height: 1; }
.mobile-bottom-nav button .bn-label { font-size: 9px; letter-spacing: .3px; }

/* Chat room card — full height between topbar and bottom nav */
.chat-room-card {
  height: calc(100vh - var(--header-h) - 24px);
}
@media (max-width: 900px) {
  .chat-room-card {
    /* topbar 56px + bottom-nav 60px + content padding 20px */
    height: calc(100svh - 56px - 60px - 20px);
    min-height: 300px;
  }
}

/* Sidebar overlay — hidden by default on ALL screen sizes */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 250;  /* above topbar (200) but below sidebar (300) */
}
.sidebar-overlay.show { display: block; }

@media (max-width: 900px) {
  .mobile-bottom-nav { display: flex; }
  /* Push content above bottom nav */
  .main { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
}

/* ============================================================
   MOBILE UX IMPROVEMENTS
   ============================================================ */
/* Touch-friendly minimum target size */
@media (max-width: 900px) {
  /* Touch-friendly buttons — but NOT topbar ghost buttons (they should stay compact) */
  .btn:not(.btn-ghost) { min-height: 38px; }
  .nav-item { min-height: 44px; }

  /* Prevent iOS auto-zoom on input focus (must be 16px+) */
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
  select, textarea { font-size: 16px !important; }

  /* Better stat cards on mobile */
  .stats-grid { gap: 10px; }
  .stat-card { border-radius: 12px; }

  /* Full-width buttons in card footers */
  .card-footer .btn, .modal-footer .btn { flex: 1; justify-content: center; }

  /* Fix table overflow */
  .table-wrap table { font-size: 12px; }

  /* Topbar — keep it clean */
  .topbar { height: 56px; padding: 0 12px; gap: 8px; }
  .topbar-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Toast above bottom nav */
  .toast-container { bottom: 70px !important; right: 8px !important; left: 8px !important; max-width: none !important; }
  .toast { width: 100%; }

  /* Info grid: single column on mobile */
  .info-grid { grid-template-columns: 1fr; }

  /* Smooth scroll */
  .content { overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }
}

/* iOS safe area insets */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
  @media (max-width: 900px) {
    /* Expand topbar height to include iPhone notch/Dynamic Island safe area.
       Without this, the fixed height of 52px is shared with the padding-top
       so content gets crushed to ~5px on iPhone 14/15. */
    .topbar {
      height: calc(52px + env(safe-area-inset-top, 0px));
      padding-top: env(safe-area-inset-top, 0px);
    }
    /* Bottom nav: also needs height expansion for home indicator bar */
    .mobile-bottom-nav {
      height: calc(60px + env(safe-area-inset-bottom, 0px));
    }
  }
}

/* ============================================================
   SKELETON LOADING
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f0f4fa 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.4s ease infinite;
  border-radius: 6px;
  display: inline-block;
}
@keyframes skeleton-wave {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
body.dark .skeleton { background: linear-gradient(90deg, #2d3748 25%, #3a4560 50%, #2d3748 75%); background-size: 200% 100%; }

/* ============================================================
   ADMIN GUIDE PAGE
   ============================================================ */
.guide-hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: white;
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.guide-hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,.06);
  border-radius: 50%;
}
.guide-hero h1 { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.guide-hero p  { opacity: .75; font-size: 14px; }

.role-card {
  border-radius: 14px;
  border: 1.5px solid var(--border);
  padding: 20px;
  background: white;
  transition: box-shadow .2s, transform .2s;
}
.role-card:hover { box-shadow: 0 6px 24px rgba(27,58,107,.1); transform: translateY(-2px); }
.role-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.role-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.role-badge.admin    { background: #fff0f0; color: #c0392b; }
.role-badge.hr       { background: #f0f6ff; color: #2563eb; }
.role-badge.wh       { background: #f0fff4; color: #16a34a; }
.role-badge.capo     { background: #fff7ed; color: #ea580c; }
.role-badge.employee { background: #f5f3ff; color: #7c3aed; }
.role-badge.client   { background: #fefce8; color: #ca8a04; }

.guide-perm-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.guide-perm-list li { font-size: 13px; color: var(--text-muted); display: flex; align-items: flex-start; gap: 6px; }
.guide-perm-list li::before { content: '✓'; color: var(--green); font-weight: 700; flex-shrink: 0; }
.guide-perm-list li.restricted::before { content: '✗'; color: #e53935; }
.guide-perm-list li.partial::before   { content: '◐'; color: #f39c12; }

.access-matrix { width: 100%; border-collapse: collapse; font-size: 12px; }
.access-matrix th { background: var(--navy); color: white; padding: 10px 8px; text-align: center; font-weight: 600; }
.access-matrix th:first-child { text-align: left; }
.access-matrix td { padding: 8px; border-bottom: 1px solid var(--border); text-align: center; }
.access-matrix tr:hover td { background: var(--bg-alt); }
.access-matrix td:first-child { text-align: left; font-weight: 600; font-size: 12px; }
.access-matrix .ck  { color: var(--green); font-size: 16px; }
.access-matrix .no  { color: #e2e8f0; font-size: 14px; }
.access-matrix .partial { color: var(--orange); font-size: 14px; }

body.dark .role-card { background: var(--navy-dark); border-color: rgba(255,255,255,.1); }
body.dark .guide-hero { background: linear-gradient(135deg, #0d1f3c 0%, #1a3a6b 100%); }

/* ============================================================
   EMPTY STATE IMPROVEMENTS
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: .7; }
.empty-state h3 { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; margin-bottom: 20px; }

/* ============================================================
   CARD IMPROVEMENTS
   ============================================================ */
.card-metric {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 12px;
  background: white;
  border: 1px solid var(--border);
}
.card-metric-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.card-metric-value { font-size: 22px; font-weight: 800; color: var(--text); }
.card-metric-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

body.dark .card-metric { background: var(--navy-dark); border-color: rgba(255,255,255,.1); }

/* ============================================================
   CALENDAR GRID (Calendario Unificato)
   ============================================================ */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border, #e2e8f0);
  min-width: 560px;
}
.cal-header-cell {
  background: var(--navy, #1B3A6B);
  color: white;
  text-align: center;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .5px;
}
.cal-cell {
  background: var(--bg-card, #fff);
  min-height: 80px;
  padding: 6px;
  cursor: pointer;
  transition: background .15s;
  vertical-align: top;
}
.cal-cell:hover { background: var(--bg-soft, #f8fafd); }
.cal-cell.cal-empty { background: var(--bg-alt, #f4f7fc); cursor: default; }
.cal-cell.cal-today { background: #EBF4FF; border: 2px solid var(--sky, #4A90C4); }
.cal-cell.cal-weekend { background: #fafafa; }
.cal-day-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy, #1B3A6B);
  margin-bottom: 4px;
}
.cal-cell.cal-weekend .cal-day-num { color: var(--muted, #6b7a99); }
body.dark .cal-cell { background: var(--bg-card, #1a2235); }
body.dark .cal-cell.cal-empty { background: var(--bg-alt, #1e2d45); }
body.dark .cal-cell.cal-today { background: #1B3A6B44; }
body.dark .cal-cell.cal-weekend { background: #151e30; }

@media (max-width: 640px) {
  .cal-grid { min-width: 100%; }
  .cal-cell { min-height: 50px; padding: 3px; }
  .cal-day-num { font-size: 11px; }
  .cal-cell div[style*="font-size:10px"] { display: none; }
}

/* ============================================================
   MOBILE RESPONSIVE IMPROVEMENTS — v20260521b
   ============================================================ */

/* ── Topbar: hide bell icon on mobile (it's in bottom nav) ── */
@media (max-width: 900px) {
  #topbarNotifBtn { display: none !important; }
}

/* ── Topbar: prevent title from being squished by action buttons ── */
@media (max-width: 900px) {
  .topbar { overflow: hidden; }
  .topbar-title {
    flex: 1 1 0;
    min-width: 0;        /* allow shrink to ellipsis */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-actions {
    flex: 0 1 auto;     /* don't grow, can shrink */
    min-width: 0;
    max-width: 42vw;    /* tighter cap to leave room for title */
  }
  /* Compact topbar permanent controls */
  #topbarPermanent { gap: 4px !important; flex-shrink: 0; }
  #topbarPermanent .dark-toggle { width: 30px; height: 30px; font-size: 13px; }
  .mobile-lang-btn { min-width: 30px !important; font-size: 11px !important; padding: 3px 6px !important; }
}

/* ── Grid collapse: missing patterns from original CSS ──────── */
@media (max-width: 900px) {
  /* 3-column → 2-column */
  [style*="grid-template-columns:repeat(3,1fr)"]    { grid-template-columns: 1fr 1fr !important; }
  /* 5-column → 3-column */
  [style*="grid-template-columns:repeat(5,1fr)"]    { grid-template-columns: 1fr 1fr 1fr !important; }
  /* 2fr+1fr side-by-side → stack */
  [style*="grid-template-columns:2fr 1fr"]          { grid-template-columns: 1fr !important; }
  /* complex form rows */
  [style*="grid-template-columns:2fr 80px 1fr auto"]{ grid-template-columns: 1fr 1fr !important; }
  /* icon + content layout → stack on mobile */
  [style*="grid-template-columns:auto 1fr;gap:20px"]{ grid-template-columns: 1fr !important; }
  /* 12-month payroll grid → 4 per row on tablet */
  [style*="grid-template-columns:repeat(12,1fr)"]   { grid-template-columns: repeat(4,1fr) !important; }
  /* 7-day week grid: keep 7 columns but use minmax so cells fit */
  [style*="grid-template-columns:repeat(7,1fr)"] {
    grid-template-columns: repeat(7, minmax(40px, 1fr)) !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Invoice / quotation line-item rows: stack description ── */
  [style*="grid-template-columns:1fr auto auto auto auto"] {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  /* Description input fills its own row */
  [style*="grid-template-columns:1fr auto auto auto auto"] > *:first-child {
    flex: 1 1 100% !important;
    min-width: 0;
  }
  /* Rest of inputs shrink to content */
  [style*="grid-template-columns:1fr auto auto auto auto"] > *:not(:first-child) {
    flex: 0 0 auto;
    min-width: 0;
  }

  /* ── Card header improvements ── */
  .card-header { padding: 10px 14px; gap: 8px; }
  .card-header .search-bar { flex: 1; min-width: 0; }

  /* ── Stat cards: prevent overflow with small values ── */
  .stat-card { padding: 12px 10px; gap: 10px; }
  .stat-icon { width: 40px; height: 40px; font-size: 19px; }
}

/* ── Small phones (≤600px) ─────────────────────────────────── */
@media (max-width: 600px) {
  /* 3-col → 2-col (already set at 900, kept here for clarity) */
  [style*="grid-template-columns:repeat(3,1fr)"]  { grid-template-columns: 1fr 1fr !important; }
  /* 5-col → 2-col */
  [style*="grid-template-columns:repeat(5,1fr)"]  { grid-template-columns: 1fr 1fr !important; }
  /* 12-month → 3 per row */
  [style*="grid-template-columns:repeat(12,1fr)"] { grid-template-columns: repeat(3,1fr) !important; }

  /* Week grid: force overflow scroll on tiny screens */
  [style*="grid-template-columns:repeat(7,1fr)"] {
    grid-template-columns: repeat(7, 44px) !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Very small phones (≤420px) ───────────────────────────── */
@media (max-width: 420px) {
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 10px; }
  .stat-icon  { width: 36px; height: 36px; font-size: 17px; }
  .stat-card  { gap: 8px; padding: 10px 8px; }

  /* Stack nav badge */
  .nav-badge { font-size: 9px; padding: 1px 5px; }

  /* Better button sizes in card headers */
  .card-header .btn { font-size: 11px !important; padding: 5px 8px !important; }

  /* Keep section topbar action buttons legible */
  .topbar-actions .btn { font-size: 10px !important; padding: 4px 7px !important; }
}

/* ── Fix modal pinned-to-bottom on small phones ────────────── */
@media (max-width: 500px) {
  /* The modal-overlay is position:fixed; modal inside needs z-index
     when it uses position:fixed too (bottom-sheet pattern) */
  .modal, .modal-box { z-index: 1001 !important; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }
}

/* ── Tables: ensure horizontal scroll on ALL table wrappers ── */
@media (max-width: 900px) {
  .table-wrap { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  /* Shrink table font slightly to fit more columns */
  .table-wrap table { font-size: 12px; }
  .table-wrap td, .table-wrap th { padding: 8px 10px; }
}

/* ── Toast: stack properly above bottom nav on all mobiles ── */
@media (max-width: 900px) {
  .toast-container {
    bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 8px) !important;
    top: auto !important;
    right: 8px !important;
    left: 8px !important;
    max-width: none !important;
  }
  .toast { width: 100%; max-width: none; min-width: 0; }
}

/* ── Empty state: tighter padding on mobile ─────────────────── */
@media (max-width: 600px) {
  .empty-state { padding: 40px 16px; }
  .empty-state .icon { font-size: 36px; }
  .empty-state h3 { font-size: 15px; }
}

/* ── Info grid: single col on mobile ───────────────────────── */
@media (max-width: 900px) {
  .info-grid { grid-template-columns: 1fr; gap: 10px; }
}

/* ── Tab bars: scrollable on mobile ────────────────────────── */
@media (max-width: 900px) {
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .tab-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { flex-shrink: 0; }
  .tab-btn { flex-shrink: 0; white-space: nowrap; }
}

/* ============================================================
   MISSING UTILITY CLASSES (compatibility fixes)
   ============================================================ */

/* Alert success variant */
.alert-success {
  background: var(--green-light, #e8f8f0);
  color: #1a6e3a;
  border: 1px solid #a8e6c0;
}
body.dark .alert-success {
  background: rgba(39,174,96,0.12);
  color: #6ee3a0;
  border-color: #1a5c36;
}

/* Warning button */
.btn-warning {
  background: var(--orange, #f39c12);
  color: #fff;
  border: none;
}
.btn-warning:hover { background: #e67e22; }
body.dark .btn-warning { background: #c87f0a; }

/* Card body — padding container inside a card */
.card-body {
  padding: 16px 20px;
}

/* Table alias — inherits base table styles */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table thead th {
  background: #f8fafd;
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #f0f4fa;
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafd; }
body.dark .table thead th { background: #182235; }
body.dark .table tbody td { border-color: #1e2d45; }
body.dark .table tbody tr:hover td { background: #1e2d45; }

/* Table wrapper alias — same as table-wrap */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 900px) {
  .table-wrapper table { min-width: 500px; }
}

/* Margin utility mb-20 */
/* ── Owner Read-Only Mode ─────────────────────────────────── */
/* When the business owner is logged in, all write actions are hidden via CSS */
body.owner-mode .btn-primary:not(.owner-keep),
body.owner-mode button[onclick*="Form("],
body.owner-mode button[onclick*="openNew"],
body.owner-mode button[onclick*="delete"],
body.owner-mode button[onclick*="Delete"],
body.owner-mode button[onclick*="remove"],
body.owner-mode button[onclick*="Remove"],
body.owner-mode button[onclick*="import"],
body.owner-mode button[onclick*="Import"],
body.owner-mode button[onclick*="bulk"],
body.owner-mode button[onclick*="Bulk"],
body.owner-mode button[onclick*="approve"],
body.owner-mode button[onclick*="Approve"],
body.owner-mode button[onclick*="reject"],
body.owner-mode button[onclick*="Reject"],
body.owner-mode button[onclick*="update"],
body.owner-mode button[onclick*="Update"],
body.owner-mode button[onclick*="clear"],
body.owner-mode button[onclick*="Clear"] {
  display: none !important;
}
/* Keep the read-only indicator visible */
body.owner-mode .topbar::after {
  content: '👁 Modalità sola lettura';
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: #e67e22;
  padding: 3px 10px;
  border-radius: 12px;
  flex-shrink: 0;
  margin-right: 4px;
}

/* ── Company Switcher ──────────────────────────────────────── */
.company-switcher {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg, #f0f4fa);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 22px;
  padding: 3px;
  flex-shrink: 0;
}
.company-tab {
  padding: 5px 16px;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: transparent;
  color: var(--text-muted, #64748b);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
  white-space: nowrap;
  text-transform: uppercase;
}
.company-tab:hover {
  background: rgba(0,0,0,.06);
  color: var(--navy, #1B3A6B);
}
.company-tab.active {
  background: var(--company-color, #1B3A6B);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  transform: scale(1.03);
}
body.dark .company-switcher {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.12);
}
body.dark .company-tab { color: rgba(255,255,255,.5); }
body.dark .company-tab:hover { background: rgba(255,255,255,.1); color: #fff; }
body.dark .company-tab.active { color: #fff; }
@media (max-width: 640px) {
  .company-switcher { gap: 2px; padding: 2px; }
  .company-tab { padding: 4px 10px; font-size: 11px; }
}

.mb-20 { margin-bottom: 20px; }

/* Form row — horizontal layout for inline form groups */
.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 140px; }

/* Toggle switch label container */
.toggle-switch { cursor: pointer; display: inline-flex; align-items: center; gap: 10px; }

/* sc-tab — site content section tabs */
.sc-tab { padding: 8px 0; }

/* Color dot utilities */
.gray   { color: var(--text-muted, #888); }
.purple { color: #7c3aed; }

/* ── Mobile Week View (myhours) ────────────────────────────────── */
.week-day-row {
  display: flex;
  align-items: center;
  background: var(--white);
  border-radius: 14px;
  padding: 14px 16px;
  gap: 14px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
  border-left: 5px solid transparent;
  transition: background .15s;
}
.week-day-row.wdr-approved  { border-left-color: #16a34a; }
.week-day-row.wdr-submitted { border-left-color: #f59e0b; }
.week-day-row.wdr-correction{ border-left-color: #dc2626; }
.week-day-row.wdr-draft     { border-left-color: var(--sky); }
.week-day-row.wdr-empty     { border-left-color: #e5e7eb; }
.week-day-row.wdr-today     { background: #f0f9ff; }
.week-day-row.wdr-weekend   { background: var(--bg, #f8fafc); border-left-color: #e5e7eb; }

.wdr-date { display:flex;flex-direction:column;align-items:center;min-width:42px; }
.wdr-date .wdr-dow  { font-size:10px;font-weight:700;color:var(--text-muted);text-transform:uppercase;letter-spacing:.5px; }
.wdr-date .wdr-num  { font-size:24px;font-weight:900;color:var(--navy);line-height:1.1; }
.wdr-date .wdr-today-dot { width:6px;height:6px;background:var(--sky);border-radius:50%;margin-top:3px; }

.wdr-body { flex:1;min-width:0; }
.wdr-h    { font-size:22px;font-weight:900;color:var(--ink);line-height:1; }
.wdr-site { font-size:12px;color:var(--text-muted);margin-top:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
.wdr-note { font-size:11px;color:#dc2626;margin-top:4px;line-height:1.3; }
.wdr-ot   { font-size:11px;color:#f59e0b;margin-top:2px; }

.wdr-actions { display:flex;align-items:center;gap:8px;flex-shrink:0; }
.wdr-status  { font-size:20px; }
.wdr-btn-add  { background:var(--navy);color:#fff;border:none;border-radius:10px;padding:11px 16px;font-size:15px;font-weight:700;cursor:pointer;min-width:48px;min-height:48px;display:flex;align-items:center;justify-content:center; }
.wdr-btn-add:active { opacity:.8; }
.wdr-btn-edit { background:var(--bg,#f3f4f6);border:1px solid var(--border);border-radius:10px;padding:11px;font-size:17px;cursor:pointer;min-width:44px;min-height:44px;display:flex;align-items:center;justify-content:center; }
.wdr-btn-edit:active { background:var(--border); }
.wdr-btn-del  { background:#fff0f0;border:1px solid #fca5a5;border-radius:10px;padding:11px;font-size:17px;cursor:pointer;min-width:44px;min-height:44px;display:flex;align-items:center;justify-content:center; }
.wdr-btn-del:active { background:#fee2e2; }

/* Mobile hours form — bigger touch targets */
.hrs-stepper { display:flex;align-items:center;gap:8px; }
.hrs-stepper input[type=number] { flex:1;text-align:center;font-size:28px;font-weight:800;padding:10px;border:2px solid var(--border);border-radius:10px;-moz-appearance:textfield; }
.hrs-stepper input[type=number]::-webkit-inner-spin-button,
.hrs-stepper input[type=number]::-webkit-outer-spin-button { -webkit-appearance:none; }
.hrs-step-btn { background:var(--navy);color:#fff;border:none;border-radius:10px;width:48px;height:48px;font-size:22px;font-weight:700;cursor:pointer;flex-shrink:0;display:flex;align-items:center;justify-content:center; }
.hrs-step-btn:active { opacity:.75; }
