:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --panel-2: #f1efea;
  --border: #e3e0d8;
  --text: #1f1e1c;
  --muted: #6f6b63;
  --accent: #c96442;
  --accent-ink: #ffffff;
  --danger: #b4322a;
  --ok: #2f7d4f;
  --warn: #a8690c;
  --code-bg: #f1efea;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18; --panel: #242320; --panel-2: #2c2b27; --border: #3a3833;
    --text: #ecebe7; --muted: #a29e95; --accent: #d97757; --code-bg: #2c2b27;
    --danger: #e0625a; --ok: #5fbf85; --warn: #e0a54a; --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.spacer { flex: 1; }
code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
a { color: var(--accent); }

/* Boutons & formulaires */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--panel)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
input, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 14px; }
legend { font-size: 13px; font-weight: 600; padding: 0 6px; }
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; }
.options label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 8px; }
.options input { width: auto; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.choice {
  position: relative; display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-weight: 400;
}
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); box-shadow: 0 0 0 1px var(--accent); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-title { font-weight: 600; font-size: 14px; }
.choice-hint { color: var(--muted); font-size: 12.5px; }
@media (max-width: 480px) { .choices { grid-template-columns: 1fr; } }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix input { border-radius: 8px 0 0 8px; }
.suffix {
  display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border); border-left: 0;
  border-radius: 0 8px 8px 0; background: var(--panel-2); color: var(--muted); font-size: 13px; white-space: nowrap;
}
.error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 6px 5px 5px; border: 2.5px solid #fff; border-bottom: 0; border-right: 0; transform: rotate(45deg) translate(2px, 2px); }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { margin-bottom: 8px; }
.login-card .btn { width: 100%; }

/* Mise en page */
.layout { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 280px; flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); gap: 8px; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); gap: 8px; }
.sidebar-foot .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.project-list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.project-list li:hover { background: var(--panel-2); }
.project-list li.active { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.project-list .p-row { display: flex; align-items: center; gap: 8px; }
.project-list .p-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.project-list .p-dom { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list .empty-list { color: var(--muted); font-size: 13px; cursor: default; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.running { background: var(--ok); }
.dot.provisioning, .dot.deleting { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.error { background: var(--danger); }
.dot.busy { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
@keyframes pulse { 50% { opacity: .35; } }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.empty { margin: auto; text-align: center; max-width: 440px; padding: 24px 16px; }
.menu-toggle { display: none; }

.project { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.project-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--panel); }
.project-title { flex: 1; min-width: 0; }
.project-title h1 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { display: flex; align-items: center; gap: 10px; font-size: 13px; flex-wrap: wrap; }
.project-actions { display: flex; gap: 8px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); font-weight: 550; }
.badge.running { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, var(--panel)); }
.badge.provisioning, .badge.deleting { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, var(--panel)); }
.badge.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, var(--panel)); }

.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--panel); }
.tab { border: 0; background: none; font: inherit; color: var(--muted); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 550; }
.tab-panel { flex: 1; min-height: 0; }

/* Discussion */
.chat { display: flex; flex-direction: column; }
.banner { margin: 12px 24px 0; padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 14%, var(--panel)); color: var(--text); font-size: 13px; }
.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 860px; width: 100%; margin: 0 auto; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.msg.user .bubble { background: var(--panel-2); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .bubble { padding: 2px 0; word-wrap: break-word; }
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 1em 0 .4em; font-size: 1.05em; }
.bubble ul, .bubble ol { margin: 0 0 .7em; padding-left: 1.4em; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font: 13px/1.45 var(--mono); }
.bubble pre code { background: none; padding: 0; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.msg .err { color: var(--danger); font-size: 13px; margin-top: 6px; white-space: pre-wrap; }
.status-line { color: var(--muted); font-size: 13px; font-style: italic; }
.cursor::after { content: "▍"; animation: pulse 1s infinite; color: var(--accent); }

.tools { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 8px; }
.tool { font: 12.5px/1.4 var(--mono); border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.tool summary { padding: 5px 9px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool .t-name { font-weight: 650; color: var(--accent); flex: none; }
.tool .t-sum { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .t-state { margin-left: auto; flex: none; }
.tool.fail .t-state { color: var(--danger); }
.tool.ok .t-state { color: var(--ok); }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 12px 24px 16px; }
.composer textarea { resize: vertical; min-height: 64px; max-height: 40vh; display: block; max-width: 860px; margin: 0 auto; }
.composer-actions { display: flex; align-items: center; gap: 8px; margin: 10px auto 0; max-width: 860px; }

/* Infrastructure */
.infra { overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 550; }
.state-running { color: var(--ok); }
.state-exited, .state-dead { color: var(--danger); }
.log { margin: 0; font: 12.5px/1.5 var(--mono); max-height: 360px; overflow: auto; white-space: pre-wrap; background: var(--code-bg); padding: 12px; border-radius: 8px; }

/* Dialogues */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(20, 18, 15, .45); }
.dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100; max-width: calc(100vw - 32px); }

/* Mobile */
@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); width: min(300px, 85vw); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-block; }
  .project-head, .tabs, .composer { padding-left: 16px; padding-right: 16px; }
  .messages, .infra { padding: 16px; }
  .project-actions .btn { padding: 5px 8px; }
  .banner { margin: 12px 16px 0; }
}

