/* =====================================================================
   CM-Teams - stile
   Interfaccia da campo: chiara e ad alto contrasto (si usa anche al sole),
   tipografia stretta tipo segnaletica industriale, un solo accento
   "giallo segnale" riservato ad azioni principali e zone di rilascio.
   ===================================================================== */

:root {
  --graphite: #20303B;
  --graphite-2: #34495A;
  --paper: #F1F3F2;
  --card: #FFFFFF;
  --line: #CBD3D6;
  --line-soft: #E2E7E8;
  --muted: #5E6E78;
  --steel: #2F6584;
  --signal: #E8A317;
  --signal-soft: #FCEFD2;
  --ok: #2E7D4F;
  --ok-soft: #E1F1E7;
  --err: #B3261E;
  --err-soft: #F8E1DF;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-sign: "Bahnschrift", "DIN Alternate", "Barlow Semi Condensed", "Roboto Condensed", "Arial Narrow", var(--font-ui);

  --r-sm: 4px;
  --r-md: 8px;
  --nav-w: 216px;
  --top-h: 56px;
  --tap: 44px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font-ui);
  color: var(--graphite);
  background: var(--paper);
}
h1, h2, h3 { font-family: var(--font-sign); font-weight: 600; line-height: 1.15; margin: 0; }
a { color: var(--steel); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--steel); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Marchio: quadrato a strisce di segnalazione ---------- */
.brand-mark {
  width: 22px; height: 22px; border-radius: 3px; display: inline-block; flex: none;
  background: repeating-linear-gradient(-45deg, var(--signal) 0 5px, var(--graphite) 5px 10px);
  box-shadow: inset 0 0 0 2px var(--signal);
}
.brand-mark--lg { width: 44px; height: 44px; border-radius: 6px; background-size: auto; }

