/* Token: _PROGETTI-INTERNI/design-systems/professionale.design.md */
:root {
  --primary: #0F172A;
  --bg: #F8FAFC;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-light: #DBEAFE;
  --slate-100: #F1F5F9;
  --slate-300: #CBD5E1;
  --border-input: #7D96B4;
  --emerald: #059669;
  --emerald-text: #05875F;
  --text-2: #475569;         /* slate-600: 7.6:1 su bianco */
  --danger: #B91C1C;         /* 6.4:1 su bianco */
  --danger-light: #FEE2E2;
  --warn: #92400E;           /* 7.1:1 su amber-100 */
  --warn-light: #FEF3C7;
  --ok-light: #D1FAE5;
  --ok-text: #065F46;         /* emerald-800: 7.6:1 su ok-light (emerald-text lì fa 3.99) */
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 1px 3px rgb(15 23 42 / .08);
  --font-heading: 'DM Sans', 'Inter', -apple-system, sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-heading); font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--primary); color: #fff;
  padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-family: var(--font-heading); font-weight: 700; font-size: 17px; padding: 4px 12px 16px; }
.brand small { display: block; font-weight: 400; font-size: 13px; color: var(--slate-300); }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: #E2E8F0; text-decoration: none; font-weight: 500; min-height: 44px;
}
.nav-link:hover { background: rgb(255 255 255 / .08); }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar .user { margin-top: auto; padding: 12px; font-size: 13px; color: var(--slate-300); }
.sidebar .user strong { color: #fff; display: block; font-size: 14px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }

/* móvil / personal: barra inferior */
.tabbar { display: none; }
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 16px 16px 96px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: #fff; border-top: 1px solid var(--slate-300);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto; /* titular: 7 voci non stanno in 360px */
  }
  .tabbar .nav-link {
    flex: 1 0 auto; min-width: 64px; flex-direction: column; gap: 2px; font-size: 12px; color: var(--text-2);
    padding: 6px 2px; justify-content: center; text-align: center;
  }
  .tabbar .nav-link.active { background: none; color: var(--accent); }
  .tabbar .nav-link:hover { background: none; }
  .mobile-head { display: flex !important; }
}
.mobile-head {
  display: none; align-items: center; justify-content: space-between; gap: 8px;
  margin: -16px -16px 16px; padding: 12px 16px; background: var(--primary); color: #fff;
}
.mobile-head .brand { padding: 0; font-size: 16px; }

/* ---------- componentes ---------- */
.card { background: #fff; border: 1px solid var(--slate-300); border-radius: var(--radius-md); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--slate-300); border-radius: var(--radius-md); padding: 14px 16px; }
.kpi .n { font-family: var(--font-heading); font-weight: 700; font-size: 28px; line-height: 1.1; }
.kpi .l { font-size: 13px; color: var(--text-2); }
.kpi.alert { border-color: var(--danger); background: var(--danger-light); }
.kpi.alert .n { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font: 600 14px var(--font-body); cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--primary); border-color: var(--border-input); }
.btn.secondary:hover { background: var(--slate-100); }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--emerald-text); }
.btn.sm { min-height: 44px; padding: 8px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time],
input[type=date], input[type=month], input[type=url], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: 15px var(--font-body); color: var(--primary);
  background: #fff; border: 1px solid var(--border-input); border-radius: var(--radius-sm);
}
textarea { min-height: 80px; resize: vertical; }
input[type=file] { width: 100%; min-height: 44px; padding: 2px 0; font: 14px var(--font-body); }
input[type=file]::file-selector-button { min-height: 44px; margin-right: 10px; padding: 0 14px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: #fff; font: 600 14px var(--font-body); color: var(--primary); cursor: pointer; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.field { margin-bottom: 14px; }
.fields-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; font-weight: 400; cursor: pointer; }
/* L'input stesso è il target da 44px; il riquadro visibile da 22px è disegnato al centro */
.check input {
  appearance: none; -webkit-appearance: none; width: 44px; height: 44px; margin: 0 -6px 0 -11px;
  flex-shrink: 0; cursor: pointer; border-radius: var(--radius-sm);
  background: center / 22px 22px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Crect x='1' y='1' width='20' height='20' rx='4' fill='%23fff' stroke='%237D96B4' stroke-width='2'/%3E%3C/svg%3E");
}
.check input:checked { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Crect width='22' height='22' rx='5' fill='%232563EB'/%3E%3Cpath d='m6 11.5 3.5 3.5L16 8' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.check input[type=radio] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Ccircle cx='11' cy='11' r='10' fill='%23fff' stroke='%237D96B4' stroke-width='2'/%3E%3C/svg%3E"); }
.check input[type=radio]:checked { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Ccircle cx='11' cy='11' r='10' fill='%23fff' stroke='%232563EB' stroke-width='2'/%3E%3Ccircle cx='11' cy='11' r='5.5' fill='%232563EB'/%3E%3C/svg%3E"); }
.check input:disabled { cursor: not-allowed; }
.check:has(input:disabled) { opacity: .55; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--slate-100); color: var(--text-2);
}
.badge.rot { background: var(--danger-light); color: var(--danger); }
.badge.ok { background: var(--ok-light); color: var(--ok-text); }
.badge.blue { background: var(--accent-light); color: var(--accent-hover); }
.badge.warn { background: var(--warn-light); color: var(--warn); }
.badge.bad { background: var(--danger-light); color: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--slate-100);
  flex-wrap: wrap;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 180px; }
