/* Version web de CCS : mêmes couleurs que l'application GTK (libadwaita), clair et sombre selon
   le système, une colonne sur téléphone (moins de 720 px), cibles tactiles d'au moins 44 px. */

:root {
  --accent: #3584e4;
  --accent-fg: #ffffff;
  --success: #2ec27e;
  --warning: #e5a50a;
  --error: #e01b24;
  --bg: #fafafb;
  --fg: #1e1e22;
  --card: #ffffff;
  --line: rgba(0, 0, 0, 0.09);
  --soft: rgba(0, 0, 0, 0.04);
  --subtle: rgba(30, 30, 34, 0.62);
  --shadow: 0 0 0 1px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.10);
  --radius: 14px;
  --mono: "JetBrains Mono", "DejaVu Sans Mono", ui-monospace, monospace;
  --nav-h: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #222226;
    --fg: #f2f2f5;
    --card: #2e2e33;
    --line: rgba(255, 255, 255, 0.10);
    --soft: rgba(255, 255, 255, 0.05);
    --subtle: rgba(242, 242, 245, 0.62);
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 Cantarell, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden; -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.15rem; }
code, pre { font-family: var(--mono); font-size: 0.9em; }
pre { overflow-x: auto; background: var(--soft); padding: 10px 12px; border-radius: 10px; }
img { max-width: 100%; }

