@import url('https://fonts.googleapis.com/css2?family=Spectral:wght@400;500;600&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --paper: #EDE7D9;
  --paper-raised: #F6F2E7;
  --ink: #24312B;
  --ink-soft: #5B6660;
  --line: #C9BFA4;
  --stamp: #B23A2E;
  --stamp-dark: #8E2D24;
  --brass: #8A7B4E;
  --brass-light: #C9B980;
  --paid-bg: #E4E4D3;

  --font-display: 'Spectral', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% 2.4em;
  background-position: 0 9.2em;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* ---------- En-tête ---------- */
.masthead-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
}

.date-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2.6rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------- Barre du mois ---------- */
.month-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin: 2.2rem 0 1.6rem;
}

.month-label {
  font-family: var(--font-display);
  font-size: 1.15rem;
  text-transform: capitalize;
  min-width: 11ch;
  text-align: center;
}

.nav-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.nav-btn:hover { background: var(--brass-light); }
.nav-btn:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
.nav-btn:active { transform: scale(0.92); }

/* ---------- Résumé / anneau ---------- */
.summary {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.4rem 1.6rem;
  margin-bottom: 2rem;
}

.ring-wrap {
  position: relative;
  width: 92px;
  height: 92px;
  flex: none;
}

.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 9;
}
.ring-progress {
  fill: none;
  stroke: var(--stamp);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.6s cubic-bezier(.4,0,.2,1);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-percent {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.15rem;
}
.ring-caption {
  font-size: 0.62rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-figures {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}
.figure {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 0.35rem;
}
.figure:last-child { border-bottom: none; padding-bottom: 0; }
.figure dt { font-size: 0.82rem; color: var(--ink-soft); }
.figure dd { margin: 0; font-family: var(--font-mono); font-weight: 600; font-size: 1rem; }
.figure-paid { color: #4C6A4F; }
.figure-remaining { color: var(--stamp-dark); }

/* ---------- Plans d'apurement (prêts) ---------- */
.loans-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.3rem 1.5rem 0.4rem;
  margin-bottom: 1.6rem;
}

.loan-row {
  padding: 0.8rem 0 1.1rem;
  border-bottom: 1px dashed var(--line);
}
.loan-row:last-child { border-bottom: none; }

.loan-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
}
.loan-name { font-weight: 600; font-size: 0.98rem; }
.loan-remaining {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--stamp-dark);
}

.loan-bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}
.loan-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brass), var(--stamp));
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(.4,0,.2,1);
}

.loan-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.loan-count {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
}

.hidden { display: none !important; }

/* ---------- Barre de compte ---------- */
.account-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px dashed var(--line);
  font-size: 0.8rem;
  color: var(--ink-soft);
  flex-wrap: wrap;
  gap: 0.4rem;
}
.account-bar-actions { display: flex; gap: 0.9rem; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--brass);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--stamp-dark); }

.admin-account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.88rem;
}
.admin-account-row:last-child { border-bottom: none; }
.admin-username { color: var(--ink-soft); font-family: var(--font-mono); font-size: 0.78rem; }
.admin-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--brass);
  border: 1px solid var(--brass);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  margin-left: 0.3rem;
}

/* ---------- Page de connexion ---------- */
.login-page { max-width: 420px; padding-top: 4rem; }
.login-form { margin-top: 2rem; }

/* ---------- Sélecteur d'utilisateur ---------- */
.user-switcher {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.4rem;
}
.user-pill {
  flex: 1;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.user-pill:hover { background: var(--brass-light); }
.user-pill.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-raised);
}
.user-pill:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }

.user-pill-wrap {
  flex: 1;
  display: flex;
  position: relative;
}
.user-pill-wrap .user-pill { flex: 1; }

.user-pill-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.6rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.user-switcher:hover .user-pill-delete { opacity: 1; }
.user-pill-delete:hover { color: var(--stamp); border-color: var(--stamp); }

.user-pill-add {
  flex: none;
  background: transparent;
  border-style: dashed;
  color: var(--brass);
}
.user-pill-add:hover { background: var(--brass-light); color: var(--ink); }

