:root {
  --bg: #0b0b12;
  --bg2: #12121c;
  --surface: rgba(255,255,255,0.04);
  --surface-2: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.09);
  --border-2: rgba(255,255,255,0.16);
  --text: #f0f0f4;
  --muted: #8b8b98;
  --accent: #6c63ff;
  --accent-2: #a89dff;
  --ok: #00d4a8;
  --warn: #ffc107;
  --err: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); }
body {
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  color: var(--text); min-height: 100vh; font-size: 14px; line-height: 1.45;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 15% 0%, rgba(108,99,255,0.12), transparent 60%),
    radial-gradient(ellipse 60% 50% at 85% 90%, rgba(0,212,168,0.07), transparent 60%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: rgba(11,11,18,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.3px; font-size: 16px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: 15px;
}
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav button {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 10px; font-weight: 500;
}
.nav button:hover { color: var(--text); background: var(--surface); }
.nav button.active { color: #fff; background: var(--surface-2); border-color: var(--border-2); }
.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.user-box strong { color: var(--text); font-weight: 600; }

/* App a tutto schermo: barra in alto + area contenuti che riempie il resto della finestra. */
body:has(> .topbar) { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.container { flex: 1; min-height: 0; overflow: auto; width: 100%; padding: 20px 24px; position: relative; z-index: 1; }
.container > section { max-width: 1400px; margin: 0 auto; }
.container > #v-calendario { max-width: none; height: 100%; display: flex; flex-direction: column; }

/* ── Bottoni / campi ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-2);
  background: var(--surface); font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #8a7dff); border-color: transparent; color: #fff; }
.btn-primary:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--accent), #8a7dff); }
.btn-danger { color: var(--err); border-color: rgba(255,107,107,0.35); }
.btn-ok { background: rgba(0,212,168,0.15); border-color: rgba(0,212,168,0.4); color: var(--ok); }
.btn-warn { background: rgba(255,193,7,0.12); border-color: rgba(255,193,7,0.4); color: var(--warn); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-icon { width: 36px; height: 36px; padding: 0; font-size: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  background: var(--bg2); border: 1px solid var(--border-2); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,99,255,0.25); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ── Intestazione vista ── */
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.view-head h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; min-width: 190px; text-align: center; }
.view-head .spacer { flex: 1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ── Calendario ── */
.cal-wrap {
  overflow: auto; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); flex: 1; min-height: 0;
}
.cal { border-collapse: separate; border-spacing: 0; width: 100%; }
.cal th, .cal td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.cal thead th {
  position: sticky; top: 0; z-index: 3; background: #161622;
  font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 6px; white-space: nowrap;
}
.cal .c-day {
  position: sticky; left: 0; z-index: 2; background: #12121c;
  padding: 8px 12px; white-space: nowrap; min-width: 118px; text-align: left;
}
.cal thead .c-day { z-index: 4; }
.cal .c-day .dn { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.cal .c-day .dd { font-size: 17px; font-weight: 700; }
.cal td.slot { padding: 4px; min-width: 128px; height: 52px; vertical-align: middle; }
.cal tr.weekend .c-day, .cal tr.weekend td.slot { background: rgba(0,0,0,0.25); }
.cal tr.weekend .c-day .dd { color: var(--muted); }
.cal tr.today .c-day { box-shadow: inset 3px 0 0 var(--accent); background: #1a1830; }
.cal tr.today td.slot { background: rgba(108,99,255,0.07); }
.badge-today { font-size: 10px; background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 6px; margin-left: 6px; font-weight: 600; vertical-align: middle; }

.cell-add {
  width: 100%; height: 100%; min-height: 42px; border: 1px dashed transparent; border-radius: 9px;
  background: none; color: transparent; font-size: 18px;
}
.cal td.slot:hover .cell-add { border-color: var(--border-2); color: var(--muted); }

.pill {
  width: 100%; min-height: 42px; text-align: left; border-radius: 9px; padding: 5px 9px;
  border: 1px solid transparent; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  font-size: 12px; line-height: 1.25;
}
.pill .pn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.pill .pq { font-size: 11px; opacity: .8; }
.pill:hover { filter: brightness(1.2); }
.pill.st-arrivata { box-shadow: inset 0 0 0 2px var(--warn); }
.pill.st-scaricata { opacity: .6; }
.pill.st-annullata { opacity: .4; }
.pill.st-annullata .pn { text-decoration: line-through; }
.pill.blocked {
  color: var(--muted); align-items: center; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0 6px, rgba(255,255,255,0.09) 6px 12px);
  border-color: var(--border);
}
.c0 { background: rgba(108,99,255,0.20); color: #c9c4ff; border-color: rgba(108,99,255,0.35); }
.c1 { background: rgba(0,212,168,0.15); color: #7ef0d4; border-color: rgba(0,212,168,0.3); }
.c2 { background: rgba(255,193,7,0.14); color: #ffd966; border-color: rgba(255,193,7,0.3); }
.c3 { background: rgba(255,107,107,0.15); color: #ffaaaa; border-color: rgba(255,107,107,0.3); }
.c4 { background: rgba(79,195,247,0.15); color: #9edcfb; border-color: rgba(79,195,247,0.3); }
.c5 { background: rgba(129,199,132,0.15); color: #b5e3b7; border-color: rgba(129,199,132,0.3); }
.c6 { background: rgba(240,98,146,0.15); color: #f7a8c4; border-color: rgba(240,98,146,0.3); }
.cal .c-tot { font-size: 11px; color: var(--muted); text-align: center; min-width: 60px; padding: 4px 8px; white-space: nowrap; }

/* ── Card / metriche ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.metric .ml { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.metric .mv { font-size: 28px; font-weight: 700; letter-spacing: -1px; margin-top: 6px; }
.metric .ms { font-size: 12px; color: var(--muted); }
.metric:nth-child(1) { border-top: 2px solid rgba(108,99,255,0.7); }
.metric:nth-child(2) { border-top: 2px solid rgba(0,212,168,0.7); }
.metric:nth-child(3) { border-top: 2px solid rgba(255,193,7,0.7); }
.metric:nth-child(4) { border-top: 2px solid rgba(255,107,107,0.7); }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 90px; gap: 12px; align-items: center; font-size: 13px; }
.bar-row .bn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.bar-bg { height: 8px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.bar { height: 100%; width: 100%; border-radius: 4px; transform-origin: left; transform: scaleX(0); transition: transform .6s cubic-bezier(.2,.8,.2,1); }
.bar-row .bq { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Oggi ── */
.today-list { display: grid; gap: 10px; }
.today-item {
  display: grid; grid-template-columns: 70px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.today-item .ti-ora { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.today-item .ti-forn { font-size: 16px; font-weight: 600; }
.today-item .ti-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.today-item .ti-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.today-item.st-arrivata { border-color: rgba(255,193,7,0.5); }
.today-item.st-scaricata { opacity: .6; }
.today-item.st-annullata { opacity: .4; }
.stato-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .4px; }
.stato-prevista { background: rgba(108,99,255,0.18); color: var(--accent-2); }
.stato-arrivata { background: rgba(255,193,7,0.15); color: var(--warn); }
.stato-scaricata { background: rgba(0,212,168,0.15); color: var(--ok); }
.stato-annullata { background: rgba(255,107,107,0.15); color: var(--err); }
.empty { padding: 40px; text-align: center; color: var(--muted); font-style: italic; }

/* ── Tabelle admin ── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border-2); }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table .input { padding: 6px 10px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.muted { color: var(--muted); }
.search { max-width: 260px; }

/* ── Modale ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 480px; background: #151520; border: 1px solid var(--border-2);
  border-radius: 18px; padding: 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  max-height: calc(100vh - 32px); overflow: auto;
}
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal .form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal .full { grid-column: 1 / -1; }
.modal .actions { display: flex; gap: 8px; margin-top: 20px; }
.modal .actions .spacer { flex: 1; }
.modal .meta { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.6; }
.modal .meta strong { color: var(--text); font-weight: 600; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #1d1d2b; border: 1px solid var(--border-2); border-radius: 12px; padding: 10px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); font-size: 13px;
}
.toast.err { border-color: rgba(255,107,107,0.5); color: #ffbaba; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 110px 1fr 70px; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 1 1 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .nav button { padding: 6px 10px; }
  .container { padding: 16px; }
  .view-head { gap: 8px; }
  .view-head h1 { font-size: 17px; min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .view-head .spacer { display: none; }
  .view-head > .muted, .view-head .legend { flex: 1 1 100%; }
  .cal .c-day { min-width: 76px; padding: 6px 8px; }
  .cal td.slot { min-width: 110px; }
  .today-item { grid-template-columns: 56px 1fr; }
  .today-item .ti-actions { grid-column: 1 / -1; justify-content: stretch; }
  .today-item .ti-actions .btn { flex: 1; padding: 12px; }
  .modal .form { grid-template-columns: 1fr; }
  .user-box .u-name { display: none; }
}

/* ── Trascinamento caselle ── */
#cal.can-drag .pill { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none;
  opacity: .95; box-shadow: 0 14px 34px rgba(0,0,0,0.55); background-color: #1d1b33;
}
.pill.drag-source { opacity: .25; }
.cal td.slot.drop-ok { background: rgba(108,99,255,0.18) !important; box-shadow: inset 0 0 0 2px var(--accent); }
.cal td.slot.drop-no { background: rgba(255,107,107,0.12) !important; box-shadow: inset 0 0 0 2px var(--err); cursor: not-allowed; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast-btn { color: var(--accent-2); border-color: rgba(108,99,255,0.5); }

/* ── Spunta conferma arrivo ── */
.pill-wrap { position: relative; }
.pill-wrap .pill { padding-right: 32px; }
.chk {
  position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; padding: 0;
  display: grid; place-items: center; border-radius: 50%;
  font-size: 12px; font-weight: 700; line-height: 1;
  background: rgba(0,0,0,0.25); border: 1.5px solid rgba(255,255,255,0.35); color: rgba(255,255,255,0.4);
  transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.chk:hover:not(:disabled) { border-color: var(--ok); color: var(--ok); transform: scale(1.1); }
.chk.done { background: var(--ok); border-color: var(--ok); color: #04221b; }
.chk.done:hover:not(:disabled) { color: #04221b; }
.chk:disabled { cursor: default; }
.chk:not(.done):disabled { opacity: .4; }

/* ── Popup conferma ── */
.modal-conf { max-width: 380px; text-align: center; }
.modal-conf h2 { font-size: 22px; letter-spacing: .5px; margin: 10px 0 8px; }
.modal-conf .sub { line-height: 1.6; margin-bottom: 4px; }
.modal-conf .sub strong { color: var(--text); font-size: 15px; }
.modal-conf .actions { justify-content: center; }
.modal-conf .actions .btn { flex: 1; padding: 11px; }
.conf-icon {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center;
  font-size: 26px; font-weight: 700; background: rgba(0,212,168,0.15); color: var(--ok); border: 2px solid rgba(0,212,168,0.5);
}
.btn-ok-solid { background: var(--ok); border-color: var(--ok); color: #04221b; font-weight: 600; }
.btn-ok-solid:hover { background: #19e6bb; }
#modal-conf.danger .conf-icon { background: rgba(255,107,107,0.12); color: var(--err); border-color: rgba(255,107,107,0.5); }
#modal-conf.danger .btn-ok-solid { background: var(--err); border-color: var(--err); color: #2a0808; }
.meta-ok { color: var(--ok); }
@media (max-width: 640px) {
  .chk { width: 26px; height: 26px; top: 3px; right: 3px; }
}

/* ── Video tutorial ── */
.btn-tutorial { background: rgba(108,99,255,0.18); border-color: rgba(108,99,255,0.55); color: #d6d1ff; font-weight: 600; letter-spacing: .4px; }
.btn-tutorial:hover { background: rgba(108,99,255,0.3); }
.modal-video { max-width: min(1200px, 96vw); padding: 16px; }
.video-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.video-head h2 { margin: 0; font-size: 17px; }
#tutorial-video { width: 100%; max-height: calc(100vh - 120px); border-radius: 10px; background: #000; display: block; }

/* ── Legenda calendario ── */
.legend span { gap: 6px; }
.lg-chk {
  width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 9px; font-weight: 700; font-style: normal; line-height: 1;
  background: rgba(0,0,0,0.25); border: 1.5px solid rgba(255,255,255,0.35); color: rgba(255,255,255,0.45);
}
.lg-chk.done { background: var(--ok); border-color: var(--ok); color: #04221b; }
.lg-box { width: 18px; height: 12px; border-radius: 4px; display: inline-block; }
.lg-arr { box-shadow: inset 0 0 0 2px var(--warn); background: rgba(255,193,7,0.08); }
.lg-blk { background: repeating-linear-gradient(45deg, rgba(255,255,255,0.06) 0 3px, rgba(255,255,255,0.16) 3px 6px); border: 1px solid var(--border-2); }
