:root {
  --bg: #0b0e14;
  --panel: #12161f;
  --panel-2: #171c27;
  --line: #232a38;
  --fg: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4d9fff;
  --accent-2: #6ee7a8;
  --danger: #ff6b6b;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(11, 14, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; letter-spacing: 0.02em; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.tab:hover { color: var(--fg); background: var(--panel); }
.tab.active { color: var(--fg); background: var(--panel-2); border-color: var(--line); }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

input, select, button {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
input { flex: 1 1 220px; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--accent); }

button { cursor: pointer; background: var(--panel-2); }
button:hover { border-color: var(--accent); }
button.ghost { background: transparent; color: var(--muted); }
button.primary { background: var(--accent); color: #04101f; border-color: var(--accent); font-weight: 600; }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; word-break: break-all; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.badge {
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.kind-model { color: var(--accent); border-color: rgba(77, 159, 255, 0.4); }
.badge.kind-dataset { color: var(--accent-2); border-color: rgba(110, 231, 168, 0.4); }

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 900px;
  width: calc(100% - 24px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(3px); }

dialog article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  max-height: 88vh;
  overflow-y: auto;
}

.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.detail-head h2 { margin: 0 0 4px; font-size: 18px; word-break: break-all; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin: 14px 0; }
.fact { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
.fact .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.fact .v { font-size: 14px; margin-top: 3px; word-break: break-word; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }

.readme {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 18px 16px;
  font-size: 14px;
  line-height: 1.62;
  color: var(--fg);
  max-height: 46vh;
  overflow-y: auto;
  word-break: break-word;
}
.readme p { margin: 10px 0; }
.readme h1, .readme h2, .readme h3, .readme h4, .readme h5, .readme h6 {
  margin: 20px 0 8px;
  line-height: 1.3;
  color: var(--fg);
}
.readme h1 { font-size: 19px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.readme h2 { font-size: 16.5px; }
.readme h3 { font-size: 15px; color: #cfd6e4; }
.readme h4, .readme h5, .readme h6 { font-size: 14px; color: var(--muted); }
.readme ul, .readme ol { margin: 8px 0; padding-left: 22px; }
.readme li { margin: 3px 0; }
.readme strong { color: #fff; font-weight: 600; }
.readme em { color: #cdd5e3; }
.readme hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.readme a { color: var(--accent); text-decoration: none; }
.readme a:hover { text-decoration: underline; }
.readme .md-code, .readme .md-pre code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #0c1018;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--accent-2);
}
.readme .md-pre {
  background: #0c1018;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.readme .md-pre code { background: none; border: none; padding: 0; color: #d7e0ee; }
.readme .md-table-wrap { overflow-x: auto; margin: 12px 0; }
.readme .md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.readme .md-table th, .readme .md-table td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.readme .md-table th { background: #0c1018; color: var(--fg); font-weight: 600; }
.readme .md-table td { color: #cfd6e4; }
.readme.empty-readme { color: var(--muted); font-style: italic; padding: 16px 18px; }

/* ------------------------------------------------------ suivi des jobs */
.job {
  display: grid;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.job-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.job-name { font-size: 14px; font-weight: 550; word-break: break-all; }
.job-kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.job-bar {
  position: relative;
  height: 7px;
  border-radius: 4px;
  background: #1d2431;
  overflow: hidden;
}
.job-bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s ease;
}
/* Barre indéterminée quand le pourcentage n'est pas encore connu. */
.job-bar.indeterminate > i {
  width: 35% !important;
  animation: job-slide 1.4s ease-in-out infinite;
}
@keyframes job-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}
.job-bar.done > i { background: var(--accent-2); }
.job-bar.error > i { background: var(--danger); width: 100% !important; }

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.job-meta b { color: var(--fg); font-weight: 550; }
.job-detail { font-size: 12.5px; color: var(--muted); }
.job-detail.err { color: #ffb0b0; }

.toggle-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  margin-left: auto;
  cursor: pointer;
  user-select: none;
}
.toggle-live input { width: auto; flex: none; accent-color: var(--accent); }

.queue-summary {
  font-size: 13px;
  color: var(--muted);
  padding: 2px 0 10px;
}

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 13px;
}
.row .label { font-size: 14px; word-break: break-all; }
.status { font-size: 12px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); }
.status.done { color: var(--accent-2); border-color: rgba(110, 231, 168, 0.45); }
.status.running, .status.queued { color: var(--accent); border-color: rgba(77, 159, 255, 0.45); }
.status.error { color: var(--danger); border-color: rgba(255, 107, 107, 0.45); }

.term {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #05070b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  height: 320px;
  overflow: hidden;
  margin: 0 0 10px;
}
/* xterm.js gère son propre défilement : le conteneur ne doit pas défiler,
   sinon on obtient deux barres et un rendu qui saute. */
.term .xterm { height: 100%; }
.term .xterm-viewport { overflow-y: auto; }
.term-input { display: flex; gap: 8px; align-items: center; }
.prompt { font-family: var(--mono); color: var(--accent-2); }

.panel { margin-top: 22px; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  z-index: 50;
  max-width: calc(100% - 32px);
}
.toast.err { border-color: var(--danger); color: var(--danger); }

.gauge { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.gauge > i { display: block; height: 100%; background: var(--accent); }
.gauge.warn > i { background: #ffb454; }
.gauge.crit > i { background: var(--danger); }

@media (max-width: 640px) {
  main { padding: 12px; }
  .tabs { width: 100%; margin-left: 0; }
  .tab { flex: 1; text-align: center; }
  .cards { grid-template-columns: 1fr; }
  dialog article { max-height: 92vh; padding: 14px; }
  .term { height: 240px; }
}

/* ------------------------------------------------------------- écran login */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  position: relative;
  overflow: hidden;
}

/* Halo discret derrière la carte : donne de la profondeur sans distraire. */
.auth-glow {
  position: fixed;
  top: -25vh;
  left: 50%;
  width: 640px;
  height: 640px;
  max-width: 140vw;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(77, 159, 255, 0.16) 0%, rgba(110, 231, 168, 0.06) 38%, transparent 68%);
  filter: blur(8px);
  pointer-events: none;
}

.auth-wrap {
  position: relative;
  width: 100%;
  max-width: 372px;
}

.auth-card {
  background: linear-gradient(180deg, rgba(23, 28, 39, 0.96), rgba(18, 22, 31, 0.96));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
}

.auth-card.shake { animation: auth-shake 0.4s ease; }
@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  68% { transform: translateX(-4px); }
  85% { transform: translateX(3px); }
}

.auth-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }

.auth-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  color: var(--accent-2);
  background: rgba(110, 231, 168, 0.09);
  border: 1px solid rgba(110, 231, 168, 0.22);
  flex: none;
}

.auth-title { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: 0.01em; }
.auth-sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

/* Champ à libellé flottant : le libellé est dans le <label> après l'input,
   positionné en absolu ; il monte quand le champ est rempli ou focalisé.
   Aucun placeholder d'exemple — la page est publique. */
.auth-field { position: relative; margin-bottom: 14px; }

.auth-field input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--fg);
  font-size: 15px;
  padding: 19px 14px 8px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.auth-field input:hover { border-color: #2c3547; }

.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  background: #141a25;
  box-shadow: 0 0 0 3px rgba(77, 159, 255, 0.14);
}

.auth-field label {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14.5px;
  pointer-events: none;
  transition: top 0.14s ease, font-size 0.14s ease, color 0.14s ease;
}

.auth-field input:focus + label,
.auth-field input:not(:placeholder-shown) + label {
  top: 10px;
  font-size: 11px;
  transform: none;
  color: var(--accent);
}

/* Le champ mot de passe réserve la place du bouton œil. */
.auth-field input#password { padding-right: 46px; }

.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.pw-toggle:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.pw-toggle.on { color: var(--accent-2); }

.auth-submit {
  position: relative;
  margin-top: 8px;
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 550;
  border-radius: 10px;
}

.auth-submit.loading .auth-submit-label { opacity: 0; }

.auth-spinner {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: auth-spin 0.7s linear infinite;
}
.auth-submit.loading .auth-spinner { display: block; }
@keyframes auth-spin { to { transform: rotate(360deg); } }

.auth-error {
  margin: 14px 0 0;
  padding: 9px 12px;
  color: #ffb0b0;
  background: rgba(255, 107, 107, 0.09);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}

.auth-foot {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.75;
}
