/*
 * KOFMoney : design system repris de KofAcademy
 * (packages/config-tailwind/theme.css) : neutres Vercel, cyan KOF #0BB7E5,
 * navy #1C4978, sombre = vrai noir. Manrope (texte), Space Grotesk (titres),
 * Geist Mono (chiffres). Aucune grille ni emoji, lavis doux cyan/navy.
 */

:root {
  --background: #ffffff;
  --surface: #fafafa;
  --surface-2: #f4f4f5;
  --border: #eaeaea;
  --border-strong: #d4d4d8;
  --foreground: #0a0a0a;
  --muted-foreground: #666666;

  --primary: #0a0a0a;
  --primary-foreground: #ffffff;

  --brand: #0bb7e5;
  --brand-strong: #0891b2;
  --brand-soft: rgb(11 183 229 / 0.1);
  --brand-text: #0e7490;
  --navy: #1c4978;
  --navy-deep: #0b1b33;

  --success: #16a34a;
  --success-soft: rgb(22 163 74 / 0.1);
  --danger: #dc2626;
  --danger-soft: rgb(220 38 38 / 0.1);

  --wash-a: rgb(11 183 229 / 0.10);
  --wash-b: rgb(28 73 120 / 0.07);

  --elev-card: 0 1px 2px rgb(10 10 10 / 0.04), 0 8px 24px rgb(10 10 10 / 0.05);
  --elev-md: 0 10px 30px rgb(10 10 10 / 0.08);
  --elev-lg: 0 20px 45px rgb(10 10 10 / 0.12);

  --r-control: 12px;
  --r-card: 20px;
  --r-block: 28px;

  --font-sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", "Manrope", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --tabbar-h: 68px;

  color-scheme: light;
}

/* Sombre : préférence système, sauf si l'utilisateur a forcé « Clair » */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #0a0a0a;
    --surface: #111111;
    --surface-2: #171717;
    --border: #1f1f1f;
    --border-strong: #262626;
    --foreground: #ededed;
    --muted-foreground: #a1a1a1;
    --primary: #ededed;
    --primary-foreground: #0a0a0a;
    --brand-soft: rgb(11 183 229 / 0.12);
    --brand-text: #38c8ee;
    --success: #22c55e;
    --success-soft: rgb(34 197 94 / 0.12);
    --danger: #ef4444;
    --danger-soft: rgb(239 68 68 / 0.12);
    --wash-a: rgb(11 183 229 / 0.08);
    --wash-b: rgb(28 73 120 / 0.16);
    --elev-card: 0 0 0 1px rgb(255 255 255 / 0.02), 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.45);
    --elev-md: 0 0 0 1px rgb(255 255 255 / 0.03), 0 10px 30px rgb(0 0 0 / 0.55);
    --elev-lg: 0 0 0 1px rgb(255 255 255 / 0.04), 0 20px 45px rgb(0 0 0 / 0.65);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --background: #0a0a0a;
  --surface: #111111;
  --surface-2: #171717;
  --border: #1f1f1f;
  --border-strong: #262626;
  --foreground: #ededed;
  --muted-foreground: #a1a1a1;
  --primary: #ededed;
  --primary-foreground: #0a0a0a;
  --brand-soft: rgb(11 183 229 / 0.12);
  --brand-text: #38c8ee;
  --success: #22c55e;
  --success-soft: rgb(34 197 94 / 0.12);
  --danger: #ef4444;
  --danger-soft: rgb(239 68 68 / 0.12);
  --wash-a: rgb(11 183 229 / 0.08);
  --wash-b: rgb(28 73 120 / 0.16);
  --elev-card: 0 0 0 1px rgb(255 255 255 / 0.02), 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.45);
  --elev-md: 0 0 0 1px rgb(255 255 255 / 0.03), 0 10px 30px rgb(0 0 0 / 0.55);
  --elev-lg: 0 0 0 1px rgb(255 255 255 / 0.04), 0 20px 45px rgb(0 0 0 / 0.65);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(60% 40% at 15% 0%, var(--wash-a), transparent 70%),
    radial-gradient(50% 35% at 95% 5%, var(--wash-b), transparent 70%),
    var(--background);
  background-attachment: fixed;
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
h2 { font-size: 17px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.muted { color: var(--muted-foreground); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--brand-text);
}

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar h1 {
  flex: 1;
  text-align: center;
  font-size: 15px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--elev-card);
}
.topbar.no-nav .icon-btn { visibility: hidden; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px);
}

