:root {
	--bg: #f7f8fa;
	--surface: #ffffff;
	--ink: #1f2733;
	--muted: #667085;
	--line: #e4e7ec;
	--line-strong: #d3d8e0;
	--accent: #3b4cca;
	--accent-ink: #2b39a8;
	--accent-weak: #eef0fb;
	--ok: #2e7d4f;
	--ok-bg: #e9f5ee;
	--warn: #b9690a;
	--warn-bg: #fbf0e0;
	--danger: #c0362c;
	--danger-bg: #fbecea;

	--s1: 4px;
	--s2: 8px;
	--s3: 12px;
	--s4: 16px;
	--s5: 24px;
	--s6: 32px;

	--radius: 6px;
	--radius-lg: 10px;
	--shadow: 0 1px 2px rgba(16, 24, 40, .06);
	--shadow-pop: 0 12px 32px rgba(16, 24, 40, .18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	background: var(--bg);
	color: var(--ink);
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { margin: 0 0 var(--s5); font-size: 1.4rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; font-weight: 600; margin: var(--s6) 0 var(--s3); }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 var(--s2); }
.muted { color: var(--muted); }

.ic { width: 1.05em; height: 1.05em; flex: none; vertical-align: -.15em; }

/* ---------- top bar ---------- */
.topbar {
	display: flex;
	align-items: center;
	gap: var(--s4);
	background: var(--surface);
	border-bottom: 1px solid var(--line);
	padding: var(--s3) var(--s5);
}
.brand {
	display: inline-flex; align-items: center; gap: var(--s2);
	font-weight: 700; font-size: 1.02rem; color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand .ic { width: 1.25em; height: 1.25em; color: var(--accent); }
.topbar nav { display: flex; gap: var(--s1); flex-wrap: wrap; }
.topbar nav a {
	padding: var(--s2) var(--s3); border-radius: var(--radius);
	color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.topbar nav a.on { background: var(--accent-weak); color: var(--accent-ink); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: var(--s4); }
.who { color: var(--muted); font-size: .9rem; }
.nav-toggle { display: none; }
.nav-logout { display: none; }

main { max-width: 1080px; margin: 0 auto; padding: var(--s5) var(--s5) 64px; }

/* ---------- messages ---------- */
.error { background: var(--danger-bg); color: var(--danger); padding: var(--s3) var(--s4); border-radius: var(--radius); border: 1px solid #f0c9c4; }
.ok-msg { background: var(--ok-bg); color: var(--ok); padding: var(--s3) var(--s4); border-radius: var(--radius); font-weight: 600; }

/* ---------- cards & forms ---------- */
.card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-lg);
	padding: var(--s4);
	margin-bottom: var(--s3);
	box-shadow: var(--shadow);
}
form.card { display: flex; flex-direction: column; gap: var(--s3); max-width: 460px; }
.card.wide { max-width: 620px; }

label { display: flex; flex-direction: column; gap: var(--s1); font-size: .88rem; font-weight: 500; color: var(--muted); }
input, select, textarea {
	font: inherit;
	padding: 10px 11px;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--ink);
	width: 100%;
}
input:focus, select:focus, textarea:focus {
	outline: none; border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-weak);
}
textarea { resize: vertical; }

