/* ==========================================================================
   Terminal area: the in-panel SSH terminal (templates/terminal/session.html, static/js/pages/terminal.js)
   and the small terminal launchers of other pages. Classes are prefixed with `term-`.
   Colours: --term-* tokens (tokens.css) — the same values feed xterm.js, so the window, its chrome and the
   terminal itself always match the panel theme. xterm's own stylesheet (vendor/xterm/xterm.css) is loaded
   lazily by terminal.js; the overrides below are scoped under .term so they win regardless of order.
   ========================================================================== */

/* ---------- Page frame: the terminal fills the main panel ---------- */
.term { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }

@media (min-width: 1024px) {
  .main__content:has(> .term) { display: flex; flex-direction: column; min-height: 0; padding-block: var(--sp-5); }
  .term { flex: 1 1 auto; min-height: 540px; }
  .term-window { flex: 1 1 auto; }
}
@media (max-width: 1023px) {
  .term-window { height: var(--term-h, calc(100dvh - 210px)); min-height: 320px; }
  .main__content:has(> .term) { padding-bottom: var(--sp-3); }
  .main:has(> .main__content > .term) > .credit { display: none; }
}

/* ---------- Head ---------- */
.term-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3) var(--sp-5); flex-wrap: wrap; }
.term-head__text { min-width: 0; }
.term-head__ident { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.term-head__names { min-width: 0; }
.term-head__title { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); line-height: var(--lh-tight); overflow-wrap: anywhere; }
.term-head__sub { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); margin-top: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.term-head__sub .mono { overflow-wrap: anywhere; }
.term-head__actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
@media (max-width: 767px) {
  .term-head { display: none; }
}

/* ---------- Window ---------- */
.term-window {
  --term-r: var(--r-xl);
  position: relative;
  isolation: isolate;
  container: termwin / inline-size;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-radius: var(--term-r);
  background: var(--term-bg);
  border: 1px solid var(--term-edge);
  box-shadow: var(--shadow-2), 0 46px 110px -60px var(--term-glow);
  color: var(--text);
  transition: border-color var(--dur-3);
}
/* Focus is visible on the whole window (xterm's own textarea is invisible). */
.term-window:has(.xterm.focus) { border-color: color-mix(in srgb, var(--indigo) 55%, var(--term-edge)); }
/* Production: a plum beam on the top edge, on top of the plum tab and the pulsing badge. */
.term-window.is-prod::before {
  content: "";
  position: absolute;
  inset-inline: 28px;
  top: -1px;
  z-index: 6;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--tone-plum) 30%, var(--tone-plum) 70%, transparent);
  pointer-events: none;
}

/* ---------- Tab strip + toolbar ---------- */
.term-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 54px;
  padding: 8px 10px;
  background: var(--term-chrome);
  border-bottom: 1px solid var(--term-edge);
  border-radius: var(--term-r) var(--term-r) 0 0;
}
.term-tabs-wrap { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; }
.term-tabs { display: flex; align-items: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.term-tabs::-webkit-scrollbar { display: none; }

.term-tab {
  position: relative;
  display: flex;
  align-items: center;
  flex: none;
  max-width: 230px;
  height: 38px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--dur-2), color var(--dur-2), box-shadow var(--dur-2);
}
.term-tab:hover { background: var(--chip); color: var(--text); }
.term-tab.is-active { background: var(--term-bg); color: var(--text); box-shadow: inset 0 0 0 1px var(--term-edge), 0 6px 16px -10px var(--overlay); }
.term-tab.is-active.is-prod { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone-plum) 45%, transparent), 0 6px 16px -10px var(--overlay); }
.term-tab__main {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 100%;
  min-width: 0;
  padding-inline: 12px 4px;
  border-radius: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.term-tab__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12.5px; }
.term-tab__flame { flex: none; color: var(--tone-plum-fg); }
.term-tab__close {
  flex: none;
  width: 26px;
  height: 26px;
  margin-inline-end: 6px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--text-3);
  opacity: 0;
  transition: opacity var(--dur-2), background var(--dur-2), color var(--dur-2);
}
.term-tab:hover .term-tab__close, .term-tab.is-active .term-tab__close, .term-tab__close:focus-visible { opacity: 1; }
.term-tab__close:hover { background: var(--chip-hover); color: var(--text); }

