/* ComptAsso — charte « La Fée ludique »
   Bleu (#0F69B4) pour la structure, jaune (#F6D223) pour l'accent,
   vert (#4A9F44) pour les recettes. Fond blanc, touches de bleu très pâle.
   Titres en police arrondie (Trebuchet MS), corps en police système. */

:root {
  --blue: #0f69b4;
  --blue-deep: #0b4f8a;
  --blue-pale: #e8f2fb;
  --yellow: #f6d223;
  --green: #4a9f44;
  --green-text: #2f7a2a;
  --red: #b5402a;
  --paper: #f5f9fc;
  --surface: #ffffff;
  --ink: #142a3d;
  --muted: #5a6d7e;
  --rule: #d3e0ea;
  --rule-strong: #142a3d;

  --display: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --radius: 8px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.5 var(--sans);
  color: var(--ink);
  background: var(--paper);
}

.hidden { display: none !important; }

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--blue);
}

/* ---------- Structure ---------- */

.shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}
body.signed-out .shell { grid-template-columns: 1fr; }
body.signed-out .side { display: none; }
/* Connexion : pleine page, centrée horizontalement et verticalement */
body.signed-out .content {
  max-width: none;
  padding: 0;
  margin: 0;
  width: 100%;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  padding: 1.5rem 1rem;
  background: var(--surface);
  border-right: 1px solid var(--rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  font-family: var(--display);
  font-weight: 700;
  color: var(--blue);
  line-height: 1.1;
}
.brand img { width: 3.1rem; height: auto; flex: none; }
.brand small {
  display: block;
  font-family: var(--sans);
  font-weight: 400;
  font-size: .8rem;
  color: var(--muted);
  margin-top: .15rem;
}

.nav { display: flex; flex-direction: column; gap: .2rem; }
.nav a {
  color: var(--ink);
  text-decoration: none;
  padding: .6rem .8rem;
  border-radius: var(--radius);
  font-weight: 500;
}
.nav a:hover { background: var(--blue-pale); color: var(--blue-deep); }
.nav a.active {
  background: var(--blue-pale);
  color: var(--blue-deep);
  font-weight: 700;
  box-shadow: inset 4px 0 0 var(--yellow);
}

.userbox {
  margin-top: auto;
  font-size: .88rem;
  line-height: 1.4;
  color: var(--muted);
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.userbox strong { display: block; color: var(--ink); font-weight: 600; }
.userbox button {
  margin-top: .6rem;
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--blue);
}

.content {
  width: 100%;
  max-width: 1100px;
  padding: 2.4rem clamp(1rem, 3vw, 2.6rem) 3rem;
  animation: page-in .45s ease both;
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .content { animation: none; }
  * { transition: none !important; }
}

/* ---------- Titres et en-têtes ---------- */

h1 {
  font-family: var(--display);
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 700;
  color: var(--blue);
  line-height: 1.15;
  margin: 0;
}
h2 {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--blue-deep);
  margin: 2.2rem 0 .7rem;
}
h3 { font-size: 1rem; font-weight: 700; margin: 1.2rem 0 .4rem; color: var(--blue-deep); }

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .9rem 1.2rem;
  padding-bottom: 1.1rem;
  margin-bottom: 1.6rem;
  border-bottom: 3px solid var(--yellow);
}
.lede { margin: .35rem 0 0; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.controls label { font-size: .85rem; }

/* ---------- Tableau de bord ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.balance {
  margin: 0 0 1.6rem;
  padding: 1.3rem 1.5rem;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
}
.balance span { display: block; font-size: .95rem; opacity: .92; }
.balance strong {
  display: block;
  font-family: var(--display);
  font-size: clamp(2.6rem, 7vw, 4rem);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums;
  margin-top: .2rem;
}
.balance.neg { background: var(--red); }

.figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .8rem;
  margin-bottom: .5rem;
}
.figure {
  padding: .9rem 1rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  border-top: 4px solid var(--rule);
}
.figure span { display: block; color: var(--muted); font-size: .9rem; }
.figure strong {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.figure.credit { border-top-color: var(--green); }
.figure.credit strong { color: var(--green-text); }
.figure.debit { border-top-color: var(--red); }
.figure.debit strong { color: var(--red); }
.figure.yellow { border-top-color: var(--yellow); }

/* ---------- Tableaux ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}
.ledger th {
  text-align: left;
  font-weight: 700;
  font-size: .85rem;
  color: var(--blue-deep);
  background: var(--blue-pale);
  padding: .7rem .8rem;
  white-space: nowrap;
}
.ledger td {
  padding: .7rem .8rem;
  border-top: 1px solid var(--rule);
  vertical-align: middle;
}
.ledger tbody tr:hover td { background: #f3f8fc; }
.ledger .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ledger td.empty {
  padding: 1.8rem .8rem;
  color: var(--muted);
  text-align: left;
}
.credit { color: var(--green-text); font-weight: 600; }
.debit { color: var(--red); font-weight: 600; }

/* Soldes des comptes au-dessus du registre */
.accounts {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  margin: 0 0 1.2rem;
}
.accounts div {
  flex: 1 1 180px;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--yellow);
}
.accounts span { display: block; color: var(--muted); font-size: .88rem; }
.accounts strong {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-block;
  font-size: .8rem;
  font-weight: 600;
  padding: .1rem .55rem;
  border-radius: 99px;
  white-space: nowrap;
}
.tag.paid { background: #dcf0d8; color: var(--green-text); }
.tag.unpaid { background: #f9e0da; color: var(--red); }
.tag.off { background: #e6edf3; color: var(--muted); }

/* ---------- Formulaires ---------- */

.form-block {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: .2rem 1.1rem 1.1rem;
  margin: 0 0 1.6rem;
  background: var(--surface);
}
.form-block summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--blue);
  padding: .8rem 0;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .9rem 1rem;
  margin-top: .4rem;
}
.full { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .88rem;
  color: var(--muted);
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  color: var(--ink);
  font-size: .95rem;
}

input, select, textarea, button { font: inherit; }
input, select, textarea {
  padding: .55rem .7rem;
  border: 1px solid #a9bfd0;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
  width: 100%;
}
input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: var(--blue);
}
input[type="search"] { max-width: 260px; }
input[type="number"].year { width: 6.5rem; }
textarea { min-height: 80px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled {
  background: #f0f5f9;
  color: var(--muted);
}

/* ---------- Boutons ---------- */

button, .button {
  display: inline-block;
  font-weight: 700;
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: .6rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
button:hover, .button:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
button.secondary, .button.secondary {
  background: var(--surface);
  color: var(--blue);
  border-color: var(--blue);
}
button.secondary:hover, .button.secondary:hover { background: var(--blue-pale); }
button.danger { background: var(--red); border-color: var(--red); }
button.danger:hover { background: #942f1d; border-color: #942f1d; }
button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--blue);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
button.link:hover { background: none; color: var(--blue-deep); }
button.link.danger-text { color: var(--red); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: flex-end;
  align-items: center;
  margin-top: .3rem;
}

/* ---------- Connexion ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(180deg, var(--blue-pale), var(--paper));
}
.login {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 14px;
  padding: 2rem 1.8rem;
  box-shadow: 0 10px 30px rgba(15, 105, 180, .12);
  text-align: left;
}
.login .logo { display: block; width: min(10rem, 60%); height: auto; margin: 0 auto 1rem; }
.login h1 { font-size: 1.6rem; text-align: center; }
.login .lede { margin: .3rem 0 1.4rem; text-align: center; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack button { width: 100%; padding: .75rem; }
.error { color: var(--red); min-height: 1.3em; margin: 0; font-size: .92rem; font-weight: 600; }

/* ---------- Fenêtre modale ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 79, 138, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 20;
}
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  border-top: 6px solid var(--yellow);
  padding: 1.5rem 1.5rem 1.3rem;
  width: min(680px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .18);
}
.modal-box h2 { margin-top: 0; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li {
  padding: .5rem 0;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}
.plain li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }

/* ---------- Notifications ---------- */

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  padding: .75rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  color: #fff;
  z-index: 30;
  max-width: calc(100% - 2rem);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
}
.toast.ok { background: var(--green); }
.toast.ko { background: var(--red); }

/* ---------- Composants : alertes, onglets, comptes, paramètres ---------- */

.hint { color: var(--muted); font-size: .9rem; margin: .3rem 0 .8rem; }
.empty { color: var(--muted); padding: 1rem 0; }
code {
  font-size: .88rem;
  background: var(--blue-pale);
  padding: .1rem .35rem;
  border-radius: 4px;
}

.alert {
  background: #fff8dc;
  border: 1px solid var(--yellow);
  border-left: 6px solid var(--yellow);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  margin-bottom: 1.4rem;
}
.alert p { margin: .3rem 0; }
.alert a { font-weight: 700; }
.tag.minor { background: var(--yellow); color: var(--ink); margin-left: .4rem; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  border-bottom: 2px solid var(--rule);
  margin: 0 0 1.4rem;
}
.tab {
  background: none;
  color: var(--muted);
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: .6rem .9rem;
  margin-bottom: -2px;
  font-weight: 700;
}
.tab:hover { background: none; color: var(--blue); filter: none; }
.tab.active { color: var(--blue-deep); border-bottom-color: var(--yellow); }

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1rem;
}
.toolbar-row .lede { margin: 0; }
.filters { margin-bottom: 1rem; align-items: flex-end; }

