:root {
  --green: #2A9D8F;
  --green-hover: #6FD1C3;
  --green-dark: #2A9D8F;
  --green-light: #E8F5F2;
  --ink: #2F3B2A;
  --muted: #6B6355;
  --border: #DCD2BC;
  --bg: #F7F2E9;
  --surface: #E9F2EE;
  --on-accent: #FFFFFF;
  --card-radius: 16px;
  --shadow: 0 2px 10px rgba(47, 59, 42, 0.08);
  --danger-bg: rgba(232, 128, 107, 0.12);
  --danger-border: #E8806B;
  --danger-ink: #B95A45;
  --status-no: #E8806B;
  color-scheme: light;
}

html[data-theme="dark"] {
  --green: #4FC3B2;
  --green-hover: #8FE0CE;
  --green-dark: #4FC3B2;
  --green-light: #2C271E;
  --ink: #F2E9DA;
  --muted: #B7AB94;
  --border: #3A352C;
  --bg: #221E17;
  --surface: #2C271E;
  --on-accent: #FFFFFF;
  --card-radius: 16px;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  --danger-bg: rgba(240, 150, 127, 0.15);
  --danger-border: #F0967F;
  --danger-ink: #F0967F;
  --status-no: #F0967F;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--green-dark); text-decoration: none; }

code {
  background: var(--green-light);
  color: var(--ink);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; color: var(--ink); }
.brand .logo { width: 34px; height: auto; flex-shrink: 0; }
.brand-sub { margin-left: 8px; font-size: 0.7rem; font-weight: 600; color: var(--green-dark); background: var(--green-light); padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a { font-size: 1.3rem; padding: 6px 10px; border-radius: 10px; }
.nav a:hover { background: var(--green-light); }
.theme-toggle {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--green-light); }

.ai-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 8px;
  border: 1px solid var(--border);
  background: var(--status-no);
}
.ai-status--online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.ai-status--local { background: #2e9e6b; }
.ai-status--offline { background: var(--status-no); }

.nav-greeting { flex: 1; text-align: center; font-weight: 600; font-size: 1.1rem; color: var(--muted); }
.lang-select {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.lang-select:hover { background: var(--green-light); }
.lang-select option { background: var(--surface); color: var(--ink); }

.container { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }
.foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 20px; }

/* ---- tagline ---- */
.tagline { text-align: center; color: var(--muted); font-size: 1.05rem; margin: 6px 0 26px; }
.tagline strong { color: var(--green-dark); }

/* ---- tool grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease;
  cursor: pointer;
  display: block;
  color: inherit;
}
.card:hover { transform: translateY(-3px); border-color: var(--green); }
.card .icon { font-size: 1.9rem; }
.card .name { font-weight: 700; font-size: 1.1rem; margin: 8px 0 4px; }
.card .desc { color: var(--muted); font-size: 0.9rem; }

/* ---- accueil : second cerveau mis en avant ---- */
.home-hero { margin-bottom: 22px; }
.card--featured { border: 2px solid var(--green); background: var(--green-light); }
.card--featured .icon { font-size: 2.8rem; margin-bottom: 6px; }
.card--featured .name { font-size: 1.35rem; color: var(--ink); }
.card--featured .desc { font-size: 0.98rem; color: var(--ink); }

.badge-new { display: inline-block; font-size: 0.65rem; font-weight: 700; color: var(--on-accent); background: var(--green); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: middle; }

/* ---- tool page ---- */
.tool-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.tool-head .icon { font-size: 2rem; }
.tool-head h1 { margin: 0; font-size: 1.5rem; }
.tool-desc { color: var(--muted); margin: 0 0 20px; }
.back { font-size: 0.9rem; }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
textarea, input[type="text"], select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--green); }
textarea { min-height: 120px; resize: vertical; }

#asst-input {
  font-size: 1.15rem;
  padding: 16px 18px;
  min-height: 56px;
}

.btn[hidden] { display: none; }

.btn {
  display: inline-block;
  border: none;
  background: var(--green);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 12px 26px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--green-hover); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: var(--green-light); color: var(--green-dark); }
.btn.secondary:hover { background: var(--border); }
.btn.small { font-size: 0.9rem; padding: 8px 16px; }

