:root {
  --bg: #0f1419; --panel: #161c23; --panel-2: #1c242d; --line: #26303b; --line-2: #33404d;
  --text: #e3e9ef; --muted: #8b98a6; --dim: #5d6b79;
  --accent: #3ddc97; --accent-ink: #062b1c; --accent-soft: rgba(61,220,151,.12);
  --danger: #ff6b6b; --danger-soft: rgba(255,107,107,.12); --warn: #ffc857; --info: #6cb6ff;
  --radius: 8px; --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-tap-highlight-color: transparent; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--dim); }
a.btn { text-decoration: none; color: inherit; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: rgba(255,107,107,.35); background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.icon { width: 34px; padding: 0; }
.btn.block { width: 100%; height: 40px; }
.btn svg { width: 16px; height: 16px; flex: none; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line-2);
  border-radius: var(--radius); outline: none; }
textarea.input { height: auto; min-height: 110px; padding: 8px 10px; font-family: var(--mono); font-size: 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.seg { align-self: flex-start; display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.code-input { font: 600 26px/1 var(--mono); letter-spacing: .4em; text-align: center; height: 52px; }

/* ---------- auth screens ---------- */
.auth-wrap { height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(61,220,151,.08), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand img { width: 34px; height: 34px; }
.brand b { font-size: 19px; letter-spacing: .2px; }
.auth-card h2 { margin: 0 0 4px; font-size: 17px; }
.auth-card p.lead { margin: 0 0 18px; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.qr { display: block; margin: 0 auto 10px; border-radius: 8px; background: #fff; padding: 6px; width: 200px; height: 200px; }
.secret { font-family: var(--mono); font-size: 12px; text-align: center; word-break: break-all; padding: 8px; background: var(--bg);
  border: 1px dashed var(--line-2); border-radius: var(--radius); margin-bottom: 14px; user-select: all; }

/* ---------- main layout ---------- */
.shell { height: 100%; display: grid; grid-template-rows: 50px 1fr; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .brand { margin: 0 8px 0 2px; }
.topbar .brand img { width: 26px; height: 26px; }
.topbar .brand b { font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; margin-right: 4px; }
.body { display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side-tools { padding: 10px; display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.side-tools .input { height: 32px; }
.tree { flex: 1; overflow: auto; padding: 6px 4px 30px; }
.node { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px; border-radius: 6px; cursor: pointer; user-select: none;
  position: relative; border: 1px solid transparent; }
.node:hover { background: var(--panel-2); }
.node.sel { background: var(--accent-soft); }
.node.drop { border-color: var(--accent); background: var(--accent-soft); }
.node .chev { width: 14px; color: var(--dim); flex: none; transition: transform .12s; }
.node .chev.open { transform: rotate(90deg); }
.node .ico { width: 16px; height: 16px; flex: none; color: var(--muted); }
.node.folder .ico { color: var(--warn); }
.node .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .meta { font: 11px var(--mono); color: var(--dim); }
.badge { font: 600 10px var(--mono); padding: 1px 5px; border-radius: 4px; text-transform: uppercase; }
.card .ico { width: 16px; height: 16px; color: var(--muted); flex: none; }
.badge.ssh { color: var(--accent); background: var(--accent-soft); }
.badge.rdp { color: var(--info); background: rgba(108,182,255,.12); }
.badge.telnet { color: var(--warn); background: rgba(255,200,87,.12); }
.node .more { opacity: 0; width: 26px; height: 26px; }
.node:hover .more, .node.sel .more { opacity: 1; }
.node .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); flex: none; }
.root-drop { margin: 8px 6px; padding: 10px; border: 1px dashed var(--line-2); border-radius: 8px; color: var(--dim); font-size: 12px; text-align: center; }
.root-drop.drop { border-color: var(--accent); color: var(--accent); }
.empty { color: var(--dim); text-align: center; padding: 30px 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 6px 0; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; background: var(--panel); scrollbar-width: none; }
.tab { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px 0 12px; border: 1px solid transparent; border-bottom: 0;
  border-radius: 8px 8px 0 0; cursor: pointer; color: var(--muted); white-space: nowrap; max-width: 220px; }
.tab .t { overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--bg); border-color: var(--line); color: var(--text); margin-bottom: -1px; }
.tab .st { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); flex: none; }
.tab .st.ok { background: var(--accent); } .tab .st.bad { background: var(--danger); } .tab .st.wait { background: var(--warn); }
.tab .x { width: 22px; height: 22px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; color: var(--dim); }
.tab .x:hover { background: var(--panel-2); color: var(--text); }
.views { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.term-host { flex: 1; min-height: 0; padding: 6px 0 0 8px; background: #0b0f13; }
.term-host .xterm { height: 100%; }
.term-bar { display: none; gap: 4px; padding: 6px 6px calc(6px + var(--safe-b)); overflow-x: auto; background: var(--panel); border-top: 1px solid var(--line); flex: none; }
.term-bar button { flex: none; min-width: 44px; height: 36px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel-2); font: 13px var(--mono); }
.term-bar button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.welcome { flex: 1; overflow: auto; padding: 28px; }
.welcome h1 { font-size: 20px; margin: 0 0 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; cursor: pointer; }
.card:hover { border-color: var(--line-2); }
.card .h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.card .h .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .addr { font: 12px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ---------- RDP ---------- */
.rdp-wrap { flex: 1; min-height: 0; position: relative; background: #05080b; }
.rdp-host { position: absolute; inset: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; outline: none; touch-action: none; }
.rdp-host > div { cursor: none; }
.rdp-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,8,11,.72); padding: 16px; }
.rdp-msg { max-width: 460px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.rdp-actions { margin-top: 14px; display: flex; justify-content: center; gap: 8px; }
.term-bar.rdp-bar { display: flex; padding-bottom: calc(6px + var(--safe-b)); }
.rdp-bar button { font-family: var(--sans); }
.rdp-bar button.danger { color: var(--danger); margin-left: auto; }
@media (hover: hover) and (pointer: fine) { .only-touch { display: none; } }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5,8,11,.66); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { max-width: 760px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px; }
.modal-h h3 { margin: 0; font-size: 16px; }
.modal-b { padding: 10px 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 18px 16px; }
@keyframes fade { from { opacity: 0 } }
.stabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.stabs button { border: 0; background: transparent; padding: 10px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.stabs button.on { color: var(--text); border-color: var(--accent); }
.list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.list .li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.list .li:first-child { border-top: 0; }
.list .li .grow { flex: 1; min-width: 0; }
.list .li .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-t { font-weight: 600; margin: 6px 0 10px; }
table.audit { width: 100%; border-collapse: collapse; font-size: 12px; }
table.audit td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.audit td:first-child { white-space: nowrap; color: var(--muted); font-family: var(--mono); }

.menu { position: fixed; z-index: 60; min-width: 190px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 5px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--line); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line-2); margin: 4px 0; }

#toast-root { position: fixed; bottom: calc(16px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); padding: 9px 14px; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 90vw; }
.toast.bad { border-color: rgba(255,107,107,.5); color: var(--danger); }

.fp { font: 12px var(--mono); background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px; word-break: break-all; margin: 8px 0 12px; }

/* ---------- mobile ---------- */
.only-m { display: none; }
.scrim { display: none; }
@media (max-width: 820px) {
  .only-m { display: inline-flex; }
  .hide-m { display: none !important; }
  .body { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 50px; bottom: 0; left: 0; width: min(88vw, 340px); z-index: 40; transform: translateX(-102%);
    transition: transform .18s ease; box-shadow: 10px 0 40px rgba(0,0,0,.4); }
  .shell.side-open .sidebar { transform: none; }
  .shell.side-open .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 50px 0 0 0; background: rgba(0,0,0,.45); z-index: 39; }
  .node { height: 40px; }
  .node .more { opacity: 1; }
  .term-bar { display: flex; }
  .welcome { padding: 18px 16px; }
  .modal { max-height: calc(100dvh - 24px); }
  .overlay { padding: 12px; align-items: end; }
}
