/* NicoNote - styles de l'application (base : design/ecran-reference/styles.css).
   Toute couleur passe par les noms de DESIGN.md (section 2). */

/* ---------- Couleurs de l'interface, thème clair ---------- */
:root {
  --accent: #1B1C20;
  --accent-texte: #FFFFFF;
  --fond: #F6F6F4;
  --surface: #FFFFFF;
  --surface-2: #EEEEEB;
  --bordure: #E2E2DE;
  --texte: #1B1C20;
  --texte-secondaire: #55585F;
  --focus: #2F6FEB;
  --danger: #B42318;
  --succes: #067647;
  /* Voile derrière les fenêtres : noir à 40 %, dans les deux thèmes (DESIGN.md § 5) */
  --voile: rgb(0 0 0 / 40%);

  /* Palette des dossiers et des tags (16 couleurs, dans l'ordre d'attribution) */
  --carte-bleu: #D1E2FA;     --pastille-bleu: #A0C0EE;
  --carte-vert: #D7F4E1;     --pastille-vert: #AEE0BE;
  --carte-ambre: #FEECCD;    --pastille-ambre: #F7D497;
  --carte-rose: #FAD1E2;     --pastille-rose: #EEA0C0;
  --carte-violet: #E3D5F6;   --pastille-violet: #C2A8E6;
  --carte-sarcelle: #D6F5F5; --pastille-sarcelle: #ABE3E3;
  --carte-orange: #FEDFCD;   --pastille-orange: #F7BA97;
  --carte-indigo: #D5D8F6;   --pastille-indigo: #A8ADE6;
  --carte-citron: #F4F7D4;   --pastille-citron: #E3E9A5;
  --carte-rouge: #FAD2D1;    --pastille-rouge: #EEA2A0;
  --carte-ciel: #D0EEFB;     --pastille-ciel: #9DD8F1;
  --carte-mauve: #F0D9F2;    --pastille-mauve: #DAB0DD;
  --carte-emeraude: #D6F5EA; --pastille-emeraude: #ABE3CE;
  --carte-jaune: #FFF6CC;    --pastille-jaune: #F9E994;
  --carte-brun: #F0E4DB;     --pastille-brun: #D8C4B6;
  --carte-ardoise: #DFE6EC;  --pastille-ardoise: #BEC7CF;

  --rayon: 12px;
  --rayon-petit: 8px;
  --espace: 8px;

  color-scheme: light dark;
}

/* ---------- Thème sombre (PRD § 21) ----------
   `data-theme` est posé par js/theme-init.js avant l'affichage : « dark » quand le thème
   choisi est sombre, ou quand c'est celui de l'appareil et que l'appareil est en sombre */
:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #ECEDF0;
  --accent-texte: #16181D;
  --fond: #16181D;
  --surface: #1F2228;
  --surface-2: #2A2E35;
  --bordure: #30343C;
  --texte: #ECEDF0;
  --texte-secondaire: #B0B4BC;
  --focus: #7AA7FF;
  --danger: #F97066;
  --succes: #47CD89;

  --carte-bleu: #233043;     --pastille-bleu: #324867;
  --carte-vert: #293D30;     --pastille-vert: #3B5E47;
  --carte-ambre: #463820;    --pastille-ambre: #6D552C;
  --carte-rose: #432330;     --pastille-rose: #673248;
  --carte-violet: #312640;   --pastille-violet: #493762;
  --carte-sarcelle: #273F3F; --pastille-sarcelle: #396060;
  --carte-orange: #462E20;   --pastille-orange: #6D442C;
  --carte-indigo: #262840;   --pastille-indigo: #373B62;
  --carte-citron: #3E4125;   --pastille-citron: #606336;
  --carte-rouge: #432423;    --pastille-rouge: #673432;
  --carte-ciel: #223A44;     --pastille-ciel: #2F586A;
  --carte-mauve: #3B2A3C;    --pastille-mauve: #593D5C;
  --carte-emeraude: #273F36; --pastille-emeraude: #396052;
  --carte-jaune: #48411E;    --pastille-jaune: #6F632A;
  --carte-brun: #3A322C;     --pastille-brun: #584B41;
  --carte-ardoise: #2F3337;  --pastille-ardoise: #464D53;
}
:root[data-theme="light"] { color-scheme: light; }

