:root {
    --md-primary-900: #0d1b4f;
    --md-primary-800: #142a72;
    --md-primary-700: #1f3f9a;
    --md-primary-600: #2d5cc6;
    --md-primary-500: #3a77da;
    --md-accent-500: #4f98ff;

    --md-surface-0: #f3f6fd;
    --md-surface-1: #ffffff;
    --md-surface-2: #e7edf8;
    --md-outline: #ced9ef;

    --md-text-strong: #132344;
    --md-text: #2a3d63;
    --md-text-soft: #5b6f94;

    --md-danger: #c62828;
    --md-danger-hover: #aa1f1f;

    --md-shadow-sm: 0 4px 14px rgba(13, 27, 79, 0.08);
    --md-shadow-md: 0 12px 34px rgba(13, 27, 79, 0.12);
}

html,
body {
    margin: 0;
    font-family: "Aptos", "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--md-text, #2a3d63);
    background: transparent;
}

* {
    box-sizing: border-box;
}

a:not(.menu-link),
.btn-link {
    color: var(--md-primary-700, #1f3f9a);
}

a:not(.menu-link):hover {
    color: var(--md-primary-600, #2d5cc6);
}

h1,
h2,
h3,
h4,
h5 {
    margin: 0 0 0.7rem;
    color: var(--md-text-strong, #132344);
    letter-spacing: 0.01em;
}

h1 {
    font-size: clamp(1.35rem, 2.4vw, 1.85rem);
    font-weight: 800;
}

h2 {
    font-size: clamp(1.15rem, 2vw, 1.45rem);
    font-weight: 750;
}

hr {
    border: 0;
    border-top: 1px solid var(--md-outline, #ced9ef);
    margin: 1.15rem 0;
}

select,
input,
textarea {
    font: inherit;
    color: var(--md-text-strong, #132344);
    background: #fff;
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 10px;
    padding: 0.5rem 0.65rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input:focus,
textarea:focus {
    outline: 0;
    border-color: var(--md-primary-500, #3a77da);
    box-shadow: 0 0 0 3px rgba(58, 119, 218, 0.2);
}

button,
.btn-primary,
.btn-secondary,
.btn-danger {
    border: 0;
    border-radius: 10px;
    padding: 0.5rem 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.16s ease;
}

button:hover,
.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
    transform: translateY(-1px);
}

button:active,
.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
    transform: translateY(0);
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--md-primary-700, #1f3f9a), var(--md-primary-500, #3a77da));
    box-shadow: 0 6px 16px rgba(31, 63, 154, 0.26);
}

.btn-primary:hover {
    filter: brightness(1.04);
}

.btn-secondary {
    color: var(--md-text-strong, #132344);
    background: linear-gradient(180deg, #f2f5fc, #e6edf9);
    border: 1px solid var(--md-outline, #ced9ef);
}

.btn-danger {
    color: #fff;
    background: var(--md-danger, #c62828);
    box-shadow: 0 6px 14px rgba(198, 40, 40, 0.3);
}

.btn-danger:hover {
    background: var(--md-danger-hover, #aa1f1f);
}

button:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
    cursor: default;
    opacity: 0.58;
    transform: none;
    box-shadow: none;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(58, 119, 218, 0.2);
}

.content {
    padding-top: 1rem;
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-bottom: 1rem;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 16px;
    padding: 0.9rem;
    box-shadow: var(--md-shadow-sm, 0 4px 14px rgba(13, 27, 79, 0.08));
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem;
}

.filter-row label {
    font-size: 0.87rem;
    font-weight: 700;
    color: var(--md-text-soft, #5b6f94);
}

.filter-row .pdf-single-page-option {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
}

.filter-row select.month-year-select {
    min-width: 96px;
    max-width: 120px;
}

.filter-row select.month-name-select {
    min-width: 128px;
    max-width: 170px;
}

.filter-row select,
.filter-row input {
    min-width: 150px;
}

.filters-body {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    align-items: start;
}

.funzionari-block {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 12px;
    padding: 0.75rem;
    background: #f9fbff;
    width: 100%;
}

.funzionari-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.7rem;
}

.funzionari-list {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    margin-top: 0.55rem;
}

.funzionari-list label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 500;
}

.appointment-filters-block {
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 12px;
    padding: 0.75rem;
    background: #f9fbff;
    width: 100%;
}

.appointment-save-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.appointment-filters-left {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: flex-start;
}

.appointment-filters-left > strong {
    color: var(--md-text-strong, #132344);
    font-size: 0.92rem;
}

.appointment-filters-left label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
    color: var(--md-text, #2a3d63);
}

.save-row-inline {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.save-row-inline label {
    font-size: 0.87rem;
    font-weight: 700;
    color: var(--md-text-soft, #5b6f94);
}

.save-row-inline input {
    min-width: 260px;
}

.table-wrapper {
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 16px;
    box-shadow: var(--md-shadow-sm, 0 4px 14px rgba(13, 27, 79, 0.08));
}

.stats-table-wrapper {
    max-height: calc(100vh - 250px);
    overflow: auto;
}

.kpi-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
}

.kpi-table th,
.kpi-table td {
    border-bottom: 1px solid #e6edf9;
    padding: 0.55rem;
    text-align: left;
    vertical-align: top;
    min-width: 110px;
}

.kpi-table th:first-child,
.kpi-table td:first-child {
    min-width: 120px;
    white-space: nowrap;
}

.kpi-table thead th {
    background: linear-gradient(180deg, #edf2fd, #e6eefb);
    color: var(--md-text-strong, #132344);
    font-weight: 800;
    border-bottom: 1px solid #d5e1f5;
}

.stats-table-wrapper .kpi-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.kpi-table tr.saturday-row td {
    background: #f5f8ff;
}

.kpi-table tr.sunday-row td {
    background: #eaf0ff;
}

.kpi-table tbody tr:hover td {
    background: #f1f6ff;
}

.kpi-cell {
    white-space: normal;
}

.kpi-token {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 0.32rem 0.32rem 0;
    padding: 0.22rem 0.5rem;
    border: 1px solid #9eb8e6;
    border-radius: 999px;
    background: #eaf2ff;
    color: var(--md-primary-900, #0d1b4f);
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1.1;
}

.kpi-token:hover {
    background: #dce9ff;
    border-color: #7ea2df;
}

.kpi-empty {
    color: #97a7c4;
    font-weight: 700;
}

.kpi-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(9, 19, 46, 0.44);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.kpi-modal-dialog {
    width: min(1220px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 16px;
    box-shadow: var(--md-shadow-md, 0 12px 34px rgba(13, 27, 79, 0.12));
    padding: 0.95rem;
}

.kpi-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.6rem;
}

.kpi-modal-header h3 {
    margin: 0;
}

.kpi-modal-header p {
    margin: 0.2rem 0 0;
    color: var(--md-text-soft, #5b6f94);
    font-weight: 600;
}

.kpi-modal-count {
    margin: 0 0 0.55rem;
    color: var(--md-text-soft, #5b6f94);
    font-size: 0.86rem;
    font-weight: 700;
}

.kpi-modal-table-wrap {
    overflow: auto;
    border: 1px solid #e2eaf8;
    border-radius: 10px;
}

.kpi-modal-table th,
.kpi-modal-table td {
    min-width: 120px;
}

.kpi-modal-table th:first-child,
.kpi-modal-table td:first-child {
    min-width: 70px;
}

.kpi-total-row td {
    background: #eaf1ff;
    font-weight: 700;
}

.kpi-week-total td {
    background: #edf3ff;
}

.kpi-period-total td {
    background: #e4eeff;
}

.kpi-column-total td {
    background: #dce9ff;
}

.kpi-token-total {
    cursor: default;
    transform: none;
}

.kpi-token-total:hover {
    background: #eaf2ff;
    border-color: #9eb8e6;
}

.kpi-total-number {
    font-weight: 800;
    color: var(--md-primary-900, #0d1b4f);
}

.error,
.validation-message {
    color: var(--md-danger, #c62828);
    font-weight: 600;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #1e8e3e;
}

.invalid {
    outline: 1px solid var(--md-danger, #c62828);
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 1.2rem;
    color: #fff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.darker-border-checkbox.form-check-input {
    border-color: #7689ad;
}

.dashboard-section {
    margin-top: 1rem;
}

.dashboard-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
}

.dashboard-chart-card {
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 12px;
    background: #fff;
    padding: 0.7rem;
    box-shadow: var(--md-shadow-sm, 0 4px 14px rgba(13, 27, 79, 0.08));
}

.dashboard-chart-card h3 {
    margin-bottom: 0.4rem;
    font-size: 0.95rem;
}

.dashboard-chart {
    width: 100%;
    min-height: 310px;
}

.dashboard-metrics-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.metric-card {
    border: 1px solid var(--md-outline, #ced9ef);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--md-shadow-sm, 0 4px 14px rgba(13, 27, 79, 0.08));
    padding: 0.7rem;
}

.metric-card h3 {
    margin-bottom: 0.25rem;
    font-size: 0.88rem;
    color: var(--md-text-soft, #5b6f94);
}

.metric-card p {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--md-primary-900, #0d1b4f);
}

@media (max-width: 768px) {
    .filters {
        padding: 0.75rem;
        border-radius: 14px;
    }

    .filter-row {
        gap: 0.45rem;
    }

    .filter-row select,
    .filter-row input {
        min-width: 132px;
        flex: 1 1 180px;
    }

    .filter-row select.month-year-select,
    .filter-row select.month-name-select {
        min-width: 132px;
        max-width: none;
        flex: 1 1 132px;
    }

    .filters-body {
        grid-template-columns: 1fr;
    }

    .funzionari-list {
        grid-template-columns: 1fr;
    }

    .appointment-save-row {
        flex-direction: column;
    }

    .save-row-inline {
        margin-left: 0;
        justify-content: flex-start;
        width: 100%;
    }

    .save-row-inline input {
        min-width: 132px;
        flex: 1 1 180px;
    }

    .kpi-modal-dialog {
        padding: 0.7rem;
        border-radius: 12px;
    }

    .kpi-modal-header {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-grid-2 {
        grid-template-columns: 1fr;
    }

    .dashboard-chart {
        min-height: 280px;
    }

    .dashboard-metrics-row {
        grid-template-columns: 1fr 1fr;
    }
}