/* ---- result ---- */
.result { margin-top: 26px; }
.result h2 { font-size: 1.1rem; margin: 0 0 12px; }
.step-list { list-style: none; padding: 0; margin: 0; }
.step {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.step .substep { color: var(--muted); font-size: 0.92rem; margin-top: 6px; padding-left: 18px; position: relative; }
.step .substep::before { content: "·"; position: absolute; left: 4px; }
.prose { background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; padding: 16px 18px; white-space: pre-wrap; }
.kv { margin-bottom: 8px; }
.kv b { color: var(--green-dark); }
.tag { display: inline-block; background: var(--green-light); color: var(--green-dark); border-radius: 999px; font-size: 0.8rem; font-weight: 600; padding: 2px 10px; margin: 2px 4px 2px 0; }
.tag--con { background: var(--danger-bg); color: var(--danger-ink); }
.total-bar { background: var(--green); color: var(--on-accent); border-radius: 12px; padding: 12px 16px; font-weight: 700; margin-top: 8px; }
.mini-item { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 8px 2px; }
.recipe { background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.recipe ol { margin: 8px 0 0; padding-left: 20px; }

/* ---- loading / error ---- */
.loading { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { background: var(--danger-bg); border: 1.5px solid var(--danger-border); color: var(--danger-ink); border-radius: 12px; padding: 14px 16px; margin-top: 16px; }
.alert a { text-decoration: underline; color: var(--danger-ink); }

/* ---- taskmaster focus ---- */
.focus-card { background: var(--surface); border: 2px solid var(--green); border-radius: 20px; padding: 34px 26px; text-align: center; box-shadow: var(--shadow); }
.focus-card .step-text { font-size: 1.5rem; font-weight: 700; margin: 10px 0 24px; }
.focus-card .sub-hint { color: var(--muted); font-size: 0.95rem; margin-bottom: 24px; white-space: pre-wrap; }
.focus-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.progress { height: 8px; background: var(--green-light); border-radius: 999px; overflow: hidden; margin: 22px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--green); transition: width 0.3s ease; }
.done-msg { font-size: 1.6rem; font-weight: 800; color: var(--green-dark); }

/* ---- taskmaster focus timer ---- */
.tm-focus-timer-section { margin: 18px 0 10px; }
.tm-focus-timer {
  background: var(--surface);
  border: 2px solid var(--green);
  border-radius: 20px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.tm-focus-remaining {
  display: block;
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: -1px;
}
.tm-focus-track {
  height: 10px;
  background: var(--green-light);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 16px;
}
.tm-focus-fill {
  display: block;
  height: 100%;
  background: var(--green);
  transition: width 0.3s ease;
}
.tm-focus-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.tm-focus-controls .btn { padding: 10px 18px; font-size: 0.95rem; }
.tm-focus-estimating {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}
.tm-focus-list {
  color: var(--green-dark);
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 4px;
}
.tm-focus-task {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 10px;
}

/* ---- modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal__panel {
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--card-radius);
  padding: 26px 30px;
  min-width: 300px;
  max-width: 520px;
  box-shadow: var(--shadow);
  text-align: center;
}
.modal__panel .btn { margin: 6px 6px 0 0; }

/* ---- settings / history ---- */
.panel { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--card-radius); padding: 22px; box-shadow: var(--shadow); }
.hist-item { border-bottom: 1px solid var(--border); padding: 12px 0; }
.hist-item .meta { color: var(--muted); font-size: 0.82rem; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status-dot.ok { background: var(--green); }
.status-dot.no { background: var(--status-no); }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .focus-card .step-text { font-size: 1.25rem; }
}

@media print {
  .topbar, .toast, .magic-todo__toolbar, .magic-todo__add, .tool-help, .magic-todo__dialog, .magic-todo__menu, button, .btn, .magic-todo__plus, .magic-todo__handle, .magic-todo__icon, .magic-todo__twist { display: none !important; }
  .magic-todo__items { margin: 0; }
  .magic-todo__item { border: 1px solid #000; background: #fff !important; color: #000 !important; break-inside: avoid; page-break-inside: avoid; }
  .magic-todo__item--done .magic-todo__text { text-decoration: line-through; color: #555; }
  .magic-todo__text { color: #000 !important; }
  .magic-todo__time, .magic-todo__deadline { color: #333; }
  .magic-todo__sub { color: #333; }
  body { background: #fff !important; color: #000 !important; }
  .container { max-width: 100%; padding: 0; }
  .magic-todo__name { color: #000 !important; }
  .magic-todo__lead { color: #333 !important; }
}

/* ---- assistant "second cerveau" (chat) ---- */
.asst-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2px;
  flex-wrap: wrap;
}
.asst-head .back {
  margin-right: auto;
  white-space: nowrap;
}
.asst-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.asst-brand .icon {
  font-size: 2rem;
  line-height: 1;
}
.asst-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.2px;
}
.asst-brand .asst-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.asst-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.asst-actions .btn.secondary.small {
  font-size: 0.85rem;
  padding: 7px 14px;
}
.asst-sessionbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  flex-wrap: wrap;
}
.asst-sessionbar .asst-session-label {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.85rem;
}
.asst-sessionbar select {
  flex: 1;
  min-width: 140px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
}
.asst-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 0 20px;
}
.msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 85%;
}
.msg--user {
  align-self: flex-end;
}
.msg--assistant {
  align-self: flex-start;
}
.msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.98rem;
}
.msg--user .msg-bubble {
  background: var(--green-light);
  border-color: var(--green-dark);
  color: var(--ink);
}
.msg--assistant .msg-bubble {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}
.msg-meta {
  font-size: 0.7rem;
  color: var(--muted);
}
.msg--user .msg-meta {
  text-align: right;
  margin-left: auto;
}
.msg--assistant .msg-meta {
  text-align: left;
}
.msg-tools {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.msg-tool {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 8px;
  background: var(--bg);
  font-size: 0.68rem;
}
.asst-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 16px;
}
.asst-empty .icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 10px;
  opacity: 0.5;
}
.asst-empty h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  color: var(--ink);
}
.asst-empty p {
  margin: 0;
  font-size: 0.9rem;
}
.asst-input-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0 14px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.asst-input-bar input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.98rem;
  padding: 10px 12px;
  color: var(--ink);
}
.asst-input-bar input:focus {
  outline: 2px solid var(--green);
  outline-offset: 0;
}
.asst-input-bar .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
  white-space: nowrap;
}
.asst-sessions {
  margin-top: 12px;
}
.asst-sessions h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.asst-session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.asst-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.asst-session-item:hover {
  border-color: var(--green);
  background: var(--green-light);
}
.asst-session-item.is-active {
  border-color: var(--green);
  background: var(--green-light);
}
.asst-session-item .name {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.92rem;
}
.asst-session-item .time {
  font-size: 0.7rem;
  color: var(--muted);
}
@media (max-width: 560px) {
  .asst-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .asst-head .back {
    margin-right: 0;
  }
  .asst-brand {
    flex: none;
    width: 100%;
  }
  .asst-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .msg {
    max-width: 92%;
  }
}
