/*
 * Composants maison (ce que les utilitaires Tailwind ne couvrent pas).
 * Toutes les couleurs viennent des jetons de css/theme.css.
 */

/* Les montants s'alignent proprement (chiffres de largeur fixe) */
.amount { font-variant-numeric: tabular-nums; }

/* ───────────── Cartes (style Copilot : 16 px d'arrondi, ombre douce en clair, sans bordure) ───────────── */
.card {
  border-radius: 1rem; background: var(--c-surface);
  border: 1px solid transparent; box-shadow: var(--shadow-card);
}
html[data-theme="sombre"] .card { border-color: var(--c-line); }

/* Étiquette (badge) : majuscules, gras, 12 px, fond coloré à 15 % */
.tag {
  display: inline-flex; align-items: center; gap: .25rem; flex: none; vertical-align: middle;
  padding: .15rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; line-height: 1.25rem;
  color: var(--tag, var(--c-muted)); background: color-mix(in srgb, var(--tag, var(--c-muted)) 15%, transparent);
}
.tag-neutral { --tag: var(--c-muted); }
.tag-primary { --tag: var(--c-primary); }
.tag-success { --tag: var(--c-success); }
.tag-notice  { --tag: var(--c-warning); }
.tag-danger  { --tag: var(--c-danger); }

/* ───────────── Coquille de l'app ───────────── */
.app-sidebar { background: var(--c-canvas); border-right: 1px solid var(--c-line); }
.app-header { background: var(--c-canvas); border-bottom: 1px solid var(--c-line); }

