:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --text: #1d2430;
    --muted: #667085;
    --line: #d8dee8;
    --brand: #00893f;
    --brand-dark: #00632f;
    --ok: #146c43;
    --error: #a61b2b;
    --blue: #245c85;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }
main { max-width: 1320px; margin: 0 auto; padding: 28px; }
.topbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 92px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.brand-row, .menu-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand { color: var(--text); font-weight: 800; font-size: 20px; text-align: center; }
nav { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
nav a, .ghost {
    color: var(--muted);
    padding: 9px 12px;
    border-radius: 6px;
}
nav a.active, nav a:hover, .ghost:hover { color: var(--brand-dark); background: #e4f3eb; }
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
h1 { margin: 0; font-size: 30px; letter-spacing: 0; }
h2 { font-size: 20px; margin: 0; }
p { color: var(--muted); margin: 4px 0 0; }
.button, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 0;
    border-radius: 6px;
    padding: 0 14px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.button.secondary, button.secondary { background: var(--blue); }
.button.small, button.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
button.danger, .danger { background: var(--error); }
button:disabled { opacity: .55; cursor: not-allowed; }
.filters, .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 18px;
}
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    align-items: end;
}
.donors-filters .filter-submit {
    grid-column: 1 / -1;
    justify-self: end;
}
.donors-filters .date-from {
    grid-column-start: 1;
}
label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
    font: inherit;
}
textarea { min-height: 86px; resize: vertical; }
input[readonly] { background: #f1f3f6; color: #596273; }
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #475467; background: #f0f3f7; font-size: 13px; text-transform: uppercase; }
td span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
tbody tr:hover { background: #eef8f2; }
.badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eef4f7;
    color: #244154;
    font-weight: 700;
}
.donor-status {
    font-weight: 800;
}
.donor-status.is-attivo { color: var(--ok); }
.donor-status.is-cessato { color: var(--error); }
.cw-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    vertical-align: middle;
    box-shadow: 0 0 0 3px #fff, 0 0 0 4px var(--line);
}
.cw-dot.is-linked { background: var(--ok); }
.cw-dot.is-unlinked { background: var(--error); }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.inline-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto;
    gap: 8px;
    align-items: center;
}
.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.page-actions form { margin: 0; }
.association-panel {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 16px;
    align-items: start;
}
.association-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
.association-actions form { margin: 0; }
.association-search {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(260px, 2fr) auto;
    gap: 12px;
    align-items: end;
}
.metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.metrics div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}
.metrics span { color: var(--muted); font-weight: 700; }
.metrics strong { display: block; margin-top: 8px; font-size: 24px; }
.grid-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.span-2 { grid-column: 1 / -1; }
.span-3 { grid-column: 1 / -1; }
.narrow { max-width: 480px; }
.auth {
    min-height: calc(100vh - 130px);
    display: grid;
    place-content: center;
}
.auth h1 { margin-bottom: 14px; }
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: #fff;
}
.alert.success { border-color: #9bd4b5; color: var(--ok); }
.alert.error { border-color: #e3a0aa; color: var(--error); }
.empty, .hint {
    background: #fff8e6;
    border: 1px solid #ecd48e;
    color: #765a15;
    padding: 12px 14px;
    border-radius: 8px;
}
.section-title { margin: 24px 0 12px; }
.import { display: flex; gap: 12px; align-items: end; }
.import label { flex: 1; }
.row-error { background: #fff2f4; }
.row-warning { background: #fff9e8; }
.import-legend {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    color: var(--muted);
}
.import-legend span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.import-preview-table { min-width: 1280px; }
.import-preview-table td { min-width: 180px; }
.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.status-dot {
    display: inline-block;
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}
.status-dot.is-ok { background: var(--ok); }
.status-dot.is-error { background: var(--error); }
.check-label {
    display: inline-block;
    font-weight: 800;
    margin-bottom: 4px;
}
.check-label.is-ok { color: var(--ok); }
.check-label.is-error { color: var(--error); }
.check-label.is-neutral { color: var(--muted); }
.import-state {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-weight: 800;
    margin-bottom: 4px;
}
.import-state.is-new { color: var(--ok); background: #e4f3eb; }
.import-state.is-existing { color: var(--blue); background: #e8f1f8; }
.import-state.is-blocked { color: var(--error); background: #fde8eb; }
.footer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.modal {
    width: min(620px, calc(100vw - 32px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 24px 80px rgba(29, 36, 48, .28);
}
.modal::backdrop { background: rgba(29, 36, 48, .42); }
.modal-box {
    display: grid;
    gap: 14px;
    padding: 18px;
}
.modal-box header,
.modal-box footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.modal-box footer { justify-content: flex-end; }
.icon-button {
    width: 34px;
    min-height: 34px;
    padding: 0;
    background: #eef2f6;
    color: var(--text);
}
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(247, 248, 250, .78);
    backdrop-filter: blur(2px);
    cursor: wait;
}
.loading-overlay.is-visible { display: flex; }
.loading-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-width: 280px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px 22px;
    box-shadow: 0 18px 60px rgba(29, 36, 48, .18);
}
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid #d8dee8;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 760px) {
    main { padding: 18px; }
    .topbar { padding: 14px 18px; }
    nav { flex-wrap: wrap; }
    .page-head, .import, .association-actions, .page-actions { align-items: stretch; flex-direction: column; }
    .metrics, .grid-form, .association-panel, .association-search { grid-template-columns: 1fr; }
}
