:root {
  --bg: #080b13;
  --panel: #0e1421;
  --panel-2: #131b2b;
  --panel-3: #182136;
  --border: #1e2a41;
  --border-soft: #172032;
  --text: #dde5f4;
  --muted: #7d8ba5;
  --accent: #4f8cff;
  --accent-dim: #2a4f8f;
  --green: #35d07f;
  --red: #ff5f6d;
  --amber: #f5b544;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --panel-3: #eef2f9;
  --border: #dbe2ee;
  --border-soft: #e8edf5;
  --text: #16203a;
  --muted: #63708a;
  --accent: #2f6fed;
  --accent-dim: #b6cdf7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #22304a; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #2c3d5c; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------- app shell */

#app { display: none; height: 100vh; }
#app.ready { display: grid; grid-template-columns: 272px 1fr; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 20;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, #4f8cff, #7b5cff 55%, #b24bff);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 4px 14px rgba(79, 140, 255, .35);
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-txt b { font-size: 14px; letter-spacing: .2px; }
.brand-txt span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.brand-actions { margin-left: auto; display: flex; gap: 4px; }

.search-wrap { padding: 10px 12px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 10px;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--accent-dim); box-shadow: 0 0 0 3px rgba(79,140,255,.12); }
.search-box input { background: none; border: none; outline: none; width: 100%; font-size: 13px; }
.search-box input::placeholder { color: var(--muted); }
.search-box svg { flex: none; opacity: .55; }

.host-list { flex: 1; overflow-y: auto; padding: 4px 8px 80px; }
.group-head {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 6px 5px; font-size: 10.5px; letter-spacing: .9px;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
  cursor: pointer; user-select: none;
}
.group-head .caret { transition: transform .15s; }
.group-head.collapsed .caret { transform: rotate(-90deg); }

.host-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent; position: relative;
  transition: background .12s, border-color .12s;
}
.host-item:hover { background: var(--panel-2); border-color: var(--border-soft); }
.host-item.active { background: var(--panel-3); border-color: var(--accent-dim); }
.host-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,.04);
}
.host-meta { min-width: 0; flex: 1; }
.host-name { font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.host-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host-acts { display: none; gap: 2px; }
.host-item:hover .host-acts { display: flex; }
.host-item .fav-star { color: var(--amber); font-size: 11px; }

.icon-btn {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  color: var(--muted); transition: background .12s, color .12s;
}
.icon-btn:hover { background: rgba(127,150,190,.14); color: var(--text); }
.icon-btn.danger:hover { background: rgba(255,95,109,.15); color: var(--red); }
.icon-btn svg { pointer-events: none; }

.sidebar-foot {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 8px; display: flex; gap: 4px;
  background: linear-gradient(to top, var(--panel) 70%, transparent);
  border-top: 1px solid var(--border-soft);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px; border-radius: 8px; color: var(--muted); font-size: 9.5px;
  letter-spacing: .3px; transition: background .12s, color .12s;
}
.nav-btn:hover, .nav-btn.on { background: var(--panel-3); color: var(--text); }
.nav-btn.on { color: var(--accent); }

/* --------------------------------------------------------------- main area */

.main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }

.tabbar {
  display: flex; align-items: stretch; gap: 2px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0 6px; height: 42px; overflow-x: auto; flex: none;
}
.tabbar::-webkit-scrollbar { height: 0; }
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; margin-top: 6px; border-radius: 8px 8px 0 0;
  color: var(--muted); font-size: 12.5px; white-space: nowrap; max-width: 210px;
  border: 1px solid transparent; border-bottom: none;
  transition: background .12s, color .12s;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); border-color: var(--border); }
.tab .tab-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.tab .tab-title { overflow: hidden; text-overflow: ellipsis; }
.tab .tab-x { opacity: .4; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; }
.tab .tab-x:hover { opacity: 1; background: rgba(255,95,109,.2); color: var(--red); }
.tab-add { width: 32px; display: grid; place-items: center; color: var(--muted); border-radius: 8px; margin: 6px 2px 0; }
.tab-add:hover { background: var(--panel-3); color: var(--text); }

.panes { flex: 1; position: relative; min-height: 0; overflow: hidden; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.pane.active { display: flex; }

/* empty state */
.empty {
  flex: 1; display: grid; place-items: center; text-align: center; padding: 32px;
}
.empty-inner { max-width: 460px; }
.empty h2 { font-size: 20px; font-weight: 650; margin-bottom: 8px; }
.empty p { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 18px; }
.kbd-grid { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.kbd-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; min-width: 130px; text-align: left;
}
.kbd-card b { display: block; font-size: 12px; margin-bottom: 3px; }
.kbd-card span { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* terminal pane */
.term-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--border-soft);
  font-size: 11.5px; color: var(--muted); flex: none;
}
.term-toolbar .badge { font-family: var(--mono); }
.badge {
  padding: 2px 7px; border-radius: 5px; font-size: 10.5px;
  background: var(--panel-3); border: 1px solid var(--border);
}
.badge.ok { color: var(--green); border-color: rgba(53,208,127,.3); background: rgba(53,208,127,.08); }
.badge.err { color: var(--red); border-color: rgba(255,95,109,.3); background: rgba(255,95,109,.08); }
.badge.warn { color: var(--amber); border-color: rgba(245,181,68,.3); background: rgba(245,181,68,.08); }
.term-toolbar .spacer { flex: 1; }

