/* Le tableau : le registre de l'atelier. Blanc galerie, encre, Charter pour
   ce qu'on lit. Aucun rouge (le rouge est l'erreur de l'atelier), aucune
   couleur d'urgence, aucun âge sur une carte à décider. Une teinte par projet,
   discrète (liseré, fond très léger, encre du nom), tirée du registre des
   thèmes de tableau.js : l'angle OKLCH arrive par la variable --th. */

:root {
  color-scheme: light dark;
  --paper: #ffffff;
  --paper-deep: #f5f5f4;
  --ink: #161616;
  --ink-2: #6e6e6e;
  --hairline: #ebebea;
  --card: #ffffff;
  --card-line: #e4e4e2;
  --focus: #2251cc;
  --danger: #b23a32;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.09), 0 2px 8px rgba(0, 0, 0, 0.04);
  --sans: "Neue Haas Grotesk Text", "Helvetica Neue", Helvetica, "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --serif: Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --top-h: calc(3.6rem + env(safe-area-inset-top));
  --detail-w: 30rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121212;
    --paper-deep: #1b1b1b;
    --ink: #ededec;
    --ink-2: #9c9c9a;
    --hairline: #262626;
    --card: #171717;
    --card-line: #2c2c2c;
    --focus: #85a8ee;
    --danger: #d67c74;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  }
  .card.ghost { box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4); }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
body.booting #tb-main { visibility: hidden; }
button, select, textarea, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* ---------- la barre du haut ---------- */

#tb-top {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  height: var(--top-h);
  padding: env(safe-area-inset-top) max(1.4rem, env(safe-area-inset-right)) 0 max(1.4rem, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 1.2rem;
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}
.tb-back, .tb-btn, .tb-who, .tb-col-h, .d-eyebrow, .d-sec h3, .tb-tab, .n-set legend {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2);
}
.tb-back { text-decoration: none; padding: 0.6rem 0; }
.chev { margin-right: 0.45em; letter-spacing: 0; }
.d-note { font-size: 0.85rem; color: var(--ink-2); line-height: 1.5; margin: -0.2rem 0 0.7rem; }
.tb-back:hover, .tb-btn:hover { color: var(--ink); }
.tb-title { font-family: var(--serif); font-weight: 400; font-size: 1.15rem; letter-spacing: -0.01em; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 1.2rem; }
.tb-btn { padding: 0.6rem 0; }

/* ---------- les outils ---------- */

#tb-main { padding: calc(var(--top-h) + 1.2rem) 1.4rem 3rem; }
.tb-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem 1.4rem; margin-bottom: 1.4rem; }
.tb-legend { position: relative; font-size: 0.78rem; color: var(--ink-2); }
.tb-legend summary { cursor: pointer; list-style: none; min-height: 32px; display: inline-flex; align-items: center; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; }
.tb-legend summary::-webkit-details-marker { display: none; }
.tb-legend summary::after { content: "+"; margin-left: 0.5em; letter-spacing: 0; }
.tb-legend[open] summary::after { content: "\2212"; }
.tb-legend summary:hover { color: var(--ink); }
.lg-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; padding: 0.3rem 0 0.2rem; }
.lg-item { display: inline-flex; align-items: center; gap: 0.45em; color: var(--ink-2); }
.lg-swatch { width: 0.9em; height: 0.9em; border-radius: 3px; background: var(--th-line, var(--ink-2)); }
.lg-item.themed .lg-name { color: var(--th-ink); }
.tb-switch { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--ink-2); min-height: 32px; cursor: pointer; }
.tb-switch input { accent-color: var(--ink); width: 1rem; height: 1rem; }
.tb-switch:hover { color: var(--ink); }
.tb-archives { min-height: 32px; }
.tb-sync { margin-left: auto; }

/* ---------- aujourd'hui : au plus cinq cartes, l'ordre du serveur ---------- */