/* Phase dot: shape and colour both change (never colour only). */
.term-dot {
  --dot: var(--tone-neutral);
  position: relative;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot);
}
[data-phase="live"] > .term-dot, [data-phase="live"] > * > .term-dot { --dot: var(--tone-green); box-shadow: 0 0 8px var(--tone-green); }
[data-phase="connecting"] > .term-dot, [data-phase="connecting"] > * > .term-dot {
  --dot: var(--tone-amber);
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--dot);
  animation: iv-pulse 1.1s ease-in-out infinite;
}
[data-phase="failed"] > .term-dot, [data-phase="failed"] > * > .term-dot { --dot: var(--tone-red); border-radius: 2px; transform: rotate(45deg) scale(0.9); }
[data-phase="ended"] > .term-dot, [data-phase="ended"] > * > .term-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--dot); }

.term-add { flex: none; }
.term-add__btn:disabled { opacity: 0.4; }

.term-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.term-tool {
  position: relative;
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background var(--dur-2), color var(--dur-2), transform var(--dur-1) var(--ease-out);
}
.term-tool:hover:not(:disabled) { background: var(--chip); color: var(--text); }
.term-tool:active:not(:disabled) { transform: scale(0.92); }
.term-tool:disabled { opacity: 0.36; cursor: default; }
.term-tool[aria-pressed="true"], .term-tool[aria-expanded="true"] { background: var(--indigo-soft); color: var(--indigo-text); }
.term-tool--label { display: inline-flex; align-items: center; gap: 6px; width: auto; padding-inline: 10px 12px; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.term-tool--label .icon { color: var(--tone-amber-fg); }
.term-tool--danger:hover:not(:disabled) { background: var(--tone-red-bg); color: var(--tone-red-fg); }
.term-tools__sep { flex: none; width: 1px; height: 20px; margin-inline: 4px; background: var(--term-edge); }
.term-tools__size { min-width: 20px; text-align: center; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; color: var(--text-3); }
.term-more { display: none; }

/* Menus (targets, quick commands, more) */
.term-menu { min-width: 300px; max-width: min(380px, calc(100vw - 32px)); }
.term-menu .dropdown__item:disabled { opacity: 0.4; pointer-events: none; }
.term-targets__list { max-height: min(46vh, 340px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.term-target { align-items: center; padding-block: 6px; }
.term-target__text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: var(--lh-snug); }
.term-target__title { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-target__flame { color: var(--tone-plum-fg); flex: none; }
.term-target__addr { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-target__env { flex: none; font-size: var(--fs-2xs); color: var(--text-3); }

.term-cmds__menu { min-width: 340px; }
.term-cmds__list { display: flex; flex-direction: column; }
.term-cmd { display: flex; align-items: center; gap: 4px; }
.term-cmd__type { flex: 1; min-width: 0; padding-block: 6px; }
.term-cmd__text { display: flex; flex-direction: column; min-width: 0; line-height: var(--lh-snug); }
.term-cmd__code { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); direction: ltr; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-cmd__label { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-cmd__run {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding-inline: 10px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  opacity: 0.75;
  transition: opacity var(--dur-2), background var(--dur-2);
}
.term-cmd:hover .term-cmd__run, .term-cmd__run:focus-visible { opacity: 1; }
.term-cmd__run:hover { background: color-mix(in srgb, var(--accent) 24%, transparent); }

.term-more__zoom { display: flex; align-items: center; gap: var(--sp-2); min-height: 44px; padding-inline: var(--sp-3) var(--sp-2); font-size: var(--fs-md); color: var(--text-2); }
.term-more__zoom > span { display: inline-flex; align-items: center; gap: var(--sp-3); flex: 1; }
.term-more__zoom b { min-width: 22px; text-align: center; font-weight: var(--fw-medium); color: var(--text); }

/* ---------- Stage ---------- */
.term-stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: var(--term-bg); }
.term-panes, .term-pane { position: absolute; inset: 0; }
.term-pane[hidden] { display: none; }
/* The pane is dir="ltr": the inset leaves room for the scrollbar on the right and a calm gutter on the left. */
.term-host { position: absolute; inset: 12px 4px 4px 14px; }

.term .xterm { height: 100%; padding: 0; font-feature-settings: "liga" 0, "calt" 0; }
.term .xterm .xterm-viewport { scrollbar-width: thin; scrollbar-color: var(--term-scrollbar) transparent; overscroll-behavior: contain; }
.term .xterm .xterm-viewport::-webkit-scrollbar { width: 8px; }
.term .xterm .xterm-viewport::-webkit-scrollbar-thumb { background: var(--term-scrollbar); border-radius: 8px; }
.term .xterm .xterm-viewport::-webkit-scrollbar-track { background: transparent; }

/* ---------- Connection sequence (browser → InfraVault → server) ---------- */
.term-seq {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: var(--sp-6) var(--sp-5);
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(55% 60% at 50% 38%, var(--term-glow), transparent 72%),
    radial-gradient(circle, var(--chart-grid) 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--term-bg);
}
/* Reconnecting over a session that was live: the previous output stays visible behind a veil. */
.term-seq.is-again { background: radial-gradient(55% 60% at 50% 38%, var(--term-glow), transparent 72%), var(--term-veil); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.term-seq__card {
  container: termseq / inline-size;
  width: min(700px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  text-align: center;
  animation: iv-rise var(--dur-4) var(--ease-out) both;
}
.term-seq__eyebrow { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--r-full); background: var(--chip); color: var(--text-2); font-size: var(--fs-xs); }
.term-seq__eyebrow .icon { color: var(--tone-green-fg); }
.term-seq.is-failed .term-seq__eyebrow .icon { color: var(--tone-red-fg); }
.term-seq__title { font-size: var(--fs-xl); font-weight: var(--fw-semibold); line-height: var(--lh-tight); color: var(--text); overflow-wrap: anywhere; }

/* The ready moment: the card sinks into the status bar while the veil fades. */
.term-seq.is-leaving { pointer-events: none; animation: term-fade-out 460ms var(--ease-in-out) both; }
.term-seq.is-leaving .term-seq__card { animation: term-sink 460ms var(--ease-in-out) both; }
@keyframes term-fade-out { to { opacity: 0; } }
@keyframes term-sink { to { opacity: 0; transform: translateY(42%) scale(0.78); } }

/* Route */
.term-route { display: flex; align-items: flex-start; width: 100%; padding-block: var(--sp-3) var(--sp-1); }
.term-route__node { flex: none; width: 116px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.term-route__chip {
  position: relative;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--term-chrome-2);
  border: 1px solid var(--term-edge);
  color: var(--text-3);
  transition: background var(--dur-3), color var(--dur-3), box-shadow var(--dur-3), border-color var(--dur-3);
}
.term-route__node.is-on .term-route__chip {
  background: var(--indigo-soft);
  border-color: color-mix(in srgb, var(--indigo) 45%, transparent);
  color: var(--indigo-text);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--indigo) 9%, transparent), 0 14px 30px -14px var(--indigo);
}
.term-route__node.is-ready .term-route__chip {
  background: var(--tone-green-bg);
  border-color: color-mix(in srgb, var(--tone-green) 45%, transparent);
  color: var(--tone-green-fg);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--tone-green) 10%, transparent), 0 14px 30px -14px var(--tone-green);
}
.term-route__node.is-fail .term-route__chip {
  background: var(--tone-red-bg);
  border-color: color-mix(in srgb, var(--tone-red) 45%, transparent);
  color: var(--tone-red-fg);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--tone-red) 9%, transparent);
}
/* The server's ring while the sequence is in its last leg (netmap halo family). */
.term-seq:not(.is-failed) .term-route__node[data-node="server"]:not(.is-ready) .term-route__chip::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1.5px solid var(--indigo);
  opacity: 0;
  animation: term-halo 2.4s var(--ease-out) infinite;
}
@keyframes term-halo { 0% { opacity: 0.6; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
.term-route__badge {
  position: absolute;
  bottom: -4px;
  inset-inline-start: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tone-green);
  box-shadow: 0 0 0 3px var(--term-bg);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity var(--dur-3), transform var(--dur-3) var(--ease-spring);
}
.term-route__badge::after { content: ""; position: absolute; inset: 5px 4px 6px; border: 2px solid var(--term-bg); border-top: 0; border-inline-end: 0; transform: rotate(-45deg); }
.term-route__node.is-ready .term-route__badge { opacity: 1; transform: none; }
.term-route__name { max-width: 100%; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-route__node[data-node="server"] .term-route__name { font-family: var(--font-mono); font-size: 12.5px; }
.term-route__meta { max-width: 100%; font-size: var(--fs-2xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.term-route__leg { position: relative; flex: 1 1 0; min-width: 48px; height: 86px; }
.term-route__wire {
  position: absolute;
  inset-inline: 2px;
  top: 27px;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--border-strong) 0 5px, transparent 5px 11px);
}
/* Flowing dashes (compositor-only: a strip one period wider than the wire slides toward the server). */
.term-route__wire i {
  --tone: var(--indigo);
  position: absolute;
  inset-block: 0;
  inset-inline-start: -24px;
  inset-inline-end: 0;
  opacity: 0;
  background: repeating-linear-gradient(90deg, var(--tone) 0 10px, transparent 10px 24px);
  transition: opacity var(--dur-3);
}
.term-route__leg.is-active .term-route__wire, .term-route__leg.is-done .term-route__wire, .term-route__leg.is-fail .term-route__wire { background: color-mix(in srgb, var(--tone, var(--indigo)) 22%, transparent); }
.term-route__leg.is-active .term-route__wire { --tone: var(--indigo); }
.term-route__leg.is-active .term-route__wire i { opacity: 1; animation: term-flow 0.7s linear infinite; }
.term-route__leg.is-done .term-route__wire { --tone: var(--tone-green); }
.term-route__leg.is-done .term-route__wire i { --tone: var(--tone-green); opacity: 0.9; animation: term-flow 1.6s linear infinite; }
.term-route__leg.is-fail .term-route__wire { --tone: var(--tone-red); }
.term-route__leg.is-fail .term-route__wire i { --tone: var(--tone-red); opacity: 0.85; animation: none; }
@keyframes term-flow { to { transform: translateX(-24px); } }

.term-route__cps { position: absolute; inset-inline: 0; top: 21px; display: flex; justify-content: space-evenly; }
.term-cp { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.term-cp i {
  position: relative;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--term-bg);
  border: 2px solid var(--border-strong);
  transition: background var(--dur-3), border-color var(--dur-3), box-shadow var(--dur-3);
}
.term-cp b { max-width: 92px; font-size: 11.5px; font-weight: var(--fw-medium); color: var(--text-3); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--dur-3); }
.term-cp.is-active i { border-color: var(--indigo); background: var(--indigo-soft); box-shadow: 0 0 0 5px color-mix(in srgb, var(--indigo) 22%, transparent); animation: term-cp 1.2s ease-in-out infinite; }
.term-cp.is-active b { color: var(--text); }
.term-cp.is-done i { border-color: var(--tone-green); background: var(--tone-green); box-shadow: 0 0 10px color-mix(in srgb, var(--tone-green) 70%, transparent); }
.term-cp.is-done i::after { content: ""; position: absolute; inset: 2px 2.5px 3.5px; border: 1.6px solid var(--term-bg); border-top: 0; border-inline-end: 0; transform: rotate(-45deg); }
.term-cp.is-done b { color: var(--text-2); }
.term-cp.is-fail i { border-color: var(--tone-red); background: var(--tone-red); box-shadow: 0 0 0 5px color-mix(in srgb, var(--tone-red) 20%, transparent); }
.term-cp.is-fail i::before, .term-cp.is-fail i::after { content: ""; position: absolute; inset: 4px 1px; height: 1.6px; margin-block: auto; background: var(--term-bg); transform: rotate(45deg); }
.term-cp.is-fail i::after { transform: rotate(-45deg); }
.term-cp.is-fail b { color: var(--tone-red-fg); }
@keyframes term-cp { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--indigo) 6%, transparent); } }

