:root {
  --bg: #f6f8f6;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --text: #17231c;
  --muted: #5d6b63;
  --line: #dbe4de;
  --accent: #047857;
  --accent-ink: #ffffff;
  --accent-soft: #d9f2e6;
  --pro: #1d4ed8;
  --pro-soft: #dbe7ff;
  --perso: #b45309;
  --perso-soft: #fdebcf;
  --danger: #b91c1c;
  --danger-soft: #fde2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 14px rgba(20, 40, 30, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101713;
    --surface: #18211c;
    --surface-2: #202c26;
    --text: #e6efe9;
    --muted: #93a39a;
    --line: #2b3a32;
    --accent: #34d399;
    --accent-ink: #052e1f;
    --accent-soft: #123a2a;
    --pro: #8fb2ff;
    --pro-soft: #1b2a52;
    --perso: #f6b873;
    --perso-soft: #45300f;
    --danger: #f87171;
    --danger-soft: #451a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .2em 0 .4em; }
h2 { font-size: 1.2rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1.02rem; margin: 1em 0 .3em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Mise en page ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; padding: 4px 8px 14px; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); }
.logo.big { width: 64px; height: 64px; font-size: 2rem; border-radius: 18px; margin: 0 auto 10px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side .grp { margin: 16px 8px 4px; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.side a, .linklike {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: .96rem;
}
.side a:hover, .linklike:hover { background: var(--surface-2); }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .ic { width: 1.4em; text-align: center; }
.side-bottom { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 12px; }
.linklike { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; text-align: left; justify-content: flex-start; min-height: 0; padding: 8px 10px; }
.main { padding: 22px clamp(16px, 4vw, 44px) 60px; max-width: 1080px; width: 100%; }

.search { display: flex; gap: 8px; margin-bottom: 18px; }
.search input { flex: 1; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
  .side nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 6px; }
  .side nav a { white-space: nowrap; }
  .side .grp { display: none; }
  .side-bottom { display: flex; border: 0; margin: 0; padding: 0; }
  .side-bottom form { margin-left: auto; }
  .linklike { width: auto; }
}

/* ---------- Composants ---------- */
input, select, textarea, button, .btn {
  font: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  padding: 9px 12px; min-height: 40px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
textarea { width: 100%; resize: vertical; }
input[type=text], input[type=search], input[type=password], input[type=url], input[type=date], input[type=file], select { width: 100%; }
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--surface-2); }
button:hover, .btn:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.primary:hover { filter: brightness(1.07); }
.ghost { background: transparent; }
.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.danger-zone { margin-top: 28px; padding-top: 18px; border-top: 1px dashed var(--line); }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.crumb { margin: 0 0 4px; font-size: .9rem; }
.lead { font-size: 1.05rem; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.empty { color: var(--muted); padding: 18px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

.cards { display: grid; gap: 14px; margin: 18px 0; }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card.space {
  display: block; padding: 20px; border-radius: 16px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.card.space:hover { transform: translateY(-2px); }
.card.space.pro { border-top: 4px solid var(--pro); }
.card.space.perso { border-top: 4px solid var(--perso); }
.card h2 { margin: .3em 0 .2em; }
.card p { margin: 0 0 .6em; color: var(--muted); }
.big-ic { font-size: 2rem; }
.count { font-weight: 600; font-size: .9rem; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 28px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text);
}
a.row:hover { border-color: var(--accent); }
.row .ic { font-size: 1.4rem; width: 1.6em; text-align: center; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row strong { overflow-wrap: anywhere; }
.row small { color: var(--muted); }
.row small.desc { margin-top: 2px; }
.row.is-done strong { text-decoration: line-through; color: var(--muted); }
.row.inline, form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline .grow { flex: 1; min-width: 140px; }
.icon-in { width: 4.5em !important; text-align: center; }
.add-cat { margin-top: 14px; }

.badge { font-size: .72rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); white-space: nowrap; }
.badge.pro { background: var(--pro-soft); color: var(--pro); }
.badge.perso { background: var(--perso-soft); color: var(--perso); }
.badge.late { background: var(--danger-soft); color: var(--danger); }
.badge.t { margin-left: 8px; background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }
.chip { padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--text); font-size: .9rem; }
.chip small { color: var(--muted); margin-left: 3px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.on small { color: inherit; opacity: .8; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tag { font-size: .82rem; text-decoration: none; background: var(--surface-2); color: var(--muted); padding: 2px 9px; border-radius: 6px; }
.tag:hover { color: var(--accent); }
.meta { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .9rem; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters input[type=search] { flex: 1; min-width: 160px; }
.filters select { width: auto; }

/* ---------- Formulaires ---------- */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.form label, .login label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .92rem; }
.form label small { font-weight: 400; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form label.check input { width: auto; min-height: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.seg label { flex-direction: row; font-weight: 500; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 16px; cursor: pointer; background: var(--surface); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.panel, .panel-static { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 14px 0; }
.panel > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.panel[open] > summary { margin-bottom: 12px; }
.panel-static h2 { margin-top: .2em; }

/* ---------- Contenu ---------- */
.prose { max-width: 75ch; }
.prose h2, .prose h3, .prose h4, .prose h5 { margin: 1.2em 0 .4em; }
.prose code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: .9em; }
.prose ul.checks { list-style: none; padding-left: 4px; }
.prose li.done { color: var(--muted); text-decoration: line-through; }
.preview-img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-top: 14px; }
.preview-pdf { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); margin-top: 14px; background: var(--surface); }

.year { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-item { display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.tl-date { color: var(--muted); font-size: .9rem; padding-top: 4px; }
.tl-date .badge { display: inline-block; margin: 4px 0 0; }
.tl-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.tl-body h3 { margin: .2em 0 .3em; }
.edit-link { font-size: .78rem; font-weight: 400; margin-left: 8px; color: var(--muted); }
@media (max-width: 640px) { .tl-item { grid-template-columns: 1fr; gap: 4px; } }

.project h2 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
progress { width: 100%; height: 8px; margin-bottom: 10px; accent-color: var(--accent); }
.cycle { margin: 0; }
.ic-btn { font-size: 1.3rem; border: 0; background: none; padding: 0 4px; min-height: 0; }

/* ---------- Connexion ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 26px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.login h1 { text-align: center; margin: 0; }
.login p { text-align: center; margin: 0 0 6px; }

/* ---------- Missions, projets, grille mensuelle ---------- */
.cards:not(.two) { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card.mission {
  display: block; padding: 16px 18px; border-radius: 14px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-top: 4px solid var(--accent);
  transition: transform .12s, border-color .12s;
}
.card.mission:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card.mission h2 { margin: 0 0 .2em; font-size: 1.05rem; }
.card.mission .badge { flex-shrink: 0; font-size: .85rem; }
.quote { margin: .4em 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); font-size: .9rem; }
.nextbox { background: var(--accent-soft); border-radius: var(--radius); padding: 4px 16px 14px; margin: 12px 0; }
.nextbox h2 { margin-top: .6em; }
.add-task { margin-top: 10px; }
.row-link { color: inherit; text-decoration: none; }
.row-link small { display: block; }
.meta form.inline { margin: 0; }
.meta select { width: auto; min-height: 34px; padding: 4px 8px; }
.meta button { min-height: 34px; padding: 4px 10px; }
.table-wrap { overflow-x: auto; margin: 10px 0; }
table.grille { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .88rem; }
table.grille th, table.grille td { border: 1px solid var(--line); padding: 8px 10px; vertical-align: top; text-align: left; }
table.grille thead th { background: var(--accent-soft); color: var(--accent); }
table.grille tbody th { background: var(--surface-2); min-width: 260px; font-weight: 600; }
table.grille .w { text-align: center; white-space: nowrap; width: 1%; }
table.grille .prose { max-width: none; font-weight: 400; }
table.grille .prose p, table.grille .prose ul { margin: .2em 0; }
table.grille tfoot th, table.grille tfoot td { background: var(--surface-2); font-weight: 600; }

@media print {
  .side, .search, .actions, .panel, .flash, nav.chips, .edit-link { display: none !important; }
  .shell { display: block; }
  body { background: #fff; color: #000; }
  .main { padding: 0; max-width: none; }
  table.grille { font-size: 8.5pt; }
  table.grille thead th { background: #e5e7eb !important; color: #000; }
  table.grille tbody th, table.grille tfoot th, table.grille tfoot td { background: #f3f4f6 !important; }
  .row, .card.mission { break-inside: avoid; box-shadow: none; }
}

/* ---------- Partage de photos (page publique et gestion) ---------- */
body.pub { min-height: 100vh; }
.pubhead { display: flex; align-items: center; gap: 10px; padding: 14px clamp(16px, 4vw, 44px); font-weight: 700; border-bottom: 1px solid var(--line); background: var(--surface); }
.pubmain { max-width: 1000px; margin: 0 auto; padding: 22px clamp(16px, 4vw, 30px) 60px; }
.pubmain > .login { margin: 40px auto; text-align: center; align-items: center; }
.dropbox { background: var(--surface); border: 2px dashed var(--accent); border-radius: var(--radius); padding: 6px 18px 16px; max-width: none; margin: 14px 0; }
.dropbox h2 { margin: .6em 0 .2em; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.photo { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.photo a { display: block; background: var(--surface-2); }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.photo figcaption { padding: 7px 10px 9px; font-size: .86rem; overflow-wrap: anywhere; }
.photo figcaption small { display: block; color: var(--muted); font-size: .76rem; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: .78rem; align-items: center; }
.photo-actions form { margin: 0; }
.linkbtn { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.linkbtn.warn { color: var(--danger); }
.danger-zone.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-zone.actions form { margin: 0; }
