/* DAI Manager — foglio di stile.

   L'idea: il mondo di DAI e' quello delle tavole tecniche e del cantiere. Il
   calendario e' una tavola di programmazione (barre che coprono i giorni, come
   un cronoprogramma), il tratteggio delle sezioni dice "ancora da decidere",
   in alto a destra c'e' il cartiglio. Tutto il resto resta sobrio.

   Regole di casa che restano: niente ombre decorative, raggi al massimo 4px,
   niente gradienti di decorazione. Le uniche sfumature sono i tratteggi, e
   sono un segno con un significato (in attesa), non un abbellimento. */

/* Euclid e' il font aziendale: se il file c'e' in public/assets/Euclid.ttf
   (allegato della pagina Notion "Procedure e Format") vince lui. Altrimenti
   Archivo, servito dall'app stessa: niente Google Fonts, i PC possono non
   avere internet. Licenza OFL in assets/fonts/Archivo-OFL.txt. */
@font-face {
  font-family: 'Euclid';
  src: url('/assets/Euclid.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Archivo';
  src: url('/assets/fonts/archivo-latin-standard-normal.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  src: url('/assets/fonts/archivo-latin-ext-standard-normal.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+2020, U+20A0-20AB,
    U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Archivo';
  src: url('/assets/fonts/archivo-latin-standard-italic.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: italic;
  font-display: swap;
}

:root {
  /* Carta e grafite */
  --paper: #f4f6f7;
  --sheet: #ffffff;
  --ink: #1f252b;
  --ink-2: #545c64;
  --ink-3: #8a929a;
  --rule: #d5dadd;
  --rule-soft: #e7eaec;
  --wash: #eef1f3;

  /* Rosso DAI: approvato, azioni principali */
  --red: #8b1a1a;
  --red-dark: #6b1414;
  --red-soft: #f6e6e6;
  --red-line: #d9a9a9;

  /* Giallo cantiere: cio' che aspetta una decisione */
  --yellow: #e0a526;
  --yellow-soft: #fbf1d9;
  --yellow-line: #f0d68f;
  --yellow-ink: #6b4a00;

  /* Azzurro lucido: oggi, collegamenti */
  --blue: #3e6d94;
  --blue-soft: #e4edf5;

  --green: #2f7d5b;
  --error: #a3271b;

  /* Il tratteggio delle sezioni: "in attesa". */
  --hatch: repeating-linear-gradient(135deg, var(--yellow-soft) 0 5px, var(--yellow-line) 5px 7px);

  --font: 'Euclid', 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 4px;
  --topbar-h: 54px;
  --tabbar-h: 62px;

  /* Nomi vecchi, ancora usati da qualche stile in linea nei moduli. */
  --dai-red: var(--red);
  --text-primary: var(--ink);
  --text-secondary: var(--ink-2);
  --text-tertiary: var(--ink-3);
  --border: var(--rule);
  --border-light: var(--rule-soft);
  --bg-subtle: var(--wash);
  --bg-surface: var(--sheet);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-size: 2rem;
  font-weight: 800;
  font-stretch: 108%;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0;
}
h2 {
  font-size: 1.2rem;
  font-weight: 700;
  font-stretch: 106%;
  letter-spacing: -0.01em;
  margin: 0;
}
h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

a {
  color: var(--blue);
}

code,
.mono {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

/* ---------- Accesso e cambio password ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--ink);
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--sheet);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0 28px 28px;
}

.login-box .brand {
  /* Il marchio in testa alla scheda, come l'intestazione di una tavola. */
  margin: 0 -28px 24px;
  padding: 18px 28px;
  background: var(--red);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
  font-stretch: 112%;
  letter-spacing: -0.01em;
}

.login-box .brand-sub {
  color: var(--ink-2);
  font-size: 14px;
  margin: -8px 0 22px;
}

/* ---------- Form ---------- */

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}

input[type='text'],
input[type='password'],
input[type='email'],
input[type='date'],
input[type='time'],
input[type='number'],
textarea,
select {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 11px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
  border-color: var(--blue);
}

/* Focus da tastiera sempre visibile, nel colore di "oggi". */
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
  min-height: 70px;
}

input:disabled,
select:disabled {
  background: var(--wash);
  color: var(--ink-3);
}

.hint {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-top: 4px;
}

/* ---------- Bottoni ---------- */

.btn-primary,
.btn-secondary,
.btn-inline {
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  line-height: 1.2;
}

.btn-primary {
  background: var(--red);
  color: #fff;
  border: 1px solid var(--red);
}
.btn-primary:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.btn-secondary {
  background: var(--sheet);
  color: var(--ink);
  border: 1px solid var(--rule);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--ink-3);
}

