/* Colori per tema. Il tema è scelto da app.js (attributo data-theme sull'elemento html)
   e coincide con le palette di MudBlazor definite in MainLayout. */
:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #f3f3f5;
    --text: #1f1f24;
    --muted: #5f5f6b;
    --line: #dedee3;
    --line-soft: #ececf0;
    --positive: #2e7d32;
    --negative: #c62828;
    --accent: #594ae2;
    --accent-text: #ffffff;
    --tag-bg-l: 90%;
    --tag-bg-s: 75%;
    --tag-fg-l: 24%;
    --tag-fg-s: 70%;
    color-scheme: light;
}

html[data-theme="dark"] {
    --bg: #1a1a22;
    --surface: #25252f;
    --surface-2: #2e2e3a;
    --text: #e6e6ea;
    --muted: #a5a5b3;
    --line: #3d3d4c;
    --line-soft: #32323f;
    --positive: #66bb6a;
    --negative: #ef5350;
    --accent: #8f85f2;
    --accent-text: #14141a;
    --tag-bg-l: 24%;
    --tag-bg-s: 45%;
    --tag-fg-l: 86%;
    --tag-fg-s: 80%;
    color-scheme: dark;
}

body {
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--accent);
}

h1:focus {
    outline: none;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}

.page-header {
    margin-bottom: 1rem;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.amount-positive {
    color: var(--positive);
}

.amount-negative {
    color: var(--negative);
}

/* ----- etichette colorate: la tinta (--h) identifica il valore, il tema decide luce e contrasto ----- */

.tag {
    display: inline-block;
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    background: hsl(var(--h) var(--tag-bg-s) var(--tag-bg-l));
    color: hsl(var(--h) var(--tag-fg-s) var(--tag-fg-l));
}

/* ----- filtri ----- */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem 0;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.filter-select {
    flex: 0 1 180px;
    min-width: 140px;
}

/* ----- KPI e pannelli ----- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.kpi-label {
    color: var(--muted);
}

.kpi-value {
    font-size: 1.2rem;
    white-space: nowrap;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
}

.kpi-secondary {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: start;
}

.stat-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.stat-list th {
    text-align: left;
    font-weight: 400;
    padding: 0.2rem 0.5rem 0.2rem 0;
    white-space: pre-wrap;
}

.stat-list td {
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding: 0.2rem 0 0.2rem 0.5rem;
    white-space: nowrap;
}

.stat-list tr + tr {
    border-top: 1px solid var(--line-soft);
}

.stat-secondary {
    color: var(--muted);
}

.stat-note {
    display: block;
    margin-top: 0.5rem;
    color: var(--muted);
}

/* ----- tabelle ----- */

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th,
.data-table td {
    padding: 0.4rem 0.6rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--line-soft);
}

.data-table thead th {
    background: var(--surface-2);
    font-weight: 600;
    border-bottom: 1px solid var(--line);
}

.data-table tbody th {
    font-weight: 600;
}

.data-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table .wrap {
    white-space: normal;
    min-width: 12rem;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table .total-row th,
.data-table .total-row td {
    background: var(--surface-2);
    font-weight: 600;
    border-top: 2px solid var(--line);
    border-bottom: none;
}

.data-table .unread-row td,
.data-table .unread-row th {
    background: var(--surface-2);
}

.data-table .row-actions {
    text-align: right;
    padding-top: 0;
    padding-bottom: 0;
}

/* ----- grafici ----- */

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

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

.chart-panel {
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
    padding: 0.75rem;
    min-width: 0;
}

.chart-panel h2 {
    margin-top: 0;
}

.chart-wide {
    grid-column: 1 / -1;
}

.chart-empty {
    color: var(--muted);
}

/* ----- form nei dialoghi ----- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.form-wide {
    grid-column: 1 / -1;
}

.form-hint {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.8125rem;
}

/* ----- pagine di accesso (HTML semplice, senza interattività) ----- */

.account-page {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 1rem 2rem;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.account-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1.5rem;
}

.account-brand {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.account-card h1 {
    margin-bottom: 1rem;
}

.account-card label {
    display: block;
    margin: 0.75rem 0 0.25rem;
    font-size: 0.875rem;
}

.account-card input[type="email"],
.account-card input[type="password"],
.account-card input[type="text"],
.account-card input:not([type]) {
    width: 100%;
    box-sizing: border-box;
    padding: 0.55rem 0.6rem;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--muted);
    border-radius: 4px;
}

.account-card .account-check {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
}

.account-card button,
.account-button {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    color: var(--accent-text);
    background: var(--accent);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
}

.account-card button:focus-visible,
.account-card input:focus-visible,
.account-button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.account-error {
    padding: 0.6rem 0.8rem;
    border-radius: 4px;
    border: 1px solid var(--negative);
    color: var(--negative);
}

.account-ok {
    padding: 0.6rem 0.8rem;
    border-radius: 4px;
    border: 1px solid var(--positive);
    color: var(--positive);
}

.account-hint {
    margin-top: 1.25rem;
    color: var(--muted);
    font-size: 0.875rem;
}

.account-steps {
    padding-left: 1.2rem;
}

.account-steps li {
    margin-bottom: 0.6rem;
}

/* Il QR resta nero su bianco in entrambi i temi, per essere leggibile dalle fotocamere. */
.account-qr svg {
    width: 180px;
    height: 180px;
    margin: 0.5rem 0;
    padding: 6px;
    background: #ffffff;
    border-radius: 4px;
}

.account-key,
.account-codes {
    display: block;
    padding: 0.5rem;
    background: var(--surface-2);
    border-radius: 4px;
    font-size: 0.95rem;
    word-break: break-all;
}

/* ----- barra di errore del framework ----- */

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    padding: 0.6rem 1.25rem;
    background: #fff8c4;
    color: #1f1f24;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
}

#blazor-error-ui .dismiss {
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
    cursor: pointer;
}