.subtle { color: var(--subtle); font-size: 0.92em; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: 0 0 0 1px var(--line); }
.empty { text-align: center; padding: 36px 16px; }
.big-number { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* ---- boutons et champs ---- */
button, .button {
  min-height: 44px; min-width: 44px; padding: 0 16px; border-radius: 10px;
  border: 0; background: var(--soft); color: var(--fg); font: inherit; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover { filter: brightness(0.96); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); }
button.danger { background: var(--error); color: #fff; }
button.flat { background: transparent; }
button.small { min-height: 36px; padding: 0 12px; font-size: 0.92em; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.92em; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: 44px; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--accent); }
label.check > span { flex: 1; min-width: 0; text-align: left; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- bandeau ---- */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; padding: 8px 14px; text-align: center;
  font-weight: 600; background: var(--accent); color: #fff;
}
.banner.warning { background: var(--warning); color: #1e1e22; }
.banner.error { background: var(--error); }

/* ---- connexion ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); display: grid; gap: 14px; padding: 24px; }
.login-head { display: flex; align-items: center; gap: 12px; }
.login-logo { width: 44px; height: 44px; }
#login-credentials { display: grid; gap: 14px; }
.enroll { display: grid; gap: 8px; }
.qr { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; justify-self: center; }
.message { color: var(--error); min-height: 1.2em; margin: 0; }

/* ---- charpente ---- */
.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; margin: 0 auto; }
.nav a {
  display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  border-radius: 10px; color: var(--fg); text-decoration: none; font-weight: 600;
}
.nav a.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.view { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
.view[data-view="sessions"] { max-width: none; padding: 0; }

/* ---- téléphone : barre de navigation en bas ---- */
@media (max-width: 719px) {
  body { font-size: 16px; }
  .topbar { padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); }
  .topbar .brand span, #logout { font-size: 0.9em; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; margin: 0; z-index: 20; justify-content: space-around;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 4px 4px max(4px, env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 0; padding: 4px 6px; font-size: 0.75em; min-width: 64px; }
  .nav-icon { font-size: 1.3em; line-height: 1.2; }
  .view { padding: 10px; padding-bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
  .view[data-view="sessions"] { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}
#logout { margin-left: auto; }

/* ---- éléments communs des écrans ---- */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; }
.grow { flex: 1; min-width: 0; }
.badge { padding: 2px 10px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 0.8em; font-weight: 700; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.invalid { outline: 2px solid var(--error); }

/* ---- accueil ---- */
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.status-line .subtle { flex: 1; min-width: 200px; }
.accounts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.accounts > *, .analysis > * { min-width: 0; }
.account { display: grid; gap: 10px; border-top: 4px solid var(--account, var(--accent)); }
.account.active { box-shadow: 0 0 0 2px var(--account, var(--accent)), var(--shadow); }
.account-head { display: flex; align-items: center; gap: 10px; }
.account-head > div { flex: 1; min-width: 0; }
.account-head .subtle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gauge { display: grid; gap: 4px; }
.gauge-head { display: flex; justify-content: space-between; font-size: 0.92em; }
.gauge-track { height: 10px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.gauge-fill.warn { background: var(--warning); }
.gauge-fill.danger { background: var(--error); }
.pause-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.pause-box select { width: auto; }

/* ---- analyse ---- */
.analysis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }
.bar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr 56px; gap: 8px; align-items: center; padding: 3px 0; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.9em; }
.hours { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.hour { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.view > .row select { width: auto; }

/* ---- réglages ---- */
.settings { display: grid; gap: 12px; max-width: 640px; }

/* ---- sessions et chat ---- */
.sessions { display: grid; grid-template-columns: auto minmax(0, 1fr); height: calc(100dvh - 57px); }
.sessions > .side { width: 320px; }
.sessions.side-hidden { grid-template-columns: 1fr; }
.sessions.side-hidden > .side { display: none; }
.side-toggle { min-width: 40px; padding: 0 8px; }
.side { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; align-content: start; }
.side h3 { font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--subtle); margin: 10px 0 0; }
.new-session { display: flex; gap: 6px; align-items: center; }
.new-session input { flex: 1; min-width: 0; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: transparent;
  text-align: left; width: 100%; font-weight: 400; min-height: 44px; }
.item:hover { background: var(--soft); }
.item.conv { flex-direction: column; align-items: flex-start; gap: 2px; }
.item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.back { display: none; }
.tabs { display: flex; overflow-x: auto; gap: 2px; padding: 4px; }
.tab { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 12px; border-radius: 8px; min-height: 40px;
  white-space: nowrap; cursor: pointer; }
.tab.active { background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 700; }
.tab-close { min-width: 36px; min-height: 36px; padding: 0; }
.stage { flex: 1; min-height: 0; display: flex; padding: 0; }
.stage > .card.empty { margin: 16px; flex: 1; }
.holder { flex: 1; min-width: 0; display: flex; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; --chat-column: 900px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.chat-head .subtle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: min(860px, 100%); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: color-mix(in srgb, var(--accent) 20%, transparent); padding: 10px 14px;
  border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.msg.claude { align-self: flex-start; }
.msg.claude table { border-collapse: collapse; display: block; overflow-x: auto; }
.msg.claude th, .msg.claude td { border: 1px solid var(--line); padding: 4px 8px; }
.tool { background: var(--soft); border-radius: 10px; border-left: 3px solid var(--accent); padding: 6px 10px; font-size: 0.92em; max-width: min(860px, 100%); }
.tool.done { border-left-color: var(--success); }
.tool.error { border-left-color: var(--error); }
.tool.nested { margin-left: 18px; }
.tool-group { max-width: min(860px, 100%); border-radius: 10px; background: var(--soft); }
.tool-group > summary { cursor: pointer; display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92em; }
.tool-group > summary .subtle { overflow: hidden; text-overflow: ellipsis; }
.tool-group-body { display: grid; gap: 4px; padding: 0 6px 6px; }
.tool summary { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 32px; display: flex; align-items: center; gap: 6px; }
.tool pre { max-height: 320px; overflow: auto; white-space: pre-wrap; }
.permission { border-left: 4px solid var(--warning); display: grid; gap: 8px; max-width: min(860px, 100%); }
.permission pre { white-space: pre-wrap; margin: 0; }
.permission fieldset { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 4px; }
.notice { align-self: center; font-size: 0.9em; color: var(--subtle); text-align: center; }
.notice.warning { color: var(--warning); }
.notice.error { color: var(--error); }
.composer { border-top: 1px solid var(--line); padding: 8px 10px; display: grid; gap: 6px; background: var(--bg); }
/* Grand écran : fil et saisie dans une même colonne centrée. */
.thread { padding-inline: max(14px, calc((100% - var(--chat-column)) / 2)); }
.composer { padding-inline: max(10px, calc((100% - var(--chat-column)) / 2)); }
.composer-row { display: flex; gap: 6px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 220px; flex: 1; }
.chat-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-bar select { width: auto; min-height: 36px; padding: 4px 8px; font-size: 0.88em; }
.todos { background: var(--soft); border-radius: 10px; padding: 6px 10px; font-size: 0.9em; display: grid; gap: 2px; max-height: 120px; overflow-y: auto; }
.todo.completed { color: var(--subtle); text-decoration: line-through; }
.todo.in_progress { font-weight: 700; }
.thumbs { display: flex; gap: 6px; }
.thumbs:empty { display: none; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; cursor: pointer; }

@media (max-width: 719px) {
  .sessions > .side { width: auto !important; }
  .sessions.side-hidden > .side { display: grid; }
  .side-toggle, .resize-handle { display: none; }
  .sessions { grid-template-columns: 1fr; height: calc(100dvh - 49px - var(--nav-h) - env(safe-area-inset-bottom)); }
  .sessions.chat-open .side { display: none; }
  .sessions:not(.chat-open) .main { display: none; }
  .side { border-right: 0; }
  .back { display: inline-flex; }
  .thread { padding: 8px; gap: 8px; }
  .composer { padding-bottom: 6px; }
  .tool, .tool-group > summary { font-size: 0.85em; }
  .tool { padding: 2px 8px; }
  .tool summary { min-height: 30px; }
  .tool-group > summary { min-height: 34px; }
  .msg.user .bubble { padding: 8px 12px; }
  .chat-head .grow .subtle { display: none; }
  /* une seule barre en haut : celle du chat (retour, titre, actions) */
  .sessions.chat-tab .tabs-row { display: none; }
  .chat-head { padding: 2px 4px; gap: 2px; }
  .chat-head .title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1em; }
  .back-chat { min-width: 40px; padding: 0 6px; font-size: 1.25em; }
  /* zone de saisie : la place au texte */
  .composer { padding: 6px 8px max(6px, env(safe-area-inset-bottom)); gap: 4px; }
  .composer-row { gap: 4px; }
  .composer-row .icon { min-width: 36px; padding: 0 4px; }
  .send-label { display: none; }
  .send { min-width: 44px; padding: 0 12px; }
  .composer-foot { font-size: 0.85em; }
  /* blocs de code plus serrés */
  .code-wrap pre { font-size: 0.8em; padding: 8px 10px; }
}

/* ---- tiroir Fichiers / Feuille de route, terminal ---- */
.chat-body { flex: 1; display: flex; min-height: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.drawer { width: min(380px, 42%); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.drawer-head { display: flex; align-items: center; padding: 4px 4px 4px 12px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow: auto; padding: 8px; }
.tree { list-style: none; margin: 0; padding-left: 12px; }
.drawer-body > .files > .tree { padding-left: 0; }
.tree-row { width: 100%; min-height: 36px; justify-content: flex-start; background: transparent; font-weight: 400; padding: 0 6px; gap: 4px; text-align: left; }
.tree-row:hover { background: var(--soft); }
.tree-row .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.twisty { width: 14px; display: inline-block; transition: transform 0.1s; }
.tree-row.open .twisty { transform: rotate(90deg); }
.mark { font-family: var(--mono); font-size: 0.8em; font-weight: 700; }
.m-M { color: var(--warning); } .m-A, .m-n { color: var(--success); } .m-D { color: var(--error); }
.file-holder { display: flex; flex-direction: column; gap: 6px; height: 100%; }
.file-head { display: flex; align-items: center; gap: 4px; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-text { flex: 1; min-height: 50vh; font-family: var(--mono); font-size: 0.85em; resize: vertical; white-space: pre; }
.file-preview { overflow-wrap: anywhere; }
.roadmap .phase { border-bottom: 1px solid var(--line); padding: 6px 0; }
.roadmap summary { display: flex; gap: 8px; cursor: pointer; font-weight: 700; min-height: 36px; align-items: center; }
.roadmap .bar-track { margin: 4px 0 6px; }
.task { font-weight: 400; min-height: 36px; align-items: flex-start; padding-top: 6px; }
.task.done span { color: var(--subtle); }
.depth-1 { margin-left: 18px; } .depth-2 { margin-left: 36px; } .depth-3 { margin-left: 54px; }
.term { flex: 1; min-width: 0; min-height: 0; padding: 6px; background: var(--card); }
.term-box { height: 360px; display: flex; margin-top: 8px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }

@media (max-width: 719px) {
  .drawer, .drawer.resizable { position: absolute; inset: 0; width: 100% !important; z-index: 15; border-right: 0; }
  .chat-body { position: relative; }
  .term-box { height: 300px; }
}

/* ---- toasts, carte de confirmation, chargement et états vides (dom.js) ---- */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 50;
  display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; border-radius: var(--radius);
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: var(--error); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
.toast button { color: inherit; min-height: 36px; }
.toast.leaving { opacity: 0; transition: opacity 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
dialog.sheet {
  border: 0; border-radius: var(--radius); padding: 18px; width: min(440px, calc(100vw - 24px));
  background: var(--card); color: var(--fg); box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
dialog.sheet h2 { margin: 0 0 6px; font-size: 1.1em; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.state { display: grid; justify-items: center; align-content: center; gap: 8px; padding: 24px 12px; text-align: center; color: var(--subtle); }
.stage > .state { flex: 1; }                     /* aucun chat ouvert : centré dans la zone */
.state p { margin: 0; }
.state.loading { grid-auto-flow: column; justify-content: center; align-items: center; }
.state.error { color: var(--error); }
.state-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.nav a { position: relative; }
.nav-badge {
  position: absolute; top: 2px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--error); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}

/* ---- téléphone : un chat ouvert prend tout l'écran (sessions.js pose body.chat-mode) ---- */
@media (max-width: 719px) {
  body.chat-mode .topbar, body.chat-mode .nav { display: none; }
  body.chat-mode .view[data-view="sessions"] { padding-bottom: 0; }
  body.chat-mode .sessions { height: 100dvh; padding-top: env(safe-area-inset-top); }
  .toasts { bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }
  body.chat-mode .toasts { bottom: 90px; }
}

/* Une grille d'une seule colonne ne s'élargit jamais au-delà de son conteneur : sans cela, une
   ligne sans retour (adresse e-mail d'un compte, chemin, commande) élargit la colonne, et les
   barres et boutons débordent de la carte. */
.view, .account, .gauge, .section, .stack, details.details > div, .health-check, .settings-group,
.settings-wrap, .settings, .running, .changes, .git, .new-sheet, .preview-body, .file-results,
.saved-list, .permission, .composer { grid-template-columns: minmax(0, 1fr); }

/* ---- sections redimensionnables (dom.js resizable) ---- */
.resizable { position: relative; flex: none; }
.resize-handle { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 5; touch-action: none; }
.resize-handle:hover, body.resizing .resize-handle { background: color-mix(in srgb, var(--accent) 35%, transparent); }
body.resizing { user-select: none; cursor: col-resize; }

.send-icon { display: none; }
@media (max-width: 719px) { .send-icon { display: inline; font-size: 1.1em; line-height: 1; } }

/* ---- installer l'application (install.js) ---- */
.install-banner { position: fixed; z-index: 40; left: 12px; right: 12px; bottom: 12px; margin: 0 auto; max-width: 520px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 12px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.25); }
.install-banner img { border-radius: 10px; flex: none; }
.install-text { flex: 1; min-width: 180px; display: grid; gap: 2px; }
.install-actions { display: flex; gap: 6px; margin-left: auto; }
.install-steps { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 4px; font-size: 0.92em; }
@media (max-width: 719px) {
  .install-banner { bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom)); }
}