/* Une classe par couleur : la carte et la pastille lisent leurs deux teintes ici */
.c-bleu { --carte: var(--carte-bleu); --pastille: var(--pastille-bleu); }
.c-vert { --carte: var(--carte-vert); --pastille: var(--pastille-vert); }
.c-ambre { --carte: var(--carte-ambre); --pastille: var(--pastille-ambre); }
.c-rose { --carte: var(--carte-rose); --pastille: var(--pastille-rose); }
.c-violet { --carte: var(--carte-violet); --pastille: var(--pastille-violet); }
.c-sarcelle { --carte: var(--carte-sarcelle); --pastille: var(--pastille-sarcelle); }
.c-orange { --carte: var(--carte-orange); --pastille: var(--pastille-orange); }
.c-indigo { --carte: var(--carte-indigo); --pastille: var(--pastille-indigo); }
.c-citron { --carte: var(--carte-citron); --pastille: var(--pastille-citron); }
.c-rouge { --carte: var(--carte-rouge); --pastille: var(--pastille-rouge); }
.c-ciel { --carte: var(--carte-ciel); --pastille: var(--pastille-ciel); }
.c-mauve { --carte: var(--carte-mauve); --pastille: var(--pastille-mauve); }
.c-emeraude { --carte: var(--carte-emeraude); --pastille: var(--pastille-emeraude); }
.c-jaune { --carte: var(--carte-jaune); --pastille: var(--pastille-jaune); }
.c-brun { --carte: var(--carte-brun); --pastille: var(--pastille-brun); }
.c-ardoise { --carte: var(--carte-ardoise); --pastille: var(--pastille-ardoise); }

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

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

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

.sprite { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.icon {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}
.icon-sm { width: 18px; height: 18px; }

/* Focus clavier toujours visible */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Mise en page ---------- */
.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 calc(var(--espace) * 2) calc(var(--espace) * 4);
}

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: var(--espace);
  height: 56px;
  margin: 0 calc(var(--espace) * -2);
  padding: 0 var(--espace);
  background: var(--fond);
}

.brand {
  flex: 1;
  margin: 0;
}
/* Logo de la barre (DESIGN.md § 9) : 34 px de haut, la version du thème en cours seulement */
.brand { display: flex; align-items: center; min-width: 0; }
.brand-logo { display: block; height: 34px; width: auto; }
:root[data-theme="dark"] .brand-logo-light,
:root:not([data-theme="dark"]) .brand-logo-dark { display: none; }

/* ---------- Recherche (PRD § 10 ; DESIGN.md § 5, « Barre du haut ») ----------
   Champ ouvert : il prend la place du nom et des icônes du thème et de la loupe */
.topbar.is-searching .brand,
.topbar.is-searching #theme-btn,
.topbar.is-searching #search-btn { display: none; }

.search-box {
  flex: 1;
  display: flex; align-items: center; gap: 4px;
  min-width: 0;
}
.search-box[hidden] { display: none; }

.search-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 16px;
}
.search-input::placeholder { color: var(--texte-secondaire); }
.search-input:focus { border-color: var(--texte-secondaire); outline: none; }
.search-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Croix propre au navigateur masquée : la croix de l'appli suffit */
.search-input::-webkit-search-cancel-button { appearance: none; }

/* ---------- Boutons ---------- */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: 0; border-radius: var(--rayon);
  background: transparent;
  color: var(--texte);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--rayon);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-texte); }
.btn-primary:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Champ « Nouvelle note... » ---------- */
.composer {
  margin-top: var(--espace);
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}
.composer:focus-within { border-color: var(--texte-secondaire); }

.composer-input {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 40vh;
  padding: 12px;
  border: 0;
  background: transparent;
  font-size: 16px;
  resize: none;
  field-sizing: content;
}
.composer-input::placeholder { color: var(--texte-secondaire); }
.composer-input:focus { outline: none; }

.composer-options {
  display: none;
  align-items: flex-end; gap: var(--espace);
  padding: 4px 8px 8px;
}
.composer:focus-within .composer-options,
.composer.is-active .composer-options { display: flex; }

.select-wrap {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; min-width: 0;
}
.select-label { font-size: 12px; color: var(--texte-secondaire); padding-left: 2px; }