button {
	font: inherit; cursor: pointer;
	background: var(--accent); color: #fff;
	border: 1px solid var(--accent); border-radius: var(--radius);
	padding: 10px 16px; font-weight: 600;
}
button:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button.small, .btn-sm { padding: 6px 12px; font-size: .85rem; border-radius: var(--radius); }
.btn-sm { display: inline-flex; align-items: center; gap: var(--s1); background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; white-space: nowrap; border: 1px solid var(--accent); cursor: pointer; }
.btn-sm:hover { text-decoration: none; background: var(--accent-ink); }
button.ghost, .btn.ghost { background: var(--surface); color: var(--accent); border: 1px solid var(--line-strong); }
button.ghost:hover, .btn.ghost:hover { background: var(--bg); border-color: var(--accent); }
button.link {
	background: none; border: none; color: var(--muted); padding: 4px 6px;
	font-weight: 500; cursor: pointer;
}
button.link:hover { color: var(--ink); }
.btn {
	display: inline-flex; align-items: center; gap: var(--s1);
	background: var(--accent); color: #fff; padding: 9px 15px;
	border: 1px solid var(--accent); border-radius: var(--radius); font-weight: 600;
}
.btn:hover { text-decoration: none; background: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #a12a22; border-color: #a12a22; }
.btn.danger .ic { width: 1.05em; height: 1.05em; }
.dash-actions { display: flex; justify-content: flex-end; margin: 0 0 var(--s4); }
.row { display: flex; gap: var(--s4); align-items: center; }

.back-link { display: inline-block; margin-bottom: var(--s4); color: var(--muted); font-weight: 500; }
.back-dash { display: inline-flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s5); padding: 12px 20px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--accent); font-weight: 700; font-size: 1.05rem; }
.back-dash:hover { background: var(--accent-weak); border-color: var(--accent); text-decoration: none; }
.back-dash .ic { width: 1.3em; height: 1.3em; }