/* iPhone : en-tête bleu dégradé, titre et onglets en blanc (comme Copilot) */
@media (max-width: 767.98px) {
  .app-header {
    background: linear-gradient(180deg, var(--c-header-top) 0%, var(--c-header-bottom) 100%);
    border-bottom: none; color: #fff;
  }
  .app-header #page-title { color: #fff; }
  .app-header .icon-button { color: rgb(255 255 255 / .85); }
  .app-header .icon-button[aria-current="page"] { color: #fff; }
  .app-header .icon-button:active { background: rgb(255 255 255 / .15); }
  .app-header .alerts-button .badge { background: #fff; color: var(--c-primary); }
  .app-header .alerts-button[data-critical] .badge { background: var(--c-danger-solid); color: #fff; }
  .app-header .tab { color: rgb(255 255 255 / .72); }
  .app-header .tab:hover { color: #fff; }
  .app-header .tab[aria-current="page"] { background: rgb(255 255 255 / .16); color: #fff; box-shadow: inset 0 0 0 1px rgb(255 255 255 / .55); }
  .app-header .tab .badge { background: #fff; color: var(--c-primary); }
  /* Les boutons d'action de l'en-tête deviennent blancs sur bleu */
  .app-header #header-actions .bg-primary { background: #fff; color: var(--c-primary); }
  .app-header #header-actions .border-line { border-color: rgb(255 255 255 / .5); background: transparent; color: #fff; }
}

/* Lien de la barre latérale (iPad / Mac) */
.nav-link {
  display: flex; align-items: center; gap: .7rem;
  padding: .5rem .7rem; border-radius: .6rem;
  color: var(--c-muted); font-size: .9rem; font-weight: 500;
  transition: background-color .15s, color .15s;
}
.nav-link svg { flex: none; }
.nav-link:hover { background: var(--c-surface-2); color: var(--c-ink); }
.nav-link[aria-current="page"] { background: color-mix(in srgb, var(--c-primary) 12%, transparent); color: var(--c-primary); font-weight: 600; }
.nav-link[aria-current="page"] svg { color: var(--c-primary); }

/* Pastille (ex. nombre de transactions à valider) */
.badge {
  margin-left: auto; min-width: 1.25rem; padding: 0 .4rem;
  border-radius: 999px; background: var(--c-pending); color: var(--c-badge-ink);
  font-size: .7rem; font-weight: 700; line-height: 1.25rem; text-align: center;
}

/* Onglets secondaires : pastilles (style « contrôle segmenté ») */
#tabs { scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; flex: none;
  padding: .4rem .85rem; border-radius: 999px;
  font-size: .875rem; font-weight: 500; white-space: nowrap;
  color: var(--c-muted);
  transition: background-color .15s, color .15s;
}
.tab:hover { color: var(--c-ink); }
.tab .badge { margin-left: .4rem; }
.tab[aria-current="page"] { background: color-mix(in srgb, var(--c-primary) 12%, transparent); color: var(--c-primary); font-weight: 600; }

/* Bouton rond d'en-tête (ex. Paramètres sur iPhone) : cible tactile de 44 px */
.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; margin-right: -.5rem; border-radius: 999px;
  color: var(--c-muted);
}
.icon-button[aria-current="page"] { color: var(--c-accent); }
.icon-button:active { background: var(--c-surface-2); }

/* Cloche des alertes : pastille en haut à droite (rouge s'il y a une alerte critique) */
.alerts-button { position: relative; margin-right: 0; }
.alerts-button .badge { position: absolute; top: .3rem; right: .2rem; margin: 0; font-size: .6rem; line-height: 1.05rem; min-width: 1.05rem; padding: 0 .3rem; }
.alerts-button[data-critical] .badge { background: var(--c-danger-solid); color: #fff; }
@media (min-width: 768px) { .alerts-button { margin-right: -.5rem; } }

/* Barre d'onglets iPhone : translucide, au-dessus de la zone du geste d'accueil */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--c-bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--c-line);
}
.bottom-link {
  position: relative; flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .5rem 0 .4rem; min-height: 3.1rem;
  font-size: .625rem; font-weight: 500; color: var(--c-muted);
  transition: color .15s, transform .1s;
}
.bottom-link:active { transform: scale(.94); }
.bottom-link[aria-current="page"] { color: var(--c-primary); }
.bottom-link .badge { position: absolute; top: .2rem; left: calc(50% + .35rem); margin: 0; font-size: .6rem; line-height: 1.05rem; min-width: 1.05rem; padding: 0 .3rem; }

/* Focus clavier visible */
a:focus-visible, button:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }

/* Apparition douce de chaque page */
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-in { animation: view-in .22s ease-out; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .view-in { animation: none; }
}

/*
 * iPhone : la zone de contenu défile SOUS la barre d'onglets translucide. L'espace libre du bas est un bloc
 * ajouté après le contenu (et non un remplissage de #view, qui décalerait les éléments collants).
 */
@media (max-width: 767.98px) {
  main#view::after { content: ""; display: block; height: calc(4.75rem + env(safe-area-inset-bottom)); }
}

/* Barre d'actions collante au bas de la zone de contenu (juste au-dessus de la barre d'onglets sur iPhone) */
.action-bar { position: sticky; bottom: calc(4rem + env(safe-area-inset-bottom)); }
@media (min-width: 768px) { .action-bar { bottom: 0; } }

/*
 * Barre de notification collante en haut de la zone de contenu (liste « Toutes »).
 * La zone #view a un remplissage haut (--view-pad-top = py-6) : sans compensation, la barre se collerait 1,5 rem plus
 * bas et laisserait voir la liste défiler au-dessus. On la remonte de cette hauteur et on la remplit de la couleur du fond.
 */
main#view { --view-pad-top: 1.5rem; }
.sticky-notice {
  position: sticky; top: calc(-1 * var(--view-pad-top)); z-index: 10;
  margin-top: calc(-1 * var(--view-pad-top)); padding-top: var(--view-pad-top);
  background: var(--c-canvas);
}
.sticky-notice:empty { display: none; }

/*
 * iPad / Mac : la barre latérale remplace la barre d'onglets et le bouton Paramètres de l'en-tête.
 * (Règle placée ici, et non en classe Tailwind « md:hidden » : les composants de ce fichier ont priorité sur les utilitaires.)
 */
@media (min-width: 768px) {
  .tab-bar, #settings-link { display: none; }
}

/* ───────────── Briques partagées (js/components/ui.js) ───────────── */

/* Tuile de chiffre : petit libellé, grand nombre */
.stat-tile { border-radius: 1rem; background: var(--c-surface); border: 1px solid transparent; box-shadow: var(--shadow-card); padding: .9rem 1rem; min-width: 0; }
html[data-theme="sombre"] .stat-tile { border-color: var(--c-line); }
.stat-tile.compact { padding: .7rem .75rem; }   /* trois tuiles côte à côte sur iPhone */
.stat-label { font-size: .875rem; font-weight: 500; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { margin-top: .15rem; font-size: 1.375rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { margin-top: .1rem; font-size: .8125rem; color: var(--c-muted); }

/* Pastille de filtre */
.chip {
  display: inline-flex; align-items: center; gap: .4rem; flex: none;
  padding: .45rem .9rem; border-radius: 999px; border: 1px solid transparent;
  background: var(--c-surface-2); color: var(--c-muted); font-size: .875rem; font-weight: 500; white-space: nowrap;
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip:hover { color: var(--c-ink); }
.chip[aria-pressed="true"] { background: color-mix(in srgb, var(--c-primary) 12%, transparent); border-color: color-mix(in srgb, var(--c-primary) 35%, transparent); color: var(--c-primary); font-weight: 600; }
.chip-count { font-size: .75rem; opacity: .75; }

/* Étapes */
.stepper { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.5rem; }
.step { display: flex; align-items: center; gap: .45rem; min-width: 0; color: var(--c-muted); font-size: .8rem; font-weight: 500; }
.step + .step::before { content: ""; width: 1.25rem; height: 1px; background: var(--c-line); flex: none; }
.step-dot {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 1.5rem; height: 1.5rem; border-radius: 999px; background: var(--c-surface-3);
  font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step[data-state="current"] { color: var(--c-ink); font-weight: 600; }
.step[data-state="current"] .step-dot { background: var(--c-primary); color: #fff; }
.step[data-state="done"] .step-dot { background: var(--c-success-soft); color: var(--c-success); }
@media (max-width: 480px) { .step:not([data-state="current"]) .step-label { display: none; } }

/* Bulle de catégorie : emoji centré dans un cercle gris clair (la couleur de la catégorie sert aux barres et graphiques) */
.bubble {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 2.5rem; height: 2.5rem; border-radius: 999px; font-size: 1.15rem; line-height: 1;
  background: var(--c-surface-2);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bubble, var(--c-muted)) 28%, transparent);
}

/* ───────────── Graphiques (js/components/charts.js) ───────────── */
.chart { position: relative; touch-action: pan-y; cursor: crosshair; outline: none; border-radius: .75rem; }
.chart:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 4px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-line { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-line[data-color="main"] { stroke: var(--c-chart-main); }
.chart-line[data-color="good"] { stroke: var(--c-chart-good); }
.chart-line[data-color="bad"] { stroke: var(--c-chart-bad); }
.chart-line[data-color="ref"] { stroke: var(--c-chart-ref); stroke-dasharray: 4 4; }
.chart-area { stroke: none; }
.chart-grid { stroke: var(--c-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
/* Repère vertical et points : éléments HTML (un cercle SVG serait déformé par l'étirement du graphique) */
.chart-guide { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--c-muted); opacity: .5; pointer-events: none; }
.chart-dot {
  position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 999px; pointer-events: none;
  border: 3px solid var(--c-chart-main); background: var(--c-surface);
}
.chart-dot[data-color="good"] { border-color: var(--c-chart-good); }
.chart-dot[data-color="bad"] { border-color: var(--c-chart-bad); }
.chart-dot[data-color="ref"] { border-color: var(--c-chart-ref); }
.chart-tip {
  position: absolute; top: -.25rem; transform: translate(-50%, -100%); z-index: 5; pointer-events: none; white-space: nowrap;
  padding: .4rem .6rem; border-radius: .7rem; background: var(--c-surface); border: 1px solid var(--c-line);
  font-size: .75rem; color: var(--c-muted); box-shadow: var(--shadow-pop);
}
.chart-tip strong { color: var(--c-ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-tip-row { display: flex; align-items: center; gap: .4rem; }
.chart-key { display: inline-block; flex: none; width: .9rem; height: 0; border-top: 3px solid var(--c-chart-main); border-radius: 2px; }
.chart-key[data-color="good"] { border-top-color: var(--c-chart-good); }
.chart-key[data-color="bad"] { border-top-color: var(--c-chart-bad); }
.chart-key[data-color="ref"] { border-top: 2px dashed var(--c-chart-ref); }
.chart-axis { display: flex; justify-content: space-between; margin-top: .4rem; font-size: .7rem; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .6rem; font-size: .75rem; color: var(--c-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.sr-only-table { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Barre de répartition (une catégorie) */
.bar-track { height: 8px; border-radius: 4px; background: var(--c-surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; min-width: 4px; background: var(--bar, var(--c-success)); }

/* Grand chiffre d'une carte du tableau de bord */
.hero-number { font-size: 2.125rem; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }   /* 34 px */

/* Ligne cliquable dans une carte (déborde jusqu'aux bords arrondis au survol). Ajouter « block » ou « flex » dans la page. */
.row-link { margin: 0 -.6rem; padding: .55rem .6rem; border-radius: .75rem; transition: background-color .15s; }
.row-link:hover, .row-link:focus-visible { background: var(--c-surface-2); }

/* Barre de budget dépassée : pleine, aux couleurs de l'erreur (le libellé « Dépassé de… » porte aussi le sens) */
.bar-fill[data-over="true"] { background: var(--c-danger); }

/* Barre d'un objectif : un peu plus épaisse (jamais « dépassée » : au-delà de 100 %, l'objectif est atteint) */
.goal-track { height: 8px; }

/* Boîtes de dialogue et menus : même géométrie que les cartes */
dialog { border-radius: 1rem !important; box-shadow: var(--shadow-pop); }
[role="menu"] { box-shadow: var(--shadow-pop) !important; }

/* ───────────── Barres et anneau (js/components/charts.js › createBarChart / createDonut) ───────────── */
.bars { position: relative; display: flex; align-items: stretch; gap: .35rem; padding-bottom: 1.1rem; }
.bars-col { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; border-radius: .5rem; outline: none; }
.bars-col:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.bars-stack { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 0 2px; }
.bar { flex: 1; max-width: 1.25rem; border-radius: 4px 4px 2px 2px; background: var(--c-chart-main); transition: height .25s ease-out; }
.bar[data-color="good"] { background: var(--c-chart-good); }
.bar[data-color="bad"] { background: var(--c-chart-bad); }
.bar[data-color="ref"] { background: var(--c-chart-ref); opacity: .55; }
.bars-label { position: absolute; left: 0; right: 0; bottom: -1.1rem; text-align: center; font-size: .7rem; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: capitalize; }
.donut { position: relative; flex: none; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-track { fill: none; stroke: var(--c-surface-3); }
.donut-arc { fill: none; stroke-linecap: butt; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }

/* ───────────── Impression (Bilans › « Imprimer / PDF ») ───────────── */
@media print {
  .app-sidebar, .app-header, .tab-bar, #header-actions, .no-print { display: none !important; }
  body, main#view { background: #fff !important; color: #000 !important; overflow: visible !important; height: auto !important; }
  .flex.h-dvh { display: block !important; height: auto !important; }
  main#view { padding: 0 !important; }
  .card, .stat-tile { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
  .print-title { display: block !important; }
  a { text-decoration: none; color: inherit; }
}
.print-title { display: none; }