select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon-petit);
  background: var(--surface);
}

/* ---------- Ligne d'actions ---------- */
.actions {
  display: flex; align-items: center; gap: var(--espace);
  margin: calc(var(--espace) * 2) 0 calc(var(--espace) * 1.5);
}
.actions-spacer { flex: 1; }
.btn-clean { padding: 0 12px; }
/* Les icônes gardent toujours 44 px : quand la place manque (tag au nom long), c'est la liste
   des tags qui rétrécit (DESIGN.md § 7) */
.actions > .icon-btn { flex: none; }
/* Sous 420 px, l'étincelle de « Nettoyer » est masquée : sinon les icônes tri et grille
   rétrécissent sous 44 px (DESIGN.md § 7) */
@media (max-width: 420px) {
  .btn-clean .icon { display: none; }
}
/* Pendant un traitement, quand « Traitement en cours... » ne tient pas sur la ligne avec la
   liste des tags et les icônes de 44 px : « En cours... » à l'écran. Le libellé long reste dans
   le bouton, masqué à l'œil seulement (mêmes réglages que .visually-hidden, qu'on ne peut pas
   poser ici sans JavaScript), et donne son nom au bouton (DESIGN.md § 5) */
@media (max-width: 460px) {
  .btn-clean.is-running #clean-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
  }
  .btn-clean.is-running::after { content: "En cours..." / ""; }
}

/* Menu de tri (PRD § 9) : panneau `surface` à bord fin, sous l'icône, aligné à droite
   pour ne jamais dépasser de l'écran ; le tri en cours porte une coche */
.sort-wrap { position: relative; flex: none; }
.sort-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  z-index: 20;
  display: flex; flex-direction: column;
  min-width: 220px;
  padding: 4px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
}
.sort-menu[hidden] { display: none; }
.sort-item {
  display: flex; align-items: center; gap: var(--espace);
  min-height: 44px;
  padding: 0 12px 0 8px;
  border: 0; border-radius: var(--rayon-petit);
  background: transparent;
  color: var(--texte);
  font: inherit; font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.sort-item:hover { background: var(--surface-2); }
.sort-check { visibility: hidden; }
.sort-item[aria-checked="true"] { font-weight: 600; }
.sort-item[aria-checked="true"] .sort-check { visibility: visible; }
/* Flèche du sens du tri, à droite du tri en cours : vers le bas, ou vers le haut inversé (PRD 9.q) */
.sort-dir { display: inline-flex; margin-left: auto; padding-left: var(--espace); color: var(--texte-secondaire); }
.sort-dir[data-dir="inversé"] .icon { transform: rotate(180deg); }

.select-chip { min-width: 0; flex: 0 1 auto; }
.select-chip select {
  width: auto;
  max-width: 100%;
  height: 40px;
  padding: 0 6px 0 10px;
  border-radius: var(--rayon);
  background: var(--surface);
  font-size: 14px;
}

/* ---------- Cartes ---------- */
.notes {
  display: flex; flex-direction: column;
  gap: calc(var(--espace) * 1.25);
}
.notes.is-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}
@media (min-width: 640px) {
  .notes.is-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.card {
  position: relative;
  padding: 14px 16px;
  background: var(--carte, var(--surface));
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  cursor: pointer;
}
.card[class*="c-"] { border-color: transparent; }
.card:hover { border-color: var(--texte-secondaire); }

.card-title {
  margin: 0 36px 4px 0;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
}

.card-text {
  margin: 0;
  padding-right: 0;
  overflow-wrap: anywhere;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}
.card.is-pending .card-text { padding-right: 36px; }
.card-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.card-bullets { margin: 0; padding-left: 20px; }

.card-copy {
  position: absolute; top: 4px; right: 4px;
  width: 40px; height: 40px;
  color: var(--texte-secondaire);
}
.card-copy:hover { background: transparent; color: var(--texte); }

.card-footer {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--espace);
  margin-top: 10px;
}
.card-date { font-size: 13px; color: var(--texte-secondaire); margin-left: auto; }

/* Pastille de tag : fond rempli de la couleur du tag */
.tag-pill {
  display: inline-flex; align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--pastille);
  color: var(--texte);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}