.today { margin: 0 0 1.6rem; }
.today-h { display: flex; align-items: baseline; gap: 0.5rem; padding: 0 0.2rem 0.7rem; border-bottom: 1px solid var(--hairline); margin-bottom: 0.8rem; font-weight: 400; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink); }
.today-list { list-style: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.7rem; }
.today-card {
  display: block; width: 100%; height: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--card-line); border-radius: 12px;
  padding: 0.8rem 0.95rem 0.8rem;
  transition: border-color 0.15s;
}
.today-card:hover { border-color: var(--ink-2); }
.today-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.6rem; margin-bottom: 0.35rem; }
.today-head .card-proj { margin-bottom: 0; }
.today-why { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink); border: 1px solid var(--ink); border-radius: 999px; padding: 0.15em 0.55em; white-space: nowrap; }
.today-why.why-urgent { background: var(--ink); color: var(--paper); }
.today-why.why-fait { color: var(--ink-2); border-color: var(--card-line); }

/* ---------- les thèmes : une teinte par projet, discrète (clair et sombre) ---------- */

.themed { --th-line: oklch(64% 0.11 var(--th)); --th-wash: oklch(98.6% 0.009 var(--th)); --th-ink: oklch(42% 0.11 var(--th)); }
@media (prefers-color-scheme: dark) {
  .themed { --th-line: oklch(70% 0.10 var(--th)); --th-wash: oklch(20.5% 0.014 var(--th)); --th-ink: oklch(80% 0.075 var(--th)); }
}
@supports not (color: oklch(50% 0.1 180)) {
  .themed { --th-line: var(--ink-2); --th-wash: var(--card); --th-ink: var(--ink-2); }
}
.card.themed, .today-card.themed, .a-card.themed { border-left: 3px solid var(--th-line); background: var(--th-wash); }
.card.themed:hover, .today-card.themed:hover, .a-card.themed:hover { border-left-color: var(--th-line); }
.card.themed[aria-current="true"] { box-shadow: 0 0 0 1px var(--ink); }
.themed .card-proj { color: var(--th-ink); }
.themed .card-proj::before { content: ""; display: inline-block; width: 0.55em; height: 0.55em; border-radius: 50%; background: var(--th-line); margin-right: 0.5em; vertical-align: 0.08em; }
.card.lane-clawdio { border-left-style: dashed; }
.detail.themed { border-left: 3px solid var(--th-line); }
.detail.themed .d-eyebrow { color: var(--th-ink); }
.tb-filter select {
  border: 1px solid var(--hairline); border-radius: 999px; background: var(--paper);
  padding: 0.35rem 0.9rem; font-size: 0.85rem; color: var(--ink);
}
.tb-sync { font-size: 0.78rem; color: var(--ink-2); }

/* ---------- les colonnes ---------- */

.board { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; align-items: start; }
body.detail-open .board { margin-right: var(--detail-w); }
.tb-col { min-width: 0; }
.tb-col-h { display: flex; gap: 0.5rem; align-items: baseline; padding: 0 0.2rem 0.7rem; border-bottom: 1px solid var(--hairline); margin-bottom: 0.8rem; }
.tb-col-h .n { color: var(--ink); letter-spacing: 0; }
.tb-col ul { list-style: none; display: flex; flex-direction: column; gap: 0.7rem; }
.tb-empty { font-size: 0.85rem; color: var(--ink-2); padding: 0.3rem 0.2rem; font-family: var(--serif); font-style: italic; }
.tb-tabs { display: none; }

