:root {
    --bg: #f4efe7;
    --panel: rgba(255, 250, 243, 0.92);
    --panel-strong: #fffaf3;
    --text: #1f2328;
    --muted: #6b6f76;
    --brand: #8f4f2e;
    --brand-2: #b66a3c;
    --line: rgba(31, 35, 40, 0.12);
    --success: #1d7d47;
    --warning: #a86c15;
    --danger: #b42318;
    --shadow: 0 16px 40px rgba(47, 33, 24, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(182, 106, 60, 0.18), transparent 28%),
        radial-gradient(circle at top right, rgba(143, 79, 46, 0.12), transparent 24%),
        linear-gradient(180deg, #f8f3ea 0%, var(--bg) 100%);
}

.page-shell {
    max-width: 1500px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.hero {
    display: grid;
    grid-template-columns: 1.45fr 0.8fr;
    gap: 18px;
    align-items: stretch;
    margin-bottom: 18px;
}

.hero > div,
.card,
.stat-card,
.hero-card,
.alert {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 22px;
}

.hero > div,
.card,
.hero-card,
.alert {
    padding: 24px;
}

.eyebrow,
.section-label,
.hero-card span,
.stat-card span {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 12px;
    color: var(--brand);
    font-weight: 700;
}

h1 {
    margin: 10px 0 10px;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.02;
}

.hero-copy {
    margin: 0;
    max-width: 70ch;
    color: var(--muted);
    line-height: 1.6;
}

.hero-card {
    display: grid;
    align-content: center;
    gap: 10px;
    background: linear-gradient(180deg, rgba(143, 79, 46, 0.12), rgba(255, 250, 243, 0.96));
}

.hero-card strong {
    font-size: 30px;
}

.hero-card small {
    color: var(--muted);
    line-height: 1.5;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    padding: 18px 20px;
}

.stat-card strong {
    display: block;
    margin-top: 10px;
    font-size: 34px;
    font-weight: 800;
}

.stat-card.warning strong { color: var(--warning); }
.stat-card.danger strong { color: var(--danger); }

.layout {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 18px;
    align-items: start;
}

.card {
    margin-bottom: 18px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.section-heading h2,
.card h2 {
    margin: 0;
    font-size: 22px;
}

.count-pill {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(143, 79, 46, 0.08);
    color: var(--brand);
    font-weight: 700;
    font-size: 13px;
}

.toolbar {
    margin-bottom: 18px;
}

.filters {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr 0.7fr auto auto;
    gap: 10px;
    align-items: center;
}

input,
select,
textarea,
button,
a.ghost-button,
a.danger-button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid rgba(31, 35, 40, 0.18);
    background: white;
    color: var(--text);
}

textarea {
    resize: vertical;
    min-height: 110px;
}

button,
a.ghost-button,
a.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 12px;
    padding: 11px 14px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
    transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:hover,
a.ghost-button:hover,
a.danger-button:hover {
    transform: translateY(-1px);
}

button {
    background: var(--brand);
    color: white;
}

button.secondary,
a.ghost-button {
    background: rgba(143, 79, 46, 0.1);
    color: var(--brand);
}

button.danger,
a.danger-button {
    background: var(--danger);
    color: white;
}

.danger-link {
    white-space: nowrap;
}

.grid.two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.grid .full {
    grid-column: 1 / -1;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #3d424a;
}

label input,
label select,
label textarea {
    display: block;
    margin-top: 6px;
    font-weight: 400;
}

label.checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 28px;
}

label.checkbox input {
    width: auto;
    margin: 0;
}

.form-actions,
.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 16px;
}

.attachment-box {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid rgba(31, 35, 40, 0.12);
}

.attachment-upload {
    margin-top: 10px;
    padding: 16px;
    border-radius: 18px;
    background: rgba(143, 79, 46, 0.06);
    border: 1px solid rgba(143, 79, 46, 0.14);
}

.attachment-upload-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
}

.attachment-upload input[type="file"] {
    padding: 10px;
    background: white;
}

.attachment-note {
    margin: 10px 0 0;
    font-size: 13px;
}

.attachment-list {
    margin-top: 14px;
    display: grid;
    gap: 10px;
}

.attachment-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(31, 35, 40, 0.09);
}

.attachment-item strong {
    display: block;
    margin-bottom: 4px;
}

.attachment-empty {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px dashed rgba(31, 35, 40, 0.16);
    color: var(--muted);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(31, 35, 40, 0.09);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

th {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 12px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: capitalize;
}

.badge-attivo {
    background: rgba(29, 125, 71, 0.12);
    color: var(--success);
}

.badge-scaduto,
.badge-cessato {
    background: rgba(180, 35, 24, 0.12);
    color: var(--danger);
}

.alert.success {
    background: rgba(29, 125, 71, 0.12);
    color: #14532d;
    border-color: rgba(29, 125, 71, 0.18);
}

.alert.error {
    background: rgba(180, 35, 24, 0.12);
    color: #7f1d1d;
    border-color: rgba(180, 35, 24, 0.18);
}

.muted {
    color: var(--muted);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 24px 10px;
}

tr.soon {
    background: rgba(168, 108, 21, 0.06);
}

tr.past {
    background: rgba(180, 35, 24, 0.06);
}

@media (max-width: 1100px) {
    .hero,
    .layout,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 720px) {
    .page-shell {
        padding: 16px 12px 28px;
    }

    .hero > div,
    .card,
    .hero-card,
    .alert {
        padding: 18px;
        border-radius: 18px;
    }

    .grid.two,
    .filters {
        grid-template-columns: 1fr;
    }

    .attachment-upload-grid,
    .attachment-item {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }
}