.acct-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.acct {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 5px solid var(--blue);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.acct.archived { border-top-color: var(--rule); opacity: .7; }
.acct header { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.acct h2 { margin: 0; font-size: 1.05rem; }
.acct p { margin: 0; }
.acct-solde {
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--blue-deep);
  font-variant-numeric: tabular-nums;
}
.acct dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .2rem .8rem;
  margin: 0;
  font-size: .9rem;
}
.acct dt { color: var(--muted); }
.acct dd { margin: 0; word-break: break-all; }
.acct button { align-self: flex-start; margin-top: auto; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.inline-form .grow { flex: 1 1 220px; }
.inline-input { padding: .35rem .5rem; }

.panel-plain {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1.4rem;
}
.danger-zone { border-color: var(--red); }

fieldset.group {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin: 0;
  min-width: 0;
}
fieldset.group legend {
  font-family: var(--display);
  font-weight: 700;
  color: var(--blue-deep);
  padding: 0 .4rem;
}

/* ---------- Téléphone ---------- */

@media (max-width: 760px) {
  body:not(.signed-out) .shell { grid-template-columns: 1fr; }

  .side {
    position: sticky;
    top: 0;
    z-index: 6;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: .6rem;
    padding: .6rem 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }
  .brand img { width: 2.2rem; }
  .brand { font-size: 1rem; }
  .brand small { display: none; }

  /* Navigation en barre du bas, à portée de pouce */
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 7;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: .3rem .3rem calc(.3rem + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 3px solid var(--yellow);
    box-shadow: 0 -4px 14px rgba(15, 105, 180, .08);
  }
  .nav a {
    flex: 1 1 0;
    text-align: center;
    font-size: .76rem;
    padding: .5rem .15rem;
    line-height: 1.2;
    border-radius: 6px;
  }
  .nav a.active { box-shadow: none; background: var(--blue); color: #fff; }
  .nav a:hover { background: var(--blue-pale); }
  .nav a.active:hover { background: var(--blue-deep); }

  .userbox {
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
    text-align: right;
    font-size: .78rem;
  }
  .userbox strong { font-size: .85rem; }
  .userbox button { margin-top: .2rem; padding: .3rem .6rem; font-size: .78rem; }

  .content { padding: 1.4rem 1rem 6.8rem; }
  h1 { font-size: 1.55rem; }
  .head { margin-bottom: 1.2rem; }
  .balance strong { font-size: 2.9rem; }
  .figures { grid-template-columns: 1fr 1fr; }

  /* Tableaux transformés en fiches : chaque ligne devient un bloc libellé / valeur */
  .ledger thead { display: none; }
  .ledger,
  .ledger tbody,
  .ledger tr,
  .ledger td { display: block; width: 100%; }
  .ledger tr {
    padding: .8rem .9rem;
    border-top: 1px solid var(--rule);
  }
  .ledger tr:first-child { border-top: 0; }
  .ledger td {
    border: 0;
    padding: .15rem 0;
    text-align: left;
  }
  .ledger td.num { text-align: left; }
  .ledger td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: .76rem;
  }
  .ledger td.empty { padding: 1.2rem .9rem; }
  .ledger td.empty::before { content: none; }
  .ledger tbody tr:hover td { background: none; }

  .controls { width: 100%; }
  .controls > * { flex: 1 1 auto; }
  input[type="search"] { max-width: none; }
  input[type="number"].year { width: 100%; }

  .grid-form { grid-template-columns: 1fr; }
  .actions > button, .actions > .button { flex: 1 1 auto; }

  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    width: 100%;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
    padding: 1.2rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom));
  }

  .toast { bottom: 5.6rem; }
}
