:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --line: #d9d5cc;
  --text: #22201c;
  --muted: #6b665c;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --room: #fbfaf7;
  --room-line: #8a8478;
  --room-sel: #fde7d8;
  --st-a-planifier: #8b7fb8;
  --st-a-faire: #d97706;
  --st-en-cours: #2563eb;
  --st-achevee: #16a34a;
  --danger: #b91c1c;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1916;
    --surface: #24231f;
    --surface-2: #2e2c27;
    --line: #444038;
    --text: #ece9e2;
    --muted: #a39d90;
    --accent: #f97316;
    --accent-text: #1a1916;
    --room: #2a2824;
    --room-line: #9a9384;
    --room-sel: #4a3222;
    --st-a-planifier: #a99ddb;
    --st-a-faire: #f59e0b;
    --st-en-cours: #60a5fa;
    --st-achevee: #4ade80;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 2px 8px; line-height: 1.2; }
.btn:disabled { opacity: .4; cursor: default; }
.muted { color: var(--muted); }
.hint { font-size: 13px; margin: 0 16px 8px; }

input[type=text], input[type=email], input[type=number], textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 7px 9px;
}
textarea { resize: vertical; min-height: 80px; }
.select { width: auto; }
label.field { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }

/* Structure */
.app { display: flex; flex-direction: column; min-height: 100%; }
.top {
  display: flex;
  align-items: center;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.progress { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; }
.progress-bar { width: 120px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--st-achevee); transition: width .3s; }
.save-state { font-size: 12px; color: var(--muted); min-width: 80px; text-align: right; }
.banner {
  margin: 8px 16px 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: #fef3c7;
  color: #78350f;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* Assistant */
.assistant-btn { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.assistant {
  margin: 10px 16px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 12px;
}
.assistant-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.assistant-form textarea { min-height: 48px; }
.assistant-result:empty { display: none; }
.assistant-result { margin-top: 10px; font-size: 14px; }
.assistant-result ul { margin: 6px 0; padding-left: 20px; }
.assistant-result .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.assistant-result .asked { color: var(--muted); font-style: italic; margin-bottom: 4px; }
.assistant-result .err { color: var(--danger); }
@media (max-width: 820px) { .assistant-form { grid-template-columns: 1fr; } }

.view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.view.active { display: flex; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
}
.modes { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mode { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.mode + .mode { border-left: 1px solid var(--line); }
.mode.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.mode:disabled { color: var(--muted); opacity: .5; cursor: not-allowed; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
}
.chip.off { opacity: .45; text-decoration: line-through; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.count { color: var(--muted); }

/* Plan */
.plan-layout { flex: 1; display: grid; grid-template-columns: 1fr 340px; gap: 12px; padding: 0 16px 16px; min-height: 0; }
.plan-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  min-height: 300px;
  display: flex;
}
#plan { width: 100%; height: 100%; max-height: calc(100vh - 170px); touch-action: none; user-select: none; display: block; }
#plan.mode-add { cursor: crosshair; }
#plan.mode-edit { cursor: crosshair; }
.room rect.body { fill: var(--room); stroke: var(--room-line); stroke-width: .06; }
.room.selected rect.body { fill: var(--room-sel); stroke: var(--accent); stroke-width: .1; }
.room rect.body.outline { stroke-width: .12; }
.room.selected rect.body.outline { stroke-width: .2; }
.room rect.body.fill { stroke: var(--room); stroke-width: .03; } /* couvre le liseré d'anticrénelage entre deux parties */
.room.selected rect.body.fill { stroke: var(--room-sel); stroke-width: .03; }
.room text { fill: var(--muted); font-size: .42px; pointer-events: none; }
.room text.name { fill: var(--text); font-weight: 600; font-size: .5px; }
.mode-edit .room rect.body { cursor: move; }
.room .handle { fill: var(--accent); cursor: nwse-resize; }
.room .bar-bg { fill: var(--surface-2); }
.room .bar { fill: var(--st-achevee); }
.grid line { stroke: var(--line); stroke-width: .02; }
.pin { cursor: pointer; }
.pin circle.hit { fill: transparent; stroke: none; }
.pin circle.mark { stroke: var(--surface); stroke-width: .04; }
.pin.selected circle.mark { stroke: var(--text); stroke-width: .06; }
.pin text { fill: #fff; font-size: .21px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.mode-edit .pin { opacity: .3; pointer-events: none; }
.ghost-rect { fill: var(--room-sel); stroke: var(--accent); stroke-width: .08; stroke-dasharray: .2 .15; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  max-height: calc(100vh - 150px);
}
.panel h2 { font-size: 16px; margin: 0 0 6px; }
.panel h3 { font-size: 14px; margin: 16px 0 6px; }
.panel .row { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.statuses { display: flex; flex-wrap: wrap; gap: 4px; }
.status-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.status-btn.active { border-color: var(--text); font-weight: 600; background: var(--surface-2); }
.mini-list { display: grid; gap: 4px; }
.mini-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.mini-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-line { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.mat-add { display: grid; grid-template-columns: 1fr 90px auto; gap: 6px; }
.size-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Listes */
.list { padding: 0 16px 24px; display: grid; gap: 6px; }
.item {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.item .num {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 12px;
}
.item .title { font-weight: 600; cursor: pointer; overflow-wrap: anywhere; }
.item .sub { font-size: 13px; color: var(--muted); }
.arrows { display: flex; flex-direction: column; gap: 2px; }
.mat-item { grid-template-columns: auto 1fr auto auto auto; }
.mat-item input[type=text] { padding: 4px 7px; }
.mat-fields { display: grid; grid-template-columns: 1fr 110px; gap: 6px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

@media (max-width: 820px) {
  .plan-layout { grid-template-columns: 1fr; }
  #plan { max-height: 60vh; }
  .panel { max-height: none; }
  .progress { margin-left: 0; }
  .item { grid-template-columns: auto auto 1fr; }
  .item > .status-select, .item > .del { grid-column: 3; justify-self: start; }
  .mat-item { grid-template-columns: auto 1fr; }
  .mat-item > :nth-child(n+3) { grid-column: 2; justify-self: start; }
  .mat-fields { grid-template-columns: 1fr; }
}

/* Fiche tâche : titre en tête, numéro discret */
.task-head { display: flex; align-items: flex-start; gap: 8px; }
.task-head .task-title { flex: 1; font-size: 18px; margin: 0; overflow-wrap: anywhere; }
.title-input { font-size: 17px; font-weight: 600; }
.muted.small { font-size: 12px; margin: 4px 0 0; }
