:root, [data-theme="dark"] {
  --bg: #1c1f26;
  --bg-2: #232731;
  --bg-3: #2b303c;
  --bg-4: #343a48;
  --sidebar: #16181e;
  --tabbar: #121419;
  --border: #2e3340;
  --text: #e7e9ef;
  --muted: #8d93a5;
  --faint: #5f6577;
  --accent: #5b7cfa;
  --accent-2: #4866e0;
  --accent-soft: rgba(91, 124, 250, .16);
  --danger: #ef5b6b;
  --ok: #3ccf8e;
  --warn: #f2b84b;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --input: #1a1d23;
}
[data-theme="light"] {
  --bg: #f4f5f8;
  --bg-2: #ffffff;
  --bg-3: #eceef3;
  --bg-4: #e1e4eb;
  --sidebar: #ebedf2;
  --tabbar: #dfe2e9;
  --border: #d6d9e1;
  --text: #1d2130;
  --muted: #646b7e;
  --faint: #9aa0b0;
  --accent-soft: rgba(91, 124, 250, .12);
  --shadow: 0 12px 40px rgba(20, 25, 40, .18);
  --input: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12px; }
svg.ic { flex: none; }
a { color: var(--accent); }

/* ---------- brand / login ---------- */
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 11l6 5-6 5M17 22h7' stroke='white' stroke-width='2.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: cover;
}
.brand-mark.big { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 10px; }
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.login-card { width: min(340px, calc(100vw - 32px)); padding: 32px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card > form > input { margin: 18px 0 12px; }
.login-err { color: var(--danger); margin-top: 10px; min-height: 18px; font-size: 13px; }
.auth-card .login-err { text-align: center; }

/* ---------- account screen ---------- */
.auth-card { width: min(400px, calc(100vw - 32px)); padding: 28px 28px 22px; text-align: left; }
.auth-card .brand-mark.big { width: 48px; height: 48px; }
.auth-card h1 { text-align: center; margin-bottom: 18px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.seg button { height: 32px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--bg-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.seg { margin-bottom: 18px; }
.auth-hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: -4px 0 16px; }
.auth-hint:empty { display: none; }
.auth-form label.field { margin-bottom: 14px; }
.auth-form label.field > span:first-child { font-size: 12.5px; color: var(--text); opacity: .85; }
.auth-card input[type=email], .auth-card input[type=password], .auth-card input[type=text] { height: 42px; padding: 0 12px; border-radius: 9px; font-size: 14px; }
.auth-card input:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card input::placeholder { color: var(--faint); }
.auth-card input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px var(--input) inset; -webkit-text-fill-color: var(--text); caret-color: var(--text); }
.btn.lg { height: 42px; border-radius: 9px; font-size: 14px; margin-top: 4px; }
.pw { position: relative; display: block; }
.pw input { padding-right: 42px !important; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; }
.pw-toggle:hover, .pw-toggle.on { color: var(--text); background: var(--bg-3); }
.link-btn { display: block; margin: 12px auto 0; padding: 4px 6px; border: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer; border-radius: 6px; }
.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { color: var(--faint); text-decoration: none; cursor: default; }
.auth-links { display: flex; justify-content: space-between; }
.auth-links .link-btn { margin: 12px 0 0; }
.auth-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 12px; word-break: break-word; }
.auth-note b { color: var(--text); }
.auth-card input.otp { height: 54px; text-align: center; font: 600 26px/1 "JetBrains Mono", Menlo, Consolas, monospace; letter-spacing: .5em; padding-left: .5em; margin-bottom: 14px; }
.steps { display: flex; list-style: none; padding: 0; margin: 0 0 18px; gap: 6px; counter-reset: none; }
.steps li { flex: 1; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--faint); }
.steps li::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.steps li:last-child { flex: 0 0 auto; }
.steps li:last-child::after { display: none; }
.steps b { width: 22px; height: 22px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border); font-size: 11px; }
.steps li.active { color: var(--text); }
.steps li.active b { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps li.done { color: var(--muted); }
.steps li.done b { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.steps.two li[data-step="code"] { display: none; }
.email-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; font-size: 13px; min-width: 0; }
.email-chip > span:nth-of-type(1) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-chip svg { color: var(--ok); flex: none; }
.email-chip .link-btn { margin: 0; flex: none; }
.meter { height: 4px; margin: -6px 0 14px; background: var(--bg-4); border-radius: 2px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.body { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: flex; }

/* ---------- tab bar ---------- */
.tabbar { display: flex; align-items: stretch; height: 40px; background: var(--tabbar); border-bottom: 1px solid var(--border); user-select: none; }
.tabs-fixed { display: flex; padding-left: 6px; gap: 2px; }
.tabs { display: flex; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; margin-top: 5px;
  background: transparent; border: 0; border-radius: 8px 8px 0 0; color: var(--muted); cursor: pointer; white-space: nowrap;
  max-width: 220px; position: relative;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); }
.tab.session { padding-right: 6px; }
.tab .label { overflow: hidden; text-overflow: ellipsis; }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.tab .dot.connected { background: var(--ok); }
.tab .dot.connecting { background: var(--warn); animation: pulse 1s infinite; }
.tab .dot.closed, .tab .dot.error { background: var(--danger); }
.tab .close { display: grid; place-items: center; width: 20px; height: 20px; border: 0; background: none; color: var(--muted); border-radius: 5px; cursor: pointer; }
.tab .close:hover { background: var(--bg-4); color: var(--text); }
.tab-add { margin: 7px 6px 7px 4px; width: 28px; border: 0; background: none; color: var(--muted); border-radius: 7px; cursor: pointer; display: grid; place-items: center; }
.tab-add:hover { background: var(--bg-3); color: var(--text); }
.tabbar-spacer { flex: 1; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- sidebar ---------- */
.sidebar { width: 220px; flex: none; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; padding: 4px 8px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-bottom { margin-top: auto; }
.nav button {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--muted); cursor: pointer; text-align: left; font-weight: 500;
}
.nav button:hover { background: var(--bg-3); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--text); }
.nav button.active svg { color: var(--accent); }

/* ---------- content ---------- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--input); border: 1px solid var(--border); border-radius: 9px; padding: 0 12px; height: 36px; max-width: 720px; }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0 !important; background: none !important; outline: none; height: 100%; padding: 0 !important; }
.search .connect-hint { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .04em; cursor: pointer; }
.scroll { flex: 1; overflow: auto; padding: 18px 22px 40px; }
.section-title { display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 0 12px; }
.section-title .count { color: var(--faint); font-weight: 600; }
.section-title .grow { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.crumbs button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.crumbs button:hover { color: var(--text); background: var(--bg-3); }
.crumbs .cur { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip { padding: 3px 10px; border-radius: 20px; background: var(--bg-3); border: 1px solid transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.tag { display: inline-block; padding: 0 7px; border-radius: 10px; background: var(--bg-4); color: var(--muted); font-size: 11px; margin-right: 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 26px; }
.grid.list { grid-template-columns: 1fr; gap: 4px; }
.card {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 11px; cursor: pointer; position: relative; min-width: 0; transition: border-color .12s, background .12s;
}
.card:hover { border-color: var(--bg-4); background: var(--bg-3); }
.card.selected { border-color: var(--accent); }
.grid.list .card { padding: 8px 12px; border-radius: 8px; }
.avatar { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; color: #fff; flex: none; background: var(--accent); }
.grid.list .avatar { width: 30px; height: 30px; border-radius: 7px; }
.avatar.group { background: var(--bg-4); color: var(--muted); }
.meta { min-width: 0; flex: 1; }
.meta .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.touch-only { display: none; }
.card:hover .actions { opacity: 1; }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big-ic { width: 64px; height: 64px; border-radius: 18px; background: var(--bg-3); display: grid; place-items: center; margin: 0 auto 16px; color: var(--accent); }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.empty .btn { margin-top: 16px; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-3); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--bg-4); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--bg-4); color: var(--text); }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.btn-group { display: flex; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; border-left: 1px solid rgba(255,255,255,.18); padding: 0 8px; }

input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--input); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
textarea.code { font-family: "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12px; min-height: 160px; white-space: pre; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row > .narrow { flex: 0 0 96px; }
.check { display: flex; align-items: center; gap: 9px; margin: 8px 0 12px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 36px; }
.pw-wrap .icon-btn { position: absolute; right: 3px; top: 3px; }
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }

.switch { position: relative; width: 36px; height: 20px; flex: none; cursor: pointer; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: var(--bg-4); border-radius: 20px; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 2px; left: 2px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 18px; }

/* ---------- side panel ---------- */
.panel { width: 0; flex: none; overflow: hidden; background: var(--bg-2); border-left: 1px solid var(--border); transition: width .18s ease; display: flex; flex-direction: column; }
.panel.open { width: 400px; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); min-width: 400px; }
.panel-head h2 { margin: 0; font-size: 15px; flex: 1; }
.panel-body { flex: 1; overflow: auto; padding: 16px; min-width: 400px; }
.panel-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); min-width: 400px; }
.panel-foot .grow { flex: 1; }
.fieldset { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 12px 2px; margin-bottom: 14px; }
.fieldset > .legend { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.swatches button { width: 24px; height: 24px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; }
.swatches button.active { border-color: var(--text); }

/* ---------- list rows ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: var(--bg-2); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: var(--faint); }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--danger); }
.status-dot.warn { background: var(--warn); }
.badge { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px; font-weight: 800; font-size: 11px; color: #fff; }
.badge.local { background: #5b7cfa; } .badge.remote { background: #b464e8; } .badge.dynamic { background: #e08a3c; }

/* ---------- settings ---------- */
.settings { max-width: 760px; }
.settings .card-s { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px 16px; margin-bottom: 18px; }
.settings .srow { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings .srow:last-child { border-bottom: 0; }
.settings .srow .lbl { flex: 1; }
.settings .srow .lbl small { display: block; color: var(--muted); }
.settings .srow .ctl { width: 260px; flex: none; display: flex; justify-content: flex-end; gap: 8px; }
.theme-preview { border-radius: 8px; padding: 10px 12px; font-family: Menlo, Consolas, monospace; font-size: 12px; line-height: 1.5; margin-top: 8px; border: 1px solid var(--border); }

/* ---------- terminal ---------- */
#view-terms { flex-direction: column; }
.term-pane { position: absolute; inset: 0; display: flex; }
.term-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.term-bar { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--border); background: var(--bg); }
.term-bar .title { flex: 1; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-wrap { flex: 1; min-height: 0; padding: 8px 4px 4px 10px; position: relative; }
.ac-popup { position: absolute; z-index: 20; min-width: 180px; max-width: min(560px, 90%); background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; font-family: Menlo, Consolas, monospace; font-size: 12px; color: var(--text); }
.ac-popup.hidden { display: none; }
.ac-item { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-radius: 5px; cursor: pointer; }
.ac-item .ac-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.ac-item .ac-text b { color: var(--text); font-weight: 600; }
.ac-item.active { background: var(--accent-soft); }
.ac-item.active .ac-text { color: var(--text); }
.ac-badge { font-family: inherit; font-size: 10px; padding: 0 6px; border-radius: 8px; background: var(--bg-4); color: var(--muted); }
.term-wrap .term { position: absolute; inset: 8px 4px 4px 10px; }
.term-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 12, 16, .72); z-index: 5; }
.term-dialog { width: 440px; max-width: calc(100% - 40px); background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); text-align: center; }
.term-dialog h3 { margin: 6px 0 8px; }
.term-dialog p { color: var(--muted); margin: 0 0 14px; word-break: break-word; }
.term-dialog .fp { font-family: Menlo, Consolas, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 14px; word-break: break-all; text-align: left; }
.term-dialog .btns { display: flex; gap: 8px; justify-content: center; margin-top: 6px; }
.term-dialog input { margin-bottom: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--bg-4); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.term-side { width: 290px; flex: none; border-left: 1px solid var(--border); background: var(--bg-2); display: flex; flex-direction: column; }
.term-side .head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
.term-side .head span { flex: 1; }
.term-side .list { flex: 1; overflow: auto; padding: 8px; }
.snip-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.snip-item:hover { background: var(--bg-3); border-color: var(--border); }
.snip-item .t { font-weight: 600; }
.snip-item pre { margin: 3px 0 0; color: var(--muted); font-size: 11px; white-space: pre-wrap; max-height: 48px; overflow: hidden; }
.no-sessions { margin: auto; }