.view { display: none; }
.view.active { display: block; animation: fade-up 0.35s var(--ease); }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 28px 4px 10px;
}

/* ------------------------------------------------------------------ */
/* Boutons                                                             */
/* ------------------------------------------------------------------ */
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: border-color 0.2s, background 0.2s;
}
.icon-btn:hover { border-color: color-mix(in srgb, var(--brand) 40%, transparent); }

.link-btn {
  border: 0;
  background: none;
  padding: 4px;
  color: var(--brand-text);
  font-weight: 600;
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--background);
  font-weight: 600;
  font-size: 14px;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); background: var(--danger-soft); }

.btn-stack { display: grid; gap: 8px; margin-top: 12px; }
.btn-stack .btn { justify-content: flex-start; }

.fab-stack {
  position: fixed;
  right: max(16px, calc(50% - 280px + 16px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.fab {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 999px;
  border: 0;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 10px 30px rgb(11 183 229 / 0.35);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }
.fab:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgb(11 183 229 / 0.45); }
.fab:active { transform: scale(0.95); }
.fab.secondary {
  width: 48px;
  height: 48px;
  background: var(--surface);
  color: var(--brand-text);
  border: 1px solid var(--border);
  box-shadow: var(--elev-md);
}
.fab.secondary svg { width: 22px; height: 22px; stroke-width: 2; }

/* ------------------------------------------------------------------ */
/* Barre d'onglets                                                     */
/* ------------------------------------------------------------------ */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(528px, calc(100% - 32px));
  height: var(--tabbar-h);
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--elev-md);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 10.5px;
  font-weight: 600;
  min-width: 0;
  transition: color 0.2s, background 0.2s;
}
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.active { color: var(--brand-text); background: var(--brand-soft); }

/* ------------------------------------------------------------------ */
/* Carte solde (cellule navy façon bento KofAcademy)                   */
/* ------------------------------------------------------------------ */
.balance-card {
  position: relative;
  overflow: hidden;
  padding: 24px;
  border-radius: var(--r-block);
  background: var(--navy-deep);
  color: #fff;
  box-shadow: var(--elev-lg);
  isolation: isolate;
}
.balance-card::before,
.balance-card::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  filter: blur(40px);
}
.balance-card::before { width: 220px; height: 220px; right: -60px; top: -80px; background: rgb(11 183 229 / 0.45); }
.balance-card::after { width: 200px; height: 200px; left: -70px; bottom: -110px; background: rgb(28 73 120 / 0.9); }
.balance-card .eyebrow { color: #7dd8f2; }
.balance {
  display: block;
  margin: 6px 0 20px;
  font-family: var(--font-mono);
  font-size: clamp(30px, 9vw, 40px);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.balance.negative { color: #fca5a5; }
.month-sums {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.month-sums > div {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.08);
}
.month-sums .label { font-size: 12px; color: rgb(255 255 255 / 0.6); }
.month-sums .sum { font-family: var(--font-mono); font-weight: 600; font-size: 16px; }
#monthIncome { color: #86efac; }
#monthExpense { color: #fca5a5; }

/* ------------------------------------------------------------------ */
/* Liste d'opérations                                                  */
/* ------------------------------------------------------------------ */
.tx-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}
.tx-list:empty { display: none; }
.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  transition: background 0.2s;
}
.tx:hover { background: var(--surface-2); }
.tx-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}
.tx-icon.income { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12.5px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amounts { display: grid; justify-items: end; gap: 1px; }
.tx-amount { font-family: var(--font-mono); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tx-original { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted-foreground); white-space: nowrap; }
.tx-sub svg { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; color: var(--brand-text); }
.pos { color: var(--success); }
.neg { color: var(--foreground); }

.empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-card);
  text-align: center;
  color: var(--muted-foreground);
}
.empty svg { width: 28px; height: 28px; color: var(--brand); }
.empty strong { color: var(--foreground); font-family: var(--font-display); font-weight: 600; }

