/* Terminal — design system
   Fond quasi noir à biais froid, accent vert « prompt ». Un seul thème : sombre. */
:root {
  --bg: #0a0c0f;
  --bar: #0d1014;
  --surface: #12151a;
  --surface-2: #1a1e25;
  --key: #232831;
  --sheet: #15181e;
  --row-hi: #1c2027;
  --border: #1d2229;
  --border-2: #262b34;
  --text: #e7e9ee;
  --text-2: #c6ccd6;
  --muted: #9aa3b2;
  --faint: #7d8594;
  --accent: #4ade80;
  --accent-ink: #04170a;
  --accent-soft: rgba(74, 222, 128, 0.14);
  --danger: #f87171;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-700.woff2") format("woff2");
  font-weight: 700;
  font-display: block;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body { position: fixed; inset: 0; }

/* La hauteur suit le viewport visible : avec le clavier ouvert, les barres
   restent collées au-dessus de lui (app.js met à jour --app-h). */
.app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
  display: flex;
  flex-direction: column;
}
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---------- Boutons ---------- */
.btn {
  height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); filter: brightness(1.12); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--key); color: var(--text); }
.btn-outline { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.btn-danger-text { background: transparent; color: var(--danger); height: 48px; }
.btn-xl { height: 56px; border-radius: 16px; font-size: 17px; gap: 10px; }
.btn-lg { height: 52px; font-size: 16px; }
.btn-icon { padding: 0; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn-fill { background: var(--surface-2); color: var(--accent); }

/* ---------- 1 · Verrou ---------- */
.lock {
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
}
.lock-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.app-icon {
  width: 92px;
  height: 92px;
  margin-bottom: 14px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--key);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-hero h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.lock-hero p { font-size: 15px; line-height: 1.45; max-width: 300px; }
.lock-actions { display: flex; flex-direction: column; gap: 14px; }
.lock-foot { text-align: center; font-size: 13px; color: var(--faint); }
.link-btn { align-self: center; height: 44px; padding: 0 12px; font-size: 14px; color: var(--accent); }
.lock-msg {
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.lock-msg.error { color: #fecaca; border-color: rgba(248, 113, 113, 0.35); }

/* ---------- 2 · Serveurs ---------- */
.servers { padding: var(--safe-top) 16px calc(var(--safe-bottom) + 16px); gap: 14px; }
.servers-top { height: 44px; margin-top: 4px; display: flex; justify-content: flex-end; gap: 6px; flex-shrink: 0; }
.servers-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.large-title { margin: 0 4px; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.server-list { display: flex; flex-direction: column; gap: 10px; }
.hint { font-size: 13px; color: var(--faint); text-align: center; }

.server-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  text-align: left;
  transition: transform 0.1s ease, background 0.15s ease;
}
.server-card:active { transform: scale(0.985); background: var(--surface-2); }
.server-icon {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.server-icon .status {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  background: #4b5260;
  border: 3px solid var(--surface);
}
.server-card.online .server-icon .status { background: var(--accent); }
.server-card.offline .server-icon { color: var(--faint); }
.server-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.server-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-label { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-card.offline .server-name { color: #b4bbc7; }
.server-card.offline .server-label { color: var(--faint); }
.chip {
  align-self: flex-start;
  margin-top: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.server-meta { display: flex; align-items: center; gap: 4px; color: var(--faint); font-family: var(--mono); font-size: 12px; flex-shrink: 0; }
.server-card.offline .server-meta { font-family: var(--sans); }
.skeleton { height: 76px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); opacity: 0.6; }
.empty { text-align: center; color: var(--muted); font-size: 15px; padding: 24px 12px; line-height: 1.5; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; }
.card-head svg { color: var(--accent); flex-shrink: 0; }
.card-text { font-size: 13px; line-height: 1.45; color: var(--muted); }
.mono-box {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- Barre de navigation (formulaire, sélection) ---------- */
.nav-bar {
  flex-shrink: 0;
  padding: var(--safe-top) 6px 0;
  height: calc(var(--safe-top) + 48px);
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 96px;
  align-items: center;
  border-bottom: 1px solid var(--surface-2);
  background: var(--bar);
}
.nav-text { height: 44px; padding: 0 10px; color: var(--muted); font-size: 16px; text-align: left; }
.nav-text:last-child { text-align: right; }
.nav-accent { color: var(--accent); font-weight: 600; }
.nav-text:disabled { opacity: 0.4; }
.nav-title { text-align: center; font-size: 16px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.nav-title small { font-size: 11.5px; font-weight: 400; color: var(--faint); }

/* ---------- 3 · Formulaire ---------- */
.form-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field input {
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--key);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  outline: none;
  width: 100%;
  min-width: 0;
  -webkit-user-select: text;
  user-select: text;
}
.field input.mono { font-family: var(--mono); font-size: 15px; }
.field input:focus { border-color: var(--accent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 10px; }
.form-error { font-size: 13px; color: var(--danger); padding: 0 4px; }
.test-block { display: flex; flex-direction: column; gap: 10px; }
.test-result { display: flex; align-items: flex-start; gap: 8px; padding: 0 4px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.test-result svg { flex-shrink: 0; margin-top: 1px; }
.test-result .mono { color: var(--text-2); word-break: break-all; }
.test-result.ok svg { color: var(--accent); }
.test-result.ko svg { color: var(--danger); }
.test-result .btn { margin-top: 8px; height: 40px; font-size: 14px; }

/* ---------- 4 · Terminal ---------- */
.term { background: var(--bar); }
.term-bar {
  flex-shrink: 0;
  height: calc(var(--safe-top) + 48px);
  padding: var(--safe-top) 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--surface-2);
}
.term-bar .icon-btn { color: var(--text-2); }
.term-title { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.term-name { display: flex; align-items: center; gap: 7px; font-size: 15px; font-weight: 600; max-width: 100%; }
.term-name span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-sub { font-family: var(--mono); font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: #4b5260; flex-shrink: 0; transition: background 0.2s ease; }
.dot.on { background: var(--accent); }
.dot.wait { background: #e0af68; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.term-wrap { position: relative; flex: 1; min-height: 0; background: var(--bg); overflow: hidden; }
.xterm-host { position: absolute; top: 8px; right: 4px; bottom: 4px; left: 10px; }
.xterm-host .xterm { height: 100%; }
.xterm-host .xterm .xterm-viewport { background-color: var(--bg) !important; }
/* JetBrains Mono a des ligatures : jamais dans un terminal (=> ou != fusionnés). */
.xterm-host .xterm-rows { font-variant-ligatures: none; font-feature-settings: "calt" 0, "liga" 0; }

.term-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(10, 12, 15, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
.term-overlay p { font-size: 15px; line-height: 1.5; color: var(--text-2); max-width: 320px; }
.term-overlay .overlay-detail { font-size: 11.5px; color: var(--muted); word-break: break-all; }
.overlay-actions { display: flex; flex-direction: column; gap: 10px; width: min(100%, 300px); }

.keyrow {
  flex-shrink: 0;
  height: 56px;
  padding: 6px 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.keyrow::-webkit-scrollbar { display: none; }
.key {
  flex-shrink: 0;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border-radius: 9px;
  background: var(--key);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  -webkit-touch-callout: none;
}
.key-arrow { font-size: 15px; }
.key:active { background: #2f3540; }
.key[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 700; }

.actionbar {
  flex-shrink: 0;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 52px 52px;
  gap: 8px;
  background: var(--surface);
}
.kbd-hide { display: none; }
body.kb-open .kbd-show { display: none; }
body.kb-open .kbd-hide { display: block; }
/* Clavier ouvert : il couvre la zone du geste d'accueil, la barre se resserre. */
body.kb-open .actionbar { padding-bottom: 8px; }
body.kb-open .actionbar .btn { height: 44px; border-radius: 12px; }

/* ---------- 5 · Sélection ---------- */
.select-text {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 10px 12px 24px;
  background: var(--bg);
  color: #c9d1d9;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
  -webkit-overflow-scrolling: touch;
}
.select-text::selection, .select-text *::selection { background: rgba(74, 222, 128, 0.32); }
.select-foot {
  flex-shrink: 0;
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.select-info { text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Feuilles ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(4, 5, 7, 0.62); animation: fade-in 0.18s ease; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 86%;
  overflow-y: auto;
  padding: 8px 12px calc(var(--safe-bottom) + 16px);
  background: var(--sheet);
  border-top: 1px solid var(--border-2);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: sheet-in 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.grabber { align-self: center; width: 38px; height: 5px; border-radius: 3px; background: #3a404b; margin-bottom: 6px; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 6px 12px; }
.sheet-head h2 { font-size: 19px; font-weight: 700; }
.sheet-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: left;
}
.sheet-row:active, .sheet-row.is-primary { background: var(--row-hi); }
.sheet-row:disabled { opacity: 0.4; }
.row-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 11px;
  background: var(--key);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-icon.accent { background: var(--accent-soft); color: var(--accent); }
.sheet-row.danger .row-icon { color: var(--danger); background: rgba(248, 113, 113, 0.12); }
.sheet-row.danger .row-title { color: var(--danger); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-title { font-size: 15.5px; font-weight: 600; }
.row-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub.mono { font-size: 12px; }
.row-chevron { color: var(--faint); flex-shrink: 0; }
.paste-preview {
  margin: 4px 4px 10px;
  max-height: 240px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}
.sheet-actions { display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.font-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 10px; font-size: 15.5px; font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .mono { min-width: 24px; text-align: center; color: var(--muted); font-size: 14px; }
.sheet-foot { text-align: center; font-size: 11px; color: var(--faint); padding-top: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: calc(var(--safe-top) + 58px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 32px);
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  animation: toast-in 0.2s ease;
  pointer-events: none;
}
.toast svg { color: #15803d; flex-shrink: 0; }
.toast.error svg { color: #b91c1c; }

@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