.term-seq__caption { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 22px; font-size: var(--fs-sm); color: var(--text-2); }
.term-seq.is-failed .term-seq__caption { color: var(--tone-red-fg); }
.term-seq__caption span { overflow-wrap: anywhere; }
.term-seq__tech { font-size: 12.5px; color: var(--text); overflow-wrap: anywhere; }
.term-seq__spinner { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--indigo); border-inline-end-color: transparent; animation: iv-spin 0.8s linear infinite; }

/* Host-key notice under the route (not .term-key: that is the touch accessory key). */
.term-hostkey {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  max-width: min(100%, 560px);
  min-height: 36px;
  margin: 0;
  padding: 7px 14px;
  border-radius: var(--r-lg);
  font-size: var(--fs-xs);
  line-height: 1.5;
  text-align: center;
  background: var(--tone-green-bg);
  color: var(--tone-green-fg);
  animation: iv-pop var(--dur-3) var(--ease-out) both;
}
.term-hostkey .icon { flex: none; }
.term-hostkey.is-new { background: var(--tone-indigo-bg); color: var(--tone-indigo-fg); }
.term-hostkey__fp { min-width: 0; max-width: 100%; font-family: var(--font-mono); font-size: 11px; color: var(--text-2); overflow-wrap: anywhere; unicode-bidi: isolate; }