.filters { display: grid; gap: 10px; margin-bottom: 16px; }
.filters input[type="search"] {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.filters input[type="search"]:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.day { margin-bottom: 18px; }
.day-head {
  display: flex;
  justify-content: space-between;
  margin: 0 6px 6px;
  font-size: 12.5px;
  color: var(--muted-foreground);
}
.day-head .mono { font-size: 12px; }

/* ------------------------------------------------------------------ */
/* Contrôle segmenté                                                   */
/* ------------------------------------------------------------------ */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 9px 12px;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted-foreground);
  transition: background 0.25s var(--ease), color 0.2s, box-shadow 0.25s;
}
.segmented.small span { padding: 7px 10px; font-size: 13px; }
.segmented input:checked + span { background: var(--background); color: var(--foreground); box-shadow: var(--elev-card); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ------------------------------------------------------------------ */
/* Cartes & formulaires                                                */
/* ------------------------------------------------------------------ */
.card {
  margin-bottom: 14px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}
.card > h2 { margin-bottom: 14px; }
.card p { margin: 0; }

.field { display: grid; gap: 6px; margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; padding: 0; }
.field input, .field select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--background);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.field small { font-size: 12.5px; }

.amount-field input {
  height: 64px;
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--background);
  color: var(--muted-foreground);
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.chip input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }
.chip input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }

.form-error {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--r-control);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* Feuille modale                                                      */
/* ------------------------------------------------------------------ */
dialog {
  width: min(560px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--r-block) var(--r-block) 0 0;
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--elev-lg);
}
dialog[open] { animation: sheet-in 0.35s var(--ease); }
dialog::backdrop { background: rgb(10 10 10 / 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

dialog form { padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px); }
dialog h2 { margin: 6px 0 16px; font-size: 19px; }
dialog .segmented { margin-bottom: 16px; }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto; border-radius: 99px; background: var(--border-strong); }

.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .primary { flex: 1; }

@media (min-width: 600px) {
  dialog { margin: auto; border-bottom: 1px solid var(--border); border-radius: var(--r-block); }
}

