:root {
    --bf-ink: #1c2430;
    --bf-ink-muted: #55606f;
    --bf-surface: #ffffff;
    --bf-surface-muted: #f4f6f8;
    --bf-border: #dde2e7;
    --bf-accent: #1f5f4f;
    --bf-accent-contrast: #ffffff;
    --bf-danger: #9c3b2e;
    --bf-danger-surface: #fbeeec;
    --bf-warning: #8a5a00;
    --bf-warning-surface: #fbf3e2;
    --bf-success: #1f6f3f;
    --bf-success-surface: #eaf5ee;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bf-surface-muted);
    color: var(--bf-ink);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.5;
}

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

.bf-auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.bf-card {
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 26rem;
}

.bf-card h1 {
    margin-top: 0;
    font-size: 1.5rem;
}

.bf-field {
    margin-bottom: 1.25rem;
}

.bf-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.bf-field input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--bf-border);
    border-radius: 8px;
    font-size: 1rem;
}

.bf-field input:focus-visible {
    outline: 3px solid var(--bf-accent);
    outline-offset: 1px;
}

.bf-field .form-error,
.bf-alert-error {
    color: var(--bf-danger);
    background: var(--bf-danger-surface);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    margin-top: 0.4rem;
}

.bf-alert-success {
    color: var(--bf-success);
    background: var(--bf-success-surface);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    margin-top: 0.4rem;
}

.bf-button {
    display: inline-block;
    width: 100%;
    background: var(--bf-accent);
    color: var(--bf-accent-contrast);
    border: none;
    border-radius: 8px;
    padding: 0.7rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.bf-button:focus-visible {
    outline: 3px solid var(--bf-ink);
    outline-offset: 2px;
}

.bf-card-footer {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--bf-ink-muted);
    text-align: center;
}

/* Tableau de bord (§26) */

.bf-page {
    min-height: 100vh;
    padding: 2rem 1.25rem 4rem;
    max-width: 60rem;
    margin: 0 auto;
}

.bf-page-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.bf-page-header h1 {
    margin: 0;
    font-size: 1.4rem;
}

.bf-page-nav {
    font-size: 0.9rem;
    color: var(--bf-ink-muted);
}

.bf-hero {
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 16px;
    padding: 2.5rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.bf-hero-label {
    color: var(--bf-ink-muted);
    font-size: 1rem;
    margin: 0 0 0.5rem;
}

.bf-hero-figure {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1.1;
    margin: 0;
}

.bf-hero-figure.is-negative {
    color: var(--bf-danger);
}

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

.bf-stat-tile {
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 12px;
    padding: 1.25rem;
}

.bf-stat-tile-label {
    color: var(--bf-ink-muted);
    font-size: 0.85rem;
    margin: 0 0 0.35rem;
}

.bf-stat-tile-value {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

.bf-details {
    margin-top: 1rem;
    text-align: left;
    font-size: 0.9rem;
    color: var(--bf-ink-muted);
}

.bf-details summary {
    cursor: pointer;
    color: var(--bf-accent);
    font-weight: 600;
}

.bf-details ul {
    margin: 0.75rem 0 0;
    padding-left: 1.25rem;
}

.bf-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Graphiques du tableau de bord (§26/§27) — palette catégorielle/séquentielle
   validée du skill dataviz (slots 1/2/8), distincte de --bf-accent/--bf-danger
   qui restent réservés au chrome UI et aux messages de statut. */

.bf-chart-blue {
    --bf-chart-color: #2a78d6;
}

.bf-chart-orange {
    --bf-chart-color: #eb6834;
}

.bf-chart-red {
    --bf-chart-color: #e34948;
}

.bf-chart-card {
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.bf-chart-card h2 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
}

.bf-chart-legend {
    display: flex;
    gap: 1.25rem;
    font-size: 0.85rem;
    color: var(--bf-ink-muted);
    margin-bottom: 1rem;
}

.bf-chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.bf-chart-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
    background: var(--bf-chart-color);
}

.bf-chart-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.bf-chart-table th,
.bf-chart-table td {
    text-align: right;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--bf-border);
}

.bf-chart-table th:first-child,
.bf-chart-table td:first-child {
    text-align: left;
}

/* Delta des tuiles KPI (vs mois précédent) */

.bf-stat-tile-delta {
    font-size: 0.8rem;
    margin: 0.3rem 0 0;
    color: var(--bf-ink-muted);
}

.bf-stat-tile-delta.is-good {
    color: var(--bf-accent);
}

.bf-stat-tile-delta.is-bad {
    color: var(--bf-danger);
}

/* Sparkbars divergentes (reste disponible, 6 derniers mois) */

.bf-sparkbars {
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin-top: 1.25rem;
}

.bf-sparkbar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.bf-sparkbar-up-zone,
.bf-sparkbar-down-zone {
    width: 100%;
    height: 28px;
    display: flex;
    justify-content: center;
}

.bf-sparkbar-up-zone {
    align-items: flex-end;
}

.bf-sparkbar-down-zone {
    align-items: flex-start;
    border-top: 1px solid var(--bf-border);
}

.bf-sparkbar {
    width: 60%;
    max-width: 14px;
    border-radius: 3px 3px 0 0;
    background: var(--bf-chart-color);
}

.bf-sparkbar-down-zone .bf-sparkbar {
    border-radius: 0 0 3px 3px;
}

.bf-sparkbar.is-muted {
    opacity: 0.4;
}

.bf-sparkbar-labels {
    display: flex;
    gap: 4px;
    margin-top: 0.35rem;
}

.bf-sparkbar-labels span {
    flex: 1;
    text-align: center;
    font-size: 0.7rem;
    color: var(--bf-ink-muted);
}

