:root {
  --fg: #111;
  --muted: #777;
  --line: #e6e6e6;
  --bg: #fff;
  --done: #9aa0a6;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  color: var(--fg);
  background: var(--bg);
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px 80px;
}
a { color: inherit; }

/* ---- en-tête ---- */
.topbar { padding: 24px 0 4px; }
.topbar .home {
  font-size: .8rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.topbar .home:hover { border-color: var(--muted); }
.topbar h1 { margin: .25em 0 0; font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }

/* ---- barre d'outils ---- */
.toolbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.add { display: flex; gap: 8px; }
.add input {
  flex: 1; padding: 10px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.add input:focus { outline: none; border-color: var(--fg); }
.add button {
  padding: 0 16px; border: 1px solid var(--fg); background: var(--fg);
  color: #fff; border-radius: var(--radius); cursor: pointer; font: inherit;
}
.add button:hover { opacity: .9; }

.controls {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 14px; margin-top: 10px; font-size: .85rem; color: var(--muted);
}
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl select { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.linkbtn {
  border: none; background: none; color: var(--muted); cursor: pointer; font: inherit;
  text-decoration: underline; text-underline-offset: 2px; padding: 0;
}
.linkbtn:hover { color: var(--fg); }
.linkbtn.strong { font-weight: 600; color: var(--fg); }
.filter-chip {
  font: inherit; font-size: .8rem; padding: 2px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--fg);
}
.filter-chip.on { color: #fff; }
.clear { margin-left: 2px; }

/* ---- arbre des tâches ---- */
main { margin-top: 14px; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree .children { margin: 0; padding: 0; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; min-height: 34px;
}
.row:hover { background: #f7f7f7; }
.row-main { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.row-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 1px; margin-left: auto; }
.twisty {
  border: none; background: none; cursor: pointer; color: var(--muted);
  width: 18px; text-align: center; font-size: .8rem; padding: 0; flex: none;
}
.twisty.placeholder { cursor: default; }
.check { width: 17px; height: 17px; cursor: pointer; flex: none; }
.title { cursor: text; flex: 1; min-width: 0; word-break: break-word; }
.row.is-done .title { text-decoration: line-through; color: var(--done); }
.title-edit {
  flex: 1; font: inherit; padding: 4px 6px;
  border: 1px solid var(--fg); border-radius: 6px;
}
.title-edit:focus { outline: none; }
.row-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-chip { font-size: .7rem; color: #fff; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.more { font-size: .72rem; color: var(--muted); background: #ececec; border-radius: 999px; padding: 0 7px; }

.row-tools .act, .row-tools .note-btn { opacity: 0; transition: opacity .12s; }
.row:hover .row-tools .act, .row:hover .row-tools .note-btn { opacity: 1; }
.row-tools .note-btn.has-note { opacity: 1; }
.act {
  border: none; background: none; cursor: pointer; font-size: .85rem; line-height: 1;
  padding: 4px; border-radius: 5px; color: var(--muted);
}
.act:hover { background: #ececec; color: var(--fg); }
.act.danger:hover { background: #fde8e8; color: #b00020; }
@media (hover: none) {
  .row-tools .act, .row-tools .note-btn { opacity: 1; }
}
/* En mobile : les options passent sur une ligne, sous le titre */
@media (max-width: 640px) {
  .row { gap: 5px; }
  .row-tools {
    flex-basis: 100%; margin-left: 28px; margin-top: 3px;
    gap: 6px; justify-content: flex-start;
  }
  .row-tools .act, .row-tools .note-btn { opacity: 1; padding: 6px; font-size: 1rem; }
}

#done-section { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 8px; }
#done-section h2 {
  font-size: .8rem; letter-spacing: .12em; color: var(--muted);
  font-weight: 700; margin: 6px;
}
.empty-hint { list-style: none; color: var(--muted); padding: 14px 6px; }
.muted { color: var(--muted); }

/* ---- popovers ---- */
.popover {
  position: fixed; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 8px; min-width: 180px; max-width: 280px; z-index: 50;
}
.pop-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; }
.pop-row:hover { background: #f6f6f6; }
.pop-row label { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 0; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.ellipsis { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.pop-empty { color: var(--muted); padding: 4px; }

/* ---- gestionnaire de tags ---- */
dialog#tag-dialog {
  border: none; border-radius: 14px; padding: 0; width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog#tag-dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); margin: 0;
}
.dialog-head h3 { margin: 0; font-size: 1rem; }
.x { border: none; background: none; font-size: 1rem; cursor: pointer; color: var(--muted); }
.tag-editor { list-style: none; margin: 0; padding: 10px 12px; max-height: 50vh; overflow: auto; }
.tag-edit-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.tag-edit-row input[type=color] { width: 30px; height: 30px; border: none; background: none; padding: 0; cursor: pointer; }
.tag-edit-row input[type=text] { flex: 1; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.tag-add { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.tag-add input[type=color] { width: 34px; height: 34px; border: none; background: none; padding: 0; cursor: pointer; }
.tag-add input[type=text] { flex: 1; font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.tag-add button { padding: 0 14px; border: 1px solid var(--fg); background: var(--fg); color: #fff; border-radius: 6px; cursor: pointer; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: .85rem; z-index: 100; max-width: 90vw;
}

/* ---- en-tête façon page d'accueil (pages-listes : tasks, papa, ...) ---- */
.page-head { padding: 30px 0 8px; text-align: center; }
.page-head .home {
  display: inline-block; font-size: .8rem; color: var(--muted);
  text-decoration: none; border-bottom: 1px solid transparent;
}
.page-head .home:hover { border-color: var(--muted); }
.page-title {
  margin: .15em 0 0; font-weight: 700; letter-spacing: -.02em;
  font-size: clamp(1.9rem, 7vw, 3.4rem);
}

/* ---- galerie de documents (bas de page) ---- */
.doc-gallery { margin-top: 34px; border-top: 1px solid var(--line); padding-top: 8px; }
.doc-gallery h2 {
  font-size: .8rem; letter-spacing: .12em; color: var(--muted);
  font-weight: 700; margin: 6px; text-transform: uppercase;
}
.doc-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 12px; padding: 8px 6px 0;
}
.doc-thumb-btn { border: none; background: none; padding: 0; cursor: pointer; font: inherit; }
.doc-thumb { margin: 0; }
.doc-thumb-img {
  width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; display: block;
  border: 1px solid var(--line); border-radius: 10px; background: #f4f4f4;
  transition: transform .12s, box-shadow .12s;
}
.doc-thumb-btn:hover .doc-thumb-img { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.14); }
.doc-thumb figcaption {
  margin-top: 5px; font-size: .74rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center;
}

/* ---- visionneuse d'un document (image + traduction) ---- */
dialog.doc-viewer {
  border: none; border-radius: 14px; padding: 0; width: min(920px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden;
}
dialog.doc-viewer::backdrop { background: rgba(0,0,0,.5); }
.doc-viewer-body { display: flex; max-height: 80vh; }
.doc-viewer-img {
  flex: 1 1 50%; background: #0e0e0e; display: flex; align-items: center;
  justify-content: center; overflow: auto;
}
.doc-viewer-img img { max-width: 100%; max-height: 80vh; display: block; }
.doc-viewer-text { flex: 1 1 50%; padding: 16px 18px; overflow: auto; max-height: 80vh; }
.doc-action {
  background: #fff7e6; border: 1px solid #ffe1a8; border-left: 4px solid #f0a020;
  border-radius: 8px; padding: 10px 12px; font-weight: 600;
  margin-bottom: 14px; white-space: pre-wrap;
}
.doc-sec-title {
  margin: 0 0 6px; font-size: .72rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.doc-translation { white-space: pre-wrap; line-height: 1.5; font-size: .95rem; }
.doc-viewer-foot { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
.danger-link { color: #b00020; }
@media (max-width: 640px) {
  .doc-viewer-body { flex-direction: column; max-height: 88vh; }
  .doc-viewer-img { max-height: 42vh; }
  .doc-viewer-img img { max-height: 42vh; }
}

/* ---- note de texte (repliable) sous un item ---- */
.note-btn { font-weight: 700; font-family: Georgia, "Times New Roman", serif; }
.note-btn.has-note { background: #ececec; }
.note-panel {
  margin: 2px 0 8px; padding: 7px 10px; background: #fafafa;
  border: 1px solid var(--line); border-left: 3px solid #d0d0d0; border-radius: 6px;
  max-width: 660px;
}
.note-text {
  width: 100%; border: none; background: transparent; resize: none;
  font: inherit; font-size: .92rem; line-height: 1.45; padding: 0;
  overflow: hidden; min-height: 1.4em;
}
.note-text:focus { outline: none; }
.note-colors { display: flex; gap: 7px; margin-top: 7px; }
.note-swatch {
  width: 14px; height: 14px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line);
}
.note-swatch.active { box-shadow: 0 0 0 2px #111; }

/* ---- footer : liens vers les sous-pages (affiché seulement si la page fournit $FOOTER_LINKS) ---- */
.page-footer {
  margin-top: 56px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  font-size: .9rem;
  color: var(--muted);
}
.page-footer a {
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
}
.page-footer a:hover { border-color: var(--fg); }