.term-fail {
  display: flex;
  gap: var(--sp-3);
  width: 100%;
  max-width: 580px;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  text-align: start;
  background: color-mix(in srgb, var(--tone-red) 7%, var(--term-chrome));
  border: 1px solid color-mix(in srgb, var(--tone-red) 32%, transparent);
  animation: iv-rise var(--dur-3) var(--ease-out) both;
}
.term-fail--amber { background: color-mix(in srgb, var(--tone-amber) 7%, var(--term-chrome)); border-color: color-mix(in srgb, var(--tone-amber) 32%, transparent); }
.term-fail--neutral { background: var(--term-chrome); border-color: var(--term-edge); }
.term-fail .chip-icon { flex: none; }
.term-fail__body { min-width: 0; flex: 1; }
.term-fail__title { font-weight: var(--fw-semibold); color: var(--text); }
.term-fail__text { margin-top: 4px; font-size: var(--fs-sm); color: var(--text-2); line-height: var(--lh-base); }
.term-fail__next { margin-top: var(--sp-2); padding-inline-start: 10px; border-inline-start: 2px solid var(--indigo); font-size: var(--fs-sm); color: var(--text); line-height: var(--lh-base); }
.term-fail__retry { margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); }
.term-fail__keys { display: grid; gap: var(--sp-2); margin-top: var(--sp-3); padding: var(--sp-3); border-radius: var(--r-md); background: var(--term-bg); border: 1px dashed color-mix(in srgb, var(--tone-red) 35%, transparent); }
.term-fail__keys dt { font-size: var(--fs-2xs); color: var(--text-3); }
.term-fail__keys dd { display: flex; flex-direction: column; gap: 2px; }
.term-fail__keys code { font-family: var(--font-mono); font-size: 11.5px; color: var(--text); overflow-wrap: anywhere; text-align: start; }
.term-fail__keys small { font-size: var(--fs-2xs); color: var(--text-3); }