/* Bar groupé (revenus vs dépenses, 6 derniers mois) */

.bf-groupedbar {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 140px;
}

.bf-groupedbar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-width: 0;
}

.bf-groupedbar-bars {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 3px;
    width: 100%;
    justify-content: center;
}

.bf-groupedbar-bar {
    width: 30%;
    max-width: 24px;
    border-radius: 4px 4px 0 0;
    background: var(--bf-chart-color);
}

.bf-groupedbar-label {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--bf-ink-muted);
}

/* Bar horizontal classé (répartition des dépenses par catégorie) */

.bf-rankedbar-row {
    display: grid;
    grid-template-columns: 8rem 1fr auto;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
    font-size: 0.85rem;
}

.bf-rankedbar-name {
    color: var(--bf-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bf-rankedbar-track {
    background: var(--bf-surface-muted);
    border-radius: 999px;
    height: 18px;
    overflow: hidden;
}

.bf-rankedbar-fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--bf-chart-color);
}

.bf-rankedbar-fill.is-other {
    background: var(--bf-ink-muted);
}

.bf-rankedbar-value {
    text-align: right;
    color: var(--bf-ink-muted);
    white-space: nowrap;
}

.bf-placeholder-card {
    background: var(--bf-surface-muted);
    border: 1px dashed var(--bf-border);
    border-radius: 12px;
    padding: 1.5rem;
    color: var(--bf-ink-muted);
    font-size: 0.9rem;
}

/* Comptes / Catégories / Transactions / Budget */

.bf-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.bf-toolbar h1 {
    margin: 0;
    font-size: 1.3rem;
}

.bf-table-wrap {
    overflow-x: auto;
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 12px;
}

.bf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.bf-table th,
.bf-table td {
    padding: 0.65rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--bf-border);
    white-space: nowrap;
}

.bf-table th {
    color: var(--bf-ink-muted);
    font-weight: 600;
    background: var(--bf-surface-muted);
}

.bf-table tr:last-child td {
    border-bottom: none;
}

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

.bf-table-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}

.bf-table-actions form {
    margin: 0;
    display: inline;
}

.bf-link-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--bf-danger);
    cursor: pointer;
    text-decoration: underline;
}

.bf-link-button:focus-visible {
    outline: 2px solid var(--bf-danger);
    outline-offset: 2px;
}

.bf-link-button.is-neutral {
    color: var(--bf-accent);
}

.bf-link-button.is-neutral:focus-visible {
    outline-color: var(--bf-accent);
}

.bf-recap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    align-items: start;
}

.bf-recap-section {
    margin-bottom: 1.5rem;
}

.bf-recap-section h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
}

.bf-table-total-row td {
    font-weight: 700;
    background: var(--bf-surface-muted);
}

.bf-empty-state {
    color: var(--bf-ink-muted);
    font-style: italic;
    padding: 1.5rem;
    text-align: center;
}

/* Saisie rapide (§15/§41) : cellules éditables directement, façon tableur —
   des champs discrets qui ne ressemblent pas à un formulaire classique. */
.bf-quick-entry-table td {
    padding: 0.3rem 0.5rem;
    white-space: normal;
}

.bf-quick-entry-table input,
.bf-quick-entry-table select {
    width: 100%;
    min-width: 6rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    font: inherit;
    color: var(--bf-ink);
}

.bf-quick-entry-table input[type="date"] {
    min-width: 8.5rem;
}

.bf-quick-entry-table input:hover,
.bf-quick-entry-table select:hover {
    border-color: var(--bf-border);
}

.bf-quick-entry-table input:focus-visible,
.bf-quick-entry-table select:focus-visible {
    outline: none;
    border-color: var(--bf-accent);
    background: var(--bf-surface);
}

.bf-quick-entry-table input[readonly],
.bf-quick-entry-table select:disabled {
    color: var(--bf-ink-muted);
}

.bf-quick-entry-notice {
    background: var(--bf-warning-surface);
    color: var(--bf-warning);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.bf-quick-entry-notice a {
    color: inherit;
    font-weight: 600;
}

.bf-tab-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.bf-tab-nav a {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--bf-border);
    color: var(--bf-ink-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.bf-tab-nav a.is-active {
    background: var(--bf-accent);
    border-color: var(--bf-accent);
    color: var(--bf-accent-contrast);
    font-weight: 600;
}

.bf-form-card {
    background: var(--bf-surface);
    border: 1px solid var(--bf-border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 34rem;
}

.bf-field select,
.bf-field textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--bf-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
}

.bf-field textarea {
    min-height: 5rem;
    resize: vertical;
}

.bf-subtitle {
    color: var(--bf-ink-muted);
    font-size: 0.85rem;
}

.bf-field .help-text {
    color: var(--bf-ink-muted);
    font-size: 0.8rem;
    margin: 0.3rem 0 0;
}

.bf-field-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bf-field-checkbox input {
    width: auto;
}

.bf-field-checkbox label {
    margin-bottom: 0;
}

.bf-budget-line {
    margin-bottom: 1.25rem;
}

.bf-budget-line-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
}

.bf-budget-line-name {
    font-weight: 600;
}

.bf-budget-meter {
    height: 10px;
    border-radius: 999px;
    background: var(--bf-surface-muted);
    overflow: hidden;
}

.bf-budget-meter-fill {
    height: 100%;
    background: var(--bf-accent);
}

.bf-budget-meter-fill.is-over {
    background: var(--bf-danger);
}

.bf-budget-overrun {
    color: var(--bf-danger);
    font-size: 0.85rem;
    margin: 0.3rem 0 0;
}