.card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--card-line); border-radius: 12px;
  padding: 0.85rem 2.1rem 0.8rem 0.95rem;    /* à droite : la place de la poignée */
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.card:hover { border-color: var(--ink-2); }
.card[aria-current="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.card-proj { display: block; font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); margin-bottom: 0.3rem; }
.card-title { display: block; font-family: var(--serif); font-size: 1.02rem; line-height: 1.35; color: var(--ink); }
.card-meta { display: block; margin-top: 0.5rem; font-size: 0.76rem; color: var(--ink-2); line-height: 1.45; }
.card-mark { display: inline-block; margin-top: 0.5rem; font-size: 0.74rem; color: var(--ink); border-top: 1px solid var(--hairline); padding-top: 0.45rem; width: 100%; }

/* ---------- déplacer une carte à la main (D3) ---------- */

.tb-item { position: relative; }
.tb-item.flip { transition: transform 0.16s cubic-bezier(0.2, 0.7, 0.2, 1); }
/* la poignée : discrète à la souris (elle paraît au survol et au clavier), toujours là au doigt */
.card-grip {
  position: absolute; top: 0.45rem; right: 0.45rem; width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center; cursor: grab;
  opacity: 0; transition: opacity 0.15s, background-color 0.15s; touch-action: none;
}
.card-grip::before {
  content: ""; width: 7px; height: 13px;
  background: radial-gradient(circle, var(--ink-2) 1.1px, transparent 1.5px) 0 0 / 3.5px 4.4px;
}
.tb-item:hover .card-grip, .tb-item:focus-within .card-grip, .card-grip:focus-visible, .card-grip[aria-pressed="true"] { opacity: 1; }
.card-grip:hover { background: var(--paper-deep); }
.card-grip[aria-pressed="true"]::before { background-image: radial-gradient(circle, var(--ink) 1.1px, transparent 1.5px); }
@media (pointer: coarse) {
  .card-grip { opacity: 0.6; width: 44px; height: 44px; top: 0; right: 0; }
}
/* le glisser : le fantôme suit le pointeur (transform seul), l'emplacement reste en creux */
body.dragging, body.dragging .card, body.dragging .card-grip { cursor: grabbing; }
body.dragging { -webkit-user-select: none; user-select: none; }
.card.ghost {
  position: fixed; z-index: 40; margin: 0; pointer-events: none; will-change: transform;
  border-color: var(--ink); box-shadow: 0 18px 44px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: opacity 0.15s;
}
.card.ghost.landing { transition: transform 0.18s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.18s, opacity 0.15s; box-shadow: none; }
.tb-item.placeholder { border-radius: 12px; outline: 1.5px dashed var(--ink-2); outline-offset: -1px; }
.tb-item.placeholder .card, .tb-item.placeholder .card-grip { visibility: hidden; }
.tb-col ul:has(.placeholder) .tb-empty { display: none; }
/* la colonne visée se souligne ; « Fait » qui refuse une décision sans réponse le dit */
.tb-col.drop-target .tb-col-h { border-bottom-color: var(--ink); color: var(--ink); }
.tb-col.drop-refuse .tb-col-h { border-bottom-style: dashed; }
.tb-col.drop-refuse .tb-col-h .n::after { content: " · une réponse d'abord"; font-family: var(--serif); font-style: italic; text-transform: none; letter-spacing: 0; color: var(--ink-2); }
.tb-tab.drop-target { color: var(--ink); border-bottom-color: var(--ink-2); }
/* la carte saisie au clavier */
.card.grabbed { border-color: var(--ink); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12); transform: translateY(-1px); }
.tb-notice { font-size: 0.85rem; color: var(--ink); border-left: 2px solid var(--ink); padding-left: 0.6rem; margin: -0.6rem 0 1rem; line-height: 1.45; max-width: 42rem; }
@media (prefers-reduced-motion: reduce) {
  .tb-item.flip, .card.ghost, .card.ghost.landing, .card { transition: none !important; }
}

/* ---------- la carte ouverte ---------- */