/* Badge « en attente de nettoyage » : neutre, en pointillés */
.badge-pending {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px;
  padding: 0 10px;
  border: 1px dashed var(--texte-secondaire);
  border-radius: 999px;
  color: var(--texte-secondaire);
  font-size: 13px;
  font-weight: 550;
}

/* En grille : cartes plus compactes */
.notes.is-grid .card { padding: 12px; }
.notes.is-grid .card-text { -webkit-line-clamp: 6; line-clamp: 6; }
.notes.is-grid .card-date { margin-left: 0; }
.notes.is-grid .badge-pending {
  height: auto;
  padding: 2px 8px;
  border-radius: var(--rayon-petit);
  line-height: 1.3;
}

/* ---------- Sélection de plusieurs notes (PRD § 12 ; DESIGN.md § 7) ----------
   Barre à la place de la barre du haut ; carte sélectionnée : contour 2 px accent et coche */
.selection-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 4px;
  height: 56px;
  margin: 0 calc(var(--espace) * -2);
  padding: 0 var(--espace);
  background: var(--fond);
}
.selection-bar[hidden] { display: none; }
.app.is-selecting .topbar { display: none; }
.selection-count {
  flex: 1; min-width: 0;
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card.is-selected,
.card.is-selected:hover { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -1px; }
.card { -webkit-touch-callout: none; }
.app.is-selecting .card { user-select: none; }

/* Case en haut à gauche : au survol sur PC, et toujours visible pendant la sélection */
.card-check {
  position: absolute; top: -8px; left: -8px; z-index: 1;
  width: 22px; height: 22px;
  margin: 0;
  appearance: none;
  border: 2px solid var(--texte-secondaire);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  visibility: hidden;
}
.card-check:checked {
  border-color: var(--accent);
  background: var(--accent);
}
.card-check:checked::after {
  content: "";
  position: absolute; left: 6px; top: 2px;
  width: 5px; height: 10px;
  border: solid var(--accent-texte);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.app.is-selecting .card-check { visibility: visible; }
@media (hover: hover) and (pointer: fine) {
  .card:hover .card-check,
  .card-check:focus-visible { visibility: visible; }
}

/* ---------- Petits écrans ---------- */
@media (max-width: 380px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .topbar,
  .selection-bar { margin: 0 -12px; padding: 0 4px; }
  .actions { gap: 4px; }
  .btn-clean { padding: 0 12px; }
  /* Champ actif : les deux choix sur une ligne, « Ajouter » en dessous, large pour le pouce */
  .composer-options { flex-wrap: wrap; }
  .composer-options .btn-primary { flex: 1 0 100%; min-height: 44px; }
}

/* ---------- État de chargement (DESIGN.md § 6) ---------- */
.card-skeleton {
  height: 96px;
  border-radius: var(--rayon);
  background: var(--surface-2);
}
.notes.is-grid .card-skeleton { height: 140px; }

/* ---------- Édition d'une note (PRD § 11 ; DESIGN.md § 5, « Édition ») ----------
   Plein écran : la barre du haut et la liste sont masquées pendant l'édition */
.app.is-editing .topbar,
.app.is-editing .home { display: none; }
.editor:focus { outline: none; }
/* Annuler la frappe et Rétablir : grisés quand il n'y a rien à faire (DESIGN.md § 6) */
.editor-bar .icon-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }

.editor-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: var(--espace);
  height: 56px;
  margin: 0 calc(var(--espace) * -2);
  padding: 0 calc(var(--espace) * 2);
  background: var(--fond);
}

.editor-body {
  display: flex; flex-direction: column; gap: calc(var(--espace) * 1.5);
  margin-top: var(--espace);
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}
.editor-body:focus-within { border-color: var(--texte-secondaire); }

.editor-title,
.editor-text {
  display: block;
  width: 100%;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--texte);
  font: inherit;
}
.editor-title { font-size: 20px; font-weight: 650; }
.editor-text {
  min-height: 40vh;
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  field-sizing: content;
}
.editor-title::placeholder,
.editor-text::placeholder { color: var(--texte-secondaire); }
.editor-title:focus,
.editor-text:focus { outline: none; }
.editor-title:focus-visible,
.editor-text:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: var(--rayon); }

