/* Mes créances — feuille de style (mobile d'abord) */
:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --text: #17201f;
  --muted: #5d6b69;
  --border: #dde3e2;
  --primary: #0f766e;
  --primary-strong: #0b5c55;
  --primary-soft: #e3f3f1;
  --on-primary: #ffffff;
  --pending: #b45309;
  --pending-soft: #fdf0dd;
  --partial: #1d4ed8;
  --partial-soft: #e4ecfd;
  --paid: #15803d;
  --paid-soft: #e1f5e7;
  --danger: #b91c1c;
  --danger-soft: #fde6e6;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --surface: #18201f;
    --text: #e7eeed;
    --muted: #9aaba8;
    --border: #2a3533;
    --primary: #2bb3a5;
    --primary-strong: #4fd0c2;
    --primary-soft: #143532;
    --on-primary: #06201d;
    --pending: #f2a74b;
    --pending-soft: #3a2a12;
    --partial: #7fa6ff;
    --partial-soft: #18264a;
    --paid: #5fd18a;
    --paid-soft: #123321;
    --danger: #ff8a8a;
    --danger-soft: #3d1717;
    --warn-bg: #3a2f10;
    --warn-text: #f5d98a;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .25rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
code { background: var(--primary-soft); padding: 0 .3em; border-radius: 4px; }
.icon { width: 22px; height: 22px; flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Structure */
.container { max-width: 760px; margin: 0 auto; padding: 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.narrow { max-width: 480px; margin-left: auto; margin-right: auto; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--primary); color: var(--on-primary);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-back { color: inherit; display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; margin-left: -10px; }
.sync-chip {
  font-size: .75rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .18); color: inherit; white-space: nowrap;
}
.sync-chip::before { content: "●"; margin-right: 5px; }
.sync-chip.is-ok::before { color: #8ff0b5; }
.sync-chip.is-offline { background: #fde68a; color: #4a3500; }
.sync-chip.is-offline::before { color: #b45309; }
.sync-chip.is-stale { background: #dbeafe; color: #10306b; }
.sync-chip.is-stale::before { color: #1d4ed8; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-head h1 { margin-bottom: .75rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-title { font-size: 1.1rem; margin: 8px 4px 10px; }

/* Bandeaux et messages */
.banner { position: sticky; z-index: 19; top: calc(54px + env(safe-area-inset-top)); padding: 10px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); display: block; }
.banner-info { background: var(--partial-soft); color: var(--text); }
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-size: .95rem; border: 1px solid transparent; }
.alert-success { background: var(--paid-soft); border-color: color-mix(in srgb, var(--paid) 30%, transparent); }
.alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert-info { background: var(--partial-soft); }
.card.alert-success { background: var(--paid-soft); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.btn:hover { background: var(--primary-strong); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-lg { min-height: 54px; font-size: 1.05rem; }
.btn-small { min-height: 44px; padding: 8px 14px; font-size: .9rem; }
.btn-block { display: flex; width: 100%; margin-bottom: 16px; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.btn-row form { margin: 0; }
.link-danger { background: none; border: 0; color: var(--danger); text-decoration: underline; cursor: pointer; font: inherit; min-height: 44px; padding: 0 4px; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); z-index: 15;
  width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
}
.fab .icon { width: 28px; height: 28px; }

/* Formulaires */
.form .field, .field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=search], input[type=date], input[type=file], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-error { display: block; color: var(--danger); font-size: .875rem; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
.grid-amount { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }
.filters { padding: 12px; }
.filters details { margin-top: 10px; }
.filters summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; color: var(--primary); }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 200px; margin-bottom: 0; }
.copy-field { margin-bottom: 10px; }

/* Montants et badges */
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; display: block; }
.amount.big { font-size: 1.4rem; }
.positive { color: var(--paid); }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-pending { background: var(--pending-soft); color: var(--pending); }
.badge-partial { background: var(--partial-soft); color: var(--partial); }
.badge-paid { background: var(--paid-soft); color: var(--paid); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-due { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--border); color: var(--muted); }
progress.progress { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 6px; border: 0; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 10px; }
progress.progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
progress.progress::-webkit-progress-value { background: var(--paid); border-radius: 999px; }
progress.progress::-moz-progress-bar { background: var(--paid); border-radius: 999px; }

/* Tableau de bord */
.hero { background: var(--primary); color: var(--on-primary); border: 0; }
.hero-label { font-size: .95rem; opacity: .9; }
.hero-amounts .amount { font-size: 2rem; line-height: 1.2; }
.hero-sub { margin-top: 6px; font-size: .95rem; opacity: .95; }
.hero-alert { color: inherit; font-weight: 700; background: rgba(255, 255, 255, .2); padding: 1px 8px; border-radius: 999px; text-decoration: none; }
.status-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
@media (min-width: 560px) { .status-grid { grid-template-columns: repeat(3, 1fr); } }
.status-tile {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 14px 16px; border-radius: var(--radius);
  text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left-width: 6px;
}
.tile-pending { border-left-color: var(--pending); }
.tile-partial { border-left-color: var(--partial); }
.tile-paid { border-left-color: var(--paid); }
.tile-label { font-weight: 700; }
.tile-count { grid-row: span 2; font-size: 1.6rem; font-weight: 800; align-self: center; }
.tile-pending .tile-count { color: var(--pending); }
.tile-partial .tile-count { color: var(--partial); }
.tile-paid .tile-count { color: var(--paid); }
.tile-amounts .amount { font-weight: 600; }
.tile-hint { font-size: .8rem; color: var(--muted); }

/* Listes */
.rows, .person-list, .timeline, .activity, .user-list, .checks { list-style: none; margin: 0; padding: 0; }
.rows li, .timeline li { border-top: 1px solid var(--border); }
.rows li:first-child, .timeline li:first-child { border-top: 0; }
.row-link, .row, .timeline a { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; min-height: 56px; color: inherit; text-decoration: none; }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-main > * { overflow-wrap: anywhere; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.row-side form { margin: 0; }
.activity li { display: flex; flex-direction: column; padding: 8px 0; border-top: 1px solid var(--border); }
.activity li:first-child { border-top: 0; }
.timeline li { padding-left: 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 0; top: 22px; width: 8px; height: 8px; border-radius: 50%; background: var(--pending); }
.timeline li.tl-repayment::before { background: var(--paid); }

.debt-list { display: grid; gap: 10px; margin-bottom: 16px; }
.debt-card {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--pending);
  color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.debt-card.status-partial { border-left-color: var(--partial); }
.debt-card.status-paid { border-left-color: var(--paid); }
.debt-card .progress { grid-column: 1 / -1; margin-top: 6px; }
.debt-card-title { font-weight: 700; overflow-wrap: anywhere; }
.debt-card-sub { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.debt-card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.debt-card-amount { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.summary-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; padding: 0 4px 10px; font-size: .9rem; color: var(--muted); }

.person-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: inherit; text-decoration: none; min-height: 64px; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.3rem; }
.person-title { display: flex; align-items: center; gap: 12px; }
.person-title h1 { margin: 0; }

/* Détail */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.detail-head h1 { margin: 2px 0 0; overflow-wrap: anywhere; }
.person-link { font-weight: 600; text-decoration: none; }
.amount-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.amount-grid > div { display: flex; flex-direction: column; }
.amount-main { grid-column: 1 / -1; background: var(--primary-soft); padding: 10px 12px; border-radius: 10px; }
@media (min-width: 560px) { .amount-grid { grid-template-columns: 1fr 1fr 1.3fr; } .amount-main { grid-column: auto; } }
.totals-table .amount-grid + .amount-grid { border-top: 1px solid var(--border); padding-top: 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 16px 0 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* États vides */
.empty-state { text-align: center; padding: 32px 20px; }
.empty-illustration { font-size: 3rem; margin-bottom: 8px; }

/* Menu */
.menu-list a { display: flex; align-items: center; min-height: 52px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; font-weight: 500; }
.menu-list a::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 1.4rem; }
.menu-list h2 { margin-top: 12px; }
.menu-list h2:first-child { margin-top: 0; }

/* Connexion */
.auth-box { max-width: 420px; margin: 24px auto; }
.auth-logo { text-align: center; }

/* Installation */
.checks li { padding: 8px 0; border-top: 1px solid var(--border); }
.checks li:first-child { border-top: 0; }
.checks .ok strong { color: var(--paid); }
.checks .ko strong { color: var(--danger); }
.checks .warn strong { color: var(--pending); }

/* Barre de navigation inférieure */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.active .icon { stroke-width: 2.6; }

/* Boîte de confirmation */
.dialog { border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 420px); background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-title { font-size: 1.15rem; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.dialog-actions .btn { flex: 1; }

/* Hors ligne : formulaires d'écriture désactivés */
body.is-offline form[method=post] button[type=submit] { opacity: .5; }
