:root {
  --bg: #0d0f11;
  --bg-soft: #121518;
  --panel: #15181b;
  --panel-2: #1a1e22;
  --line: #24282d;
  --line-soft: #1c2024;
  --text: #e8e5e0;
  --muted: #8c9196;
  --muted-2: #646a70;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --ok: #5fd39a;
  --warn: #e8b04b;
  --danger: #e2685f;
  --radius: 12px;
  --mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ── shared bits ───────────────────────────────────────────── */
.brand-mark {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(150deg, var(--accent), #a8543a);
  color: #140f0c; font-family: var(--mono); font-weight: 700; font-size: 18px;
  letter-spacing: -1px;
}
.brand-mark.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 12px; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: #202529; border-color: #2e343a; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #17100c; font-weight: 650;
}
.btn-primary:hover { background: #e08363; border-color: #e08363; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted-2); margin-bottom: 6px; font-weight: 600;
}
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  background: var(--bg-soft); border: 1px solid var(--line); outline: none;
  font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field 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% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
code, kbd { font-family: var(--mono); font-size: .9em; }

/* ── login ─────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(217,119,87,.16), transparent 65%),
    radial-gradient(600px 400px at 90% 110%, rgba(95,211,154,.05), transparent 60%),
    var(--bg);
}
.login::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 78%);
}
.login-card {
  position: relative; width: 100%; max-width: 372px; padding: 30px 26px 24px;
  background: rgba(21,24,27,.86); border: 1px solid var(--line);
  border-radius: 18px; backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.8);
  animation: rise .4s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.login-err { color: var(--danger); font-size: 12.5px; margin: 10px 0 0; min-height: 16px; }
.login-foot { color: var(--muted-2); font-size: 11.5px; line-height: 1.6; margin: 16px 0 0; }
.login-foot code { color: var(--muted); }

/* ── shell ─────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 268px 1fr; height: 100vh; height: 100dvh; }

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 10px 14px;
}
.side-brand { display: flex; align-items: center; gap: 9px; font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: -.02em; }

.new-session {
  display: flex; align-items: center; gap: 8px;
  margin: 0 10px 14px; padding: 9px 11px;
  background: var(--bg-soft); border: 1px dashed var(--line); border-radius: 9px;
  color: var(--muted); font-size: 12.5px; transition: .15s;
}
.new-session:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.new-session svg { width: 15px; height: 15px; }
.new-session kbd { margin-left: auto; font-size: 10px; color: var(--muted-2); border: 1px solid var(--line); padding: 1px 4px; border-radius: 4px; }

.side-label {
  padding: 0 16px 8px; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted-2); font-weight: 700;
}
.session-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.session-item {
  position: relative; display: block; width: 100%; text-align: left;
  padding: 9px 10px 9px 11px; margin-bottom: 2px;
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  color: var(--muted); transition: .12s;
}
.session-item:hover { background: var(--bg-soft); color: var(--text); }
.session-item.active { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.session-item.active::before {
  content: ""; position: absolute; left: -1px; top: 9px; bottom: 9px; width: 2px;
  background: var(--accent); border-radius: 2px;
}
.si-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.si-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); flex: none; }
.si-dot.run { background: var(--ok); box-shadow: 0 0 0 3px rgba(95,211,154,.12); }
.si-sub {
  display: flex; gap: 6px; margin-top: 3px; padding-left: 12px;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.si-del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: none; width: 24px; height: 24px; place-items: center;
  border: none; border-radius: 6px; background: transparent; color: var(--muted-2);
}
.si-del svg { width: 13px; height: 13px; }
.session-item:hover .si-del { display: grid; }
.si-del:hover { background: rgba(226,104,95,.15); color: var(--danger); }

.side-foot {
  padding: 10px 14px 12px; border-top: 1px solid var(--line-soft);
  font-size: 11px; color: var(--muted-2);
}
.host-info { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.link-btn { background: none; border: none; padding: 0; color: var(--muted-2); font-size: 11px; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--danger); }

/* ── main ──────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--bg-soft), var(--bg));
}
.title-block { min-width: 0; flex: 1; }
.title-block h1 {
  margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-family: var(--mono); font-size: 10.5px; color: var(--muted-2); }
.meta .cwd { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--muted-2); flex: none; }

.top-actions { display: flex; align-items: center; gap: 2px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--muted);
  margin-right: 4px; white-space: nowrap;
}
.pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-run { color: var(--ok); border-color: rgba(95,211,154,.28); background: rgba(95,211,154,.08); }
.pill-run i { animation: pulse 1.6s ease-in-out infinite; }
.pill-stop { color: var(--muted-2); }
@keyframes pulse { 50% { opacity: .35; } }

.term-wrap { position: relative; flex: 1; min-height: 0; padding: 10px 8px 4px 14px; }
#terminal { width: 100%; height: 100%; }
#terminal .xterm-viewport { scrollbar-width: thin; }
.xterm .xterm-viewport::-webkit-scrollbar { width: 8px; }
.xterm .xterm-viewport::-webkit-scrollbar-thumb { background: #2c3238; border-radius: 4px; }

.empty-state {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  text-align: center; padding: 24px; gap: 4px; background: var(--bg);
}
.empty-mark {
  width: 56px; height: 56px; display: grid; place-items: center; margin-bottom: 10px;
  border-radius: 15px; border: 1px solid var(--line); background: var(--panel);
  font-family: var(--mono); color: var(--accent); font-size: 22px; font-weight: 700;
}
.empty-state h2 { margin: 0; font-size: 16px; font-weight: 600; }
.empty-state p { margin: 6px 0 18px; color: var(--muted); font-size: 13px; max-width: 340px; line-height: 1.6; }

/* ── trust bar ─────────────────────────────────────────────── */
.trust-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 0 14px 8px; padding: 10px 12px;
  border: 1px solid rgba(232,176,75,.35); border-radius: 11px;
  background: rgba(232,176,75,.07);
}
.trust-bar[hidden] { display: none; }
.trust-text { flex: 1; min-width: 200px; }
.trust-text strong { display: block; font-size: 12.5px; color: #f0c777; margin-bottom: 2px; }
.trust-text span { font-size: 12px; color: var(--muted); line-height: 1.5; }
.trust-actions { display: flex; gap: 8px; }
.trust-actions .btn { padding: 6px 12px; font-size: 12.5px; }

/* ── composer ──────────────────────────────────────────────── */
.composer { border-top: 1px solid var(--line); background: var(--bg-soft); padding: 8px 14px 12px; }
.quick-row { display: flex; gap: 6px; align-items: center; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.quick-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 3px 8px; border-radius: 6px; font-family: var(--mono); font-size: 11px;
  background: transparent; border: 1px solid var(--line-soft); color: var(--muted-2); transition: .12s;
}
.chip:hover { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.chip-sep { width: 1px; height: 14px; background: var(--line); flex: none; margin: 0 2px; }

.input-row { display: flex; align-items: flex-end; gap: 8px; }
#prompt {
  flex: 1; resize: none; max-height: 168px; padding: 10px 12px; line-height: 1.55;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  outline: none; font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
#prompt:focus { border-color: rgba(217,119,87,.6); box-shadow: 0 0 0 3px var(--accent-soft); }
#prompt::placeholder { color: var(--muted-2); }
.send-btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 11px; }
.send-btn svg { width: 17px; height: 17px; }

/* ── modal ─────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(5,7,8,.66); backdrop-filter: blur(4px); }
.modal-card {
  width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 30px 80px -18px #000; animation: rise .25s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px; }
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 0 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px 18px; border-top: 1px solid var(--line-soft); margin-top: 14px; }

.dir-row { display: flex; gap: 6px; }
.dir-row input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.dir-row .btn { padding: 0 12px; }
.dir-list {
  height: 208px; overflow-y: auto; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-soft); padding: 4px;
}
.dir-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 9px; border: none; background: transparent; border-radius: 7px;
  color: var(--muted); font-family: var(--mono); font-size: 12px;
}
.dir-item:hover { background: var(--panel-2); color: var(--text); }
.dir-item svg { width: 14px; height: 14px; color: var(--muted-2); flex: none; }
.dir-item .git { margin-left: auto; font-size: 9.5px; color: var(--ok); border: 1px solid rgba(95,211,154,.3); padding: 0 4px; border-radius: 4px; }
.dir-empty { padding: 14px; text-align: center; color: var(--muted-2); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  padding: 9px 16px; border-radius: 9px; background: #23282d; border: 1px solid #333a41;
  color: var(--text); font-size: 12.5px; opacity: 0; pointer-events: none;
  transition: .22s; z-index: 90; box-shadow: 0 10px 30px -8px #000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(226,104,95,.5); color: #ffb4ae; }

.scrim { display: none; }
.only-mobile { display: none; }

/* ── responsive ────────────────────────────────────────────── */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: 282px;
    transform: translateX(-102%); transition: transform .24s cubic-bezier(.3,.8,.3,1);
    box-shadow: 20px 0 60px -20px #000;
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); }
  .meta .cwd { max-width: 52vw; }
  .pill span { display: none; }
  .composer { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .term-wrap { padding: 6px 4px 0 8px; }
  .grid-2 { grid-template-columns: 1fr; }
}