.row .title { font-weight: 600; }
.row select { width: auto; min-width: 170px; }

.alert-box { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-box.bad { background: var(--danger-light); color: var(--danger); }
.alert-box.warn { background: var(--warn-light); color: var(--warn); }
.alert-box.ok { background: var(--ok-light); color: var(--ok-text); }
.empty { color: var(--text-2); padding: 12px 0; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--text-2); padding: 8px; border-bottom: 1px solid var(--slate-300); }
td { padding: 10px 8px; border-bottom: 1px solid var(--slate-100); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
/* Tabella chiavi: sotto 640px ogni riga diventa una card, con l'azione sempre visibile */
@media (max-width: 640px) {
  .stack thead { display: none; }
  .stack tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--slate-100); }
  .stack tr:last-child { border-bottom: 0; }
  .stack td { display: block; border: 0; padding: 2px 0; }
  .stack td[data-l]::before { content: attr(data-l) ': '; font-size: 13px; color: var(--text-2); }
  .stack td:last-child { padding-top: 8px; }
  .stack td:last-child select { flex: 1; }
}

/* ---------- calendario ---------- */
.cal-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--slate-300); border-radius: var(--radius-md); }
.cal { display: grid; min-width: 880px; font-size: 13px; }
.cal .h { background: var(--slate-100); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--slate-300); text-align: center; }
.cal .h.today { background: var(--accent-light); color: var(--accent-hover); }
.cal .apt { padding: 8px 10px; border-bottom: 1px solid var(--slate-100); border-right: 1px solid var(--slate-300); position: sticky; left: 0; background: #fff; z-index: 1; }
.cal .apt .zona { font-size: 12px; color: var(--text-2); }
.cal .c { border-bottom: 1px solid var(--slate-100); border-right: 1px solid var(--slate-100); padding: 4px; min-height: 64px; position: relative; display: flex; flex-direction: column; gap: 4px; }
.cal .c.occ::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: #93C5FD; }
.cal .c.occ.in::before { left: 50%; }
.cal .c.occ.out::before { right: 50%; }
.cal .c.occ.in.out::before { left: 0; right: 0; }
.chip {
  margin-top: 6px; border: 1px solid var(--border-input); border-left-width: 4px; border-radius: var(--radius-sm);
  background: #fff; padding: 4px 6px; text-align: left; font: 12px/1.3 var(--font-body); color: var(--primary);
  cursor: pointer; min-height: 44px; width: 100%;
}
.chip:hover { background: var(--slate-100); }
.chip.rot { border-left-color: var(--danger); }
.chip.none { background: var(--warn-light); }
.chip.hecha { border-left-color: var(--emerald); background: var(--ok-light); }
.chip.en_curso { border-left-color: var(--accent); }
.chip b { display: block; font-weight: 600; }
.cal .team .c { min-height: 36px; justify-content: center; align-items: center; flex-direction: row; flex-wrap: wrap; gap: 3px; }
.dot { width: 28px; height: 28px; border-radius: 50%; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.dot.si { background: var(--ok-light); color: var(--ok-text); }
.dot.no { background: var(--danger-light); color: var(--danger); text-decoration: line-through; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 0; font-size: 13px; color: var(--text-2); }
.legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* ---------- personal (móvil) ---------- */
.job { border-left: 4px solid var(--slate-300); }
.job.rot { border-left-color: var(--danger); }
.job.hecha { border-left-color: var(--emerald); }
.job.en_curso { border-left-color: var(--accent); }
.job .ventana { font-family: var(--font-heading); font-weight: 700; font-size: 18px; }
.day-title { font-family: var(--font-heading); font-weight: 700; font-size: 15px; margin: 20px 0 8px; color: var(--text-2); }
.day-title:first-child { margin-top: 0; }
.avail { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; } /* 7×44px entrano in 328px */
.avail button {
  min-height: 58px; border-radius: var(--radius-sm); border: 1px solid var(--border-input); background: #fff;
  font: 600 13px var(--font-body); color: var(--primary); cursor: pointer; padding: 4px 2px;
}
.avail button small { display: block; font-weight: 400; font-size: 12px; }
.avail button.si { background: var(--ok-light); border-color: var(--emerald); color: var(--ok-text); }
.avail button.no { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.avail .wd { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-2); }
.photo-prev { max-width: 100%; max-height: 220px; border-radius: var(--radius-sm); display: block; margin-top: 8px; }

/* ---------- modal / toast ---------- */
dialog { border: 0; border-radius: var(--radius-md); padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgb(15 23 42 / .3); color: var(--primary); }
dialog::backdrop { background: rgb(15 23 42 / .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--slate-300); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--slate-300); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 26px; cursor: pointer; width: 44px; height: 44px; color: var(--text-2); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--primary); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--danger); }
@media (max-width: 860px) { .toast { bottom: 88px; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(420px, 100%); padding: 28px; }
.demo-users { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.demo-users .btn { font-size: 13px; }
