/* Connect console.
   Dark, dense, and information-first: the operator is scanning a fleet, so
   rows stay tight and status reads at a glance. */

:root {
  --bg:        #0e1116;
  --bg-2:      #151a21;
  --bg-3:      #1b222b;
  --line:      #262e3a;
  --line-soft: #1f2632;
  --fg:        #e6edf3;
  --fg-dim:    #8d99a8;
  --fg-faint:  #5d6673;
  --accent:    #3b82f6;
  --accent-dk: #1d4ed8;
  --green:     #22c55e;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The layout rules below set display on elements that are also toggled with the
   `hidden` attribute, and an explicit display beats the user-agent's
   `[hidden] { display: none }`. Without this the login shell, the app shell,
   and the modal would all be visible at once on first paint. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent-dk);
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  border-radius: 6px;
  transition: filter .12s ease;
}
button:hover:not(:disabled) { filter: brightness(1.12); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--fg-dim);
}
button.ghost:hover:not(:disabled) { color: var(--fg); border-color: var(--fg-faint); }
button.mini {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 5px;
}
button.linkish {
  background: none; border: none; color: var(--accent);
  padding: 0; text-decoration: underline;
}

input, select, textarea {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 6px;
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; }

kbd {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; font-family: var(--mono); font-size: 12px;
}

/* ----------------------------------------------------------------- login */

.login-shell {
  height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #17202c 0%, var(--bg) 60%);
}
.login-card {
  width: 340px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
}
.login-mark { font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.login-sub { color: var(--fg-dim); margin: 4px 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 6px; }
.login-card button { width: 100%; margin-top: 14px; }
.login-error {
  margin-top: 12px; color: var(--red); font-size: 13px;
  background: rgba(239,68,68,.09); border: 1px solid rgba(239,68,68,.3);
  border-radius: 6px; padding: 8px 10px;
}

/* ---------------------------------------------------------------- topbar */

#app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px; height: 52px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { font-weight: 650; letter-spacing: -.01em; }
.search-wrap { flex: 1; max-width: 460px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.stat { color: var(--fg-dim); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.stat b { color: var(--fg); font-weight: 600; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-faint); display: inline-block; flex: none;
}
.dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }

/* ---------------------------------------------------------------- layout */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 460px;
  min-height: 0;
}

/* --------------------------------------------------------------- sidebar */

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  overflow-y: auto;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--fg-faint); padding: 14px 8px 6px;
}
.side-head:first-child { padding-top: 0; }
.tree { display: flex; flex-direction: column; gap: 1px; }
.tree-item {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--fg-dim);
  padding: 7px 9px; border-radius: 6px; text-align: left; width: 100%;
  font-size: 13px;
}
.tree-item:hover { background: var(--bg-3); color: var(--fg); }
.tree-item.active { background: var(--bg-3); color: var(--fg); font-weight: 550; }
.tree-item .count { margin-left: auto; color: var(--fg-faint); font-size: 12px; }
.tree-item .del {
  margin-left: 6px; opacity: 0; color: var(--fg-faint); font-size: 14px; line-height: 1;
}
.tree-item:hover .del { opacity: 1; }
.tree-item .del:hover { color: var(--red); }

/* ----------------------------------------------------------------- table */

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

.table-head, .row {
  display: grid;
  grid-template-columns: 34px minmax(140px, 2fr) minmax(90px, 1fr) 96px 118px 108px 40px;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}