/* ---------- sftp ---------- */
#view-sftp { flex-direction: column; }
.sftp { flex: 1; display: flex; min-height: 0; }
.sftp-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); position: relative; }
.sftp-pane:last-child { border-right: 0; }
.sftp-pane.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
.sftp-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 8px; }
.host-pick { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-2); cursor: pointer; font-weight: 600; max-width: 260px; }
.host-pick:hover { background: var(--bg-3); }
.host-pick .avatar { width: 24px; height: 24px; border-radius: 6px; }
.host-pick .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sftp-head .grow { flex: 1; }
.sftp-path { display: flex; align-items: center; gap: 4px; padding: 0 10px 8px; }
.sftp-path input { height: 30px; padding: 4px 10px; font-family: Menlo, Consolas, monospace; font-size: 12px; }
.sftp-list { flex: 1; overflow: auto; user-select: none; }
.sftp-list .table td { padding: 5px 10px; border-bottom: 0; white-space: nowrap; }
.sftp-list .table { table-layout: fixed; width: 100%; }
.sftp-list .table td.name { overflow: hidden; }
.sftp-list .table td.name .nm { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sftp-list .table td.name .nm span { overflow: hidden; text-overflow: ellipsis; }
.sftp-list .table th { cursor: pointer; background: var(--bg); }
.sftp-list .table th.sorted { color: var(--text); }
.sftp-list tr.sel td { background: var(--accent-soft) !important; }
.sftp-list .fi-dir { color: var(--accent); }
.sftp-list .fi-file { color: var(--muted); }
.sftp-foot { padding: 6px 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; display: flex; gap: 10px; }
.sftp-empty { flex: 1; display: grid; place-items: center; padding: 20px; }
.sftp-empty .pick-list { width: 320px; max-height: 340px; overflow: auto; text-align: left; margin-top: 12px; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.pick-item:hover, .pick-item.hl { background: var(--bg-3); }
.pick-item .avatar { width: 28px; height: 28px; border-radius: 7px; }
.transfers { border-top: 1px solid var(--border); background: var(--bg-2); max-height: 190px; overflow: auto; }
.transfers .thead { display: flex; align-items: center; padding: 6px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.transfers .thead span { flex: 1; }
.xfer { display: flex; align-items: center; gap: 12px; padding: 6px 12px; font-size: 12px; }
.xfer .nm { width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfer .route { width: 220px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfer .bar { flex: 1; height: 6px; background: var(--bg-4); border-radius: 4px; overflow: hidden; }
.xfer .bar i { display: block; height: 100%; background: var(--accent); }
.xfer.done .bar i { background: var(--ok); } .xfer.error .bar i, .xfer.canceled .bar i { background: var(--danger); }
.xfer .st { width: 150px; text-align: right; color: var(--muted); }

/* ---------- modal / ctx / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5, 7, 10, .6); display: grid; place-items: center; z-index: 100; animation: fade .12s; }
.modal { width: 460px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px); display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 14px 16px 6px 18px; }
.modal-head h3 { flex: 1; margin: 0; font-size: 15px; }
.modal-body { padding: 8px 18px 6px; overflow: auto; }
.modal-body p { margin: 0 0 12px; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
.modal pre.out { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; max-height: 340px; overflow: auto; white-space: pre-wrap; font-size: 12px; margin: 4px 0 12px; }
@keyframes fade { from { opacity: 0; } }
.ctx { position: fixed; z-index: 200; min-width: 190px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.ctx button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; }
.ctx button:hover { background: var(--bg-3); }
.ctx button.danger { color: var(--danger); }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--bg-3); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow); max-width: 420px; animation: fade .15s; word-break: break-word; }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.perm-grid { display: grid; grid-template-columns: 80px repeat(3, 1fr); gap: 8px; align-items: center; margin-bottom: 12px; }
.perm-grid .h { color: var(--muted); font-size: 12px; text-align: center; }
.perm-grid label { display: flex; justify-content: center; }
.dropdown-menu { position: absolute; }

.replay-screen { overflow: auto; max-height: 62vh; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.replay-term { width: max-content; }
.replay-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.replay-seek { flex: 1; accent-color: var(--accent); }
.replay-time { font-size: 12px; min-width: 84px; text-align: right; }
.replay-speed { width: 64px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- mobile helpers (hidden on desktop) ---------- */
.xkeys, .sftp-switch { display: none; }
.xkeys { gap: 4px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg-2); overflow-x: auto; scrollbar-width: none; flex: none; }
.xkeys::-webkit-scrollbar { display: none; }
.xkeys button { flex: 1 0 auto; min-width: 40px; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-3); font-weight: 600; touch-action: manipulation; }
.xkeys button:active { background: var(--bg-4); }
.xkeys button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sftp-switch { gap: 6px; padding: 8px 10px 0; flex: none; }
.sftp-switch button { flex: 1; min-width: 0; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-2); color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sftp-switch button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* touch devices: no hover, so show card actions and the overflow button */
@media (hover: none) {
  .card .actions { opacity: 1; }
  .touch-only { display: grid; }
  .card, .tab, .sftp-list { -webkit-touch-callout: none; }
  .card, .sftp-list { -webkit-user-select: none; user-select: none; }
}
@media (hover: none) and (pointer: coarse) { .xkeys { display: flex; } }

/* tablet */
@media (max-width: 900px) {
  .touch-only { display: grid; }
  .xkeys { display: flex; }
  .app { position: fixed; top: 0; left: 0; right: 0; height: var(--vvh, 100dvh);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  .tabbar { height: 44px; }
  .tab { margin-top: 4px; }
  .tab-add { margin: 5px 6px 5px 4px; width: 34px; }
  .tab .close { width: 28px; height: 28px; }

  /* sidebar becomes a horizontal strip */
  #view-vault { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; align-items: center; gap: 4px; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .brand { display: none; }
  .nav { flex-direction: row; gap: 2px; flex: none; }
  .nav-bottom { margin-top: 0; margin-left: auto; }
  .nav button { min-height: 40px; padding: 0 12px; white-space: nowrap; }
  .content { min-height: 0; }

  /* editor panel is a full overlay */
  .panel { position: absolute; top: 0; right: 0; bottom: 0; z-index: 30; border-left: 0; transition: none; }
  .panel.open { width: 100%; }
  .panel-head, .panel-body, .panel-foot { min-width: 0; }
  .panel-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); flex-wrap: wrap; }

  .btn { height: 40px; }
  .btn.sm { height: 36px; }
  .icon-btn { width: 40px; height: 40px; }
  .search { height: 42px; }
  input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea:not(.xterm-helper-textarea), textarea.code { font-size: 16px; padding: 10px; }
  .search input { font-size: 16px; }
  .check input { width: 20px; height: 20px; }

  .toolbar { padding: 10px 12px; flex-wrap: wrap; }
  .scroll { padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); }
  .scroll .table { display: block; overflow-x: auto; white-space: nowrap; }
  .card { padding: 12px; }
  .row { flex-wrap: wrap; }
  .row > .narrow { flex: 1 1 96px; }

  .modal { width: calc(100vw - 24px) !important; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  .modal-foot { flex-wrap: wrap; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .ctx { max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; }
  .ctx button { padding: 11px 12px; }
  #toasts { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  /* terminal */
  .term-side { position: absolute; top: 0; right: 0; bottom: 0; z-index: 10; width: min(340px, 100%); box-shadow: var(--shadow); }
  .term-bar { height: 44px; }
  .term-wrap { padding: 4px 2px 2px 6px; }
  .term-wrap .term { inset: 4px 2px 2px 6px; }
  .term-dialog { padding: 18px; }

  /* sftp: one pane at a time */
  .sftp-switch { display: flex; }
  .sftp { flex-direction: column; }
  .sftp-pane { display: none; border-right: 0; }
  .sftp[data-mp="0"] .sftp-pane[data-pane="0"], .sftp[data-mp="1"] .sftp-pane[data-pane="1"] { display: flex; flex: 1; min-height: 0; }
  .sftp-head { flex-wrap: wrap; }
  .host-pick { max-width: 100%; min-height: 40px; }
  .sftp-path input { height: 40px; }
  .sftp-list .table th:nth-child(2), .sftp-list .table td:nth-child(2),
  .sftp-list .table th:nth-child(4), .sftp-list .table td:nth-child(4) { display: none; }
  .sftp-list .table th:nth-child(3) { width: 80px !important; }
  .sftp-list .table td { padding: 11px 10px; }
  .sftp-empty .pick-list { width: 100%; }
  .sftp-empty input { width: 100% !important; }
  .sftp-empty > div { width: 100%; }
  .transfers { max-height: 160px; }
  .xfer { flex-wrap: wrap; gap: 4px 10px; }
  .xfer .nm { width: 100%; }
  .xfer .route { width: 100%; }
  .xfer .st { width: auto; }
}

/* phone */
@media (max-width: 640px) {
  .tabs-fixed .tab.fixed { padding: 0 12px; }
  .tabs-fixed .tab.fixed > span:last-child { display: none; }
  .tab { max-width: 150px; }
  .grid { grid-template-columns: 1fr; }
  .search { flex: 1 1 100%; max-width: none; }
  .settings .srow { flex-wrap: wrap; gap: 8px; }
  .settings .srow .lbl { flex: 1 1 100%; }
  .settings .srow .ctl { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .settings .card-s { padding: 4px 12px; }
  .perm-grid { grid-template-columns: 64px repeat(3, 1fr); }
  .replay-bar { flex-wrap: wrap; }
  .modal-head { padding-left: 14px; }
  .modal-body { padding: 8px 14px 6px; }
}

/* ---------- guest page and shares ---------- */
.guest-mode .term-bar [data-a="snippets"], .guest-mode .term-bar [data-a="sftp"], .guest-mode .term-bar [data-a="close"] { display: none; }
.guest-mode .sftp-pane[data-pane="1"], .guest-mode #sftpSwitch { display: none !important; }
.guest-mode .host-pick.static { cursor: default; }
.guest-info { display: flex; align-items: center; gap: 10px; padding: 0 12px; min-width: 0; }
.guest-host { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.share-list { display: flex; flex-direction: column; gap: 8px; }
.share-row { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; }
.share-row .meta { flex: 1; min-width: 0; }
.share-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.share-row .actions { display: flex; gap: 6px; flex: none; }
.share-status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; background: var(--bg-4); color: var(--muted); }
.share-status.active { background: rgba(60, 207, 142, .18); color: var(--ok); }
.share-status.pending { background: rgba(242, 184, 75, .18); color: var(--warn); }
.share-status.revoked, .share-status.expired { background: var(--bg-4); color: var(--faint); }
.tag.guest { background: var(--accent-soft); color: var(--text); }
@media (max-width: 900px) {
  .share-row { flex-wrap: wrap; }
  .share-row .actions { width: 100%; justify-content: flex-end; }
  .guest-mode .tabs-fixed .tab.fixed > span:last-child { display: inline; }
  .guest-host { display: none; }
}