.btn-inline {
  background: var(--sheet);
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 5px 11px;
  font-size: 13px;
}
.btn-inline:hover:not(:disabled) {
  border-color: var(--ink-3);
}
/* "Approva" e' l'azione che si fa piu' spesso: piena, scura. */
.btn-inline.approve {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn-inline.approve:hover:not(:disabled) {
  background: #000;
}
.btn-inline.danger {
  color: var(--error);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

/* ---------- Messaggi ---------- */

.msg {
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 4px solid var(--rule);
  background: var(--sheet);
  margin-bottom: 16px;
}
.msg.error {
  border-left-color: var(--error);
  color: var(--error);
}
.msg.success {
  border-left-color: var(--green);
  color: var(--green);
}
/* Avviso persistente (richieste da evadere): resta finche' c'e' qualcosa da fare. */
.msg.alert {
  border: 1px solid var(--yellow-line);
  border-left: 4px solid var(--yellow);
  background: var(--yellow-soft);
  color: var(--yellow-ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ---------- Barra in alto: marchio, schede, chi sei ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  height: var(--topbar-h);
  background: var(--ink);
  color: #fff;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  background: var(--red);
  text-decoration: none;
  color: #fff;
}
.brand-mark {
  font-weight: 800;
  font-stretch: 115%;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-name {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
}

.nav {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 10px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 14px;
  color: #c3cad1;
  background: none;
  border: none;
  /* Il filetto trasparente riserva lo spazio: la scheda attiva non fa saltare il testo. */
  border-bottom: 3px solid transparent;
  border-top: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.nav-item:hover {
  color: #fff;
}
.nav-item.active {
  color: #fff;
  font-weight: 600;
  border-bottom-color: var(--yellow);
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex: none;
  display: none;
}
.nav-short {
  display: none;
}
/* Quanto aspetta una decisione: il giallo delle cose da fare. */
.nav-count {
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border-radius: 9px;
  padding: 1px 7px;
  line-height: 1.5;
}

.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  font-size: 13px;
  color: #c3cad1;
  white-space: nowrap;
}
.topbar-user .user-name {
  color: #fff;
  font-weight: 600;
}
.topbar-user .user-role::before {
  content: ', ';
}
.topbar-user .btn-logout {
  font-family: inherit;
  font-size: 13px;
  background: transparent;
  color: #c3cad1;
  border: 1px solid #4a535b;
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
}
.topbar-user .btn-logout:hover {
  color: #fff;
  border-color: #8a929a;
}

.lang-toggle {
  display: inline-flex;
  border: 1px solid #4a535b;
  border-radius: var(--radius);
  overflow: hidden;
}
.lang-toggle button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border: none;
  background: transparent;
  color: #c3cad1;
  cursor: pointer;
}
.lang-toggle button.active {
  background: #fff;
  color: var(--ink);
}

.main {
  padding: 28px 32px 64px;
  max-width: 1600px;
  margin: 0 auto;
}

/* Le schede della pagina Richieste: lo stesso controllo di Anno/Mese/Settimana. */
.req-tabs {
  margin-bottom: 18px;
}
.req-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
}
.tab-count:empty {
  display: none;
}
.tab-count {
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border-radius: 9px;
  padding: 0 7px;
  line-height: 1.6;
}
.req-tabs button.active .tab-count {
  background: #fff;
}
.archive-head {
  align-items: center;
}
.archive-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.archive-filters select {
  width: auto;
  min-width: 150px;
  padding: 7px 10px;
  font-size: 14px;
}
.tag-past {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--error);
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

/* ---------- Testa della pagina: titolo, sottotitolo, cartiglio ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.page-sub {
  color: var(--ink-2);
  font-size: 15px;
  margin: 6px 0 22px;
  max-width: 66ch;
}

/* Il cartiglio: il riquadro dati in un angolo della tavola. Il numero grande
   e' la cosa da sapere entrando nella pagina; i campi sotto la completano. */
.cartiglio {
  border: 1.5px solid var(--ink);
  background: var(--sheet);
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  font-size: 13px;
  min-width: 290px;
}
.cartiglio > div {
  padding: 8px 12px;
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  min-width: 0;
}
.cartiglio > div:nth-child(2n + 1):not(.cart-big) {
  border-right: 1px solid var(--rule);
}
.cartiglio > div:nth-child(2n) {
  border-right: none;
}
.cartiglio > div:last-child,
.cartiglio > div:nth-last-child(2):not(.cart-big):nth-child(even) {
  border-bottom: none;
}
.cart-big {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-right: none !important;
}
.cart-k {
  display: block;
  color: var(--ink-3);
  font-size: 11.5px;
  line-height: 1.3;
}
.cart-v {
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
/* Il numero grande non si taglia mai: e' l'etichetta accanto che va a capo. */
.cart-big .cart-v {
  display: inline;
  flex: none;
  overflow: visible;
  white-space: nowrap;
  font-size: 30px;
  font-stretch: 112%;
  color: var(--red);
  line-height: 1;
}
.cart-big .cart-k {
  display: inline;
  flex: 1;
  min-width: 0;
  white-space: normal;
  font-size: 13.5px;
  color: var(--ink-2);
}

.section {
  margin-bottom: 44px;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Riga secondaria sotto un contenuto principale: nota di decisione,
   "disattivato" accanto a un nome, e simili. */
.subtext {
  font-size: 12.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- Barra del calendario: quanto da vicino, e quando ---------- */

.year-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}
.year-nav .year {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 3.5ch;
  text-align: center;
}
.year-nav button,
.period-nav .step {
  font-family: inherit;
  font-size: 15px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  color: var(--ink-2);
}
.year-nav button:hover,
.period-nav .step:hover {
  border-color: var(--ink-3);
  color: var(--ink);
}

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.cal-toolbar .toolbar-action {
  margin-left: auto;
}

/* Tre distanze dallo stesso calendario: segmentato, si vedono tutte insieme. */
.view-switch {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--sheet);
  overflow: hidden;
}
.view-switch button {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 14px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.view-switch button + button {
  border-left: 1px solid var(--rule-soft);
}
.view-switch button:hover {
  color: var(--ink);
}
.view-switch button.active {
  background: var(--ink);
  color: #fff;
  font-weight: 600;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.period-label {
  font-size: 1.35rem;
  font-weight: 700;
  font-stretch: 106%;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  margin: 0 6px;
}
/* In italiano i mesi vanno minuscoli: si alza solo l'iniziale della riga. */
.period-label::first-letter {
  text-transform: uppercase;
}
.cal-toolbar[data-view='year'] .period-label {
  min-width: 4ch;
}
.cal-toolbar[data-view='month'] .period-label {
  min-width: 11ch;
}

/* Anno dell'elenco sotto al calendario: e' un chiarimento, non un titolo. */
.head-year {
  font-weight: 400;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- Calendario: struttura ---------- */

/* Calendario a sinistra, colonna a destra (da decidere, legenda). */
.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 26px;
  align-items: start;
}
.side-col {
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
}

/* Vista anno: tanti mesi quanti ne stanno, che si allargano per riempire. */
.calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}
.calendar--team {
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
}
.calendar--month,
.calendar--week {
  grid-template-columns: 1fr;
}

.month {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 12px;
}
.month-name {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.month-name::first-letter {
  text-transform: uppercase;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.dow {
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  padding-bottom: 4px;
}

.day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  padding: 0;
  overflow: visible;
}
.day.empty {
  cursor: default;
}
.day:not(.empty):hover {
  background: var(--blue-soft);
}

/* Tipo di giorno: il weekend ha il fondo rigato, il festivo il numero rosso
   (convenzione dei calendari italiani), la chiusura un fondo pieno. Gli stessi
   selettori valgono per i campioni della legenda. */
.day.weekend,
.legend-day.weekend {
  color: var(--ink-3);
  font-weight: 500;
  background: repeating-linear-gradient(0deg, #f6f7f8 0 7px, #eceff1 7px 8px);
}
.day.holiday,
.legend-day.holiday {
  color: var(--red);
  background: var(--wash);
}
.day.closure,
.legend-day.closure {
  color: var(--ink-3);
  background: var(--rule-soft);
}

/* Oggi: il numero in un cerchio azzurro. */
.day.today > .day-num,
.calendar--year .day.today > span:first-child,
.calendar:not(.calendar--month):not(.calendar--week) .day.today > span:first-child {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
}

/* ---------- Vista anno: un segno per giorno ---------- */

.dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 6px;
}
/* Pieno rosso = approvata, tratteggio giallo = in attesa, meta' = mezza giornata. */
.dot {
  width: 7px;
  height: 6px;
  border-radius: 1px;
  flex: none;
}
.dot.approved {
  background: var(--red);
}
.dot.pending {
  background: var(--yellow);
}
.dot.half {
  width: 4px;
}

/* Calendario squadra, vista anno: le sigle di chi e' via. */
.calendar--team:not(.calendar--month):not(.calendar--week) .day {
  aspect-ratio: auto;
  min-height: 32px;
  justify-content: flex-start;
  padding: 3px 2px;
}
.people {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 1px 4px;
  width: 100%;
}
.person {
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--red);
}
.person.pending {
  color: var(--yellow-ink);
  border-bottom: 1.5px dashed var(--yellow);
}
.person.half {
  font-style: italic;
  font-weight: 600;
}
.person.more {
  color: var(--ink-3);
  font-weight: 600;
}
.person.key {
  color: var(--ink);
  font-size: 11px;
  min-width: 3.4ch;
}
.team-key-item {
  gap: 8px;
  font-size: 12.5px;
}

/* ---------- Viste mese e settimana: la tavola con le barre ---------- */

.month--panel {
  padding: 0;
}
.calendar--month .month-grid {
  gap: 0;
}
.calendar--month .dow {
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
  border-bottom: 1.5px solid var(--ink);
}
.calendar--month .day {
  aspect-ratio: auto;
  min-height: 108px;
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
  gap: 4px;
  padding: 7px 8px 8px;
  border-left: 1px solid var(--rule-soft);
  border-top: 1px solid var(--rule-soft);
  font-size: 15px;
}
.calendar--month .day:nth-child(7n + 1) {
  border-left: none;
}
.calendar--month .day.empty {
  background: var(--paper);
}
.calendar--month .day-num {
  align-self: flex-start;
  line-height: 22px;
  min-width: 22px;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.week-col {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--rule-soft);
}
.week-col:first-child {
  border-left: none;
}
.week-col.weekend {
  background: repeating-linear-gradient(0deg, #f6f7f8 0 7px, #eceff1 7px 8px);
}
.week-col.holiday {
  background: var(--wash);
}
.week-col.closure {
  background: var(--rule-soft);
}
.week-col.holiday .week-num {
  color: var(--red);
}
.week-col.weekend .week-num,
.week-col.closure .week-num {
  color: var(--ink-3);
}
.week-col-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1.5px solid var(--ink);
}
.week-dow {
  font-size: 12px;
  color: var(--ink-3);
}
.week-num {
  margin-left: auto;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.week-col.is-today .week-num {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
}
.week-grid .day {
  aspect-ratio: auto;
  flex: 1;
  min-height: 190px;
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
  gap: 4px;
  padding: 8px;
  background: transparent;
}

.day-note {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.calendar--week .day-note {
  white-space: normal;
}

/* Le corsie: ogni indisponibilita' ha la sua riga dentro la settimana, uguale
   in tutte le celle, cosi' la barra che parte lunedi' e arriva giovedi' resta
   dritta. La barra e' disegnata nella cella dove comincia ed e' larga quanto i
   giorni che copre (--span): passa sopra le celle accanto. */
.lanes {
  position: relative;
  /* Fino ai bordi della cella: la barra deve toccare quella accanto. */
  margin: 0 -8px;
  height: calc(var(--lanes, 0) * (var(--lane-h) + var(--lane-gap)));
  --lane-h: 22px;
  --lane-gap: 4px;
}
.bar {
  position: absolute;
  z-index: 1;
  left: 2px;
  top: calc(var(--lane) * (var(--lane-h) + var(--lane-gap)));
  height: var(--lane-h);
  width: calc(var(--span) * 100% + (var(--span) - 1) * 1px - 4px);
  border-radius: 3px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: var(--lane-h);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  background: var(--red);
  color: #fff;
}
/* Continua dalla settimana prima o nella successiva: lato dritto, come un taglio. */
.bar.cont-l {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  left: 0;
  width: calc(var(--span) * 100% + (var(--span) - 1) * 1px - 2px);
}
.bar.cont-r {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  width: calc(var(--span) * 100% + (var(--span) - 1) * 1px - 2px);
}
.bar.cont-l.cont-r {
  width: calc(var(--span) * 100% + (var(--span) - 1) * 1px);
}
.bar.half {
  background: var(--red-soft);
  color: var(--red);
  box-shadow: inset 0 0 0 1px var(--red-line);
}
.bar.pending {
  background: var(--hatch);
  color: var(--yellow-ink);
  box-shadow: inset 0 0 0 1px var(--yellow);
}
/* Annullamento chiesto: ancora approvata, ma con il bordo tratteggiato. */
.bar.cancel-asked {
  outline: 2px dashed var(--yellow);
  outline-offset: -2px;
}
.lanes-more {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.calendar--week .lanes {
  --lane-h: 26px;
  --lane-gap: 5px;
}
.calendar--week .bar {
  font-size: 13px;
}
/* Pezzi successivi della stessa barra nella settimana: il testo sta sul primo. */
.bar.repeat {
  color: transparent;
}

/* ---------- Colonna a destra: da decidere, legenda ---------- */

.side-title {
  font-size: 1.05rem;
  font-weight: 700;
  font-stretch: 106%;
  margin: 0 0 10px;
}

.decide-card {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--yellow);
  padding: 11px 13px;
  margin-bottom: 10px;
}
.decide-card.urgent {
  border-left-color: var(--red);
}
.decide-card.cancel {
  border-left-color: var(--blue);
}
.decide-card .who {
  font-weight: 700;
  font-size: 15px;
}
.decide-card .what {
  color: var(--ink-2);
  font-size: 13px;
  margin-top: 1px;
}
.decide-card .acts {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.decide-card .acts button {
  flex: 1;
}
.decide-empty {
  color: var(--ink-3);
  font-size: 13.5px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-size: 12.5px;
  color: var(--ink-2);
}
.legend-title {
  font-size: 1.05rem;
  font-weight: 700;
  font-stretch: 106%;
  color: var(--ink);
}
.legend-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.legend-group-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
/* Campioni delle barre: gli stessi colori del calendario. */
.legend-bar {
  width: 26px;
  height: 11px;
  border-radius: 2px;
  flex: none;
  background: var(--red);
}
.legend-bar.pending {
  background: var(--hatch);
  box-shadow: inset 0 0 0 1px var(--yellow);
}
.legend-bar.half {
  background: var(--red-soft);
  box-shadow: inset 0 0 0 1px var(--red-line);
}
.legend-bar.cancel-asked {
  outline: 2px dashed var(--yellow);
  outline-offset: -2px;
}

/* ---------- Tabelle ---------- */

.table-wrap,
table {
  width: 100%;
}
table {
  border-collapse: collapse;
  font-size: 14px;
  background: var(--sheet);
  border: 1px solid var(--rule);
}
thead th {
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink-3);
  padding: 9px 12px;
  border-bottom: 1.5px solid var(--ink);
  background: var(--sheet);
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}
tbody tr:last-child td {
  border-bottom: none;
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.actions {
  white-space: nowrap;
  text-align: right;
}
.actions button + button {
  margin-left: 4px;
}

.empty-state {
  color: var(--ink-3);
  font-size: 14px;
  padding: 18px 0;
}

/* Stato come piccolo segno + testo: lo stesso codice delle barre. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font-weight: 600;
  font-size: 13px;
}
.status::before {
  content: '';
  width: 12px;
  height: 8px;
  border-radius: 2px;
  flex: none;
}
.status.pending {
  color: var(--yellow-ink);
}
.status.pending::before {
  background: var(--hatch);
  box-shadow: inset 0 0 0 1px var(--yellow);
}
.status.approved {
  color: var(--red);
}
.status.approved::before {
  background: var(--red);
}
.status.rejected {
  color: var(--ink-2);
}
.status.rejected::before {
  background: var(--ink-2);
}
.status.cancelled {
  color: var(--ink-3);
  font-weight: 500;
}
.status.cancelled::before {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--ink-3);
}

/* Richieste inviate come urgenza (fuori regola): risaltano tra quelle in attesa. */
.badge-urgent {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 3px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}
.row-urgent td:first-child {
  box-shadow: inset 4px 0 0 var(--red);
}

/* Chi altro e' gia' fuori negli stessi giorni: un fatto da valutare, non un errore. */
.overlap-note {
  display: inline-block;
  font-size: 12px;
  color: var(--yellow-ink);
  background: var(--yellow-soft);
  border-radius: 10px;
  padding: 1px 9px;
  margin-top: 4px;
}

/* ---------- Finestre ---------- */

dialog {
  border: none;
  border-top: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 0;
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  background: var(--sheet);
  color: var(--ink);
}
dialog::backdrop {
  background: rgba(31, 37, 43, 0.55);
}
.modal-head {
  padding: 20px 24px 12px;
}
.modal-title {
  font-size: 1.3rem;
  font-weight: 800;
  font-stretch: 106%;
  letter-spacing: -0.01em;
}
.modal-date {
  font-size: 14px;
  color: var(--ink-2);
}
.modal-date::first-letter {
  text-transform: uppercase;
}
.modal-body {
  padding: 0 24px 8px;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--rule-soft);
  margin-top: 16px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary {
  font-size: 13.5px;
  color: var(--ink-2);
  border-left: 4px solid var(--rule);
  padding: 7px 11px;
  background: var(--wash);
  font-variant-numeric: tabular-nums;
}

/* Chi e' via in un giorno, nel dettaglio del calendario squadra. */
.team-day-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 14px;
}
.team-day-row:last-child {
  border-bottom: none;
}
.team-day-row .who {
  font-weight: 600;
}
.team-day-row .what {
  color: var(--ink-2);
  font-size: 13px;
  margin-left: auto;
  text-align: right;
}
.team-day-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 0 0 10px 20px;
  border-bottom: 1px solid var(--rule-soft);
}
.team-day-actions .subtext {
  margin-right: auto;
}
.team-day-actions button + button {
  margin-left: 0;
}
.team-day-row:has(+ .team-day-actions) {
  border-bottom: none;
}
.team-day-actions:last-child {
  border-bottom: none;
}

.existing {
  border: 1px solid var(--rule-soft);
  background: var(--sheet);
  padding: 10px 12px;
  margin-bottom: 20px;
  font-size: 13.5px;
}
.existing-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.existing-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}

/* Cronologia di una richiesta. */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
  border-left: 2px solid var(--rule);
}
.history-list li {
  position: relative;
  padding: 0 0 14px 4px;
}
.history-list li::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--sheet);
  border: 2px solid var(--ink-3);
}
.history-list li:last-child::before {
  border-color: var(--red);
  background: var(--red);
}
.history-list .when {
  font-size: 12.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.history-list .what {
  font-weight: 700;
}

/* ---------- Scheda di un collaboratore ---------- */

dialog.modal-wide {
  width: min(760px, calc(100vw - 24px));
}
.person-period {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.person-period select {
  width: auto;
  min-width: 170px;
}
.person-custom {
  display: flex;
  align-items: center;
  gap: 8px;
}
.person-custom input {
  width: auto;
}
.person-totals {
  min-width: 0;
  margin-bottom: 14px;
}
/* Giorni per mese: una striscia di celle, alte quanto i giorni (su 22). */
.person-months {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  align-items: end;
  /* Sopra le barre lo spazio per i numeri, sotto quello per i mesi. */
  height: 92px;
  padding-top: 18px;
  margin-bottom: 22px;
  position: relative;
}
.person-months:empty {
  display: none;
}
.pm {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.pm-bar {
  background: var(--red);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.pm-bar.zero {
  background: var(--rule);
}
.pm-label {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10.5px;
  color: var(--ink-3);
  margin-top: 3px;
}
.pm-value {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 2px;
}
.pm-bar.zero + .pm-value,
.pm .pm-value.zero {
  color: var(--ink-3);
  font-weight: 500;
}
.btn-link {
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
}
.btn-link:hover {
  text-decoration-color: var(--red);
}

/* ---------- Schermi medi ---------- */

@media (max-width: 1100px) {
  .calendar-layout {
    grid-template-columns: 1fr;
  }
  .side-col {
    position: static;
  }
  .legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 14px 28px;
  }
  .legend-title {
    width: 100%;
  }
  .legend-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px 18px;
    align-items: center;
  }
  .legend-group-label {
    width: 100%;
  }
  .topbar-user .user-role {
    display: none;
  }
}

/* ---------- Telefono ---------- */

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }
  h1 {
    font-size: 1.6rem;
  }

  /* In alto resta solo il marchio e chi sei; le schede scendono in fondo,
     dove arriva il pollice. */
  .topbar {
    height: 50px;
  }
  .topbar .brand {
    padding: 0 14px;
  }
  .brand-name {
    display: none;
  }
  .topbar-user {
    gap: 10px;
    padding: 0 12px;
  }
  .topbar-user .user-name {
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    gap: 0;
    background: var(--sheet);
    border-top: 1px solid var(--rule);
    overflow: visible;
  }
  .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 0 2px;
    font-size: 11px;
    color: var(--ink-3);
    border: none;
    position: relative;
    min-width: 0;
  }
  .nav-item:hover {
    color: var(--ink);
  }
  .nav-item.active {
    color: var(--red);
    border: none;
  }
  .nav-icon {
    display: block;
    width: 22px;
    height: 22px;
  }
  .nav-text {
    display: none;
  }
  .nav-short {
    display: block;
  }
  .nav-count {
    position: absolute;
    top: 6px;
    left: calc(50% + 6px);
    font-size: 10px;
    padding: 0 5px;
  }
  /* Un collaboratore ha una schermata sola: niente barra con una scheda. */
  body.single-view .nav {
    display: none;
  }
  body:not(.single-view) .main {
    padding-bottom: calc(var(--tabbar-h) + 32px);
  }

  .main {
    padding: 18px 14px 40px;
  }
  .page-head {
    gap: 12px;
  }
  .page-sub {
    font-size: 14px;
    margin-bottom: 16px;
  }
  .cartiglio {
    min-width: 0;
    width: 100%;
  }
  .cart-big .cart-v {
    font-size: 24px;
  }

  .cal-toolbar {
    gap: 10px;
  }
  .cal-toolbar .toolbar-action {
    margin-left: 0;
    width: 100%;
  }
  .period-label {
    font-size: 1.15rem;
    min-width: 0 !important;
  }

  /* Mese su un telefono: sette colonne strette, le barre diventano fili
     colorati senza testo (il dettaglio e' a un tocco). */
  .calendar--month .dow {
    padding: 6px 0;
    text-align: center;
  }
  .calendar--month .day {
    min-height: 58px;
    padding: 4px 3px 6px;
    align-items: center;
    font-size: 13px;
  }
  .calendar--month .day-num {
    align-self: center;
  }
  .calendar--month .day-note {
    display: none;
  }
  .calendar--month .lanes {
    --lane-h: 6px;
    --lane-gap: 3px;
    margin: 0 -3px;
    align-self: stretch;
  }
  .calendar--month .bar {
    font-size: 0;
    padding: 0;
    left: 1px;
    border-radius: 2px;
  }
  .lanes-more {
    font-size: 10px;
  }

  /* La settimana si srotola: un giorno per riga, barre a tutta larghezza. */
  .week-grid {
    grid-template-columns: 1fr;
  }
  .week-col {
    border-left: none;
    border-top: 1px solid var(--rule-soft);
  }
  .week-col-head {
    border-bottom: none;
    padding-bottom: 0;
  }
  .week-grid .day {
    min-height: 34px;
  }
  /* Srotolata, ogni giorno ripete il nome sulla sua barra. */
  .calendar--week .bar.repeat {
    color: inherit;
  }
  .calendar--week .bar.pending.repeat {
    color: var(--yellow-ink);
  }
  .calendar--week .bar.half.repeat {
    color: var(--red);
  }
  .calendar--week .bar.repeat:not(.pending):not(.half) {
    color: #fff;
  }

  /* Le tabelle diventano schede: una riga, una scheda; ogni cella con la sua
     etichetta (data-label, messa da util.cardTable). */
  table.cards,
  table.cards tbody,
  table.cards tr,
  table.cards td {
    display: block;
    width: 100%;
  }
  table.cards {
    border: none;
    background: transparent;
  }
  table.cards thead {
    display: none;
  }
  table.cards tr {
    background: var(--sheet);
    border: 1px solid var(--rule);
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  table.cards tr.row-urgent {
    border-left: 4px solid var(--red);
  }
  table.cards td {
    border: none;
    padding: 3px 0;
    text-align: left;
  }
  table.cards td:first-child {
    font-weight: 700;
    font-size: 15px;
    box-shadow: none;
  }
  table.cards td[data-label]:not(:first-child):not(.actions)::before {
    content: attr(data-label);
    display: block;
    font-size: 11.5px;
    color: var(--ink-3);
  }
  table.cards td:empty {
    display: none;
  }
  table.cards td.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
    white-space: normal;
  }
  table.cards td.actions button {
    flex: 1 1 auto;
    margin: 0;
    padding: 9px 12px;
  }

  .req-tabs {
    display: flex;
    width: 100%;
  }
  .req-tabs button {
    flex: 1;
    justify-content: center;
    padding: 9px 6px;
    font-size: 13px;
  }
  .archive-filters select {
    flex: 1;
    min-width: 0;
  }

  .row-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .modal-head,
  .modal-body {
    padding-left: 18px;
    padding-right: 18px;
  }
  .modal-foot {
    padding: 12px 18px 16px;
  }
  .modal-foot button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
