/*
 * iCalendar - foglio di stile unico (calendario, login, aree di amministrazione)
 * Carattere: Instrument Sans (SIL Open Font License), ospitato in locale: nessuna richiesta a server esterni.
 */
@font-face { font-family: "Instrument Sans"; src: url("fonts/instrument-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Instrument Sans"; src: url("fonts/instrument-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Instrument Sans"; src: url("fonts/instrument-sans-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
	--paper: #F4F5F7;      /* sfondo pagina */
	--sheet: #FFFFFF;      /* fogli: calendario, pannelli */
	--ink: #1B2232;        /* testo */
	--muted: #5E6679;      /* testo secondario */
	--rule: #DCE0E7;       /* righe della griglia */
	--rule-soft: #ECEEF2;
	--pen: #2340B0;        /* blu penna: azioni, link, selezione */
	--pen-soft: #E9EDFB;
	--marker: #FFE94D;     /* evidenziatore: oggi */
	--danger: #B3261E;
	--ok: #1D6E4A;

	--font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--r-sm: 4px;
	--r-md: 8px;
	--step--1: 0.8125rem;
	--step-0: 0.9375rem;
	--step-1: 1.125rem;
	--step-2: 1.5rem;
	--step-3: 2.25rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--paper);
	color: var(--ink);
	font: 400 var(--step-0)/1.45 var(--font);
	font-variant-numeric: tabular-nums;
}
a { color: var(--pen); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.15; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* ------------------------------------------------------------ pulsanti */
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	min-height: 36px; padding: 0 14px;
	border: 1px solid transparent; border-radius: var(--r-sm);
	background: none; cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--pen); color: #fff; }
.btn-primary:hover { background: #1A3290; }
.btn-quiet { border-color: var(--rule); background: var(--sheet); color: var(--ink); }
.btn-quiet:hover { border-color: var(--muted); }
.btn-icon { width: 36px; padding: 0; border-color: var(--rule); background: var(--sheet); font-size: 1.4rem; line-height: 1; }
.btn-icon:hover { border-color: var(--muted); }
.btn-danger-quiet { color: var(--danger); border-color: transparent; }
.btn-danger-quiet:hover { border-color: currentColor; }
.btn-link { min-height: 0; padding: 0; color: var(--pen); font-weight: 600; text-decoration: underline; }
.btn-link.danger { color: var(--danger); }

/* --------------------------------------------------------------- campi */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; min-width: 0; }
.field > span:first-child { font-size: var(--step--1); font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea,
.jump select, table.list input, table.list select, .inline-form input, .inline-form select {
	width: 100%; min-height: 36px; padding: 6px 10px;
	border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--sheet);
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--pen); outline: none; box-shadow: 0 0 0 3px var(--pen-soft); }
.field [aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--step--1); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-style: normal; font-weight: 400; font-size: var(--step--1); color: var(--muted); }
.time { display: flex; align-items: center; gap: 4px; }
.time b { color: var(--muted); }

