:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.view { height: 100vh; }
.centered { display: flex; align-items: center; justify-content: center; }

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 12px;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #2d333b; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: var(--accent); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); text-align: left; }
button.ghost:hover { background: var(--bg-3); color: var(--text); }
button.danger { color: var(--red); border-color: transparent; background: transparent; }
button.danger:hover { background: rgba(248, 81, 73, 0.12); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { padding: 2px 9px; font-size: 18px; line-height: 1; }

label { display: block; margin: 12px 0; color: var(--muted); font-size: 12px; }
input, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}
.login-card { width: 340px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 4px 0 16px; }
.login-card button { width: 100%; margin-top: 8px; padding: 10px; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ── App layout ─────────────────────────────────────────────── */
.app { display: flex; position: relative; }
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.15s ease, min-width 0.15s ease;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; border-right: none; }
.sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 8px;
  z-index: 20;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--muted);
  padding: 5px 8px;
  transition: left 0.15s ease;
}
.sidebar-toggle:hover { background: var(--bg-3); color: var(--text); }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
.conn-list { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-foot { padding: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot button { padding: 8px 10px; }

.conn-item {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 4px;
}
.conn-item:hover { background: var(--bg-3); border-color: var(--border); }
.conn-item .conn-label { font-weight: 600; }
.conn-item .conn-sub { color: var(--muted); font-size: 12px; margin-top: 2px; font-family: var(--mono); }
.conn-item .conn-actions { margin-top: 8px; display: flex; gap: 6px; }
.conn-item .conn-actions button { padding: 4px 10px; font-size: 12px; }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabbar {
  display: flex; gap: 2px; padding: 6px 8px 0;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  overflow-x: auto; min-height: 42px;
}
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px 8px 0 0;
  background: var(--bg-3); border: 1px solid var(--border); border-bottom: none;
  color: var(--muted); white-space: nowrap; cursor: pointer; font-size: 13px;
}
.tab.active { background: var(--bg); color: var(--text); }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.tab .dot.connected { background: var(--green); }
.tab .dot.connecting, .tab .dot.reconnecting { background: var(--yellow); }
.tab .dot.error, .tab .dot.ended { background: var(--red); }
.tab .tab-close { border: none; background: transparent; color: inherit; padding: 0 2px; font-size: 15px; }
.tab .tab-close:hover { color: var(--red); background: transparent; }
.tab .tab-name { font-family: var(--mono); font-size: 11px; opacity: 0.8; }

.terminals { flex: 1; position: relative; background: var(--bg); min-height: 0; }
.term-pane { position: absolute; inset: 0; }
.term-pane .xterm { height: 100%; width: 100%; }
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; }

.term-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 20px;
  padding: 5px 14px; font-size: 12px; z-index: 5; color: var(--yellow);
  display: flex; align-items: center; gap: 8px;
}
.term-banner.error { color: var(--red); }
.term-banner.ended { color: var(--muted); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-root { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(1, 4, 9, 0.7); }
.modal {
  position: relative; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; width: 440px; max-width: 92vw;
  max-height: 86vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.picker-list { margin: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.picker-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--bg);
}
.picker-item:hover { border-color: var(--accent); }
.picker-item.new { border-style: dashed; color: var(--accent); justify-content: center; }
.picker-item .p-name { font-family: var(--mono); font-weight: 600; }
.picker-item .p-meta { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; }
.picker-item .p-drop { margin-left: 6px; }
.picker-item .p-kill { margin-left: 4px; padding: 4px 8px; }
.notice { background: rgba(210, 153, 34, 0.12); border: 1px solid var(--yellow);
  color: var(--yellow); border-radius: 8px; padding: 10px 12px; font-size: 12px; line-height: 1.4; }

.section { margin-bottom: 4px; }
.section h3 { margin: 0 0 6px; font-size: 15px; }
.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.ok-text { color: var(--green); font-size: 13px; }
.qr { display: block; width: 200px; height: 200px; background: #fff; padding: 8px;
  border-radius: 8px; margin: 8px 0; }
.secret { display: inline-block; font-family: var(--mono); font-size: 13px; letter-spacing: 1px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  margin: 2px 0 8px; user-select: all; word-break: break-all; }

.audit-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.audit-table th, .audit-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.audit-table th { color: var(--muted); font-weight: 600; }
.audit-table td.ts { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--bg-3); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 8px; z-index: 100; font-size: 13px;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--green); }

.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted);
  border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
