/* Feuille de style du classeur. Publique : la page de connexion s'en sert. Rien de personnel ici. */

:root {
  color-scheme: light dark;
  --bureau: #e8e2d6;
  --couverture: #2f6286;
  --couverture-sombre: #244d69;
  --papier: #fffdf8;
  --encre: #23303b;
  --encre-douce: #5d6873;
  --ligne: #d6e2ee;
  --marge: #e6a1a1;
  --etiquette: #fffdf8;
  --etiquette-texte: #23303b;
  --metal-clair: #f5f7f9;
  --metal: #c5cbd1;
  --metal-ombre: #868e96;
  --champ: #ffffff;
  --bord: #b9c2cb;
  --bouton: #2f6286;
  --focus: #7fb0d6;
  --erreur: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bureau: #15171b;
    --couverture: #2b587a;
    --couverture-sombre: #1f4260;
    --papier: #22262c;
    --encre: #e9e6e0;
    --encre-douce: #aab1b8;
    --ligne: #323d48;
    --marge: #6b3d3d;
    --etiquette: #e7e2d8;
    --metal-clair: #d9dee3;
    --metal: #9aa2aa;
    --metal-ombre: #5b636a;
    --champ: #1a1d22;
    --bord: #4a535c;
    --bouton: #3f7aa6;
    --erreur: #f2b8b5;
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bureau);
  color: var(--encre);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.6;
}

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

/* ------------------------------------------------------------------ connexion : le classeur fermé, vu de face */

.page-connexion {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.couverture {
  display: flex;
  width: 100%;
  max-width: 360px;
  min-height: 480px;
  border-radius: 6px 16px 16px 6px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 7px),
    var(--couverture);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 3px 8px rgba(0, 0, 0, 0.18),
    0 18px 40px rgba(0, 0, 0, 0.22);
}

/* La charnière, à gauche, avec ses deux rivets */
.couverture-dos {
  flex: 0 0 32px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 56px 0;
  border-right: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px 0 0 6px;
  background: linear-gradient(90deg, var(--couverture-sombre), var(--couverture));
}

.rivet {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--metal-clair), var(--metal) 45%, var(--metal-ombre));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.couverture-face {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 40px 22px 26px 18px;
}

/* Le porte-étiquette, où l'on écrit le nom du classeur */
.etiquette {
  align-self: center;
  width: 100%;
  max-width: 240px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255, 255, 255, 0.12);
}

.etiquette h1 {
  margin: 0;
  padding: 18px 12px 16px;
  border-radius: 4px;
  background: var(--etiquette);
  color: var(--etiquette-texte);
  text-align: center;
  font: 600 30px/1.1 Georgia, "Times New Roman", serif;
  letter-spacing: 0.02em;
}

.connexion {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px 14px;
  border-radius: 10px;
  background: var(--papier);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.connexion label {
  font-weight: 600;
}

.connexion input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--champ);
  font-size: 17px; /* 16 px au moins : sinon l'iPhone agrandit la page en touchant le champ */
}

.connexion button {
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--bouton);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}

.connexion-erreur {
  min-height: 1.5em;
  margin: 0;
  color: var(--erreur);
  font-weight: 600;
}

/* ------------------------------------------------------------------ le classeur ouvert */

.entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--couverture);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.entete h1 {
  margin: 0;
  font: 600 22px/1.2 Georgia, "Times New Roman", serif;
}