.add-user-panel {
  margin-top: 0.8rem;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.circle-options {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.3rem;
}
.circle-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.circle-option input[type="radio"] {
  margin-top: 0.2rem;
  accent-color: var(--stamp);
  width: 16px;
  height: 16px;
  flex: none;
}

.locked-notice {
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 0.9rem;
  padding: 0.5rem;
}
.locked-notice.hidden { display: none; }
.locked-notice strong { color: var(--ink); }
.locked-notice a { color: var(--brass); }

/* ---------- Bannière de solde ---------- */
.balance-banner {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.9rem 1.2rem;
  border-radius: 8px;
  margin: 1rem 0 1.6rem;
  border: 1px solid var(--line);
}
.balance-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.balance-row-sub {
  padding-top: 0.5rem;
  border-top: 1px dashed var(--line);
}
.balance-row-sub .balance-value { font-size: 1rem; }
.balance-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.balance-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
}
.balance-banner.balance-positive {
  background: var(--paid-bg);
  border-color: #A9B79C;
}
.balance-banner.balance-positive .balance-value { color: #3D5A40; }
.balance-banner.balance-negative {
  background: #F1DEDA;
  border-color: var(--stamp);
}
.balance-banner.balance-negative .balance-value { color: var(--stamp-dark); }

/* ---------- Revenus ---------- */
.incomes-section { margin-top: 2.4rem; }
.section-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 0.8rem;
}
.income-summary { margin-bottom: 1.4rem; }
.income-ring-progress { stroke: #3D5A40; }
.income-summary .figure-paid { color: #3D5A40; }
.income-summary .figure-remaining { color: var(--brass); }
.income-amount { color: #3D5A40; }
.income-check.checked {
  border-color: #3D5A40;
  background: #3D5A40;
}
.income-stamp {
  color: #3D5A40;
  border-color: #3D5A40;
}
.add-toggle-income {
  border-color: #3D5A40;
  color: #3D5A40;
}
.add-toggle-income:hover { background: #DCE6D6; color: var(--ink); }

/* ---------- Registre ---------- */
.ledger-category {
  margin-bottom: 1.6rem;
}
.category-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 0.4rem;
  padding-left: 0.1rem;
}

.bill-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0.2rem;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.bill-row:last-child { border-bottom: none; }

.check-btn {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-soft);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}
.check-btn:hover { border-color: var(--stamp); }
.check-btn:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
.check-btn.checked {
  border-color: var(--stamp);
  background: var(--stamp);
}
.check-btn.checked::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--paper-raised);
  font-size: 0.85rem;
}

.bill-info { flex: 1; min-width: 0; }
.bill-name {
  font-size: 0.98rem;
  font-weight: 500;
}
.bill-due {
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.bill-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
}

.bill-delete {
  flex: none;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.85rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.bill-row:hover .bill-delete { opacity: 0.6; }
.bill-delete:hover { color: var(--stamp); opacity: 1; }

.bill-row.paid .bill-name,
.bill-row.paid .bill-due {
  color: var(--ink-soft);
  text-decoration: line-through;
  text-decoration-color: var(--line);
}
.bill-row.paid { background: linear-gradient(90deg, var(--paid-bg), transparent 40%); }

/* Tampon "PAYÉ" */
.stamp-mark {
  position: absolute;
  right: 2.6rem;
  top: 50%;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.06em;
  color: var(--stamp);
  border: 2px solid var(--stamp);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  transform: translateY(-50%) rotate(-9deg) scale(0);
  opacity: 0;
  pointer-events: none;
}
.stamp-mark.stamping {
  animation: stampDown 0.42s cubic-bezier(.2,1.4,.4,1) forwards;
}
@keyframes stampDown {
  0%   { transform: translateY(-50%) rotate(-9deg) scale(2.4); opacity: 0; }
  55%  { transform: translateY(-50%) rotate(-9deg) scale(0.92); opacity: 1; }
  75%  { transform: translateY(-50%) rotate(-9deg) scale(1.08); }
  100% { transform: translateY(-50%) rotate(-9deg) scale(1); opacity: 1; }
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 2rem 1rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

/* ---------- Ajout de facture ---------- */
.add-bill { margin-top: 2rem; }

.add-toggle {
  width: 100%;
  padding: 0.85rem;
  background: var(--paper-raised);
  border: 1px dashed var(--brass);
  border-radius: 8px;
  color: var(--brass);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.add-toggle:hover { background: var(--brass-light); color: var(--ink); }
.add-toggle:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }

.add-form {
  margin-top: 1rem;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  min-width: 0;
}
.add-form.hidden { display: none; }

.field { display: flex; flex-direction: column; gap: 0.3rem; grid-column: span 2; min-width: 0; }
.field-small { grid-column: span 1; }

.field label {
  font-size: 0.76rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field input, .field select {
  width: 100%;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
.field input:focus-visible, .field select:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 1px;
}

.field-checkbox {
  grid-column: span 2;
}
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.checkbox-label input[type="checkbox"] {
  margin-top: 0.15rem;
  accent-color: var(--stamp);
  width: 16px;
  height: 16px;
  flex: none;
}

.loan-fields {
  grid-column: span 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  min-width: 0;
  background: var(--paper);
  border: 1px dashed var(--brass);
  border-radius: 8px;
  padding: 0.9rem;
}
.loan-fields.hidden { display: none; }

.field-actions {
  grid-column: span 2;
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 0.2rem;
}

.btn-ghost, .btn-primary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--paper); }
.btn-primary {
  background: var(--stamp);
  color: var(--paper-raised);
}
.btn-primary:hover { background: var(--stamp-dark); }
.btn-ghost:focus-visible, .btn-primary:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .masthead h1 { font-size: 2.1rem; }
  .summary { flex-direction: column; align-items: flex-start; gap: 1.2rem; }
  .stamp-mark { right: 2.2rem; font-size: 0.8rem; }
}