/* =============================================================== APP */
.topbar {
	display: flex; align-items: center; justify-content: space-between; gap: 16px;
	padding: 10px 24px; background: var(--sheet); border-bottom: 1px solid var(--rule);
	position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
	width: 22px; height: 24px; flex: none; border-radius: 3px;
	border: 2px solid var(--ink); border-top-width: 6px;
	background: linear-gradient(transparent 55%, var(--marker) 55%, var(--marker) 85%, transparent 85%);
}
.brand-name { font-weight: 700; font-size: var(--step-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; align-items: center; gap: 18px; font-weight: 600; }
.topnav > a, .topnav summary { color: var(--ink); text-decoration: none; cursor: pointer; }
.topnav > a:hover, .topnav summary:hover { color: var(--pen); }
.topnav .user { color: var(--muted); font-weight: 400; padding-left: 18px; border-left: 1px solid var(--rule); }
.topnav .logout { color: var(--pen); }

details.menu { position: relative; }
details.menu summary { list-style: none; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu summary::after { content: ""; display: inline-block; margin-left: 6px; border: 4px solid transparent; border-top-color: currentColor; transform: translateY(2px); }
.menu-list {
	position: absolute; right: 0; top: calc(100% + 10px); min-width: 200px; padding: 6px;
	background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md);
	box-shadow: 0 8px 24px rgba(27, 34, 50, .12); z-index: 30;
}
.menu-list a { display: block; padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; font-weight: 400; }
.menu-list a:hover { background: var(--pen-soft); }

.workspace {
	display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start;
	max-width: 1440px; margin: 0 auto; padding: 24px;
}

/* ---------------------------------------------------------- calendario */
.calendar-wrap { min-width: 0; }
.cal-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cal-title { font-size: var(--step-3); font-weight: 700; letter-spacing: -0.01em; }
.cal-title span { font-weight: 400; color: var(--muted); }
.cal-title small { display: block; font-size: var(--step--1); font-weight: 400; color: var(--muted); letter-spacing: 0; margin-top: 4px; }
.cal-nav { display: flex; gap: 6px; }

table.calendar {
	width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0;
	background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden;
}
table.calendar th.dayheader {
	padding: 10px 10px 8px; text-align: left; font-size: var(--step--1); font-weight: 600; color: var(--muted);
	border-bottom: 1px solid var(--rule); background: var(--sheet);
}
table.calendar td {
	vertical-align: top; padding: 6px 6px 8px; cursor: pointer;
	border-right: 1px solid var(--rule-soft); border-bottom: 1px solid var(--rule-soft);
	transition: background-color .12s;
}
table.calendar tr > td:last-child { border-right: 0; }
table.calendar tbody tr:last-child > td { border-bottom: 0; }
table.month td { height: 118px; }
table.calendar td:hover { background: #FAFBFC; }
table.calendar td.is-selected { background: var(--pen-soft); box-shadow: inset 0 0 0 2px var(--pen); }

#daystamp, #daystamp_light { font-weight: 700; padding: 0 4px 4px; }
#daystamp_light { color: #A3A9B6; font-weight: 400; }

/* oggi: il numero evidenziato come con un evidenziatore */
td.currentday #daystamp .num, td.currentdayright #daystamp .num {
	padding: 0 5px; margin-left: -5px;
	background: linear-gradient(100deg, transparent 2%, var(--marker) 6%, var(--marker) 92%, transparent 97%);
	background-size: 100% 70%; background-position: 0 70%; background-repeat: no-repeat;
}
.today-tag { font-size: var(--step--1); font-weight: 400; color: var(--muted); }

#dayevents ul { list-style: none; margin: 0; padding: 0; }
li.ev {
	margin: 0 0 3px; padding: 2px 6px 3px; font-size: var(--step--1); line-height: 1.3;
	border-left: 3px solid var(--ev, var(--muted)); border-radius: 0 var(--r-sm) var(--r-sm) 0;
	background: color-mix(in srgb, var(--ev, #888) 9%, white);
	overflow: hidden; text-overflow: ellipsis;
}
.ev-time { color: var(--muted); }
a.ev-link { color: var(--ink); text-decoration: none; }
a.ev-link:hover, a.ev-link:focus { text-decoration: underline; }
.ev-bar {
	margin: 0 -6px 3px; padding: 2px 8px; font-size: var(--step--1); line-height: 1.3;
	background: var(--ev, var(--muted)); color: #fff; font-weight: 600;
}
.ev-bar a.ev-link { color: #fff; }

/* vista settimana */
table.week td { height: 46px; padding: 3px 4px; }
table.week th.hourcell { width: 58px; padding: 0 8px; text-align: right; vertical-align: top; font-size: var(--step--1); font-weight: 400; color: var(--muted); border-right: 1px solid var(--rule); }
table.week tbody th.hourcell { padding-top: 4px; }
table.week th.dayheader .num { display: block; font-size: var(--step-1); font-weight: 700; color: var(--ink); }
table.week th.dayheader.is-today .num { width: fit-content; padding: 0 4px; margin-left: -4px; background: linear-gradient(transparent 30%, var(--marker) 30%, var(--marker) 92%, transparent 92%); }
table.week td[data-busy] { background: color-mix(in srgb, var(--ev) 14%, white); }
table.week td.currentday:not([data-busy]) { background: #F6F8FE; }
table.week li.ev { background: rgba(255, 255, 255, .7); }

/* ------------------------------------------------------------- pannello */
.panel {
	background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md);
	padding: 18px 20px 20px; position: sticky; top: 74px;
}
.viewing { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--rule-soft); font-size: var(--step--1); color: var(--muted); }
.viewing strong { color: var(--ink); }
.viewing a { margin-left: 6px; }
.viewing.is-readonly ~ #form_addevent { display: none; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; background: #FFF4C2; color: #6B5800; font-size: var(--step--1); font-weight: 600; }

.day-title { font-size: var(--step-2); font-weight: 700; margin: 0 0 10px; }
.day-title.is-today::after { content: "oggi"; margin-left: 10px; padding: 0 6px; font-size: var(--step--1); font-weight: 600; vertical-align: middle; background: var(--marker); border-radius: 2px; }

.day-list { margin: 0 0 18px; color: var(--muted); font-size: var(--step--1); line-height: 1.9; }
.day-list a { font-size: var(--step-0); font-weight: 600; margin-right: 6px; text-decoration: none; border-left: 3px solid currentColor; padding-left: 8px; }
.day-list a:hover { text-decoration: underline; }

.event-form { border-top: 1px solid var(--rule-soft); padding-top: 16px; }
.form-title { font-size: var(--step-1); font-weight: 700; margin-bottom: 12px; }
.move { grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-bottom: 12px; }
.move .move-label { grid-column: 1 / -1; }
.move[style*="display: none"] { display: none !important; }
.move-label { font-size: var(--step--1); font-weight: 600; color: var(--muted); }
.move select { width: 100%; min-height: 36px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--sheet); }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.loader { width: 18px; height: 18px; border: 2px solid var(--rule); border-top-color: var(--pen); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.jump { display: flex; align-items: center; gap: 6px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule-soft); }
.jump-label { font-size: var(--step--1); font-weight: 600; color: var(--muted); margin-right: 2px; }
.jump select { width: auto; flex: 1; }

.legend { margin-top: 16px; }
.legend-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--step--1); color: var(--muted); }
.legend-list li { display: flex; align-items: center; gap: 6px; }
.swatch, #small_block { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--ev, #888); }