.term-seq__actions { display: flex; justify-content: center; min-height: 36px; }
.term-seq__buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2); }

/* Narrow windows: icons and a caption carry the route; checkpoint names step back. */
@container termseq (max-width: 540px) {
  .term-route__node { width: 66px; }
  .term-route__chip { width: 44px; height: 44px; border-radius: 15px; }
  .term-route__chip .icon { width: 18px; height: 18px; }
  .term-route__wire { top: 21px; }
  .term-route__cps { top: 17px; justify-content: space-around; }
  .term-route__leg { min-width: 0; height: 52px; }
  .term-cp i { width: 10px; height: 10px; border-width: 1.5px; }
  .term-cp.is-active i { box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent); }
  .term-cp.is-done i::after { inset: 1.5px 1.5px 2.5px; border-width: 1.2px; }
  .term-cp.is-fail i::before, .term-cp.is-fail i::after { inset: 3px 1px; height: 1.2px; }
  .term-cp b { display: none; }
  .term-route__meta { display: none; }
  .term-route__name { font-size: var(--fs-xs); }
  .term-seq__title { font-size: var(--fs-lg); }
}

/* ---------- After a session: banner over the kept output ---------- */
.term-banner { position: absolute; inset-inline: var(--sp-4); bottom: var(--sp-4); z-index: 3; display: flex; justify-content: center; pointer-events: none; }
.term-banner__inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  max-width: 640px;
  padding: 10px 12px;
  padding-inline-start: 14px;
  border-radius: var(--r-lg);
  background: var(--popover-bg);
  -webkit-backdrop-filter: var(--popover-backdrop);
  backdrop-filter: var(--popover-backdrop);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  animation: iv-rise var(--dur-3) var(--ease-out) both;
}
.term-banner--amber .term-banner__inner { border-color: color-mix(in srgb, var(--tone-amber) 40%, var(--border-strong)); }
.term-banner--red .term-banner__inner { border-color: color-mix(in srgb, var(--tone-red) 40%, var(--border-strong)); }
.term-banner__text { flex: 1; min-width: 0; }
.term-banner__title { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text); }
.term-banner__sub { font-size: var(--fs-xs); color: var(--text-2); }
.term-banner__actions { display: flex; flex: none; gap: 6px; }

