/* =========================
	BNI Arcadia - Segretario
	Palette ufficiale BNI:
	- BNI Red:		   #CF2030
	- Granite Grey:	  #64666A
	- Sterling Grey:	 #C8C8C8
	- Sterling Light:	#F2F2F2
	========================= */
:root {
	--bni-red: #cf2030;
	--bni-red-dark: #a01825;
	--black: #000000;
	--granite: #64666a;
	--sterling: #c8c8c8;
	--sterling-light: #f2f2f2;
	--white: #ffffff;

	--bg: var(--sterling-light);
	--surface: var(--white);
	--text: #111111;
	--muted: var(--granite);

	--success: #1f8f4a;
	--warning: #c08000;

	--border: rgba(0, 0, 0, 0.10);
	--border-strong: rgba(0, 0, 0, 0.16);

	--radius: 12px;
	--radius-sm: 10px;

	--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
	--shadow-md: 0 8px 24px rgba(0, 0, 0, 0.10);

	--focus: rgba(207, 32, 48, 0.28);
}

* { box-sizing: border-box; }

body {
	font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
	margin: 24px;
	color: var(--text);
	background: linear-gradient(180deg, var(--bg), #ffffff 70%);
}

.app {
	max-width: 1200px;
	margin: 0 auto;
}

.app.blank {
	max-width: 420px;
	margin-top: 12vh;
}

/* ======= Top Navigation (gestionale) ======= */
.topnav {
	display: flex;
	align-items: center;
	gap: 18px;
	flex-wrap: wrap;

	background: var(--surface);
	border: 1px solid var(--border);
	border-left: 6px solid var(--bni-red);
	border-radius: var(--radius);
	padding: 12px 16px;
	box-shadow: var(--shadow-sm);
	margin-bottom: 18px;
}

.topnav .brand {
	font-weight: 800;
	font-size: 16px;
	color: var(--black);
	text-decoration: none;
	letter-spacing: 0.2px;
}

.topnav .navlinks {
	display: flex;
	gap: 4px;
	flex-wrap: wrap;
	flex: 1;
	min-width: 0;
}

.topnav .navlinks a {
	text-decoration: none;
	color: var(--text);
	padding: 7px 12px;
	border-radius: var(--radius-sm);
	font-size: 14px;
	font-weight: 600;
	transition: background 120ms ease;
}

.topnav .navlinks a:hover {
	background: var(--sterling-light);
}

.topnav .navlinks a.active {
	background: var(--bni-red);
	color: var(--white);
}

.topnav .navright {
	display: flex;
	gap: 10px;
	align-items: center;
}

/* ======= Banner staging ======= */
.banner-staging {
	background: #fff3cd;
	border: 1px solid #ffeeba;
	color: #856404;
	border-radius: var(--radius-sm);
	padding: 10px 14px;
	font-size: 13px;
	margin-bottom: 14px;
}

.banner-staging code {
	background: rgba(0, 0, 0, 0.05);
	padding: 2px 6px;
	border-radius: 4px;
}

/* ======= Flash ======= */
.flash {
	border-radius: var(--radius-sm);
	padding: 10px 14px;
	margin-bottom: 12px;
	font-size: 14px;
	border: 1px solid;
}

.flash-ok	{ background: #e7f7ec; border-color: #b8e0c4; color: #1a6a36; }
.flash-err   { background: #fdecec; border-color: #f4b8b8; color: #8a1f24; }
.flash-info  { background: #e7f1fb; border-color: #b8d4ee; color: #1a4e8a; }

/* ======= Topbar (sezioni filtro) ======= */
.topbar {
	display: flex;
	gap: 12px;
	align-items: end;
	flex-wrap: wrap;

	background: var(--surface);
	border: 1px solid var(--border);
	border-left: 6px solid var(--bni-red);
	border-radius: var(--radius);
	padding: 14px;
	box-shadow: var(--shadow-sm);
	margin-bottom: 14px;
}

.row {
	display: flex;
	gap: 10px;
	align-items: center;
	flex-wrap: wrap;
}

.right { text-align: right; }
.muted { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; }

/* ======= Form elements ======= */
label { font-size: 13px; color: var(--text); }

input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea,
.note {
	padding: 9px 10px;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--white);
	color: var(--text);
	outline: none;
	font-family: inherit;
	font-size: 14px;
	box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.02);
	transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input[type="text"] { width: 140px; }
input[type="search"] { width: 220px; }
input[type="number"] { width: 120px; }
input[type="date"] { width: 160px; }
.note { width: 260px; }

input:focus, select:focus, textarea:focus, .note:focus {
	border-color: rgba(207, 32, 48, 0.55);
	box-shadow: 0 0 0 4px var(--focus);
}

input::placeholder, .note::placeholder {
	color: rgba(100, 102, 106, 0.75);
}

/* ======= Buttons ======= */
button, .btn-primary {
	padding: 9px 12px;
	cursor: pointer;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border-strong);
	background: var(--white);
	color: var(--text);
	font-size: 14px;
	font-weight: 600;
	box-shadow: var(--shadow-sm);
	transition: transform 120ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
}

button:hover {
	transform: translateY(-1px);
	box-shadow: 0 10px 22px rgba(0, 0, 0, 0.10);
	border-color: rgba(0, 0, 0, 0.22);
}

button:active { transform: translateY(0); box-shadow: var(--shadow-sm); }

button:focus-visible {
	outline: none;
	box-shadow: 0 0 0 4px var(--focus), var(--shadow-sm);
	border-color: rgba(207, 32, 48, 0.55);
}

.btn-primary, button.primary, button[type="submit"].btn-primary {
	background: var(--bni-red);
	border-color: rgba(0, 0, 0, 0.12);
	color: var(--white);
	box-shadow: 0 10px 22px rgba(207, 32, 48, 0.18);
}

.btn-primary:hover, button.primary:hover { background: var(--bni-red-dark); }

button.danger {
	background: var(--white);
	border-color: rgba(207, 32, 48, 0.4);
	color: var(--bni-red);
}

button.danger:hover {
	background: var(--bni-red);
	color: var(--white);
}

/* ======= Actions ======= */
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ======= Tables ======= */
table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	margin-top: 16px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	overflow: hidden;
	box-shadow: var(--shadow-sm);
}

th, td {
	padding: 12px;
	text-align: left;
	border-bottom: 1px solid var(--border);
	vertical-align: middle;
	font-size: 14px;
}

th {
	background: linear-gradient(180deg, #ffffff, var(--sterling-light));
	color: var(--black);
	font-weight: 700;
	letter-spacing: 0.2px;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(200, 200, 200, 0.18); }

tr.totale td { background: var(--sterling-light); }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.actions-cell button { padding: 6px 10px; font-size: 13px; }

/* ======= Table sort & search ======= */
th.th-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sortable:hover { color: var(--bni-red); }
th.th-sortable::after { content: '↕'; margin-left: 6px; opacity: 0.35; font-size: 12px; }
th.th-sortable[data-sort-dir="asc"]::after { content: '↑'; opacity: 1; color: var(--bni-red); }
th.th-sortable[data-sort-dir="desc"]::after { content: '↓'; opacity: 1; color: var(--bni-red); }

.table-search { margin-top: 16px; }
.table-search input[type="search"] { min-width: 240px; }
.table-search + table { margin-top: 8px; }

/* ======= Badges ======= */
.badge {
	padding: 4px 10px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 700;
	display: inline-block;
	border: 1px solid var(--border);
}

.paid { background: rgba(31, 143, 74, 0.18); color: #155a2f; border-color: rgba(31, 143, 74, 0.30); }
.unpaid { background: rgba(207, 32, 48, 0.12); color: var(--bni-red-dark); border-color: rgba(207, 32, 48, 0.22); }

/* ======= Cards / Sezioni ======= */
.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	box-shadow: var(--shadow-sm);
	margin-bottom: 16px;
}

.card table { margin-top: 8px; }

.section { margin-top: 24px; }
.section-title {
	margin: 0 0 8px 0;
	font-size: 18px;
	padding-left: 10px;
	border-left: 4px solid var(--sterling);
}
.section-title .visible-count { color: var(--muted); font-weight: 600; }
.unpaid-title { border-left-color: var(--bni-red); }
.paid-title { border-left-color: var(--success); }
.section .empty { margin: 10px 4px 0; }

/* Bottone "Segna NON pagato": visibile ma dimesso, non confondibile con il primario rosso */
button.toggle.unpaidBtn {
	background: var(--sterling-light);
	border-color: var(--border-strong);
	color: var(--granite);
	box-shadow: none;
	font-weight: 600;
}
button.toggle.unpaidBtn:hover {
	background: var(--white);
	color: var(--bni-red);
	border-color: rgba(207, 32, 48, 0.45);
}

/* ======= Grid ======= */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 900px) {
	.grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ======= Stats (dashboard) ======= */
.grid.stats {
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat { text-align: center; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 28px; font-weight: 800; margin-top: 6px; color: var(--text); }
.stat-in .stat-value { color: var(--success); }
.stat-out .stat-value { color: var(--bni-red); }

.balance-card {
	text-align: center;
	padding: 24px;
}
.balance-card.positive h2 { color: var(--success); }
.balance-card.negative h2 { color: var(--bni-red); }
.balance-card h2 { margin: 0; font-size: 32px; }

/* ======= Forms (create/edit) ======= */
form.form {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.form-row {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.form-row input,
.form-row select,
.form-row textarea {
	width: 100%;
	max-width: 480px;
}

.form-actions {
	display: flex;
	gap: 10px;
	margin-top: 6px;
}

/* ======= Footer ======= */
.footer {
	text-align: center;
	margin-top: 28px;
	padding: 14px;
	border-top: 1px solid var(--border);
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 900px) {
	.topbar { align-items: stretch; }
	.topbar .row, .topbar form.row { width: 100%; }
	input[type="search"] { flex: 1; width: auto; min-width: 0; }

	.topnav { flex-direction: column; align-items: stretch; }
	.topnav .navlinks { justify-content: center; }
}

@media (max-width: 720px) {
	body { margin: 12px; }

	h1 { font-size: 22px; margin: 6px 0 14px; line-height: 1.2; }
	h2 { font-size: 17px; }

	.topbar {
		flex-direction: column;
		gap: 10px;
		padding: 12px;
		border-left-width: 4px;
	}

	.topbar .row { width: 100%; gap: 8px; }
	.topbar .row label { flex: 0 0 100%; font-size: 13px; }

	.topbar .row input[type="text"],
	.topbar .row input[type="search"] {
		flex: 1; width: auto; min-width: 0; font-size: 16px;
	}

	.actions {
		flex-direction: column;
		width: 100%;
		margin-top: 4px;
		gap: 8px;
	}
	.actions a { display: block; width: 100%; }
	.actions a button, .actions > button {
		width: 100%;
		padding: 12px 14px;
		font-size: 15px;
	}

	/* Tabelle "quote" → card su mobile (solo per la sezione quote colazione) */
	.section table { background: transparent; border: none; border-radius: 0; box-shadow: none; overflow: visible; margin-top: 10px; }
	.section thead { display: none; }
	.section tbody, .section tr, .section td { display: block; width: 100%; }
	.section tr {
		background: var(--surface);
		border: 1px solid var(--border);
		border-radius: var(--radius);
		box-shadow: var(--shadow-sm);
		padding: 12px 14px;
		margin-bottom: 10px;
	}
	.section td { border: none; padding: 6px 0; text-align: left; }
	.section td:first-child {
		font-size: 17px;
		font-weight: 700;
		padding: 2px 0 10px;
		margin-bottom: 4px;
		border-bottom: 1px solid var(--border);
	}
	.section .note { width: 100%; font-size: 16px; padding: 11px 12px; }
	.section button.toggle {
		width: 100%;
		padding: 12px 14px;
		font-size: 15px;
		margin-top: 4px;
	}
	.section button.toggle.paidBtn {
		background: var(--bni-red);
		color: var(--white);
		border-color: rgba(0, 0, 0, 0.12);
		box-shadow: 0 6px 14px rgba(207, 32, 48, 0.18);
	}
	.section tbody tr:hover td { background: transparent; }
}

@media (max-width: 380px) {
	body { margin: 10px; }
	.section tr { padding: 10px 12px; }
	h1 { font-size: 20px; }
}