/* ---------- page head / filters / pager ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s4); }
.page-head h1 { margin: 0; }
.head-actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }

.filterbar { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin: var(--s4) 0; }
.filterbar input, .filterbar select { width: auto; }
.filterbar input[type=search] { min-width: 220px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s4); flex-wrap: wrap; }
.pager-left { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.pager-left label { flex-direction: row; align-items: center; gap: var(--s2); }
.pager-left select { padding: 5px 8px; }
.pager .pages { display: flex; gap: var(--s1); align-items: center; }
.pager .pages a, .pager .pages .cur { padding: 6px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius); }
.pager .pages .cur { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager .pages a:hover { background: var(--bg); text-decoration: none; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--s4); box-shadow: var(--shadow); }
.stat .n { font-size: 1.8rem; font-weight: 700; display: block; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- grid / zone cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--s3); }
.zone .bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: var(--s3) 0 var(--s1); }
.zone .bar span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.zone-partial .bar span { background: var(--warn); }
.zone-done { background: var(--ok-bg); border-color: #bfe2cc; }
.zone-partial { background: var(--warn-bg); border-color: #f0d8ad; }

/* ---------- tables ---------- */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
table.list th { text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--bg); font-weight: 600; }
table.list th, table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
td.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:target td { background: #fffae6; }

.iconbtn {
	display: inline-flex; align-items: center; justify-content: center;
	width: 34px; height: 34px; margin-left: var(--s1); padding: 0;
	border: 1px solid var(--line-strong); border-radius: var(--radius);
	background: var(--surface); color: var(--muted);
	cursor: pointer; text-decoration: none;
}
.iconbtn:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.iconbtn.danger:hover { background: var(--danger-bg); border-color: #f0c9c4; color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: var(--s1); padding: 3px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.badge .ic { width: .95em; height: .95em; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.wait { background: var(--warn-bg); color: var(--warn); }
.badge.done { background: var(--line); color: var(--muted); }

.chip { display: inline-block; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 99px; padding: 2px 10px; margin: 0 var(--s1) var(--s1) 0; font-size: .85rem; white-space: nowrap; }
.chip.big { font-size: 1rem; font-weight: 600; padding: 5px 13px; }

/* ---------- materials: stepper form ---------- */
.steppers { display: flex; flex-direction: column; gap: var(--s2); }
.stepper-row {
	display: flex; align-items: center; justify-content: space-between;
	padding: var(--s3) var(--s4); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
}
.stepper-label { font-size: 1.05rem; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: var(--s2); }
.step-btn {
	width: 46px; height: 46px; padding: 0; border-radius: var(--radius);
	border: 1px solid var(--line-strong); background: var(--surface); color: var(--accent);
	font-size: 1.6rem; font-weight: 700; line-height: 1;
}
.step-btn:hover { background: var(--accent-weak); border-color: var(--accent); }
.step-val {
	width: 64px; height: 46px; text-align: center;
	font-size: 1.5rem; font-weight: 700;
	border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0;
	font-variant-numeric: slashed-zero tabular-nums;
}
.fixed-zone { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3) var(--s4); }

/* ---------- deposit list ---------- */
.dep-list { display: flex; flex-direction: column; gap: var(--s3); }
.dep-row { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: var(--radius-lg); padding: var(--s4); box-shadow: var(--shadow); }
.dep-row.is-ready { border-left-color: var(--ok); opacity: .7; }
.dep-mats { margin-bottom: var(--s2); }
.dep-info { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.dep-meta { color: var(--muted); font-size: .9rem; }
.dep-meta strong { color: var(--ink); }

/* ---------- segnalazioni cards ---------- */
.thumb-btn { padding: 0; border: none; background: none; cursor: pointer; line-height: 0; }
.thumb-sm { width: 52px; height: 52px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line-strong); display: block; }
.thumb-btn:hover .thumb-sm { border-color: var(--accent); }
dialog.modal-img { max-width: min(92vw, 900px); width: auto; padding: var(--s3); }
.modal-img img { display: block; max-width: 100%; max-height: 78vh; border-radius: var(--radius); margin: 0 auto var(--s3); }
.note { margin-top: var(--s1); }

/* ---------- captain: large, low-friction ---------- */
.bigcard {
	display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
	background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
	padding: var(--s5); margin-bottom: var(--s3); color: var(--ink); text-decoration: none;
	width: 100%; font: inherit; text-align: left; cursor: pointer; appearance: none;
	box-shadow: var(--shadow);
}
.bigcard.todo { border: 2px solid var(--accent); }
.bigcard.todo:hover { background: var(--accent-weak); text-decoration: none; }
.bigcard.done { background: var(--ok-bg); border-color: #bfe2cc; }
.bc-title { font-size: 1.35rem; font-weight: 700; margin-bottom: var(--s1); }
.bc-sub { color: var(--muted); }
.bc-arrow { color: var(--accent); flex: none; }
.bc-arrow .ic { width: 2rem; height: 2rem; }
.biglinks { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.bigbtn {
	display: flex; flex-direction: column; align-items: center; gap: var(--s2);
	text-align: center; background: var(--surface);
	border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--s5) var(--s4);
	font-size: 1.1rem; font-weight: 700; color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
.bigbtn:hover { background: var(--bg); text-decoration: none; }
.bigbtn .ic { width: 2rem; height: 2rem; color: var(--accent); }

/* ---------- modals ---------- */
dialog.modal { border: none; border-radius: var(--radius-lg); padding: var(--s5); max-width: 460px; width: 92%; box-shadow: var(--shadow-pop); color: var(--ink); white-space: normal; overflow-wrap: anywhere; }
dialog.modal::backdrop { background: rgba(16, 24, 40, .45); }
.confirm-q { font-size: 1.25rem; line-height: 1.4; margin: 0 0 var(--s5); text-align: center; }
.confirm-detail { max-width: 460px; margin: 0 auto var(--s5); text-align: left; }
.confirm-detail .chips { margin-bottom: var(--s2); }
.confirm-detail .cd-note { margin: var(--s2) 0; }
.confirm-actions { display: flex; gap: var(--s4); justify-content: center; }
.big-yes, .big-no {
	display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
	min-width: 130px; padding: 16px 26px; font-size: 1.15rem;
	font-weight: 700; border-radius: var(--radius); border: 1px solid; cursor: pointer; text-decoration: none;
}
.big-yes { background: var(--ok); color: #fff; border-color: var(--ok); }
.big-yes.del { background: var(--danger); border-color: var(--danger); }
.big-no { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.big-no:hover { background: var(--bg); }

/* ---------- auth ---------- */
.auth { max-width: 380px; margin: 9vh auto; text-align: center; }
.auth h1 { display: inline-flex; align-items: center; gap: var(--s2); justify-content: center; }
.auth h1 .ic { color: var(--accent); width: 1.3em; height: 1.3em; }
.auth .card { text-align: left; }
.devbox { margin-top: var(--s5); border-style: dashed; box-shadow: none; }
.devbtns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.devbtns .btn { justify-content: center; padding: 8px 10px; font-size: .9rem; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
	.topbar { flex-wrap: wrap; gap: var(--s2); padding: var(--s3) var(--s4); }
	.nav-toggle {
		display: inline-flex; align-items: center; justify-content: center;
		width: 40px; height: 40px; margin-left: auto; padding: 0;
		background: var(--surface); color: var(--ink);
		border: 1px solid var(--line-strong); border-radius: var(--radius);
	}
	.topbar nav { display: none; flex-basis: 100%; flex-direction: column; gap: 2px; }
	.topbar.open nav { display: flex; }
	.topbar nav a { padding: var(--s3); }
	.topbar .right { flex-basis: 100%; margin-left: 0; justify-content: space-between; }
	.topbar.has-nav .right-logout { display: none; }
	.nav-logout { display: block; border-top: 1px solid var(--line); margin-top: var(--s1); padding-top: var(--s1); }
	.nav-logout button.link { width: 100%; text-align: left; padding: var(--s3); }
	main { padding: var(--s4) var(--s4) 56px; }
}

@media (max-width: 640px) {
	table.list { border: none; background: none; box-shadow: none; overflow: visible; }
	table.list tr:has(th) { display: none; }
	table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
	table.list tr {
		background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
		margin-bottom: var(--s3); padding: var(--s2) var(--s4); box-shadow: var(--shadow);
	}
	table.list td {
		display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4);
		padding: var(--s2) 0; border-bottom: 1px solid var(--line); text-align: right;
	}
	table.list tr td:last-child { border-bottom: none; }
	table.list td { overflow-wrap: anywhere; }
	table.list td::before {
		content: attr(data-label); flex: none; text-align: left;
		font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
	}
	/* chip-heavy cells stack: label on top, chips wrap below */
	table.list td[data-label="Materiale"] { display: block; text-align: left; }
	table.list td[data-label="Materiale"]::before { display: block; margin-bottom: var(--s1); }
	table.list td.actions { justify-content: flex-end; text-align: right; }
	table.list td.actions::before { content: none; }
	.iconbtn { width: 40px; height: 40px; }
	.biglinks { grid-template-columns: 1fr; }
	.confirm-actions { flex-direction: column-reverse; }
	.big-yes, .big-no { width: 100%; }
}

/* Stadium zone map */
.zmap { margin: 0 0 var(--s5); }
.zmap-svg { width: 100%; height: auto; display: block; background: var(--surface);
	border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--s3); }
.zmap-frame { fill: var(--bg); stroke: var(--line-strong); stroke-width: 4; }
.zmap-zone .zarea { fill: #eef0f3; stroke: #c2c8d0; stroke-width: 3; transition: fill .15s; }
.zmap-zone.clickable { cursor: pointer; }
.zmap-zone.clickable:hover .zarea { stroke: var(--accent); stroke-width: 5; }
.card.zone.zone-link { display: block; color: inherit; transition: box-shadow .12s, border-color .12s; }
.card.zone.zone-link:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-pop); }
.zmap-zone.is-done .zarea { fill: var(--ok-bg); stroke: #86c79a; }
.zmap-zone.is-todo .zarea { fill: var(--warn-bg); stroke: #e3a463; }
.zmap-zone text { fill: var(--ink); font-size: 46px; font-weight: 700;
	text-anchor: middle; dominant-baseline: middle;
	paint-order: stroke; stroke: var(--surface); stroke-width: 7px; }
.zmap-legend { display: flex; gap: var(--s5); flex-wrap: wrap; margin-top: var(--s3);
	color: var(--muted); font-size: 14px; }
.zmap-legend span { display: inline-flex; align-items: center; gap: var(--s2); }
.zmap-dot { width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid; }
.zmap-dot.done { background: var(--ok-bg); border-color: #86c79a; }
.zmap-dot.todo { background: var(--warn-bg); border-color: #e3a463; }
.zmap-dot.none { background: #eef0f3; border-color: var(--line-strong); }