/* Contrôle des conteneurs */
.sidebar-nav { padding: 8px; border-top: 1px solid var(--border); }
.sidebar-nav .btn { width: 100%; text-align: left; }
.sidebar-nav .btn.active { background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.ctl { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.ctl .btn { padding: 3px 8px; font-size: 12px; }
.dialog.wide { width: min(1000px, calc(100vw - 32px)); }
.log.tall { max-height: 65vh; min-height: 200px; }
#server .table td { vertical-align: middle; }

/* Onglets supplémentaires */
.tabs { overflow-x: auto; }
.tab { white-space: nowrap; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; text-align: center; margin-left: 4px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 14px; }
.crumbs button { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 2px 4px; border-radius: 4px; }
.crumbs button:hover { background: var(--panel-2); }
.crumbs .sep { color: var(--muted); }
.file-btn { position: relative; overflow: hidden; flex-direction: row; margin: 0; font-weight: 500; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.table .num { text-align: right; white-space: nowrap; }
.table.files td { vertical-align: middle; }
.table.files .fname { display: flex; align-items: center; gap: 8px; word-break: break-all; }
.table.files .fname button { border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; padding: 0; text-align: left; }
.table.files .fname button:hover { color: var(--accent); text-decoration: underline; }
.table.files tr:hover td { background: var(--panel-2); }
.ficon { width: 18px; text-align: center; flex: none; }
.files-card.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
.drop-hint { text-align: center; margin: 12px 0 0; }
.progress { position: relative; height: 22px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: color-mix(in srgb, var(--accent) 35%, transparent); transition: width .2s; }
.progress span { position: relative; font-size: 12px; padding: 0 8px; line-height: 22px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.row > label { flex: 1 1 200px; margin-bottom: 0; }
.row > .btn { flex: none; }
.stack { display: flex; flex-direction: column; gap: 16px; }
select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
.git-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.git-head .branch { font: 600 15px var(--mono); }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, var(--panel)); }
.changes { margin: 0; padding: 0; list-style: none; font: 12.5px/1.6 var(--mono); max-height: 220px; overflow: auto; }
.changes .st { display: inline-block; width: 2.5em; color: var(--warn); font-weight: 700; }
.commits { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.commits li { padding: 5px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.commits code { flex: none; }
.commits .who { color: var(--muted); flex: none; margin-left: auto; white-space: nowrap; }
.out { margin: 10px 0 0; font: 12px/1.45 var(--mono); white-space: pre-wrap; background: var(--code-bg); padding: 8px 10px; border-radius: 6px; max-height: 200px; overflow: auto; }
.env-table input { font-family: var(--mono); font-size: 13px; padding: 6px 8px; }
.env-table td { vertical-align: middle; }
.env-table .key { font: 600 13px var(--mono); word-break: break-all; }
.env-table .hint { display: block; color: var(--muted); font: 12px system-ui, sans-serif; }
.secret-cell { display: flex; gap: 4px; }
.badge.requested { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, var(--panel)); }
.env-file h3 { display: flex; gap: 8px; align-items: center; text-transform: none; letter-spacing: 0; font: 600 14px var(--mono); color: var(--text); }
.env-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Contexte / doc / sauvegardes / équipe / queue / stack */
#context-text, #docs-edit { font: 13.5px/1.5 var(--mono); width: 100%; resize: vertical; }
.docs-view { max-width: none; }
.docs-view:empty::before { content: "Aucune documentation. Cliquez « Générer avec Claude » ou « Modifier »."; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; margin: 0; }
.switch input { width: auto; }
.import-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; }
.import-block summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.import-block label { margin-top: 10px; }
.agent-select { width: auto; max-width: 180px; padding: 6px 8px; font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 10px; }
.tag { font-size: 12.5px; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--border); }
.tag.svc { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.stack-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 14px; align-items: baseline; }
.stack-grid dt { color: var(--muted); }
.stack-grid dd { margin: 0; }
.queue { border-top: 1px solid var(--border); background: var(--panel); padding: 8px 24px; max-height: 32vh; overflow-y: auto; }
.queue h4 { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.qitem { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--bg); }
.qitem.running { border-color: var(--accent); }
.qitem .grip { cursor: grab; color: var(--muted); flex: none; }
.qitem.running .grip { cursor: default; visibility: hidden; }
.qitem .qtext { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.qitem .qrole { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 13%, var(--panel)); color: var(--accent); }
.qitem .qstate { flex: none; font-size: 12px; color: var(--muted); }
.qitem.running .qstate { color: var(--accent); font-weight: 600; }
.qitem.drag { opacity: .4; }
.qitem .x { flex: none; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; }
.qitem .x:hover { color: var(--danger); }
.team-agent { display: flex; gap: 10px; align-items: flex-start; }
.team-agent .aname { flex: none; width: 150px; }
.team-agent .arole { flex: 1; }
.team-agent textarea { width: 100%; resize: vertical; font-size: 13px; }
.msg .role-tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 13%, var(--panel)); color: var(--accent); margin-left: 6px; }