.bouton-fermer {
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

/* Le mécanisme à gauche, la feuille au milieu, les onglets qui dépassent à droite (en haut sur le téléphone) */
.classeur {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  grid-template-areas: "mecanisme feuille onglets";
  align-items: start;
  max-width: 980px;
  margin: 20px auto 24px;
  padding: 0 16px;
}

/* Le mécanisme à anneaux, à gauche de la feuille */
.mecanisme {
  grid-area: mecanisme;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-end;
  padding: 40px 0;
  border-radius: 10px 0 0 10px;
  background: var(--couverture-sombre);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.anneau {
  position: relative;
  z-index: 1;
  width: 40px;
  height: 14px;
  margin-right: -20px; /* l'anneau passe dans le trou de la feuille */
  border-radius: 7px;
  background: linear-gradient(180deg, var(--metal-clair), var(--metal) 55%, var(--metal-ombre));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

/* La feuille : lignes tous les 32 px et marge rouge, le texte posé sur les lignes */
.feuille {
  grid-area: feuille;
  min-width: 0;
  min-height: 65vh;
  padding: 32px 20px 32px 52px;
  border-radius: 0 10px 10px 0;
  background:
    linear-gradient(90deg, transparent 38px, var(--marge) 38px, var(--marge) 40px, transparent 40px),
    repeating-linear-gradient(180deg, transparent 0 31px, var(--ligne) 31px 32px),
    var(--papier);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  line-height: 32px;
}

.feuille h2 {
  margin: 0;
  font: 600 22px/32px Georgia, "Times New Roman", serif;
}

.feuille p {
  margin: 0;
  color: var(--encre-douce);
}

/* ------------------------------------------------------------------ les onglets */

.onglets {
  grid-area: onglets;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 28px;
}

.onglet {
  flex: 0 0 auto;
  max-width: 160px;
  padding: 8px 14px 8px 10px;
  border-radius: 0 10px 10px 0;
  background: var(--onglet, var(--metal));
  color: #22303c;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  opacity: 0.8;
}

.onglet.actif {
  padding-right: 22px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
  opacity: 1;
}

.onglet-plus {
  border: 2px dashed var(--bord);
  background: transparent;
  color: var(--encre-douce);
  text-align: center;
  font-size: 20px;
  line-height: 1;
  box-shadow: none;
  opacity: 1;
}

/* Les 8 couleurs des onglets, dans l'ordre de COULEURS (server/classeur.py et classeur.js) */
.couleur-rouge { --onglet: #f28b82; }
.couleur-orange { --onglet: #fbbc6b; }
.couleur-jaune { --onglet: #fde68a; }
.couleur-vert { --onglet: #a7dca5; }
.couleur-bleu { --onglet: #9cc7f0; }
.couleur-violet { --onglet: #c8b3f0; }
.couleur-rose { --onglet: #f6b3d1; }
.couleur-gris { --onglet: #cfd5db; }

/* L'intercalaire : une bande de la couleur de l'onglet, en haut de la feuille, posée sur les lignes */
.intercalaire {
  margin: -32px -20px 32px -52px;
  padding: 16px 20px 16px 52px;
  border-radius: 0 10px 0 0;
  background: var(--onglet);
  color: #22303c;
}

.intercalaire h2 {
  margin: 0;
  font: 600 24px/32px Georgia, "Times New Roman", serif;
  overflow-wrap: anywhere;
}

.intercalaire-mince {
  padding-top: 0;
  padding-bottom: 0;
}

.retour-onglet {
  color: #22303c;
  font-weight: 600;
  text-decoration: none;
}

.retour-onglet::before {
  content: "← ";
}

/* ------------------------------------------------------------------ les pages */

.liste-pages {
  margin: 0 0 32px;
  padding: 0;
  list-style: none;
}

.liste-pages a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--encre);
  text-decoration: none;
}

.liste-pages .titre {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.liste-pages a:hover .titre,
.liste-pages a:focus-visible .titre {
  text-decoration: underline;
}

.liste-pages .date {
  flex: 0 0 auto;
  color: var(--encre-douce);
  font-size: 13px;
}

.feuille .feuille-vide {
  color: var(--encre-douce);
  font-style: italic;
}

.feuille .date-page {
  color: var(--encre-douce);
  font-size: 14px;
}

.page-texte {
  margin: 0 0 32px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.feuille h2 {
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ formulaires et boutons */

.formulaire label,
.feuille .legende {
  display: block;
  margin: 0;
  color: var(--encre);
  font-weight: 600;
}

.formulaire input[type="text"],
.formulaire select,
.formulaire textarea {
  display: block;
  width: 100%;
  margin: 0 0 16px;
  padding: 8px 10px;
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--champ);
  color: var(--encre);
  font-size: 17px; /* 16 px au moins : sinon l'iPhone agrandit la page en touchant le champ */
  line-height: 1.5;
}

.formulaire textarea {
  min-height: 45vh;
  resize: vertical;
}

.nuancier {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 16px;
}

.pastille {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
  background: var(--onglet);
}

.pastille[aria-pressed="true"] {
  outline: 3px solid var(--encre);
  outline-offset: 2px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
  line-height: 1.4;
}

.reglages {
  padding-top: 16px;
  border-top: 1px dashed var(--bord);
}

.bouton {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--bord);
  border-radius: 8px;
  background: var(--champ);
  color: var(--encre);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
}

.bouton-principal {
  border-color: var(--bouton);
  background: var(--bouton);
  color: #fff;
}

.bouton-danger {
  border-color: var(--erreur);
  background: transparent;
  color: var(--erreur);
}

.feuille .message {
  margin: 0 0 16px;
  color: var(--erreur);
  font-weight: 600;
}

/* ------------------------------------------------------------------ les comptes d'un mois
   (noms de styles neutres : ce fichier se voit sans mot de passe) */

.feuille h3 {
  margin: 32px 0 0;
  font: 600 18px/32px Georgia, "Times New Roman", serif;
}

.comptes {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
}

.comptes th,
.comptes td {
  padding: 0;
  font-weight: normal;
  line-height: 32px;
  text-align: left;
  vertical-align: top;
}

.comptes td:first-child,
.comptes th {
  padding-right: 12px;
  overflow-wrap: anywhere;
}

.somme,
.comptes td.somme {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* 2 px de trait + 30 px : la ligne garde la hauteur des lignes du papier */
.comptes .total th,
.comptes .total td {
  border-top: 2px solid var(--encre-douce);
  font-weight: 600;
  line-height: 30px;
}

.feuille .reste {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 32px 0;
  padding: 0 14px;
  border: 2px solid var(--encre);
  border-radius: 8px;
  color: var(--encre);
  font-weight: 600;
  line-height: 60px;
}

.reste strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.feuille .reste.negatif {
  border-color: var(--erreur);
  color: var(--erreur);
}

.feuille .aide {
  margin: 0 0 16px;
  font-size: 14px;
}

/* L'année prend juste sa largeur, le mois tout le reste (« septembre » tient sur un téléphone) */
.choix-mois {
  display: flex;
  gap: 8px;
}

.formulaire .choix-mois select {
  width: auto;
}

.formulaire .choix-mois select:first-child {
  flex: 1 1 0;
  min-width: 0;
}

.ligne-saisie {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6.5em 40px;
  gap: 6px;
  margin: 0 0 8px;
}

.formulaire .ligne-saisie input[type="text"] {
  margin: 0;
}

.formulaire .ligne-saisie .somme {
  padding-right: 8px;
  padding-left: 8px;
}

.formulaire .ligne-saisie .invalide {
  border-color: var(--erreur);
  outline: 2px solid var(--erreur);
  outline-offset: 0;
}

.bouton-retirer {
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.feuille .total-saisie {
  margin: 0;
  color: var(--encre);
  font-weight: 600;
  text-align: right;
}

/* ------------------------------------------------------------------ téléphone : les onglets passent en haut */

@media (max-width: 699px) {
  .classeur {
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas:
      "onglets onglets"
      "mecanisme feuille";
  }

  .onglets {
    flex-direction: row;
    gap: 4px;
    padding: 0 0 0 44px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .onglet {
    max-width: 150px;
    padding: 8px 12px;
    border-radius: 10px 10px 0 0;
  }

  .onglet.actif {
    padding-right: 12px;
  }

  /* En premier : au bout de la rangée, il serait caché dès qu'il y a quelques onglets */
  .onglet-plus {
    order: -1;
  }

  /* Sur deux rangs, sinon l'intitulé serait coupé : l'intitulé sur toute la largeur, puis le montant et ✕ */
  .ligne-saisie {
    grid-template-columns: minmax(0, 1fr) 7em 40px;
    grid-template-areas:
      "intitule intitule intitule"
      ". somme retirer";
    gap: 4px;
    margin-bottom: 14px;
  }

  .ligne-saisie .intitule {
    grid-area: intitule;
  }

  .ligne-saisie .somme {
    grid-area: somme;
  }

  .ligne-saisie .bouton-retirer {
    grid-area: retirer;
  }
}