/* ------------------------------------------------------------------ */
/* Statistiques                                                        */
/* ------------------------------------------------------------------ */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat-tile {
  display: grid;
  gap: 4px;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  min-width: 0;
}
.stat-tile .eyebrow { font-size: 10px; letter-spacing: 0.12em; color: var(--muted-foreground); }
.stat-tile strong { font-family: var(--font-mono); font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.donut { display: grid; place-items: center; margin: 4px 0 18px; }
.donut svg { width: 200px; height: 200px; stroke-linecap: butt; }
.donut .total { font-family: var(--font-mono); font-weight: 600; fill: var(--foreground); stroke: none; }
.donut .caption { font-family: var(--font-sans); fill: var(--muted-foreground); stroke: none; }

.breakdown { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.breakdown li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 10px; }
.breakdown .swatch { width: 10px; height: 10px; border-radius: 3px; }
.breakdown .name { font-weight: 600; font-size: 14px; }
.breakdown .amt { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; text-align: right; }
.breakdown .pct { color: var(--muted-foreground); font-weight: 500; margin-left: 6px; }
.breakdown .track { grid-column: 2 / 4; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.breakdown .track i { display: block; height: 100%; border-radius: inherit; }

.bars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  height: 170px;
  align-items: end;
}
.bar-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; }
.bar-pair { display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bar { width: 40%; max-width: 16px; min-height: 2px; border-radius: 4px 4px 2px 2px; transition: height 0.5s var(--ease); }
.bar.inc { background: var(--brand); }
.bar.exp { background: var(--navy); }
.bar-col span { font-size: 11px; text-align: center; color: var(--muted-foreground); font-weight: 600; }
.bar-col.current span { color: var(--foreground); }

.legend { display: flex; gap: 16px; justify-content: center; margin-top: 14px; font-size: 12.5px; color: var(--muted-foreground); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.inc { background: var(--brand); }
.dot.exp { background: var(--navy); }

:root[data-theme="dark"] .bar.exp, :root[data-theme="dark"] .dot.exp { background: #4f7fb3; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bar.exp,
  :root:not([data-theme="light"]) .dot.exp { background: #4f7fb3; }
}

/* ------------------------------------------------------------------ */
/* Toast                                                               */
/* ------------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--elev-lg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.25s, transform 0.3s var(--ease);
}
.toast:not(:has(button)) { padding-right: 18px; }
.toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast button {
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--primary-foreground) 15%, transparent);
  color: var(--brand);
  font-weight: 700;
}

/* ------------------------------------------------------------------ */
/* Boutons : variantes et état « en cours »                            */
/* ------------------------------------------------------------------ */
.btn.lg { min-height: 52px; font-size: 15px; justify-content: center; }
.btn-stack .btn.lg { justify-content: center; }
.btn.small-btn { min-height: 38px; padding: 0 14px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: var(--muted-foreground) transparent var(--muted-foreground) transparent;
  animation: spin 0.8s linear infinite;
}
.btn.primary.busy::after { border-color: var(--primary-foreground) transparent var(--primary-foreground) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 32px;
  height: 32px;
  margin: 40px auto;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}

/* ------------------------------------------------------------------ */
/* Écran d'accès : création de compte, connexion, code PIN             */
/* ------------------------------------------------------------------ */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.auth-inner { width: min(400px, 100%); }
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.auth-brand img { border-radius: 12px; }
.auth-step { display: grid; gap: 14px; animation: fade-up 0.35s var(--ease); }
.auth-step p { margin: 0; }
.auth-title { font-size: clamp(26px, 7vw, 32px); line-height: 1.15; letter-spacing: -0.03em; }
.auth-step .btn-stack { margin-top: 12px; }
.auth-step .back { justify-self: start; padding-left: 0; }
.auth-step[data-step="pin"] { justify-items: center; text-align: center; }
.auth-step[data-step="pin"] .back { justify-self: start; }

.pin-dots { display: flex; gap: 14px; margin: 18px 0 4px; }
.pin-dots i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  transition: background 0.15s, border-color 0.15s, transform 0.15s var(--ease);
}
.pin-dots i.filled { background: var(--brand); border-color: var(--brand); transform: scale(1.1); }
.pin-dots.shake { animation: shake 0.4s; }
.pin-dots.shake i { border-color: var(--danger); }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.pin-error { min-height: 20px; color: var(--danger); font-size: 13.5px; font-weight: 600; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 14px 22px;
  margin: 6px 0 10px;
}
.keypad.busy { opacity: 0.5; pointer-events: none; }
.keypad button {
  display: grid;
  place-items: center;
  height: 76px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
}
.keypad button:active { background: var(--brand-soft); transform: scale(0.94); }
.keypad button[data-key="back"] { border-color: transparent; background: transparent; color: var(--muted-foreground); }
.keypad button svg { width: 26px; height: 26px; }

/* ------------------------------------------------------------------ */
/* Réglages : carte compte                                             */
/* ------------------------------------------------------------------ */
.account-card { display: flex; align-items: center; gap: 14px; }
.avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 14px;
  background: var(--navy-deep);
  color: #7dd8f2;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}
.account-info { flex: 1; min-width: 0; display: grid; }
.account-info strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* Note vocale                                                         */
/* ------------------------------------------------------------------ */
.sheet { padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px); }
.mic-zone { display: grid; justify-items: center; gap: 10px; margin: 18px 0 20px; }
.mic-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 999px;
  border: 0;
  background: var(--navy-deep);
  color: #fff;
  box-shadow: var(--elev-md);
  transition: background 0.25s, transform 0.2s var(--ease);
}
.mic-btn svg { width: 32px; height: 32px; }
.mic-btn.listening { background: var(--brand); }
.mic-btn.listening::before,
.mic-btn.listening::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--brand);
  animation: ripple 1.8s var(--ease) infinite;
}
.mic-btn.listening::after { animation-delay: 0.9s; }
@keyframes ripple {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(1.7); opacity: 0; }
}
.mic-status { font-size: 13px; color: var(--muted-foreground); text-align: center; }

.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-control);
  background: var(--background);
  font: inherit;
  color: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.draft-list { margin: 12px 0 4px; }
