/* Nommage Client-First (Finsweet) */
:root {
  --color-background: #0b0d10;
  --color-surface: #12151a;
  --color-surface-alt: #1b1f27;
  --color-border: #272c36;
  --color-text: #e9ebee;
  --color-text-muted: #8b93a0;
  --color-accent: #f5a524;
  --color-accent-contrast: #1a1204;
  --color-error: #ff6b6b;
  --color-success: #4cd787;
  /* Apparence arrondie (par défaut) */
  --radius-field: 1.4rem;
  --radius-control: 999px;
  --radius-item: 999px;
  --radius-bubble: 1.5rem;
  --radius-block: 1.1rem;
  --radius-modal: 1.75rem;
  --radius-panel: 1.6rem;
  --layout-gap: 0.75rem;
  --panel-border-width: 1px;
  --panel-background: rgba(18, 21, 26, 0.72);
  --item-padding-x: 0.9rem;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}
/* Apparence classique : angles peu arrondis, panneaux bord à bord */
html.is-classic {
  --radius-field: 0.6rem;
  --radius-control: 0.6rem;
  --radius-item: 0.5rem;
  --radius-bubble: 0.9rem;
  --radius-block: 0.6rem;
  --radius-modal: 0.9rem;
  --radius-panel: 0;
  --layout-gap: 0;
  --panel-border-width: 0;
  --panel-background: transparent;
  --item-padding-x: 0.6rem;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: radial-gradient(60rem 22rem at 50% -8rem, rgba(245, 165, 36, 0.13), transparent 70%) no-repeat, var(--color-background);
  color: var(--color-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}
.page-wrapper { height: 100vh; height: 100dvh; } /* dvh : tient compte des barres du navigateur mobile */
.main-wrapper { height: 100%; }

/* Utilitaires */
.padding-global { padding-left: 1.25rem; padding-right: 1.25rem; }
.container-small { max-width: 24rem; margin: 0 auto; }
.heading-style-h3 { font-size: 1.25rem; margin: 0; }
.text-size-regular { font-size: 1rem; margin: 0; }
.text-size-small { font-size: 0.875rem; margin: 0; }
.text-color-muted { color: var(--color-text-muted); }
.text-color-error { color: var(--color-error); }
.text-color-success { color: var(--color-success); }

/* Marque */
.brand_component { display: flex; align-items: center; gap: 0.6rem; }
.brand_logo { width: 1.75rem; height: 1.75rem; flex-shrink: 0; }
.brand_logo rect { fill: var(--color-surface-alt); }
.brand_logo path { fill: var(--color-accent); }
.brand_name { font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem; letter-spacing: -0.02em; }
.brand_component.is-large .brand_logo { width: 2.25rem; height: 2.25rem; }
.brand_component.is-large .brand_name { font-size: 1.6rem; }

/* Formulaires et boutons */
.form_field-wrapper { display: flex; flex-direction: column; gap: 0.3rem; }
.form_label { font-size: 0.875rem; color: var(--color-text-muted); }
.form_input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--color-background);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-field);
  font: inherit;
}
input.form_input, select.form_input { border-radius: var(--radius-control); padding-left: 1rem; padding-right: 1rem; }
html.is-classic input.form_input, html.is-classic select.form_input { padding-left: 0.75rem; padding-right: 0.75rem; }
.form_input:focus { outline: 2px solid var(--color-accent); outline-offset: -1px; }
.form_input.is-textarea { resize: none; max-height: 12rem; background: var(--color-surface); }
.form_input.is-select { width: auto; max-width: 100%; background: var(--color-surface); }
.form_input.is-small { padding: 0.45rem 0.65rem; font-size: 0.9rem; }
.button {
  padding: 0.65rem 1rem;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border: 1px solid var(--color-accent);
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.button:hover { filter: brightness(1.08); }
.button.is-secondary { background: transparent; color: var(--color-text); border-color: var(--color-border); font-weight: 500; }
.button.is-secondary:hover { background: var(--color-surface-alt); filter: none; }
.button.is-small { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.button.is-icon { width: 2.75rem; height: 2.75rem; padding: 0; font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.button.is-stop { background: var(--color-error); border-color: var(--color-error); color: #fff; }
.button:disabled { opacity: 0.5; cursor: default; }
.button-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.button-group.is-nowrap { flex-wrap: nowrap; }

/* Pastille d'état du gros PC et mesures d'utilisation */
.status_component { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
/* Jauges : CPU au-dessus de GPU, RAM au-dessus de VRAM, juste à droite du milieu de l'écran */
/* Le bord gauche vise 53 % de la largeur d'écran ; sur un écran étroit, les jauges se rangent juste après le bouton d'aide (800px = largeur de ce qui les précède) */
.status_stats { display: grid; grid-template-columns: auto auto; gap: 0.5rem 1.4rem; margin-left: max(2rem, calc(52vw - 800px)); }
.gauge_component { display: flex; align-items: center; gap: 0.5rem; }
.gauge_component.is-unknown { opacity: 0.4; }
.gauge_label { width: 3rem; font-family: var(--font-mono); font-size: 0.9rem; font-weight: 600; letter-spacing: 0.03em; color: var(--color-text); }
.gauge_track { display: block; width: 4.75rem; height: 0.6rem; border-radius: 999px; background: var(--color-surface-alt); box-shadow: inset 0 0 0 1px var(--color-border); overflow: hidden; }
.gauge_fill {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, #2fb872, var(--color-success));
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.4s;
}
.gauge_fill.is-mid { background: linear-gradient(90deg, #d98a12, var(--color-accent)); }
.gauge_fill.is-high { background: linear-gradient(90deg, #e04848, var(--color-error)); box-shadow: 0 0 0.5rem rgba(255, 107, 107, 0.6); }
.status_pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--color-border); border-radius: 999px;
  font-size: 0.8125rem; color: var(--color-text-muted); white-space: nowrap;
}
.status_pill::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--color-text-muted); }
.status_pill.is-online { color: var(--color-text); }
.status_pill.is-online::before { background: var(--color-success); }
.status_pill.is-offline { color: var(--color-error); border-color: var(--color-error); }
.status_pill.is-offline::before { background: var(--color-error); }

/* Fenêtres */
.modal_component { width: min(26rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-modal); background: var(--color-surface); color: var(--color-text); }
.modal_component.is-wide { width: min(46rem, calc(100% - 2rem)); }
.modal_component::backdrop { background: rgba(0, 0, 0, 0.65); }
.modal_content { display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; }

/* Tableaux */
.table_wrapper { overflow-x: auto; }
.table_component { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table_component th, .table_component td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: top; }
.table_component th { color: var(--color-text-muted); font-weight: 500; font-size: 0.8125rem; white-space: nowrap; }
.table_name { font-weight: 600; }
.table_sub { display: block; white-space: nowrap; font-family: var(--font-mono); font-size: 0.75rem; color: var(--color-text-muted); }
.badge { display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: rgba(245, 165, 36, 0.15); color: var(--color-accent); font-size: 0.7rem; font-weight: 600; }

/* Connexion */
.section_login { height: 100%; display: flex; align-items: center; }
.section_login > .padding-global { width: 100%; }
.login_component { display: flex; flex-direction: column; gap: 1rem; }
.login_component .button { width: 100%; }

/* Chat */
.section_chat, .chat_component { height: 100%; }
.chat_component { display: flex; gap: var(--layout-gap); padding: var(--layout-gap); }
.chat_sidebar {
  width: 18rem; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 0.75rem;
  padding: 0.9rem 0.75rem;
  background: var(--color-surface);
  border: var(--panel-border-width) solid var(--color-border);
  border-right: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
}
.chat_list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.15rem; }
.chat_list-group { margin: 0.6rem 0 0.2rem 0.6rem; font-size: 0.75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.chat_list-item { display: flex; align-items: center; border-radius: var(--radius-item); }
.chat_list-item.is-active, .chat_list-item:hover { background: var(--color-surface-alt); }
.chat_list-item.is-active .chat_list-link { color: var(--color-accent); }
.chat_list-link {
  flex: 1; min-width: 0;
  padding: 0.5rem var(--item-padding-x);
  background: none; border: 0; color: var(--color-text);
  font: inherit; font-size: 0.875rem; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.chat_list-action { padding: 0.3rem 0.45rem; background: none; border: 0; color: var(--color-text-muted); font-size: 0.95rem; cursor: pointer; }
.chat_list-action:hover { color: var(--color-text); }
.chat_list-action.is-delete:hover { color: var(--color-error); }
.chat_list-empty { padding: 0.6rem; font-size: 0.875rem; color: var(--color-text-muted); }
.chat_sidebar-footer { display: flex; flex-direction: column; gap: 0.5rem; }
.chat_main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel-background); border: var(--panel-border-width) solid var(--color-border); border-radius: var(--radius-panel); overflow: hidden; }
.chat_header { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.6rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--color-border); }
.chat_menu-button { display: none; }
.chat_model-label { font-size: 0.875rem; color: var(--color-text-muted); white-space: nowrap; }
.chat_model-hint { flex-basis: 100%; font-size: 0.8125rem; color: var(--color-text-muted); }
.chat_model-hint:empty { display: none; }
.chat_messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 1.1rem; }
.chat_empty { margin: auto; text-align: center; color: var(--color-text-muted); }
.chat_message { max-width: 48rem; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 0.5rem; }
.chat_message.is-user { align-items: flex-end; }
.chat_bubble { background: var(--color-surface-alt); padding: 0.6rem 1rem; border-radius: var(--radius-bubble); max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat_images { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.chat_image { max-width: 12rem; max-height: 12rem; border-radius: var(--radius-block); border: 1px solid var(--color-border); }
.chat_message.is-error .chat_text { color: var(--color-error); }
.chat_actions { display: flex; gap: 0.4rem; }
.chat_action { white-space: nowrap; padding: 0.2rem 0.6rem; background: none; border: 1px solid var(--color-border); border-radius: 999px; color: var(--color-text-muted); font: inherit; font-size: 0.75rem; cursor: pointer; }
.chat_action:hover { color: var(--color-text); border-color: var(--color-text-muted); }
.chat_status { color: var(--color-text-muted); font-size: 0.9rem; }
.chat_status::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: chat-dots 1.4s steps(4, end) infinite; }
@keyframes chat-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.chat_thinking { color: var(--color-text-muted); font-size: 0.875rem; }
.chat_thinking summary { cursor: pointer; }
.chat_thinking .chat_text { white-space: pre-wrap; }
.chat_banner { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; max-width: 50rem; width: calc(100% - 2rem); margin: 0 auto; padding: 0.4rem 0.75rem; border: 1px solid var(--color-accent); border-radius: var(--radius-block); font-size: 0.8125rem; color: var(--color-accent); }
.chat_attachments { display: flex; gap: 0.4rem; flex-wrap: wrap; max-width: 50rem; width: 100%; margin: 0 auto; padding: 0.5rem 1rem 0; }
.chat_chip { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.3rem 0.25rem 0.7rem; background: var(--color-surface-alt); border-radius: 999px; font-size: 0.8125rem; max-width: 100%; }
.chat_chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat_chip button { background: none; border: 0; color: var(--color-text-muted); font-size: 1rem; cursor: pointer; padding: 0 0.4rem; }
.chat_composer { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.75rem 1rem 1rem; max-width: 50rem; width: 100%; margin: 0 auto; }

/* Texte mis en forme des réponses */
.chat_text { overflow-wrap: anywhere; }
.chat_text > * { margin: 0 0 0.7rem; }
.chat_text > *:last-child { margin-bottom: 0; }
.chat_text p { white-space: pre-wrap; }
.chat_text h1, .chat_text h2, .chat_text h3, .chat_text h4 { line-height: 1.3; margin-top: 1.1rem; }
.chat_text h1 { font-size: 1.35rem; } .chat_text h2 { font-size: 1.2rem; } .chat_text h3 { font-size: 1.05rem; } .chat_text h4 { font-size: 1rem; }
.chat_text ul, .chat_text ol { padding-left: 1.4rem; }
.chat_text li { margin: 0.2rem 0; }
.chat_text li > ul, .chat_text li > ol { margin-top: 0.2rem; }
.chat_text blockquote { padding-left: 0.8rem; border-left: 3px solid var(--color-border); color: var(--color-text-muted); }
.chat_text hr { border: 0; border-top: 1px solid var(--color-border); }
.chat_text a { color: var(--color-accent); }
.chat_text code { background: var(--color-surface-alt); padding: 0.1rem 0.3rem; border-radius: 0.25rem; font-family: var(--font-mono); font-size: 0.875em; }
.chat_text table { border-collapse: collapse; font-size: 0.9rem; }
.chat_text th, .chat_text td { padding: 0.4rem 0.6rem; border: 1px solid var(--color-border); text-align: left; }
.chat_text th { background: var(--color-surface-alt); }
.chat_code { border: 1px solid var(--color-border); border-radius: var(--radius-block); overflow: hidden; background: #07090b; }
.chat_code-header { display: flex; align-items: center; justify-content: space-between; padding: 0.3rem 0.5rem 0.3rem 0.9rem; background: var(--color-surface-alt); font-family: var(--font-mono); font-size: 0.75rem; color: var(--color-text-muted); }
.chat_code pre { margin: 0; padding: 0.75rem 0.9rem; overflow-x: auto; font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.45; }
.chat_code code { background: none; padding: 0; font-size: inherit; }
.code_comment { color: #6b7686; font-style: italic; }
.code_string { color: #9ece6a; }
.code_number { color: #ff9e64; }
.code_keyword { color: var(--color-accent); }

.chat_overlay { position: fixed; inset: 0; z-index: 9; background: rgba(0, 0, 0, 0.5); }

/* Écran d'ordinateur étroit : jauges un peu plus courtes pour que la pastille reste sur la même ligne */
@media (min-width: 768px) and (max-width: 1450px) {
  .status_stats { gap: 0.5rem 0.9rem; margin-left: 0.75rem; }
  .gauge_track { width: 2.75rem; }
  .gauge_label { width: 2.8rem; }
}

/* Mobile et tactile */
@media (max-width: 767px) {
  :root { --layout-gap: 0; --panel-border-width: 0; --panel-background: transparent; }
  .chat_main { border-radius: 0; }
  .chat_sidebar { border-radius: 0 var(--radius-panel) var(--radius-panel) 0; }
  .chat_menu-button { display: block; }
  .chat_sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 10; width: min(19rem, 85vw);
    padding-top: calc(0.9rem + env(safe-area-inset-top));
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    transform: translateX(-100%); transition: transform 0.2s;
  }
  .chat_sidebar.is-open { transform: none; }
  .chat_header { padding-top: calc(0.75rem + env(safe-area-inset-top)); }
  .chat_composer { padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }
  /* En-tête sur deux lignes : menu, libellé et pastille, puis liste des modèles et aide */
  .chat_header .form_input.is-select { order: 1; min-width: 0; flex: 1 1 40%; }
  #open-models { order: 1; }
  .chat_model-hint { order: 2; }
  /* Sur mobile, les quatre jauges tiennent sur une ligne pour économiser la hauteur */
  .status_stats { grid-template-columns: repeat(4, auto); gap: 0.45rem; margin-left: 0; order: 1; flex-basis: 100%; justify-content: start; }
  .gauge_label { width: auto; font-size: 0.75rem; }
  .gauge_track { width: 2.25rem; height: 0.5rem; }
  .chat_header .form_input.is-select, #open-models { order: 2; }
  .chat_model-hint { order: 3; }
  .chat_bubble { max-width: 92%; }
  .modal_content { padding: 1.1rem; }
}
@media (min-width: 768px) { .chat_overlay { display: none; } }
@media (pointer: coarse) {
  /* Zones de toucher d'au moins 44 px */
  .button, .form_input.is-select { min-height: 2.75rem; }
  .button.is-small { min-height: 2.5rem; }
  .chat_list-link { padding-top: 0.8rem; padding-bottom: 0.8rem; font-size: 1rem; }
  .chat_list-action { padding: 0.6rem 0.7rem; font-size: 1.15rem; }
  .chat_action { padding: 0.45rem 0.9rem; font-size: 0.8125rem; }
}

/* Interrupteur CPU / GPU (gemma4 uniquement) */
.compute_switch { display: inline-flex; padding: 0.15rem; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-surface-alt); }
.compute_switch[hidden] { display: none; }
.compute_option {
  padding: 0.25rem 0.8rem; border: 0; border-radius: 999px; background: transparent;
  color: var(--color-text-muted); font: inherit; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.03em; cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.compute_option.is-active { background: var(--color-accent); color: var(--color-accent-contrast); }
.compute_switch.is-busy { opacity: 0.6; pointer-events: none; }

/* Voyant « in game » : un jeu Steam tourne sur le gros PC (information, n'empêche rien) */
.status_row { display: flex; align-items: center; gap: 0.6rem; }
.status_game { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8125rem; font-weight: 600; color: var(--color-accent); white-space: nowrap; }
.status_game[hidden] { display: none; }
.status_game-icon { animation: game-blink 1.6s ease-in-out infinite; }
@keyframes game-blink { 50% { opacity: 0.35; } }

/* Réveil à distance du gros PC : bouton à gauche de la pastille quand le service est inaccessible */
.status_wake { white-space: nowrap; }
.status_pill.is-waking { color: var(--color-accent); border-color: var(--color-accent); }
.status_pill.is-waking::before { background: var(--color-accent); animation: game-blink 1.2s ease-in-out infinite; }
.status_pill.is-waking::after { content: ""; width: 1em; margin-left: -0.35rem; text-align: left; animation: chat-dots 1.4s steps(4, end) infinite; }
.status_message { max-width: 20rem; font-size: 0.75rem; line-height: 1.35; text-align: right; color: var(--color-error); }
@media (max-width: 767px) {
  .status_row { flex-wrap: wrap; justify-content: flex-end; }
}