/* ---------- Struttura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; gap: 16px;
  background: var(--graphite); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand-name { font-family: var(--font-sign); font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-name { color: #C9D4DA; white-space: nowrap; }
.btn-icon {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-sm);
  color: #fff; background: transparent; border: 0; cursor: pointer;
}
.btn-icon:hover { background: var(--graphite-2); }

.nav {
  position: fixed; z-index: 20; top: calc(var(--top-h) + env(safe-area-inset-top)); left: 0; bottom: 0;
  width: var(--nav-w); padding: 12px 8px; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 12px;
  border-radius: var(--r-sm); color: var(--graphite); text-decoration: none; font-weight: 500;
}
.nav-item:hover { background: var(--paper); }
.nav-item.is-active { background: var(--graphite); color: #fff; }
.nav-item.is-active .ico { color: var(--signal); }

.main { margin-left: var(--nav-w); padding: 24px 28px 48px; max-width: 1400px; }
.page-title { font-size: 28px; margin-bottom: 16px; }

@media (max-width: 899px) {
  .user-name { display: none; }
  .nav {
    top: auto; right: 0; width: auto; height: calc(64px + env(safe-area-inset-bottom));
    padding: 4px 4px env(safe-area-inset-bottom); flex-direction: row; gap: 0;
    border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; scrollbar-width: none;
  }
  .nav-item {
    flex: 1 0 76px; flex-direction: column; justify-content: center; gap: 2px;
    padding: 4px; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 1.1;
  }
  .main { margin-left: 0; padding: 16px 12px calc(88px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 24px; margin-bottom: 12px; }
}

/* ---------- Controlli ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--card); color: var(--graphite);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--graphite-2); }
.btn--primary { background: var(--signal); border-color: #C98B0C; color: var(--graphite); }
.btn--primary:hover { background: #F0B12E; border-color: #A87308; }
.btn--danger { color: var(--err); border-color: #E2B4B0; }
.btn--danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--small { min-height: 32px; padding: 0 10px; font-size: 13.5px; }
.btn--block { width: 100%; }
.btn--big { min-height: 56px; font-size: 17px; padding: 0 24px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search],
input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 40px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--steel); outline: 2px solid rgba(47,101,132,.25); outline-offset: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--graphite-2); }
.field small { color: var(--muted); font-size: 12.5px; }
.field--wide { grid-column: 1 / -1; }
.field .req { color: var(--err); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: var(--tap); }
.check input { width: 18px; height: 18px; accent-color: var(--graphite); }
.hm { display: flex; gap: 6px; align-items: center; }
.hm input { width: 72px; text-align: right; }
.hm span { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 260px; max-width: 420px; }
.toolbar-count { color: var(--muted); font-size: 14px; margin-left: auto; }
.filter { display: inline-flex; align-items: center; gap: 8px; }
.filter span { font-size: 13px; font-weight: 600; color: var(--graphite-2); }
.filter select { width: auto; min-width: 200px; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--card);
  border: 1px dashed var(--line); border-radius: var(--r-md); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); }
.form-panel { padding: 18px; margin-bottom: 16px; border-top: 4px solid var(--signal); }
.form-panel h2 { font-size: 20px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 16px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; align-items: center; }
.form-actions .spacer { flex: 1; }
.form-note { font-size: 13px; color: var(--muted); }

.alert { padding: 10px 12px; border-radius: var(--r-sm); margin: 0 0 12px; }
.alert--err { background: var(--err-soft); color: var(--err); border: 1px solid #E8BDB9; }

/* ---------- Tabelle ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); overflow: auto; max-height: calc(100vh - 230px); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table thead th { position: sticky; top: 0; z-index: 2; background: #E7ECEE; font-weight: 600; white-space: nowrap; }
.table thead tr.filters th { top: 40px; background: #F4F6F7; padding: 6px 8px; }
.table thead tr.filters input, .table thead tr.filters select { min-height: 32px; padding: 4px 8px; font-size: 13px; font-weight: 400; }
.th-sort { all: unset; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.th-sort:focus-visible { outline: 3px solid var(--steel); }
.th-sort::after { content: "↕"; color: #9AA8B0; font-size: 12px; }
.th-sort[data-dir="asc"]::after { content: "▲"; color: var(--graphite); }
.th-sort[data-dir="desc"]::after { content: "▼"; color: var(--graphite); }
.table tbody tr:hover { background: #F7F9F9; }
.table tbody tr.is-off td { color: #8D9AA2; }
.table tbody tr.is-editing { background: var(--signal-soft); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { white-space: nowrap; text-align: right; }
.table tfoot td { font-weight: 700; background: #F4F6F7; border-top: 2px solid var(--line); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--line-soft); }
.tag--on { background: var(--ok-soft); color: var(--ok); }
.tag--off { background: var(--err-soft); color: var(--err); }
.tag--s1 { background: var(--ok-soft); color: var(--ok); }
.tag--s2 { background: var(--signal-soft); color: #8A5D00; }
.tag--s3 { background: var(--line-soft); color: var(--muted); }
.table td .clip { min-width: 180px; }
.clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; }

/* Tabelle come schede su schermo stretto */
@media (max-width: 719px) {
  .table-wrap { max-height: none; background: transparent; border: 0; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead tr:first-child { display: none; }
  .table thead tr.filters { display: none; }
  .table tbody tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 10px; padding: 8px 12px; }
  .table td { border: 0; padding: 4px 0; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  .table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; flex: none; }
  .table td.num { text-align: right; }
  .table td.actions { justify-content: flex-end; padding-top: 8px; }
  .table td.actions::before { content: none; }
  .table tfoot { display: block; }
  .table tfoot tr { display: block; background: var(--card); border-radius: var(--r-md); }
  .table tfoot td:empty { display: none; }
  .clip { max-width: 60vw; }
}