.editor-options {
  display: flex; gap: var(--espace);
  padding: 0 8px 8px;
}
/* Actions sur la note : rangée sous le bloc, qui passe à la ligne plutôt que de déborder */
.editor-actions {
  display: flex; flex-wrap: wrap; gap: var(--espace);
  margin-top: calc(var(--espace) * 2);
}
.editor-actions .btn { padding: 0 12px; }
.editor-actions .btn[hidden] { display: none; }

/* Sous 380 px, les marges de la page passent à 12 px (DESIGN.md § 7) */
@media (max-width: 380px) {
  .editor-bar { margin: 0 -12px; padding: 0 12px; }
  .editor-actions .btn { padding: 0 9px; }
}

/* ---------- Filtres actifs (PRD § 10 ; DESIGN.md § 5, « Filtres actifs ») ----------
   Au-dessus de la liste : une puce par filtre, nom puis croix ; un tap la retire.
   Dossier : rond de sa couleur à gauche (comme le menu) ; tag : fond de sa pastille (comme les cartes) */
.active-filters {
  display: flex; flex-wrap: wrap; gap: var(--espace);
  margin-bottom: calc(var(--espace) * 1.25);
}
.active-filters[hidden] { display: none; }

.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  min-height: 40px;
  padding: 0 10px 0 14px;
  border: 1px solid var(--bordure);
  border-radius: 999px;
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.filter-chip:hover { background: var(--surface-2); }
.filter-chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-chip .icon { color: var(--texte-secondaire); }
.filter-chip-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--pastille); }
.filter-chip.is-tag { border-color: transparent; background: var(--pastille); }
.filter-chip.is-tag:hover { background: var(--pastille); opacity: 0.88; }
.filter-chip.is-tag .icon { color: var(--texte); }

/* ---------- Liste vide (DESIGN.md § 6) : texte centré à la place des cartes ---------- */
.notes-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: calc(var(--espace) * 5) var(--espace);
  text-align: center;
  color: var(--texte-secondaire);
}

/* ---------- Moins d'animations si l'appareil le demande (DESIGN.md § 6) ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Un élément masqué reste masqué, quelle que soit sa mise en page */
[hidden] { display: none !important; }

/* ---------- Écran de connexion (PRD § 6 ; DESIGN.md § 5, « Champs de saisie ») ---------- */
.login {
  display: flex; flex-direction: column;
  max-width: 400px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 12vh calc(var(--espace) * 2) calc(var(--espace) * 4);
}

.login-brand {
  margin: 0 0 calc(var(--espace) * 3);
}
/* Logo de l'écran de connexion : 44 px de haut, centré (DESIGN.md § 9) */
.login-brand { display: flex; justify-content: center; }
.login-brand .brand-logo { height: 44px; }

.login-form {
  display: flex; flex-direction: column;
  gap: calc(var(--espace) * 2);
}
.login-form .field-error { margin-top: -8px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--texte-secondaire); padding-left: 2px; }

.field-input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 16px;
}
.field-input:focus { border-color: var(--texte-secondaire); outline: none; }
.field-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.field-input.is-error { border-color: var(--danger); }

/* Message d'erreur sous un champ : un petit espace le sépare du contour du champ actif.
   Sur l'écran de connexion, l'espace de 16 px entre les éléments est réduit pour le
   rapprocher des champs */
.field-error {
  margin: 8px 0 0;
  padding-left: 2px;
  font-size: 13px;
  color: var(--danger);
}

.btn-block { width: 100%; min-height: 44px; }

@media (max-width: 380px) {
  .login { padding-left: 12px; padding-right: 12px; }
}

/* ---------- Boutons secondaire et danger (DESIGN.md § 5) ---------- */
.btn-secondary { background: var(--surface); color: var(--texte); border-color: var(--bordure); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: var(--accent-texte); }
.btn-danger:hover { opacity: 0.88; }