.draft-row { display: flex; align-items: center; gap: 2px; padding-left: 8px; }
.draft-check { display: grid; place-items: center; width: 32px; height: 44px; flex-shrink: 0; cursor: pointer; }
.draft-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); cursor: pointer; }
.draft-row.off .tx { opacity: 0.4; }
.tx.draft { flex: 1; min-width: 0; }
.draft-edit { display: grid; place-items: center; color: var(--muted-foreground); }
.draft-edit svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ */
/* Voyages                                                             */
/* ------------------------------------------------------------------ */
.section-head.first { margin-top: 8px; align-items: center; }
.section-head .eyebrow { display: block; margin-bottom: 2px; }
.link-btn.back { padding: 4px 0; margin-bottom: 10px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row .field { margin-bottom: 14px; }

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted-foreground);
}
.pill.ongoing { background: var(--brand-soft); color: var(--brand-text); }
.pill.upcoming { background: rgb(139 92 246 / 0.12); color: #7c3aed; }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width 0.5s var(--ease); }
.progress.warn i { background: var(--warning, #d97706); }
.progress.over i { background: var(--danger); }

.trip-list { display: grid; gap: 10px; }
.trip-card {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  text-align: left;
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.trip-card:hover { border-color: color-mix(in srgb, var(--brand) 40%, transparent); }
.trip-card:active { transform: scale(0.99); }
.trip-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.trip-card-title { display: grid; min-width: 0; }
.trip-card-title strong { font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.trip-card-sums { display: flex; align-items: baseline; gap: 6px; }
.trip-card-sums .mono { font-size: 18px; font-weight: 600; }

.trip-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--border));
  border-radius: var(--r-card);
  background: var(--brand-soft);
  text-align: left;
}
.trip-banner > svg { color: var(--muted-foreground); }
.trip-banner-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--navy-deep);
  color: #7dd8f2;
}
.trip-banner-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.trip-banner-main strong { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; }
.trip-banner-main .eyebrow { font-size: 10px; }
.trip-banner .progress { margin-top: 4px; height: 6px; background: rgb(255 255 255 / 0.5); }

.trip-hero {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 20px 22px 22px;
  border-radius: var(--r-block);
  background: var(--navy-deep);
  color: #fff;
  box-shadow: var(--elev-lg);
  isolation: isolate;
}
.trip-hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: 240px;
  height: 240px;
  right: -80px;
  top: -90px;
  border-radius: 50%;
  background: rgb(11 183 229 / 0.4);
  filter: blur(42px);
}
.trip-hero-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.trip-hero .pill { background: rgb(255 255 255 / 0.12); color: #fff; }
.trip-hero .pill.ongoing { background: var(--brand); color: #fff; }
.trip-hero .eyebrow { color: #7dd8f2; }
.trip-hero h2 { font-size: 24px; letter-spacing: -0.03em; }
.trip-hero-dates { display: flex; align-items: center; gap: 6px; font-size: 13px; color: rgb(255 255 255 / 0.65); }
.trip-hero-dates svg { width: 14px; height: 14px; }
.trip-hero .balance { margin: 14px 0 0; font-size: clamp(28px, 8vw, 36px); }
.trip-hero-sub { font-size: 13px; color: rgb(255 255 255 / 0.7); }
.trip-hero-rate { margin-top: 6px; font-family: var(--font-mono); font-size: 11.5px; color: rgb(255 255 255 / 0.5); }
.trip-budget { display: grid; gap: 6px; margin: 12px 0 4px; font-size: 13px; color: rgb(255 255 255 / 0.85); }
.trip-budget .progress { background: rgb(255 255 255 / 0.12); }
.icon-btn.on-dark { background: rgb(255 255 255 / 0.08); border-color: rgb(255 255 255 / 0.14); color: #fff; backdrop-filter: none; }

/* ------------------------------------------------------------------ */
/* Code de secours                                                     */
/* ------------------------------------------------------------------ */
.recovery-box {
  padding: 18px 12px;
  border: 1px dashed color-mix(in srgb, var(--brand) 60%, var(--border));
  border-radius: var(--r-control);
  background: var(--brand-soft);
  font-family: var(--font-mono);
  font-size: clamp(18px, 5.4vw, 22px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-align: center;
  user-select: all;
  word-break: break-all;
}
dialog .recovery-box { margin: 14px 0 4px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); }
.code-input { text-transform: uppercase; letter-spacing: 0.08em; }
.pin-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; }
.notice {
  margin: -4px 0 12px !important;
  padding: 10px 12px;
  border-radius: var(--r-control);
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: 13px;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