/* ---------- No tab ---------- */
.term-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-6); text-align: center; }
.term-empty__art { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 20px; background: var(--chip); color: var(--text-3); }
.term-empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.term-empty__text { max-width: 420px; font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- Find ---------- */
.term-find {
  position: absolute;
  top: 10px;
  inset-inline-end: 18px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100% - 28px);
  padding: 4px;
  padding-inline-start: 10px;
  border-radius: var(--r-md);
  background: var(--popover-bg);
  -webkit-backdrop-filter: var(--popover-backdrop);
  backdrop-filter: var(--popover-backdrop);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  animation: iv-pop var(--dur-2) var(--ease-out) both;
}
.term-find__icon { display: grid; color: var(--text-3); }
.term-find__input { width: 190px; min-width: 0; height: 32px; padding-inline: 6px; border: 0; background: transparent; color: var(--text); font-family: var(--font-mono); font-size: var(--fs-sm); }
.term-find__input:focus-visible { box-shadow: none; }
.term-find:focus-within { border-color: color-mix(in srgb, var(--indigo) 55%, var(--border-strong)); }
.term-find__count { min-width: 52px; font-size: var(--fs-2xs); color: var(--text-3); text-align: center; white-space: nowrap; }
.term-find__opt { flex: none; min-width: 30px; height: 28px; padding-inline: 6px; border-radius: 8px; font-family: var(--font-mono); font-size: 12px; color: var(--text-3); direction: ltr; }
.term-find__opt:hover { background: var(--chip); color: var(--text); }
.term-find__opt[aria-pressed="true"] { background: var(--indigo-soft); color: var(--indigo-text); }

/* ---------- Accessory keys (touch) ---------- */
.term-keys {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--term-chrome);
  border-top: 1px solid var(--term-edge);
}
.term-keys::-webkit-scrollbar { display: none; }
.term-key {
  flex: none;
  min-width: 44px;
  height: 42px;
  padding-inline: 10px;
  display: inline-grid;
  place-items: center;
  border-radius: 11px;
  background: var(--term-chrome-2);
  border: 1px solid var(--term-edge);
  border-bottom-width: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  direction: ltr;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-1), transform var(--dur-1);
}
.term-key:active { transform: translateY(1px); background: var(--chip-hover); }
.term-key--mod[aria-pressed="true"] { background: var(--indigo-soft); border-color: var(--indigo); color: var(--indigo-text); }