.error_message { margin: 0; padding: 14px 16px; border-radius: var(--r-md); background: #FCEDEC; color: var(--danger); }

.foot { max-width: 1440px; margin: 0 auto; padding: 8px 24px 32px; font-size: var(--step--1); color: var(--muted); }

/* fumetto descrizione evento */
.tip {
	position: fixed; z-index: 100; max-width: 320px; padding: 10px 12px;
	background: var(--ink); color: #fff; border-radius: var(--r-md); font-size: var(--step--1); line-height: 1.45;
	pointer-events: none; opacity: 0; transform: translateY(2px); transition: opacity .1s, transform .1s;
}
.tip.is-on { opacity: 1; transform: none; }
.tip table, .tip td { all: unset; }

/* ================================================================ LOGIN */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 32px 28px 28px; }
.login-card .brand { margin-bottom: 26px; }
.login-card h1 { font-size: var(--step-2); margin-bottom: 6px; }
.login-card .lead { margin: 0 0 22px; color: var(--muted); }
.login-card .btn-primary { width: 100%; min-height: 42px; margin-top: 6px; }
.login-card .foot-note { margin: 22px 0 0; font-size: var(--step--1); color: var(--muted); }
.notice { margin: 0 0 18px; padding: 10px 12px; border-radius: var(--r-sm); font-size: var(--step--1); }
.notice.error { background: #FCEDEC; color: var(--danger); }
.notice.info { background: #E7F4EE; color: var(--ok); }

/* ======================================================= AMMINISTRAZIONE */
.admin { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--sheet); border-right: 1px solid var(--rule); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { padding: 0 8px 18px; }
.side .area { padding: 0 8px 10px; font-size: var(--step--1); color: var(--muted); }
.side nav a { display: block; padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; font-weight: 600; }
.side nav a:hover { background: var(--rule-soft); }
.side nav a[aria-current="page"] { background: var(--pen-soft); color: var(--pen); }
.side .side-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--rule-soft); font-size: var(--step--1); color: var(--muted); }
.side .side-foot form { margin: 6px 0 0; }

