:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f232c;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a5;
  --accent: #d97757;
  --ok: #3fb950;
  --bad: #f85149;
  --side-w: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif; }
button { font: inherit; color: var(--text); background: var(--accent); border: 0; border-radius: 6px;
  padding: 8px 14px; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.small { padding: 4px 10px; font-size: 12px; }
button.icon { padding: 4px 10px; font-size: 18px; }
button.danger { background: transparent; border: 1px solid #5a2a2a; color: #ff9b94; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50; padding: 16px; }
.overlay[hidden] { display: none; }
.card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: auto; }

#app { display: flex; height: 100%; height: 100dvh; }
#sidebar { width: var(--side-w); flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px;
  border-bottom: 1px solid var(--line); }
.side-foot { padding: 10px 14px; border-top: 1px solid var(--line); }
#agents { flex: 1; overflow-y: auto; padding: 8px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--bad); }

.agent { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; background: var(--bg); }
.agent-head { padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.agent-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.agent-head .name { font-weight: 600; }
.agent-head .host { color: var(--muted); font-size: 12px; margin-left: auto; }
.new-sess { padding: 0 12px 10px; display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.new-sess input { grid-column: 1 / -1; font-size: 12px; }
.sess { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.sess:hover { background: var(--panel2); }
.sess.active { background: #2a1f1b; box-shadow: inset 3px 0 0 var(--accent); }
.sess .info { flex: 1; min-width: 0; }
.sess .label { font-weight: 500; }
.sess .meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); padding: 16px; text-align: center; }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line);
  background: var(--panel); min-height: 44px; }
#topbar #title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
#topbar .spacer { flex: 1; }
#topbar button { flex: none; white-space: nowrap; }
#menuBtn { display: none; }
#termWrap { flex: 1; min-height: 0; padding: 4px 0 0 6px; background: #0b0d10; }
#term { width: 100%; height: 100%; }

#keybar { display: none; gap: 4px; padding: 6px; background: var(--panel); border-top: 1px solid var(--line);
  overflow-x: auto; flex: none; }
#keybar button { background: var(--panel2); border: 1px solid var(--line); padding: 8px 10px; min-width: 40px; flex: none; }
#inputBar { display: flex; gap: 6px; padding: 6px; background: var(--panel); border-top: 1px solid var(--line); flex: none; }
#inputBar[hidden] { display: none; }
#inputBar textarea { resize: none; }

/* ---- 파일 패널 */
#files { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: 0 0 40px #000;
  display: flex; flex-direction: column; }
#files[hidden] { display: none; }
.files-head, .files-path, .files-actions { display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); }
.files-head .spacer { flex: 1; }
.files-head select { width: auto; max-width: 60%; padding: 4px 6px; }
#filesPath { flex: 1; min-width: 0; font-family: Consolas, monospace; font-size: 12px; color: var(--muted);
  overflow-wrap: anywhere; }
.files-actions { flex-wrap: wrap; }
.files-actions[hidden] { display: none; }
.dir-sel { grid-column: 1 / -1; }
.cwd-btn { grid-column: 1 / -1; text-align: left; font-size: 12px; background: var(--panel2);
  border: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.small-text { font-size: 11px; }
#filesList { flex: 1; overflow-y: auto; }
.fent { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid #20242c; cursor: pointer; }
.fent:hover { background: var(--panel2); }
.fent .ico { width: 20px; text-align: center; flex: none; }
.fent .fname { flex: 1; min-width: 0; overflow-wrap: anywhere; word-break: break-all; }
.fbtn { flex: none; padding: 3px 7px; font-size: 13px; }
.tr .fbtn { margin-left: 4px; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 60; max-width: 90vw;
  background: #2a2f3a; color: var(--text); padding: 8px 14px; border-radius: 8px; box-shadow: 0 4px 20px #000;
  font-size: 13px; overflow-wrap: anywhere; }
.fent .fmeta { font-size: 11px; color: var(--muted); white-space: nowrap; text-align: right; }
#transfers:empty { display: none; }
#transfers { border-top: 1px solid var(--line); max-height: 30%; overflow-y: auto; padding: 6px 12px; }
.tr { padding: 4px 0; font-size: 12px; }
.tr .bar { height: 4px; background: var(--panel2); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.tr .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.tr.done .bar i { background: var(--ok); }
.tr.fail { color: var(--bad); }
#filesDrop { display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
  background: rgba(217, 119, 87, .15); border: 2px dashed var(--accent); font-size: 16px; pointer-events: none; }
#files.dragging #filesDrop { display: flex; }

@media (max-width: 800px) {
  #sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(88vw, 340px);
    transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px #000; }
  #app.side-open #sidebar { transform: none; }
  #menuBtn { display: inline-block; }
  #keybar { display: flex; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) { #keybar { display: flex; } }