/* ---------- Status bar ---------- */
.term-status {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 40px;
  padding: 6px 14px;
  background: var(--term-chrome);
  border-top: 1px solid var(--term-edge);
  border-radius: 0 0 var(--term-r) var(--term-r);
  font-size: var(--fs-xs);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
}
.term-status__state { display: inline-flex; align-items: center; gap: 7px; flex: none; font-weight: var(--fw-medium); color: var(--text); }
.term-status__env { flex: none; }
.term-status__addr {
  min-width: 0;
  max-width: 340px;
  padding: 3px 8px;
  border-radius: 8px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--dur-2), color var(--dur-2);
}
.term-status__addr .mono { font-size: 12px; }
.term-status__addr:hover { background: var(--chip); color: var(--text); }
.term-status__spacer { flex: 1; min-width: 0; }
.term-status__warn { display: inline-flex; align-items: center; gap: 5px; flex: none; padding: 3px 9px; border-radius: var(--r-full); background: var(--tone-amber-bg); color: var(--tone-amber-fg); font-weight: var(--fw-medium); }
.term-metric { display: inline-flex; align-items: center; gap: 5px; flex: none; color: var(--text-2); font-variant-numeric: tabular-nums; }
.term-metric .icon { color: var(--text-3); }
.term-metric[data-quality="good"] .icon { color: var(--tone-green-fg); }
.term-metric[data-quality="fair"] .icon { color: var(--tone-amber-fg); }
.term-metric[data-quality="poor"] .icon { color: var(--tone-red-fg); }
.term-metric__q { color: var(--text-3); }
.term-metric.mono { font-size: 11.5px; color: var(--text-3); }

/* Mini route of the status bar: the connection sequence, collapsed. Packets fly on Rx/Tx (terminal.js). */
.term-wire { position: relative; display: inline-flex; align-items: center; justify-content: space-between; flex: none; width: 56px; height: 14px; }
.term-wire::before {
  content: "";
  position: absolute;
  inset-inline: 4px;
  top: 50%;
  height: 1.5px;
  margin-top: -0.75px;
  background: repeating-linear-gradient(90deg, var(--border-strong) 0 3px, transparent 3px 6px);
  transition: background var(--dur-3);
}
.term-wire.is-on::before { background: linear-gradient(90deg, color-mix(in srgb, var(--tone-green) 65%, transparent), color-mix(in srgb, var(--indigo) 65%, transparent)); }
.term-wire__node { position: relative; z-index: 1; width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); transition: background var(--dur-3), box-shadow var(--dur-3); }
.term-wire.is-on .term-wire__node { background: var(--tone-green); box-shadow: 0 0 6px var(--tone-green); animation: term-node-on 560ms var(--ease-spring) both; }
.term-wire.is-on .term-wire__node:nth-child(2) { animation-delay: 90ms; }
.term-wire.is-on .term-wire__node:nth-child(3) { animation-delay: 180ms; }
@keyframes term-node-on { from { transform: scale(0.2); } }
.term-wire__pkt {
  position: absolute;
  z-index: 2;
  top: 50%;
  inset-inline-start: 2px;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--indigo);
  box-shadow: 0 0 8px var(--indigo);
  opacity: 0;
  pointer-events: none;
}
.term-wire__pkt[data-kind="rx"] { background: var(--tone-green); box-shadow: 0 0 8px var(--tone-green); }

/* ---------- Responsive window (container query on the window) ---------- */
@container termwin (max-width: 900px) {
  .term-tool--wide { display: none; }
  .term-more { display: inline-flex; }
}
@container termwin (max-width: 640px) {
  .term-bar { padding: 6px; gap: 4px; }
  .term-tool__label { display: none; }
  .term-tool--label { width: 36px; padding: 0; justify-content: center; }
  /* Menus span the bar instead of hanging off a button near the edge. */
  .term-add, .term-cmds, .term-more { position: static; }
  .term-bar .term-menu { inset-inline: 6px; top: calc(100% + 4px); min-width: 0; max-width: none; }
  .term-tab { max-width: 168px; }
  .term-status { gap: var(--sp-2); padding-inline: 10px; }
  .term-status__addr, .term-metric--wide, .term-metric__q { display: none; }
  .term-wire { width: 40px; }
  .term-find { inset-inline: 8px; max-width: none; }
  .term-find__input { width: auto; flex: 1; }
  .term-banner { inset-inline: var(--sp-2); bottom: var(--sp-2); }
  .term-banner__inner { flex-wrap: wrap; }
  .term-banner__actions { width: 100%; justify-content: flex-end; }
  .term-host { inset: 8px 2px 2px 8px; }
}
@container termwin (max-width: 420px) {
  .term-seq { padding: var(--sp-4) var(--sp-3); }
  .term-metric.mono { display: none; }
}