.content { padding: 28px 32px 48px; max-width: 1180px; }
.content > h1 { font-size: var(--step-3); margin-bottom: 6px; letter-spacing: -0.01em; }
.content > .lead { margin: 0 0 24px; color: var(--muted); max-width: 70ch; }
.section { margin-bottom: 32px; }
.section h2 { font-size: var(--step-1); margin-bottom: 12px; }
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; max-width: 760px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.checks { display: flex; gap: 18px; padding-top: 6px; }
.checks label { display: flex; align-items: center; gap: 6px; }

table.list { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; }
table.list th { text-align: left; font-size: var(--step--1); font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--rule); background: #FAFBFC; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.is-editing td { background: var(--pen-soft); }
table.list .num { text-align: right; }
table.list .row-actions { white-space: nowrap; text-align: right; }
table.list .row-actions > * + * { margin-left: 14px; }
.table-scroll { overflow-x: auto; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.inline-form input[type="text"], .inline-form input[type="number"] { width: 84px; min-height: 32px; }
.inline-form input[type="color"] { width: 44px; min-height: 36px; padding: 3px; cursor: pointer; }
.inline-form input.name { width: 200px; }
.muted { color: var(--muted); }
.state { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: var(--step--1); font-weight: 600; }
.state.on { background: #E7F4EE; color: var(--ok); }
.state.off { background: var(--rule-soft); color: var(--muted); }
.state.warn { background: #FFF4C2; color: #6B5800; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; }
.stats div { background: var(--sheet); padding: 14px 16px; }
.stats dt { font-size: var(--step--1); color: var(--muted); }
.stats dd { margin: 4px 0 0; font-size: var(--step-1); font-weight: 700; }
.priv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.priv-cols ul { list-style: none; margin: 0 0 12px; padding: 0; }
.priv-cols li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--rule-soft); }
.empty { color: var(--muted); padding: 8px 0; }

/* ============================================================ responsive */
@media (max-width: 1100px) {
	.workspace { grid-template-columns: 1fr; }
	.panel { position: static; }
}
@media (max-width: 760px) {
	.topbar { flex-wrap: wrap; padding: 10px 16px; }
	.topnav { gap: 14px; font-size: var(--step--1); flex-wrap: wrap; }
	.topnav .user { display: none; }
	.workspace { padding: 16px; gap: 16px; }
	.cal-title { font-size: var(--step-2); }
	table.month td { height: 64px; padding: 4px 3px; }
	table.month #dayevents li.ev { font-size: 0; padding: 0; height: 5px; border-left-width: 0; background: var(--ev); margin-bottom: 2px; border-radius: 2px; }
	table.month .ev-bar { font-size: 0; height: 5px; padding: 0; margin: 0 0 2px; }
	table.calendar th.dayheader { padding: 8px 4px; }
	.today-tag, .mname { display: none; }
	.table-scroll table.calendar.week { min-width: 680px; }
	.field-row { grid-template-columns: 1fr; gap: 0; }
	.admin { grid-template-columns: 1fr; }
	.side { border-right: 0; border-bottom: 1px solid var(--rule); }
	.side nav { display: flex; flex-wrap: wrap; gap: 4px; }
	.content { padding: 20px 16px 40px; }
	.form-grid, .priv-cols { grid-template-columns: 1fr; }
	.foot { padding: 8px 16px 24px; }
}
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