.detail {
  position: fixed; z-index: 15; top: var(--top-h); right: 0; bottom: 0;
  width: var(--detail-w); overflow-y: auto;
  background: var(--paper); border-left: 1px solid var(--hairline);
  padding: 1.2rem 1.6rem calc(3rem + env(safe-area-inset-bottom));
}
.d-head { margin-bottom: 0.8rem; }
.d-close { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-2); padding: 0.5rem 0; min-height: 44px; }
.d-close:hover { color: var(--ink); }
.d-title { font-family: var(--serif); font-weight: 400; font-size: 1.5rem; line-height: 1.3; margin: 0.35rem 0 0.4rem; letter-spacing: -0.01em; }
.d-state { font-size: 0.85rem; color: var(--ink-2); }
.d-sec { margin-top: 1.6rem; }
.d-sec h3 { font-weight: 400; margin-bottom: 0.55rem; }
.d-md { font-family: var(--serif); font-size: 1.02rem; line-height: 1.65; }
.d-md p + p, .d-md ul, .d-md ol { margin-top: 0.6rem; }
.d-md ul, .d-md ol { padding-left: 1.2rem; }
.d-md code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85em; background: var(--paper-deep); padding: 0.05em 0.3em; border-radius: 4px; }
.d-reco { font-family: var(--serif); font-size: 1.1rem; margin-bottom: 0.35rem; }
.d-sources { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.92rem; }
.d-sources a { text-underline-offset: 3px; text-decoration-color: var(--ink-2); }
.d-sources .path { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.82rem; color: var(--ink-2); word-break: break-all; }
.d-sources .lbl { display: block; }

.d-options { border: 0; display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.7rem; }
.d-opt { display: flex; gap: 0.6rem; align-items: flex-start; font-family: var(--serif); font-size: 1rem; line-height: 1.45; padding: 0.45rem 0.6rem; border: 1px solid var(--hairline); border-radius: 10px; cursor: pointer; min-height: 44px; }
.d-opt input { margin-top: 0.3rem; accent-color: var(--ink); }
.d-opt:has(input:checked) { border-color: var(--ink); }
#d-text { width: 100%; border: 1px solid var(--hairline); border-radius: 10px; padding: 0.6rem 0.75rem; background: var(--paper); font-family: var(--serif); font-size: 1rem; line-height: 1.5; resize: vertical; }
.d-go { display: flex; gap: 0.55rem; align-items: center; margin-top: 0.7rem; font-size: 0.92rem; min-height: 44px; }
/* la réponse posée, en lecture : ce que l'auteur a dit, et ce que clawdio en a fait */
.d-answered { border-left: 2px solid var(--ink); padding: 0.1rem 0 0.1rem 0.8rem; }
.d-ans-choice { font-family: var(--serif); font-size: 1.05rem; line-height: 1.45; }
.d-ans-text { font-family: var(--serif); font-size: 1rem; line-height: 1.55; margin-top: 0.4rem; white-space: pre-wrap; }
.d-ans-go { margin-top: 0.45rem; font-size: 0.88rem; }
.d-ans-state { margin-top: 0.5rem; font-size: 0.85rem; color: var(--ink-2); line-height: 1.45; }
.d-actions-left { justify-content: flex-start; margin-top: 0.3rem; }
.d-go input { accent-color: var(--ink); width: 1.05rem; height: 1.05rem; }
.d-actions { margin-top: 0.8rem; display: flex; justify-content: flex-end; }
.d-err { margin-top: 0.6rem; font-size: 0.85rem; color: var(--ink); border-left: 2px solid var(--ink); padding-left: 0.6rem; }
.d-hist { list-style: none; display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.85rem; line-height: 1.45; }
.d-hist time { color: var(--ink-2); font-variant-numeric: tabular-nums; margin-right: 0.4rem; }
.d-hist .who { color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px;
  padding: 0.5rem 1.2rem; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-size: 0.88rem; text-decoration: none;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.linkish { text-decoration: underline; text-underline-offset: 3px; color: var(--ink-2); font-size: 0.88rem; min-height: 40px; }

/* ---------- les notifications ---------- */

.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.18); display: flex; align-items: flex-start; justify-content: center; padding: calc(var(--top-h) + 1rem) 1rem 1rem; overflow-y: auto; }
.sheet-in { width: min(32rem, 100%); background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); padding: 1.4rem 1.5rem; }
.sheet h2 { font-family: var(--serif); font-weight: 400; font-size: 1.3rem; margin-bottom: 0.6rem; }
.n-help, .n-note, .n-device { font-size: 0.88rem; color: var(--ink-2); line-height: 1.5; margin-bottom: 0.8rem; }
.n-device { color: var(--ink); }
.n-row { display: flex; gap: 1rem; align-items: center; margin: 0.6rem 0 1rem; }
.n-set { border: 0; margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.92rem; }
.a-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; max-height: 55vh; overflow-y: auto; margin-bottom: 0.6rem; padding: 2px; }
.a-card { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--card-line); border-radius: 12px; padding: 0.8rem 0.95rem; }
.a-card:hover { border-color: var(--ink-2); }
.n-set legend { margin-bottom: 0.4rem; }
.n-set label { display: flex; gap: 0.5rem; align-items: center; min-height: 32px; }
.n-set select { border: 1px solid var(--hairline); border-radius: 8px; background: var(--paper); padding: 0.2rem 0.4rem; }
.n-set input { accent-color: var(--ink); }