/* Touch: 44px targets in the bar. */
@media (pointer: coarse) {
  .term-tab { height: 44px; }
  .term-tab__close { width: 36px; height: 36px; margin-inline-end: 4px; opacity: 1; }
  .term-tool { width: 44px; height: 44px; }
  .term-tool--label { width: auto; }
  .term-add__btn { --ib: 44px; }
}

/* ---------- Docked to the visual viewport (on-screen keyboard) / immersive / fullscreen ---------- */
.term.is-docked::after { content: ""; display: block; height: var(--term-h, 60vh); }
.term.is-docked .term-window {
  position: fixed;
  z-index: 45;
  top: var(--vv-top, 0px);
  left: var(--vv-left, 0px);
  width: var(--vv-w, 100vw);
  height: var(--vv-h, 100dvh);
  min-height: 0;
  border-radius: 0;
  border-width: 0;
}
.term.is-docked .term-bar, .term.is-docked .term-status { border-radius: 0; }
.term-window:fullscreen { width: 100%; height: 100%; border-radius: 0; border: 0; }
.term-window:fullscreen .term-bar, .term-window:fullscreen .term-status { border-radius: 0; }
.term-window::backdrop { background: var(--term-bg); }

/* ---------- Pop-out window (?window=1): only the terminal ---------- */
.app:has(.term--window) { display: block; height: 100dvh; max-width: none; padding: 0; }
.app:has(.term--window) :is(.sidebar, .shell-overlay, .topbar, .bottom-nav, .credit) { display: none !important; }
.app:has(.term--window) .main { height: 100dvh; min-height: 0; border: 0; border-radius: 0; overflow: hidden; }
.app:has(.term--window) .main__content { display: flex; flex-direction: column; height: 100%; max-width: none; padding: 0; }
.term--window { flex: 1 1 auto; min-height: 0; gap: 0; }
.term--window .term-head { display: none; }
.term--window .term-window { flex: 1 1 auto; height: auto; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
.term--window .term-bar, .term--window .term-status { border-radius: 0; }

/* ---------- Command palette: «ترمینال» on SSH results (row layout: vault-quick.css) ---------- */
.palette__hit--term > .palette__item { padding-inline-end: 150px; }
.palette__hit--term.palette__hit--term-copy > .palette__item { padding-inline-end: 246px; }
.palette__hit--term .palette__act[data-palette-act="ssh"] { width: 30px; padding: 0; justify-content: center; }
.palette__hit--term .palette__act[data-palette-act="ssh"] > span { display: none; }
.palette__act--terminal { background: var(--indigo-soft); border-color: color-mix(in srgb, var(--indigo) 34%, transparent); color: var(--indigo-text); }
.palette__act--terminal:hover { background: color-mix(in srgb, var(--indigo) 24%, transparent); color: var(--indigo-text); }
@media (max-width: 767px) {
  .palette__hit--term > .palette__item { padding-inline-end: 112px; }
  .palette__hit--term.palette__hit--term-copy > .palette__item { padding-inline-end: 156px; }
  .palette__hit--term .palette__act[data-palette-act="ssh"] { width: 40px; }
}

/* ---------- Launchers on other pages ---------- */
.term-launch { color: var(--tone-green-fg); }
.term-launch:hover { background: var(--tone-green-bg); color: var(--tone-green-fg); }
.term-cta { flex: none; margin-top: var(--sp-3); }
.term-cta[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .term-route__wire i, .term-cp.is-active i, .term-seq__spinner, .term-wire__node,
  .term-seq:not(.is-failed) .term-route__node[data-node="server"]:not(.is-ready) .term-route__chip::after,
  [data-phase="connecting"] > .term-dot, [data-phase="connecting"] > * > .term-dot { animation: none !important; }
  .term-route__leg.is-active .term-route__wire i, .term-route__leg.is-done .term-route__wire i { opacity: 0.8; }
  .term-seq__card, .term-fail, .term-hostkey, .term-banner__inner, .term-find { animation: none; }
}