/* ---------- Bandeau « Pas de connexion » (DESIGN.md § 5) ---------- */
.offline-banner {
  position: sticky; top: 56px; z-index: 2;
  margin: 0 calc(var(--espace) * -2);
  padding: 8px calc(var(--espace) * 2);
  background: var(--danger);
  color: var(--accent-texte);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* ---------- Messages de 5 secondes (DESIGN.md § 5) ---------- */
.toast-zone {
  position: fixed; left: 0; right: 0; z-index: 10;
  bottom: calc(var(--espace) * 2 + env(safe-area-inset-bottom, 0px));
  display: flex; justify-content: center;
  padding: 0 calc(var(--espace) * 2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--espace);
  max-width: 560px;
  min-width: 0;
  padding: 12px 16px;
  border-radius: var(--rayon);
  background: var(--accent);
  color: var(--accent-texte);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.35;
  overflow-wrap: anywhere;
  pointer-events: auto;
}
.toast-icon { display: none; margin-top: 0; color: var(--danger); }
.toast.is-error .toast-icon { display: block; }

/* ---------- Fenêtres (DESIGN.md § 5) ---------- */
.modal {
  width: min(400px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
}
.modal::backdrop { background: var(--voile); }
.modal-body { padding: 20px; }
.modal-title { margin: 0 0 8px; font-size: 18px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.modal-message { margin: 0; color: var(--texte-secondaire); overflow-wrap: anywhere; }
.modal-actions {
  display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--espace);
  margin-top: 20px;
}

/* ---------- Écran « Gérer les dossiers » (PRD § 13 ; DESIGN.md § 5) ----------
   Plein écran comme l'édition : la barre du haut et la liste sont masquées */
.app.is-managing .topbar,
.app.is-managing .selection-bar,
.app.is-managing .home { display: none; }
.manage:focus { outline: none; }
.manage-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: var(--espace);
  height: 56px;
  margin: 0 calc(var(--espace) * -2);
  padding: 0 var(--espace);
  background: var(--fond);
}
.manage-title {
  flex: 1; min-width: 0;
  margin: 0;
  font-size: 20px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.manage-bar .btn { flex: none; gap: 6px; }
/* Petit écran : « Nouveau dossier » devient un bouton rond « + » pour que le titre tienne en entier */
@media (max-width: 420px) {
  .manage-new { width: 40px; padding: 0; justify-content: center; border-radius: 50%; }
  .manage-new-label { display: none; }
}
.manage-list {
  margin: 8px 0 0; padding: 0;
  list-style: none;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
  overflow: hidden;
}
.manage-list li + li { border-top: 1px solid var(--bordure); }
.manage-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px;
  padding: 0 16px;
  border: 0;
  background: transparent; color: var(--texte);
  font: inherit; font-size: 15px; text-align: left;
  cursor: pointer;
}
.manage-row:hover { background: var(--surface-2); }
.manage-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.manage-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--pastille); }
.manage-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.manage-count { flex: none; color: var(--texte-secondaire); font-size: 13px; }
/* Tags : le nom dans sa pastille, comme sur les cartes, coupé par « ... » s'il est trop long */
.manage-pill { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.manage-spacer { flex: 1; }

/* ---------- Corbeille (PRD § 16 ; DESIGN.md § 5) ----------
   Une carte neutre par note : titre ou début du texte, date de suppression, deux actions */
.trash-list {
  display: flex; flex-direction: column; gap: calc(var(--espace) * 1.25);
  margin: 8px 0 0; padding: 0;
  list-style: none;
}
.trash-row {
  padding: 12px 16px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
}
.trash-label {
  margin: 0;
  font-size: 16px; font-weight: 650; line-height: 1.3;
  overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.trash-label.is-text { font-size: 15px; font-weight: 400; line-height: 1.45; }
.trash-date { margin: 4px 0 0; font-size: 13px; color: var(--texte-secondaire); }
.trash-actions { display: flex; flex-wrap: wrap; gap: var(--espace); margin-top: 12px; }
.trash-list .notes-empty { list-style: none; }
.manage-bar .btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Sauvegarde (PRD § 19 ; DESIGN.md § 5) ----------
   Une carte neutre par action, comme les cartes de la corbeille */
.backup-list { display: flex; flex-direction: column; gap: calc(var(--espace) * 1.25); margin-top: 8px; }
.backup-row {
  padding: 12px 16px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
}
.backup-row[hidden] { display: none; }
.backup-row .btn { max-width: 100%; white-space: normal; text-align: center; }
.backup-row a.btn { text-decoration: none; }
.backup-label { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.3; }
.backup-date { margin: 4px 0 0; font-size: 13px; color: var(--texte-secondaire); }
.backup-actions { margin-top: 12px; }
/* Le vrai champ de fichier reste caché : le bouton « Restaurer depuis un fichier » l'ouvre */
.backup-file { display: none; }

/* Fenêtre « Modifier le dossier » : 16 ronds de couleur sur deux rangées de 8 */
.color-field { margin: 16px 0 0; padding: 0; border: 0; min-width: 0; }
.color-grid {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}
.color-choice { position: relative; display: flex; justify-content: center; cursor: pointer; }
.color-choice input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.color-swatch {
  width: 32px; height: 32px; max-width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pastille);
  border: 2px solid transparent;
}
.color-choice input:checked + .color-swatch { border-color: var(--surface); outline: 2px solid var(--accent); }
/* « Supprimer » en bas à gauche de la fenêtre, loin d'« Enregistrer » */
.modal-action-start { margin-right: auto; }
/* Question à trois réponses : les boutons passent les uns sous les autres plutôt que de déborder */
.choice-answers { display: contents; }
@media (max-width: 420px) {
  .modal-actions-stack { flex-direction: column-reverse; align-items: stretch; }
}
.color-choice input:focus-visible + .color-swatch { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (max-width: 380px) {
  .manage-bar { margin: 0 -12px; padding: 0 4px; }
  .offline-banner { margin: 0 -12px; }
  .toast-zone { padding: 0 12px; }
}

/* ---------- Menu latéral (PRD § 7 ; DESIGN.md § 5, « Menu latéral ») ---------- */
/* Panneau `surface` collé à gauche, 300 px au plus, sur toute la hauteur, voile derrière */
.side-menu {
  position: fixed; inset: 0 auto 0 0;
  width: min(300px, calc(100vw - 48px));
  max-width: none;
  height: 100%; max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--texte);
}
.side-menu::backdrop { background: var(--voile); }
.side-menu[open] { animation: menu-in 150ms ease-out; }
@keyframes menu-in { from { transform: translateX(-100%); } to { transform: none; } }
.side-menu-body {
  display: flex; flex-direction: column;
  min-height: 100%;
  padding: 12px 8px 16px;
  overflow-wrap: anywhere;
}
.side-menu-brand { margin: 0 0 8px; padding: 10px 12px; font-size: 20px; font-weight: 650; }
.menu-list { margin: 0; padding: 0; list-style: none; }
.menu-section { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--bordure); }
.menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 44px;
  padding: 0 12px;
  border: 0; border-radius: var(--rayon-petit);
  background: transparent;
  color: var(--texte);
  font: inherit; font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover:not(:disabled) { background: var(--surface-2); }