.gate { min-height: 100vh; display: flex; flex-direction: column; gap: 1.2rem; align-items: center; justify-content: center; padding: 2rem; text-align: center; }
.gate-msg { font-family: var(--serif); font-size: 1.15rem; max-width: 26rem; line-height: 1.5; }
body.gated #tb-main, body.gated #tb-top .tb-right { display: none; }

/* ---------- l'écran moyen : trois colonnes visibles, le reste défile ---------- */

@media (max-width: 1279.98px) {
  .board { grid-template-columns: repeat(6, minmax(14rem, 1fr)); overflow-x: auto; padding-bottom: 0.6rem; scroll-snap-type: x proximity; }
  .today-list { grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); }
  .tb-col { scroll-snap-align: start; }
  body.detail-open .board { margin-right: 0; }
  .detail { box-shadow: var(--shadow); }
}

/* ---------- le téléphone : une colonne à la fois, la carte en plein écran ---------- */

@media (max-width: 700px) {
  #tb-top { gap: 0.8rem; padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .tb-who { display: none; }
  .tb-back, .tb-btn { min-height: 44px; display: inline-flex; align-items: center; }
  #tb-main { padding: calc(var(--top-h) + 0.8rem) 1rem 3rem; }
  .tb-tools { flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-bottom: 0.8rem; }
  .tb-sync { margin-left: 0; }
  .tb-legend summary, .tb-switch, .tb-archives { min-height: 44px; }
  /* au téléphone, « Aujourd'hui » est une rangée qui défile au doigt : la colonne reste sous le pouce */
  .today { margin: 0 -1rem 0.9rem; }
  .today-h { margin: 0 1rem 0.6rem; }
  .today-list { display: flex; gap: 0.6rem; overflow-x: auto; padding: 2px 1rem 0.4rem; scroll-snap-type: x mandatory; scrollbar-width: none; }
  .today-list::-webkit-scrollbar { display: none; }
  .today-item { flex: 0 0 76%; scroll-snap-align: start; }
  .today-card { padding: 0.8rem 0.9rem; min-height: 44px; }
  .today-card .card-title { font-size: 0.98rem; }
  /* six onglets sur deux lignes : tout se voit d'un coup, rien ne défile sous le doigt */
  .tb-tabs {
    display: flex; flex-wrap: wrap; gap: 0 0.3rem; margin: 0 0 1rem;
    border-bottom: 1px solid var(--hairline);
  }
  .tb-tab { flex: 1 0 30%; padding: 0 0.5rem; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; border-bottom: 2px solid transparent; white-space: nowrap; }
  .tb-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
  .tb-tab .n { letter-spacing: 0; }
  .board { display: block; overflow: visible; }
  .tb-col { display: none; }
  .tb-col.current { display: block; }
  .tb-col-h { display: none; }
  .card { padding: 0.95rem 1rem; }
  .detail { top: var(--top-h); left: 0; width: auto; border-left: 0; box-shadow: none; padding: 0.6rem 1rem calc(3rem + env(safe-area-inset-bottom)); }
  .d-actions .btn { width: 100%; min-height: 48px; }
  .btn { min-height: 44px; }
  .linkish { min-height: 44px; }
}
