:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface2: #f6f8fb;
  --border: #e4e8ef;
  --border-strong: #d4dae3;
  --text: #17203a;
  --muted: #67708a;
  --accent: #3556f0;
  --accent-soft: #eef1fe;
  --accent-grad: linear-gradient(135deg, #3556f0, #5a71f5);
  --green: #17924a;
  --green-soft: #e7f7ee;
  --red: #d5303e;
  --red-soft: #fdeeef;
  --amber: #b26a00;
  --amber-soft: #fff6e6;
  --shadow-sm: 0 1px 2px rgba(23, 32, 58, 0.06), 0 1px 3px rgba(23, 32, 58, 0.08);
  --shadow-md: 0 4px 16px rgba(23, 32, 58, 0.10);
  --shadow-lg: 0 12px 40px rgba(23, 32, 58, 0.16);
  --r-lg: 18px;
  --r-md: 13px;
  --r-sm: 9px;
  --z-header: 100;
  --z-composer: 100;
  --z-welcome: 50;
  --z-drawer: 200;
  --z-login: 300;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font: 15.5px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior: none;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ================= Login ================= */
.login {
  position: fixed; inset: 0; z-index: var(--z-login);
  background:
    radial-gradient(1200px 600px at 50% -200px, #e3e9ff 0%, transparent 60%),
    var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 36px 28px 28px;
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.login-mark {
  width: 64px; height: 64px; margin: 0 auto 4px;
  background: var(--accent-grad); color: #fff;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; letter-spacing: 0.5px;
  box-shadow: 0 8px 24px rgba(53, 86, 240, 0.35);
}
.login-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.login-sub { margin: 0 0 10px; color: var(--muted); font-size: 13.5px; }
.login input {
  background: var(--surface2); border: 1.5px solid var(--border); color: var(--text);
  border-radius: var(--r-md); padding: 14px 16px; font-size: 16px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.login button {
  background: var(--accent-grad); color: #fff; font-weight: 600; font-size: 16px;
  border: none; border-radius: var(--r-md); padding: 14px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(53, 86, 240, 0.3);
  transition: transform 0.1s;
}
.login button:active { transform: scale(0.98); }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }
.login-foot { margin-top: 20px; color: var(--muted); font-size: 12px; font-family: var(--mono); }

/* ================= Layout ================= */
.app { display: flex; flex-direction: column; height: 100dvh; }

.header {
  position: sticky; top: 0; z-index: var(--z-header);
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
}
.header-mid { flex: 1; min-width: 0; }
.project-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px 6px 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; transition: background 0.3s; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.project-sel {
  flex: 1; min-width: 0;
  background: none; color: var(--text); border: none;
  font-size: 15px; font-weight: 600; outline: none;
  appearance: none; -webkit-appearance: none;
  text-overflow: ellipsis;
  padding-right: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%2367708a' stroke-width='2.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right center; background-size: 13px;
}
.icon-btn {
  background: none; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active { background: var(--surface2); }
.icon-btn.accent { color: var(--accent); background: var(--accent-soft); }
.mode-btn {
  border: 1px solid var(--border); background: var(--green-soft); color: var(--green);
  font-size: 12.5px; font-weight: 700; border-radius: 999px; padding: 7px 13px;
  cursor: pointer; flex-shrink: 0; letter-spacing: 0.2px;
}
.mode-btn.auto { color: var(--amber); background: var(--amber-soft); }

/* ================= Welcome ================= */
.welcome {
  position: absolute; inset: 0; z-index: var(--z-welcome);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 32px; text-align: center; pointer-events: none;
}
.welcome > * { pointer-events: auto; }
.welcome-mark {
  width: 72px; height: 72px;
  background: var(--accent-grad); color: #fff;
  border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 25px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(53, 86, 240, 0.3);
  margin-bottom: 8px;
}
.welcome h2 { margin: 0; font-size: 21px; letter-spacing: -0.3px; }
.welcome p { margin: 0; color: var(--muted); font-size: 14.5px; max-width: 300px; }
.hints { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.hint {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: 13.5px;
  border-radius: 999px; padding: 9px 15px; cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.hint:active { background: var(--surface2); }

/* ================= Messages ================= */
.app { position: relative; }
.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 24px;
  display: flex; flex-direction: column; gap: 12px;
  max-width: 780px; width: 100%; margin: 0 auto;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.messages > * { animation: msg-in 0.22s ease-out; }

.msg-user {
  align-self: flex-end; max-width: 85%;
  background: var(--accent-grad); color: #fff;
  border-radius: 20px 20px 6px 20px;
  padding: 11px 16px;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 3px 10px rgba(53, 86, 240, 0.25);
  font-size: 15.5px;
}
.msg-claude {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 13px 16px;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}
.msg-claude .md > :first-child { margin-top: 0; }
.msg-claude .md > :last-child { margin-bottom: 0; }
.md p { margin: 0.55em 0; }
.md pre {
  background: #f6f8fa; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 11px; overflow-x: auto; font-size: 12.5px; line-height: 1.5;
}
.md code { font-family: var(--mono); font-size: 0.88em; }
.md :not(pre) > code { background: var(--accent-soft); color: #2c46c8; padding: 1px 6px; border-radius: 6px; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.02em; margin: 0.9em 0 0.35em; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; }
.md th { background: var(--surface2); }
.md a { color: var(--accent); }
.md ul, .md ol { padding-left: 1.35em; margin: 0.5em 0; }
.md blockquote { margin: 0.6em 0; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--border); }

.thinking {
  color: var(--muted); font-style: italic; font-size: 13px;
  border-left: 2.5px solid var(--border-strong); padding-left: 12px;
  white-space: pre-wrap; word-break: break-word;
}
details.thinking-box { padding: 2px 4px; }
details.thinking-box summary { color: var(--muted); font-size: 12.5px; cursor: pointer; }

.meta-line {
  align-self: center; text-align: center;
  color: var(--muted); font-size: 11px; font-family: var(--mono);
  background: var(--surface2); border-radius: 999px; padding: 3px 12px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.error-box {
  background: var(--red-soft); border: 1px solid #f3c2c6;
  color: var(--red); border-radius: var(--r-md); padding: 11px 14px;
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
}

/* ================= Cartes outils ================= */
.tool {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; font-size: 13px;
  box-shadow: var(--shadow-sm);
}
.tool summary {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 13px; cursor: pointer; list-style: none; user-select: none;
  min-height: 44px;
}
.tool summary::-webkit-details-marker { display: none; }
.tool .t-icon {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; background: var(--surface2);
}
.tool .t-icon.bash { background: #eceff5; }
.tool .t-icon.edit { background: var(--amber-soft); }
.tool .t-icon.read { background: #e8f3fd; }
.tool .t-icon.web { background: #e9f6f2; }
.tool .t-name { font-weight: 700; font-family: var(--mono); font-size: 12.5px; flex-shrink: 0; color: var(--text); }
.tool .t-sub {
  color: var(--muted); font-family: var(--mono); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.tool .t-state { flex-shrink: 0; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 3px 8px; }
.tool .t-state.pending { color: var(--amber); background: var(--amber-soft); }
.tool .t-state.ok { color: var(--green); background: var(--green-soft); }
.tool .t-state.err { color: var(--red); background: var(--red-soft); }
.tool-body { border-top: 1px solid var(--border); padding: 9px 13px 11px; background: var(--surface2); }
.tool-body pre {
  margin: 6px 0; background: #ffffff; border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px;
  overflow-x: auto; font-size: 12px; font-family: var(--mono);
  white-space: pre-wrap; word-break: break-word;
}
.tool-body .label {
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.7px; margin-top: 6px;
}
.see-more { background: none; border: none; color: var(--accent); font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 4px 0; }

/* diffs — style GitHub clair */
.diff {
  font-family: var(--mono); font-size: 12px; margin: 6px 0;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden; background: #fff;
}
.diff .dl { padding: 2px 10px; white-space: pre-wrap; word-break: break-word; }
.diff .del { background: #ffebe9; color: #82071e; }
.diff .add { background: #e6ffec; color: #055d20; }

/* todos */
.todos { margin: 4px 0; padding: 0; list-style: none; font-size: 13.5px; }
.todos li { padding: 3px 0; }
.todos .done { color: var(--muted); text-decoration: line-through; }
.todos .doing { color: var(--accent); font-weight: 600; }

/* ================= Permission ================= */
.perm {
  background: var(--amber-soft); border: 1.5px solid #f0c36b;
  border-radius: var(--r-lg); padding: 14px; font-size: 13.5px;
  box-shadow: var(--shadow-md);
}
.perm-title { font-weight: 700; color: var(--amber); margin-bottom: 8px; font-size: 14px; }
.perm pre {
  background: #fff; border: 1px solid #eddcb8; border-radius: var(--r-sm); padding: 9px;
  overflow-x: auto; font-size: 12px; font-family: var(--mono);
  white-space: pre-wrap; word-break: break-word;
  max-height: 200px; overflow-y: auto; margin: 0;
}
.perm-actions { display: flex; gap: 10px; margin-top: 12px; }
.perm-actions button {
  flex: 1; padding: 12px; border-radius: var(--r-md); border: none;
  font-size: 15px; font-weight: 700; cursor: pointer; min-height: 46px;
}
.perm-allow { background: var(--green); color: #fff; box-shadow: 0 3px 10px rgba(23, 146, 74, 0.3); }
.perm-deny { background: #fff; color: var(--red); border: 1.5px solid #f3c2c6 !important; }
.perm-resolved { color: var(--muted); font-size: 12.5px; margin-top: 10px; font-weight: 600; }

/* ================= Indicateur travail ================= */
.working {
  align-self: flex-start;
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px;
  box-shadow: var(--shadow-sm);
}
.dots { display: flex; gap: 4px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1.1); } }

/* ================= Composer ================= */
.composer {
  position: sticky; bottom: 0; z-index: var(--z-composer);
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 780px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 7px 7px 7px 18px;
  box-shadow: var(--shadow-md);
}
#input {
  flex: 1; background: none; color: var(--text);
  border: none;
  padding: 9px 0; font-size: 16px; line-height: 1.45;
  resize: none; outline: none; max-height: 140px;
  font-family: inherit;
}
#input::placeholder { color: var(--muted); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--accent-grad); color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(53, 86, 240, 0.35);
  transition: transform 0.1s, opacity 0.15s;
}
.send-btn svg { width: 19px; height: 19px; }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.35; }
.send-btn.stop { background: var(--red); box-shadow: 0 3px 10px rgba(213, 48, 62, 0.35); }

/* ================= Drawer ================= */
.drawer { position: fixed; inset: 0; z-index: var(--z-drawer); }
.drawer-back { position: absolute; inset: 0; background: rgba(23, 32, 58, 0.35); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
@keyframes slide-in { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-panel {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(330px, 88vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  animation: slide-in 0.22s ease-out;
  border-radius: 0 20px 20px 0;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 10px 12px 20px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 17px;
}
.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  padding: 12px 12px; border-radius: var(--r-md); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 2px;
}
.chat-item:active { background: var(--surface2); }
.chat-item.active { background: var(--accent-soft); }
.chat-item .ci-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-item .ci-title { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-meta { font-size: 11.5px; color: var(--muted); }
.chat-item .ci-running { color: var(--green); font-weight: 700; }
.ci-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.ci-del:active { background: var(--red-soft); color: var(--red); }
.chat-empty { color: var(--muted); text-align: center; padding: 32px 16px; font-size: 14px; }
.logout-btn {
  margin: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface2); border: 1px solid var(--border); color: var(--red);
  border-radius: var(--r-md); padding: 13px; font-size: 14.5px; font-weight: 600; cursor: pointer;
}

/* écrans plus larges */
@media (min-width: 700px) {
  .header { padding-left: 16px; padding-right: 16px; }
  .messages { padding: 24px 20px 32px; }
}