.table-head {
  height: 34px; flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--fg-faint);
}
.rows { overflow-y: auto; flex: 1; }
.row {
  height: 46px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.row:hover { background: var(--bg-2); }
.row.selected { background: rgba(59,130,246,.10); }
.row.selected:hover { background: rgba(59,130,246,.15); }

.cell-name { display: flex; align-items: center; gap: 9px; min-width: 0; }
.name-text { min-width: 0; }
.name-text .n {
  font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.name-text .h {
  font-size: 11.5px; color: var(--fg-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell-dim { color: var(--fg-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-mono { font-family: var(--mono); font-size: 12px; color: var(--fg-dim); }
.os-badge {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 4px;
  background: var(--bg-3); color: var(--fg-dim); border: 1px solid var(--line);
}
.row-menu {
  background: none; border: none; color: var(--fg-faint); padding: 4px 6px;
  border-radius: 5px; font-size: 15px; line-height: 1;
}
.row-menu:hover { background: var(--bg-3); color: var(--fg); }

.chk { display: inline-flex; align-items: center; cursor: pointer; }
.chk input { position: absolute; opacity: 0; width: 0; height: 0; }
.chk span {
  width: 15px; height: 15px; border: 1.5px solid var(--line);
  border-radius: 4px; display: inline-block; position: relative; background: var(--bg);
}
.chk input:checked + span { background: var(--accent); border-color: var(--accent); }
.chk input:checked + span::after {
  content: ""; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.empty { padding: 40px; text-align: center; color: var(--fg-faint); }

/* ----------------------------------------------------------------- panel */

.panel {
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--fg-dim); padding: 11px 15px; border-radius: 0; font-size: 13px;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 550; }

.selection-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; font-size: 12.5px; color: var(--fg-dim);
  border-bottom: 1px solid var(--line-soft); background: var(--bg-3); flex: none;
}

.tab-body { display: none; flex-direction: column; min-height: 0; flex: 1; padding: 14px; gap: 12px; overflow-y: auto; }
.tab-body.active { display: flex; }
.tab-body[data-body="terminal"] { padding: 0; gap: 0; overflow: hidden; }

/* terminal */
.term-output {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
}
.hint { color: var(--fg-faint); font-family: var(--sans); font-size: 13px; }
.job { margin-bottom: 16px; }
.job-cmd {
  color: var(--fg); background: var(--bg-3); border-left: 2px solid var(--accent);
  padding: 6px 10px; border-radius: 0 5px 5px 0; margin-bottom: 8px;
  white-space: pre-wrap; word-break: break-word;
}
.job-cmd .meta { color: var(--fg-faint); font-size: 11px; display: block; margin-top: 3px; }
.host-block { margin: 0 0 8px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.host-head {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3); padding: 5px 10px; font-size: 12px;
}
.host-head .hn { font-weight: 600; }
.host-head .code { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.code.ok   { background: rgba(34,197,94,.15);  color: var(--green); }
.code.bad  { background: rgba(239,68,68,.15);  color: var(--red); }
.code.wait { background: rgba(245,158,11,.15); color: var(--amber); }
.host-out {
  padding: 7px 10px; white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow-y: auto; color: var(--fg-dim);
}
.host-out .e { color: #fca5a5; }

.term-input {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--line); background: var(--bg-3); flex: none;
}
.term-input select { width: 110px; flex: none; }
.term-input input { font-family: var(--mono); font-size: 13px; }
.term-input button { flex: none; }

/* files + clipboard */
.field label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 6px; }
.row-btns { display: flex; gap: 8px; }

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 26px;
  text-align: center;
  color: var(--fg-dim);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.over { border-color: var(--accent); background: rgba(59,130,246,.07); }
.dz-icon { font-size: 26px; color: var(--fg-faint); }
.dz-inner p { margin: 6px 0 0; font-size: 13px; }
.dz-sub { color: var(--fg-faint); font-size: 12px !important; }

.file-log { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.log-line {
  padding: 7px 10px; border-radius: 6px; background: var(--bg-3);
  border-left: 2px solid var(--line); color: var(--fg-dim);
}
.log-line.ok  { border-left-color: var(--green); }
.log-line.err { border-left-color: var(--red); color: #fca5a5; }

.action-card {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--line); border-radius: 8px; padding: 14px;
}
.action-card p { margin: 3px 0 0; color: var(--fg-dim); font-size: 12.5px; }
.action-card button { margin-left: auto; flex: none; }

/* ---------------------------------------------------------------- viewer */

.viewer {
  position: fixed; inset: 0; z-index: 70;
  background: #05070a;
  display: flex; flex-direction: column;
}
.viewer-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--bg-2);
  border-bottom: 1px solid var(--line); flex: none;
}
.vb-name { font-weight: 600; }
.vb-stat { color: var(--fg-faint); font-size: 12px; font-family: var(--mono); }
.vb-spacer { flex: 1; }
.viewer-bar select { width: auto; padding: 5px 8px; font-size: 12.5px; }
.vb-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-dim); font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.vb-toggle input { width: auto; }

.viewer-stage {
  flex: 1; min-height: 0; position: relative;
  display: grid; place-items: center; overflow: hidden;
}
#screen {
  max-width: 100%; max-height: 100%;
  /* The frame is a downscaled JPEG; letting the browser smooth it on the way
     back up reads better than blocky nearest-neighbour. */
  image-rendering: auto;
  cursor: crosshair;
  background: #000;
}
#screen.controlling { cursor: none; }
.viewer-msg {
  position: absolute; color: var(--fg-faint); font-size: 13px;
  pointer-events: none; text-align: center; padding: 0 20px;
}

/* ----------------------------------------------------------------- modal */

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 50;
}
.modal-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px; width: min(560px, calc(100vw - 40px)); max-height: 80vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 14px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-card pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 11px; overflow-x: auto; font-family: var(--mono); font-size: 12px;
  color: var(--fg-dim); white-space: pre-wrap; word-break: break-all;
}
.modal-card .step { color: var(--fg-dim); font-size: 13px; margin: 14px 0 6px; }

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-3); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 7px; padding: 10px 14px; font-size: 13px;
  min-width: 220px; max-width: 380px;
  animation: rise .18s ease;
}
.toast.ok  { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* --------------------------------------------------------------- narrow */

@media (max-width: 1180px) {
  .layout { grid-template-columns: 190px minmax(0,1fr) 380px; }
  .table-head, .row { grid-template-columns: 34px minmax(120px,2fr) 90px 80px 0 96px 36px; }
  .th-ip, .cell-ip { display: none; }
}