.menu-item[aria-current="page"] { font-weight: 600; background: var(--surface-2); }
/* Entrée pas encore disponible : grisée (DESIGN.md § 6, « Désactivé ») */
.menu-item:disabled { opacity: 0.4; cursor: default; }
.menu-label { flex: 1; min-width: 0; }
.menu-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--pastille); }
.menu-count { flex: none; color: var(--texte-secondaire); font-size: 13px; }
.menu-version { margin: auto 0 0; padding: 16px 12px 0; color: var(--texte-secondaire); font-size: 12px; }

/* Fenêtre de choix d'un dossier ou d'un tag (PRD § 12) : lignes de 44 px, comme le menu de tri */
.choose-list {
  margin: 8px -8px 0; padding: 0;
  list-style: none;
  max-height: 50vh; overflow-y: auto;
}
.choose-item {
  display: flex; align-items: center;
  width: 100%; min-height: 44px;
  padding: 0 8px;
  border: 0; border-radius: var(--rayon-petit);
  background: transparent; color: var(--texte);
  font: inherit; font-size: 15px; text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.choose-item:hover { background: var(--surface-2); }
.choose-item { gap: 12px; }
/* Dossiers : rond de leur couleur devant le nom, comme dans le menu ; « Sans dossier » : rond vide */
.choose-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--pastille); }
.choose-dot.is-none { background: transparent; border: 1.5px solid var(--texte-secondaire); }
/* Tags : nom dans sa pastille, comme sur les cartes ; « Sans tag » : pastille neutre à bord fin */
.choose-pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.choose-pill.is-none { background: transparent; border: 1px solid var(--bordure); color: var(--texte-secondaire); }