/* ---------- Zone drag & drop ---------- */
.draggable { cursor: grab; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.draggable.is-dragging { opacity: .45; }
.draggable.is-picked { outline: 3px solid var(--signal); outline-offset: 1px; }
.drop.is-over, .drop.is-target {
  background-image: repeating-linear-gradient(-45deg, rgba(232,163,23,.20) 0 10px, rgba(232,163,23,.06) 10px 20px);
  box-shadow: inset 0 0 0 2px var(--signal);
}

.pool { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chip-u {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 6px 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.chip-u .avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--graphite); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.chip-u .meta { min-width: 0; flex: 1; }
.chip-u .meta b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-u .meta small { color: var(--muted); font-size: 12px; }
.chip-u .x { margin-left: auto; }

/* ---------- Squadre ---------- */
.sq-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.sq-col h2 { font-size: 20px; }
.sq-col-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sq-new { display: flex; gap: 8px; flex: 1 1 320px; max-width: 460px; }
.sq-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.sq-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); display: flex; flex-direction: column; min-height: 170px; }
.sq-card.is-off { opacity: .6; }
.sq-card-head { padding: 12px 14px 6px; border-bottom: 1px solid var(--line-soft); }
.sq-title { display: flex; align-items: baseline; gap: 10px; }
.sq-card-head h3 { font-size: 19px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sq-actions { display: flex; flex-wrap: wrap; gap: 2px; margin: 4px 0 0 -10px; }
.sq-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.sq-members { list-style: none; margin: 0; padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; border-radius: 0 0 var(--r-md) var(--r-md); }
.sq-members .empty-drop { color: var(--muted); font-size: 13.5px; padding: 18px 8px; text-align: center; border: 1px dashed var(--line); border-radius: var(--r-sm); }
.sq-col--utenti { position: sticky; top: calc(var(--top-h) + 16px); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; max-height: calc(100vh - var(--top-h) - 40px); overflow: auto; }
.sq-col--utenti .search { display: block; margin-top: 10px; }
@media (max-width: 899px) {
  .sq-layout { grid-template-columns: 1fr; }
  .sq-col--utenti { position: static; max-height: none; order: -1; }
  .sq-col--utenti .pool { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .sq-col--utenti .chip-u { flex: none; }
}

/* ---------- Pianificazione ---------- */
.pian-range { font-family: var(--font-sign); font-size: 19px; font-weight: 600; }
.pian-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.pian-layout:has(.pian-palette[hidden]) { grid-template-columns: 1fr; }
.pian-palette { position: sticky; top: calc(var(--top-h) + 16px); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; max-height: calc(100vh - var(--top-h) - 40px); overflow: auto; }
.pian-palette h2 { font-size: 17px; margin-top: 4px; }
.pian-palette .pool { margin-bottom: 14px; }
.pian-palette .search { display: block; margin: 8px 0 0; }
.chip-sq { border-left: 5px solid var(--signal); }
.chip-sq .avatar { background: var(--signal); color: var(--graphite); }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); overflow: hidden; }
.day { border-left: 1px solid var(--line-soft); min-height: 340px; display: flex; flex-direction: column; min-width: 0; }
.day:first-child { border-left: 0; }
.day-head { padding: 8px 10px; border-bottom: 1px solid var(--line); background: #F4F6F7; display: flex; align-items: baseline; gap: 6px; }
.day-head b { font-family: var(--font-sign); font-size: 22px; font-weight: 600; }
.day-head span { color: var(--muted); font-size: 13px; text-transform: capitalize; }
.day.is-today .day-head { background: var(--graphite); color: #fff; }
.day.is-today .day-head span { color: #C9D4DA; }
.day.is-weekend { background: #FAFBFB; }
.day-body { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.day-empty { color: #9AA8B0; font-size: 13px; text-align: center; margin: auto 0; padding: 14px 0; }
.ev {
  display: block; width: 100%; text-align: left; padding: 6px 8px; border-radius: var(--r-sm);
  background: #EAF1F5; border: 1px solid #C7D8E2; border-left: 4px solid var(--steel); font-size: 13px; line-height: 1.3;
}
.ev.is-squadra { border-left-color: var(--signal); background: #FBF4E4; border-color: #EBD9AE; }
.ev.is-mine { box-shadow: inset 0 0 0 1px var(--graphite); }
.ev time { font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.ev .who { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.ev { cursor: pointer; font: inherit; color: inherit; }
button.ev:hover { border-color: var(--graphite-2); }
.ev-group { border: 1px solid #EBD9AE; border-left: 4px solid var(--signal); border-radius: var(--r-sm); background: #FFFBF1; padding: 6px 8px 8px; font-size: 13px; }
.ev-group-head { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; line-height: 1.25; }
.ev-group-head time { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.ev-group-head span { display: block; font-weight: 700; color: #7A5200; overflow-wrap: anywhere; }
button.ev-group-head { cursor: grab; border-radius: 3px; }
button.ev-group-head:hover span { text-decoration: underline; }
.ev-commessa { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev-members { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pill { display: inline-block; padding: 2px 7px; border-radius: 99px; background: #fff; border: 1px solid #E3CF9E;
  font-size: 12.5px; font-weight: 600; line-height: 1.4; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.is-mine { background: var(--graphite); color: #fff; border-color: var(--graphite); }
button.pill { cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; color: inherit; }
button.pill:hover { border-color: var(--graphite-2); }

@media (max-width: 1499px) {
  .pian-layout { grid-template-columns: 1fr; }
  .pian-palette { position: static; max-height: none; }
  .pian-palette .pool { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .pian-palette .chip-u { flex: none; }
}
@media (max-width: 719px) {
  .week { grid-template-columns: 1fr; }
  .day { border-left: 0; border-top: 1px solid var(--line); min-height: 0; }
  .day:first-child { border-top: 0; }
  .day-body { min-height: 56px; }
}

/* ---------- Dialog ---------- */
.dialog { border: 0; border-radius: var(--r-md); padding: 0; width: min(460px, calc(100vw - 24px)); box-shadow: 0 18px 50px rgba(20,32,40,.35); }
.dialog::backdrop { background: rgba(20,32,40,.5); }
.dialog-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; border-top: 4px solid var(--signal); }
.dialog-form h2 { font-size: 21px; }
.dialog-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-form .who-line { color: var(--muted); margin: -6px 0 0; }

/* ---------- Home ---------- */
.home { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.home-oggi, .home-team { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px; }
.home-data { font-size: 26px; margin-bottom: 14px; text-transform: capitalize; }
.home-oggi .btn--big { margin-top: 16px; width: 100%; }
.home-ore { margin: 10px 0 0; color: var(--muted); }
.turno { padding: 12px 14px; border-left: 5px solid var(--signal); background: #FFFBF1; border-radius: var(--r-sm); margin-bottom: 8px; }
.turno time { font-family: var(--font-sign); font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.turno p { margin: 2px 0 0; }
.home-team h2 { font-size: 20px; margin-bottom: 12px; }
.kpi { display: flex; gap: 24px; margin-bottom: 16px; }
.kpi div b { font-family: var(--font-sign); font-size: 34px; font-weight: 600; display: block; line-height: 1; }
.kpi div span { color: var(--muted); font-size: 13.5px; }
.home-team ul { margin: 6px 0 0; padding-left: 18px; }
@media (max-width: 899px) { .home { grid-template-columns: 1fr; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 100;
  max-width: min(520px, calc(100vw - 24px)); padding: 12px 16px; border-radius: var(--r-sm);
  background: var(--graphite); color: #fff; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-err { background: var(--err); }
@media (max-width: 899px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--graphite); }
.login { width: min(400px, 100%); background: var(--card); border-radius: var(--r-md); padding: 28px 24px 18px; border-top: 6px solid var(--signal); }
.login-head { margin-bottom: 20px; }
.login-head h1 { font-size: 32px; margin: 12px 0 4px; }
.login-head p { margin: 0; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .btn { min-height: 48px; margin-top: 6px; }
.login-foot { margin: 16px 0 0; text-align: right; color: var(--muted); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
.sq-actions .btn { padding: 0 8px; min-height: 30px; }
