/* Clutch — terminal surfaces and the SSH workspace.
   Companion to style.css. Greyscale only; --danger is inherited, never added to. */

:root {
  --term-bg: #ffffff;
  --term-fg: #101010;
  --term-dim: #6e6e6e;
  --term-sel: rgba(0, 0, 0, .16);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --term-bg: #000000;
    --term-fg: #f2f2f2;
    --term-dim: #8d8d8d;
    --term-sel: rgba(255, 255, 255, .24);
  }
}

:root[data-theme="dark"] {
  --term-bg: #000000;
  --term-fg: #f2f2f2;
  --term-dim: #8d8d8d;
  --term-sel: rgba(255, 255, 255, .24);
}

/* ── xterm.js 5.5.0 baseline (the tarball ships no stylesheet) ───────── */

.xterm { position: relative; height: 100%; user-select: none; -webkit-user-select: none; }
.xterm.focus, .xterm:focus { outline: none; }
.xterm-viewport { overflow-y: scroll; background-color: transparent; scrollbar-width: thin; }
.xterm-screen { position: relative; }
.xterm-screen canvas { position: absolute; left: 0; top: 0; }
.xterm-helper-textarea {
  position: absolute; opacity: 0; left: -9999em; top: 0; width: 0; height: 0;
  z-index: -5; white-space: nowrap; overflow: hidden; resize: none;
}
.xterm-char-measure-element { display: inline-block; visibility: hidden; position: absolute; left: -9999em; top: 0; line-height: normal; }
.xterm-decoration-container, .xterm-decoration-overview-ruler { position: absolute; top: 0; pointer-events: none; z-index: 6; }
.xterm-accessibility, .xterm-message { position: absolute; left: 0; top: 0; bottom: 0; right: 0; z-index: 10; color: transparent; pointer-events: none; }
.xterm-accessibility-tree:not(:focus-within) { font-size: 0; }
.xterm-accessibility-tree textarea { pointer-events: auto; }
.xterm-rows { position: absolute; left: 0; top: 0; }
.xterm-cursor-pointer, .xterm-decoration { cursor: pointer; }

/* ── Single terminal (server detail) ────────────────────────────────── */

.terminal {
  width: 100%; height: 28rem;
  border: 1px solid var(--line);
  background: var(--term-bg);
  padding: var(--s1);
  margin-bottom: var(--s2);
}

/* ── SSH workspace ──────────────────────────────────────────────────── */

.ssh {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  border: 1px solid var(--line);
  min-height: 36rem;
}

.ssh-hosts {
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto; max-height: calc(100vh - var(--bar) - 9rem);
}
.ssh-hosts-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: var(--s1) var(--s2);
  border-bottom: 1px solid var(--line);
  font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3);
}
.hosts { list-style: none; margin: 0; padding: 0; }
.ssh-host { border-bottom: 1px solid var(--line-2); }
.ssh-host:last-child { border-bottom: 0; }
.ssh-host.on { background: var(--bg-3); }

.ssh-host-open {
  display: block; width: 100%; text-align: left;
  border: 0; border-left: 2px solid transparent; background: none; color: var(--ink);
  padding: var(--s1) var(--s2) var(--s-half); font-weight: 500;
}
.ssh-host-open:hover { background: var(--bg-3); color: var(--ink); }
.ssh-host.on .ssh-host-open { border-left-color: var(--ink); }
.ssh-host-name { display: flex; align-items: center; gap: var(--s1); font-size: 13px; }
.ssh-host-meta {
  display: block; margin-top: 1px; padding-left: calc(8px + var(--s1));
  font-size: 11px; font-weight: 400; color: var(--ink-3);
}
.ssh-host-meta.bad { color: var(--danger); }

.ssh-host-foot { display: flex; gap: var(--s1); padding: 0 var(--s2) var(--s1) calc(var(--s2) + 8px + var(--s1)); }
.ssh-host-foot button {
  border: 0; padding: 0; background: none; color: var(--ink-3);
  font-size: 10px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase;
}
.ssh-host-foot button:hover { background: none; color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.ssh-host-foot .detail {
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); text-decoration: none;
}
.ssh-host-foot .detail:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }

.ssh-main { display: flex; flex-direction: column; min-width: 0; }

.tabs { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); background: var(--bg-2); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s1);
  border: 0; border-right: 1px solid var(--line); border-bottom: 2px solid transparent;
  background: none; color: var(--ink-2);
  padding: var(--s1) var(--s2);
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.tab:hover { background: var(--bg-3); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--bg); color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.tab-close { border: 0; background: none; color: var(--ink-3); padding: 0 2px; font-size: 13px; line-height: 1; }
.tab-close:hover { background: none; color: var(--danger); }
.tab-new { margin-left: auto; border-right: 0; color: var(--ink-3); font-weight: 600; }

.panes { flex: 1 1 auto; display: flex; min-height: 30rem; }
.pane { display: none; flex: 1 1 auto; flex-direction: column; min-width: 0; }
.pane.on { display: flex; }

.cmdbar {
  display: flex; align-items: center; gap: var(--s1);
  padding: var(--s1) var(--s2);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.cmdbar .prompt { color: var(--ink-3); font-size: 13px; }
.cmdbar input {
  flex: 1 1 auto; width: auto; min-width: 0;
  border: 0; border-bottom: 1px solid var(--line); padding: 4px 0;
  font-family: var(--mono); font-size: 12px; background: none;
}
.cmdbar input:hover { border-color: var(--ink-3); }
.cmdbar input:focus-visible { outline: none; border-bottom: 1px solid var(--ink); }
.cmdbar .cmdbar-hint { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }

.cmdout {
  margin: 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  max-height: 12rem; background: var(--bg-2); font-size: 11px;
}
.cmdout .meta { color: var(--ink-3); }
.cmdout .stderr, .cmdout .error { color: var(--danger); }

.term { flex: 1 1 auto; min-height: 20rem; background: var(--term-bg); padding: var(--s1); }

.pane-empty { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.pane-empty div { max-width: 30rem; text-align: center; color: var(--ink-3); }
.pane-empty strong { display: block; margin-bottom: var(--s1); font-size: 13px; color: var(--ink); }

/* ── CLI drawer (fan-out) ───────────────────────────────────────────── */

.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; flex-direction: column;
  max-height: 74vh;
  background: var(--bg);
  border-top: 1px solid var(--ink);
  box-shadow: 0 -6px 24px var(--shadow);
  transform: translateY(101%);
  visibility: hidden;
  transition: transform .14s ease-out, visibility 0s linear .14s;
}
.drawer[data-open] { transform: none; visibility: visible; transition: transform .14s ease-out, visibility 0s; }

.drawer-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s1) var(--s3);
  border-bottom: 1px solid var(--line);
}
.drawer-head strong { font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.drawer-head .muted { font-size: 11px; }
.drawer-head button { margin-left: auto; }

.drawer-body { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.drawer-body .row { align-items: flex-end; }
.drawer-body textarea { min-height: 3.5rem; width: min(100%, 44rem); }
.drawer-body label { margin-top: 0; }

.fanout { overflow-y: auto; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1px; background: var(--line); }
.fanout:empty { display: none; }
.fanout-host { background: var(--bg); padding: var(--s1) var(--s2) var(--s2); min-width: 0; }
.fanout-host header {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s1);
  padding-bottom: var(--s-half); margin-bottom: var(--s-half);
  border-bottom: 1px solid var(--line-2);
}
.fanout-host h4 { margin: 0; font-size: 12px; font-weight: 600; }
.fanout-host .state { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.fanout-host .state.bad { color: var(--danger); }
.fanout-host pre {
  border: 0; padding: 0; margin: 0; background: none;
  max-height: 13rem; font-size: 11px; line-height: 1.45;
}
.fanout-host pre .stderr, .fanout-host pre .error { color: var(--danger); }
.fanout-host pre .meta { color: var(--ink-3); }

@media (max-width: 900px) {
  .ssh { grid-template-columns: minmax(0, 1fr); }
  .ssh-hosts { border-right: 0; border-bottom: 1px solid var(--line); max-height: 14rem; }
  .panes { min-height: 24rem; }
  .drawer { max-height: 86vh; }
}
