@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --stone: #eef0ec;
  --surface: #ffffff;
  --ink: #1c2a30;
  --muted: #5d6b70;
  --line: #d3d9d2;
  --basalt: #2e4a52;
  --basalt-dark: #213840;
  --moss: #4f7d57;
  --moss-soft: #e3ede2;
  --danger: #a63d2f;
  --danger-soft: #f6e4e1;
  --amber-soft: #fbf0d9;
  --radius: 8px;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }
body { display: flex; flex-direction: column; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--stone); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--basalt); }
:focus-visible { outline: 3px solid var(--moss); outline-offset: 2px; }

/* Barre du haut */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.25rem; background: var(--basalt); color: #fff; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1rem; color: #fff; text-decoration: none; }
.brand svg { flex: none; }
.brand small { font-weight: 400; opacity: .75; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .875rem; opacity: .85; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .35); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .1); }

/* Boutons et champs */
.btn { font: inherit; font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; background: var(--basalt); color: #fff; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--basalt-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-moss { background: var(--moss); }
.btn-moss:hover { background: #3f6847; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--stone); }
.btn-danger { background: transparent; color: var(--danger); border-color: #e2c3be; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .35rem .7rem; font-size: .825rem; }

label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
input, select, textarea { font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
textarea { resize: vertical; min-height: 5rem; }
input[type=checkbox] { width: auto; margin-right: .45rem; }
.check { display: flex; align-items: center; font-weight: 500; }
.field { margin-bottom: .9rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* Pastilles de statut */
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--stone); color: var(--muted); }
.pill.devis_valide { background: var(--amber-soft); color: #7a5a12; }
.pill.en_conception { background: #e2eaf0; color: var(--basalt); }
.pill.en_ligne { background: var(--moss-soft); color: #2f5a37; }
.pill.suspendu { background: var(--danger-soft); color: var(--danger); }
.pill.alert { background: var(--danger); color: #fff; }

/* Connexion */
.login-wrap { flex: 1; display: grid; place-items: center; padding: 2rem 1rem; }
.login { width: 100%; max-width: 380px; }
.login .peak { display: block; margin: 0 auto 1.25rem; }
.login h1 { text-align: center; margin-bottom: .35rem; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 1.5rem; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.5rem; }
.login .btn { width: 100%; justify-content: center; margin-top: .4rem; }
.login footer { text-align: center; font-size: .8rem; color: var(--muted); margin-top: 1.25rem; }

/* Administration */
#top { flex: none; }
.admin { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 360px) 1fr; }
.client-list { border-right: 1px solid var(--line); background: var(--surface); overflow: auto; }
.client-list header { position: sticky; top: 0; background: var(--surface); padding: 1rem; border-bottom: 1px solid var(--line); display: flex; gap: .5rem; align-items: center; }
.client-list header input { flex: 1; }
.client-item { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; border-bottom: 1px solid var(--line); padding: .8rem 1rem; cursor: pointer; }
.client-item:hover { background: var(--stone); }
.client-item[aria-current=true] { background: #e2eaf0; box-shadow: inset 3px 0 0 var(--basalt); }
.client-item strong { display: block; }
.client-item .meta { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.detail { overflow: auto; padding: 1.5rem 2rem 4rem; }
.detail-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1.5rem; }
.detail-head h1 { margin-right: auto; }
.detail form { max-width: 860px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0 0 1.25rem; padding: 1.1rem 0 0; }
legend { font-weight: 700; font-size: 1rem; padding-right: .6rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid2 .wide { grid-column: 1 / -1; }
.account-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; max-width: 860px; }
.account-box .info { margin-right: auto; }
.sticky-save { position: sticky; bottom: 0; z-index: 2; box-shadow: 0 -6px 12px -8px rgba(28, 42, 48, .25); background: var(--stone); padding: .9rem 0; border-top: 1px solid var(--line); display: flex; gap: .6rem; }
.empty { color: var(--muted); padding: 3rem 1rem; text-align: center; }
.log { font-family: var(--mono); font-size: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; white-space: pre-wrap; max-height: 220px; overflow: auto; }

/* Espace client */
.espace { width: 100%; max-width: 920px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.espace .hello { margin-bottom: 1.75rem; }
.espace .hello p { color: var(--muted); margin: .3rem 0 0; }
.site-band { background: var(--basalt); color: #fff; border-radius: 12px; padding: 1.5rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 2rem; }
.site-band .txt { margin-right: auto; }
.site-band a { color: #fff; }
.site-band .pill { background: rgba(255, 255, 255, .15); color: #fff; }
.site-band .btn { background: #fff; color: var(--basalt); }
.site-band .btn:hover { background: var(--stone); }
.info-section { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.info-section h2 { margin-bottom: .8rem; }
dl.kv { display: grid; grid-template-columns: 180px 1fr; gap: .45rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.secret { font-family: var(--mono); font-size: .875rem; }
.copy-line { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* Studio : conversation façon ChatGPT */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.studio { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, 460px) 1fr; }
.chat { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); min-height: 0; }
.thread { flex: 1; overflow: auto; padding: 1.25rem 1rem .5rem; display: flex; flex-direction: column; gap: 1.1rem; }
.avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--basalt); display: grid; place-items: center; }
.turn.user { align-self: flex-end; max-width: 88%; display: flex; flex-direction: column; align-items: flex-end; }
.turn.user .who { font-size: .72rem; font-weight: 600; color: var(--muted); margin: 0 .4rem .2rem; }
.turn.user .bubble { background: #e6ecee; padding: .6rem .9rem; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn.user.by-admin .bubble { background: var(--moss-soft); }
.turn.assistant { display: flex; gap: .7rem; align-items: flex-start; }
.turn.assistant .body { flex: 1; min-width: 0; padding-top: .15rem; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 .6rem; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: .2rem 0 .7rem; padding-left: 1.25rem; }
.md li { margin: .2rem 0; }
.md h4 { font-size: .95rem; margin: .8rem 0 .35rem; }
.md code { font-family: var(--mono); font-size: .85em; background: var(--stone); padding: .05rem .3rem; border-radius: 4px; }
.md pre { font-family: var(--mono); font-size: .8rem; background: var(--stone); padding: .7rem; border-radius: 8px; overflow-x: auto; }
.md .thinking { color: var(--muted); }
.streaming .md > :last-child::after { content: ''; display: inline-block; width: .5em; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--basalt); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.chip { display: inline-block; margin-top: .5rem; font-size: .78rem; font-weight: 600; padding: .25rem .65rem; border-radius: 999px; background: var(--moss-soft); color: #2f5a37; }
.chip.building { background: #e2eaf0; color: var(--basalt); }
.actions { margin-top: .3rem; opacity: 0; transition: opacity .15s; }
.turn.assistant:hover .actions, .actions:focus-within { opacity: 1; }
.actions button { font: inherit; font-size: .78rem; color: var(--muted); background: none; border: 0; padding: .2rem .35rem; border-radius: 6px; cursor: pointer; }
.actions button:hover { background: var(--stone); color: var(--ink); }
.note { align-self: center; font-size: .8rem; color: var(--muted); text-align: center; max-width: 90%; }
.welcome { margin: auto 0; text-align: center; padding: 1rem .5rem; display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.welcome .avatar { width: 44px; height: 44px; }
.welcome .avatar svg { width: 24px; height: 24px; }
.welcome p { color: var(--muted); margin: 0; max-width: 32ch; }
.suggestions { display: grid; gap: .5rem; width: 100%; margin-top: .75rem; }
.suggestions button { font: inherit; font-size: .875rem; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .85rem; cursor: pointer; }
.suggestions button:hover { border-color: var(--basalt); background: #f6f8f7; }
.composer { padding: .6rem .9rem .8rem; }
.composer-box { display: flex; align-items: flex-end; gap: .4rem; border: 1px solid var(--line); border-radius: 22px; padding: .35rem .35rem .35rem .95rem; background: var(--surface); box-shadow: 0 2px 10px -4px rgba(28, 42, 48, .15); }
.composer-box:focus-within { border-color: var(--basalt); }
.composer-box textarea { border: 0; padding: .45rem 0; min-height: 0; max-height: 200px; resize: none; background: transparent; line-height: 1.45; }
.composer-box textarea:focus-visible { outline: none; }
.send { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--basalt); color: #fff; display: grid; place-items: center; cursor: pointer; }
.send:hover { background: var(--basalt-dark); }
.send .i-stop, .generating .send .i-send { display: none; }
.generating .send .i-stop { display: block; }
.composer-meta { display: flex; align-items: center; gap: .6rem; margin-top: .45rem; font-size: .74rem; color: var(--muted); padding: 0 .4rem; }
.composer-meta select { width: auto; font-size: .8rem; padding: .25rem .4rem; }
.live { font-size: .78rem; font-weight: 600; color: var(--basalt); }
.live::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--moss); margin-right: .35rem; animation: caret 1.2s steps(1) infinite; }

.workbench { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wb-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .55rem .75rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.tabs { display: flex; gap: .2rem; margin-right: auto; overflow-x: auto; }
.tab { font: inherit; font-size: .85rem; font-weight: 600; background: none; border: 0; border-radius: 6px; padding: .4rem .75rem; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab[aria-selected=true] { background: var(--stone); color: var(--ink); }
.tab.code { font-family: var(--mono); font-weight: 500; }
.tab .dirty { color: var(--danger); }
.devices { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.devices button { font: inherit; font-size: .8rem; background: var(--surface); border: 0; padding: .35rem .6rem; cursor: pointer; }
.devices button[aria-pressed=true] { background: var(--basalt); color: #fff; }
.wb-bar select { width: auto; font-size: .85rem; padding: .35rem .5rem; }
.stage { flex: 1; min-height: 0; overflow: auto; display: flex; justify-content: center; background: #dfe3de; }
.stage iframe { border: 0; background: #fff; width: 100%; height: 100%; transition: width .25s ease; }
.stage.tablet iframe { width: 820px; max-width: 100%; box-shadow: 0 0 0 1px var(--line); }
.stage.mobile iframe { width: 390px; max-width: 100%; box-shadow: 0 0 0 1px var(--line); }
.code-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.code-pane textarea { flex: 1; border: 0; border-radius: 0; resize: none; font-family: var(--mono); font-size: .825rem; line-height: 1.6; padding: 1rem; tab-size: 2; background: #f8f9f7; white-space: pre; overflow: auto; }
.code-pane textarea[readonly] { background: #fbfcfa; }

/* Dialogues et notifications */
dialog { border: 0; border-radius: 12px; padding: 1.5rem; width: min(560px, calc(100% - 2rem)); color: var(--ink); }
dialog::backdrop { background: rgba(28, 42, 48, .45); }
dialog h2 { margin-bottom: 1rem; }
dialog .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }
.credentials { background: var(--stone); border-radius: var(--radius); padding: 1rem; font-family: var(--mono); font-size: .9rem; }
#toast { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: var(--radius); font-size: .875rem; max-width: 380px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--moss); }

@media (max-width: 860px) {
  .admin, .studio { grid-template-columns: 1fr; height: auto; }
  .client-list { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat { border-right: 0; border-bottom: 1px solid var(--line); height: 60vh; }
  .workbench { height: 80vh; }
  .detail { padding: 1.25rem 1rem 4rem; }
  dl.kv { grid-template-columns: 1fr; gap: .1rem; }
  dl.kv dd { margin-bottom: .6rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.studio.full { grid-template-columns: 1fr; }
.studio.full .chat { display: none; }