.term-host { flex: 1; min-height: 0; background: #080b13; padding: 4px 6px 0 8px; }
[data-theme="light"] .term-host { background: #fbfcff; }
.term-host .xterm-viewport::-webkit-scrollbar-thumb { background: #24324c; background-clip: content-box; }

/* sftp pane */
.sftp-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft); background: var(--panel); flex: none;
}
.crumbs { display: flex; align-items: center; gap: 2px; font-family: var(--mono); font-size: 12px; overflow-x: auto; flex: 1; }
.crumbs::-webkit-scrollbar { height: 0; }
.crumb { padding: 3px 5px; border-radius: 5px; color: var(--muted); white-space: nowrap; }
.crumb:hover { background: var(--panel-3); color: var(--text); }
.crumb.last { color: var(--text); }

.file-table { flex: 1; overflow: auto; }
table.files { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.files th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; padding: 8px 12px;
  position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; z-index: 2;
}
table.files td { padding: 7px 12px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
table.files tr:hover td { background: var(--panel-2); }
table.files .fname { display: flex; align-items: center; gap: 8px; cursor: pointer; }
table.files .fname svg { flex: none; opacity: .75; }
table.files .fsize, table.files .fmode, table.files .ftime { font-family: var(--mono); color: var(--muted); font-size: 11.5px; }
table.files tr.dir td:first-child { font-weight: 550; }
.row-acts { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; }
table.files tr:hover .row-acts { opacity: 1; }

/* generic content view */
.view { flex: 1; overflow: auto; padding: 20px 24px 80px; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.view-head h1 { font-size: 18px; font-weight: 650; }
.view-head .sub { color: var(--muted); font-size: 12px; }
.view-head .spacer { flex: 1; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.card h3 { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card .mono { font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; }
.card-acts { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border-radius: 8px; font-size: 12.5px; font-weight: 550;
  background: var(--panel-3); border: 1px solid var(--border);
  color: var(--text); transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: #1f2b43; border-color: #2b3d5e; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3d7bf0; }
.btn.danger { color: var(--red); border-color: rgba(255,95,109,.3); background: rgba(255,95,109,.08); }
.btn.danger:hover { background: rgba(255,95,109,.16); }
.btn.sm { padding: 5px 9px; font-size: 11.5px; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > label { font-size: 11.5px; color: var(--muted); font-weight: 550; letter-spacing: .2px; }
.field input, .field select, .field textarea {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; outline: none; font-size: 13px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent-dim); box-shadow: 0 0 0 3px rgba(79,140,255,.12);
}
.field textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 90px; }
.field .hint { font-size: 11px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }

/* modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(4,7,14,.72); backdrop-filter: blur(3px);
  display: none; place-items: center; z-index: 100; padding: 20px;
}
.modal-back.open { display: grid; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.modal.wide { max-width: 780px; }
.modal-head {
  display: flex; align-items: center; padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h3 { font-size: 15px; font-weight: 650; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px 16px; border-top: 1px solid var(--border-soft);
}

/* login */
.auth-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16224a 0%, #080b13 60%);
  z-index: 200;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 26px 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.auth-card .brand { justify-content: center; border: none; padding: 0 0 6px; }
.auth-card h1 { font-size: 17px; text-align: center; margin: 10px 0 4px; }
.auth-card p.sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.auth-err { color: var(--red); font-size: 12px; min-height: 16px; margin-bottom: 8px; }

/* toast */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast {
  background: var(--panel-3); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 9px; padding: 10px 14px; font-size: 12.5px; max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: slideIn .18s ease-out;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* misc */
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pillbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.pill {
  padding: 4px 10px; border-radius: 999px; font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.on { background: rgba(79,140,255,.14); border-color: var(--accent-dim); color: var(--text); }
.snippet-item {
  display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border-soft); background: var(--panel-2); cursor: pointer;
}
.snippet-item:hover { border-color: var(--accent-dim); }
.snippet-item code { font-family: var(--mono); font-size: 11px; color: var(--muted); display: block; margin-top: 3px; word-break: break-all; }

.mobile-only { display: none; }
@media (max-width: 820px) {  #app.ready { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%);
    transition: transform .2s ease; z-index: 60; box-shadow: 0 0 60px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: none; }
  .mobile-only { display: grid; }
  .view { padding: 14px 14px 80px; }
  .row2, .row3 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------- multi-user UI */

.vault-bar {
  display: flex; gap: 4px; align-items: center;
  padding: 8px 12px 0 12px;
}
.vault-bar select {
  flex: 1; min-width: 0;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; outline: none;
  color: var(--text);
}
.vault-bar select:focus { border-color: var(--accent-dim); }

.suggest {
  font-family: var(--mono); font-size: 11.5px;
  color: var(--accent); opacity: .8;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-left: 6px;
}

.badge.role-owner { color: var(--green); }
.pillbar .pill[data-sec] { cursor: pointer; }

