:root {
  --bg: #1a1a1d;
  --surface: #232327;
  --surface2: #2b2b30;
  --line: #3a3a40;
  --text: #ececef;
  --muted: #9a9aa3;
  --accent: #e5484d;
  --accent-press: #c93b40;
  --green: #3fb950;
  --amber: #d9a521;
  --gray: #6e6e76;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
/* hidden 속성은 어떤 display 규칙보다도 우선해 숨긴다(오버레이/제어바/패널 토글 버그 방지) */
[hidden] { display: none !important; }

/* ===== App bar ===== */
.appbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
/* 한글이 음절 단위로 쪼개지지 않게(공백에서만 줄바꿈) — 버튼 라벨 안정화 */
.appbar button { word-break: keep-all; }
.user-info { color: var(--muted); font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Buttons / inputs ===== */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); padding: 9px 16px; font-weight: 600; }
button.primary:hover { background: var(--accent-press); }
button.ghost { background: transparent; color: var(--text); padding: 7px 12px; }
button.ghost:hover { background: var(--surface2); }
button.danger { background: transparent; color: var(--accent); border-color: var(--accent); padding: 7px 12px; }
button.danger:hover { background: rgba(229,72,77,.15); color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
input {
  font: inherit; color: var(--text);
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; outline: none;
}
input:focus { border-color: var(--accent); }

/* ===== Home ===== */
.home-main { max-width: 960px; margin: 0 auto; padding: 16px 14px 40px; }
/* 로그인 게이트 */
.login-gate { max-width: 420px; margin: 48px auto; padding: 0 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 24px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card h2 { margin: 0; }
.login-card p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.login-card button { width: 100%; }
.connect-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; margin-bottom: 22px;
}
.connect-bar #addr-input { flex: 2; min-width: 160px; }
.connect-bar #pw-input { flex: 1; min-width: 120px; }
.connect-bar .error { flex-basis: 100%; color: var(--accent); font-size: 13px; }
/* 상단 연결 버튼(PC 기본): 입력칸 옆 인라인 붉은 버튼. 모바일은 아래 미디어쿼리에서 가로 꽉. */
.connect-bar .connect-main {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 8px; padding: 9px 16px; font-weight: 600;
}
.connect-bar .connect-main:hover { background: var(--accent-press); }

.list-section { margin-bottom: 24px; }
.list-section h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 10px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

/* ===== Device card ===== */
.card {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.card-top { display: flex; align-items: center; gap: 8px; }
.card-top .spacer { flex: 1; }
.card .star, .card .menu { background: transparent; border: none; color: var(--muted); font-size: 16px; padding: 2px 4px; }
.card .star.on { color: var(--amber); }
.card-name { font-weight: 600; }
.card-addr { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.card .card-connect { margin-top: 6px; background: var(--surface2); color: var(--text); padding: 8px; }
.card .card-connect:hover { background: var(--line); }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.online { color: var(--green); border-color: var(--green); }
.badge.busy   { color: var(--amber); border-color: var(--amber); }
.badge.offline{ color: var(--gray); }
.badge.unknown{ color: var(--muted); }
.badge.checking{ color: var(--amber); border-color: var(--amber); }

/* ===== 목록 상태 재확인 바 ===== */
.status-bar { display: flex; justify-content: flex-end; margin: 4px 0 2px; }
.status-refresh {
  background: var(--surface2); color: var(--text); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.status-refresh:hover { background: var(--line); }
.status-refresh:disabled { opacity: .6; cursor: default; }

/* ===== card overflow menu ===== */
.menu-pop { position: absolute; top: 36px; right: 10px; background: var(--surface2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; z-index: 50; min-width: 120px; }
.menu-pop button { display: block; width: 100%; text-align: left; background: transparent; border: none; color: var(--text); padding: 8px 10px; border-radius: 6px; }
.menu-pop button:hover { background: var(--line); }

/* ===== Session ===== */
#session-view { display: flex; flex-direction: column; height: 100vh; }
.session-bar { gap: 8px; }
.stage {
  position: relative; flex: 1; min-height: 0;
  background: #000; display: flex; align-items: center; justify-content: center;
}
#remote-video { max-width: 100%; max-height: 100%; background: #000; touch-action: none; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); color: #fff; font-size: 16px;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 로그인 진행 표시(전체화면 오버레이) */
.login-loading {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); color: #fff; font-size: 16px;
}

/* 제어 바: 데스크톱=우측 세로, 모바일=하단 가로 */
.controls {
  position: absolute; top: 50%; right: 10px; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px;
}
.controls .key { background: rgba(40,40,46,.9); color: #fff; border: 1px solid var(--line); padding: 8px 10px; }
.controls .key:hover { background: rgba(60,60,68,.95); }
.controls .key-exit-fs { background: rgba(180,40,48,.92); border-color: rgba(220,80,88,.9); margin-top: 4px; }
.controls .key-exit-fs:hover { background: rgba(210,56,64,.96); }
/* 숨기기 토글: 크기는 다른 .key 버튼과 동일, 색만 파랗게 구분 + 굵게. */
.controls .controls-toggle {
  background: rgba(36,98,176,.92); color: #fff;
  border: 1px solid rgba(90,150,230,.9); font-weight: 700;
  touch-action: none;  /* 드래그 이동 시 스크롤 제스처와 충돌 방지 */
}
.controls .controls-toggle:hover { background: rgba(48,116,200,.96); }
/* 접힘: 토글만 남기고 나머지 버튼 숨김 → 원격 화면 하단(폴더 선택 등)을 가리지 않음.
   접힌 토글도 .key 크기(높이)를 유지하고, 폭만 한 칸 크기로 고정. */
.controls.collapsed { background: transparent; border: 0; padding: 0; gap: 0; }
.controls.collapsed > button:not(.controls-toggle) { display: none; }
.controls.collapsed > .controls-toggle { flex: 0 0 auto; min-width: 60px; }

/* 파일 패널: 우측 패널 */
.file-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: 320px; max-width: 80%;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.file-panel-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.file-status { font-size: 13px; color: var(--muted); margin-top: 6px; }
.note { font-size: 12px; color: var(--muted); }

.fp-section { display: flex; flex-direction: column; gap: 6px; }
.fp-dest { flex: 1; min-height: 0; }
.fp-label { font-size: 12px; color: var(--muted); }
.fp-selected { font-size: 12px; color: var(--text); max-height: 80px; overflow: auto; }
.fp-path { font-size: 12px; color: var(--text); background: var(--surface2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; word-break: break-all; }
.fp-row { display: flex; gap: 6px; }
.fp-row button { padding: 5px 8px; font-size: 12px; }
.fp-list { flex: 1; min-height: 80px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.fp-item { display: flex; gap: 8px; padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.fp-item.dir { cursor: pointer; }
.fp-item.dir:hover { background: var(--surface2); }
.fp-item.file { color: var(--muted); }
.fp-item .fp-spacer { flex: 1; }
.fp-item .fp-size { color: var(--muted); font-size: 12px; }
.fp-item .fp-del { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 13px; }
.fp-item .fp-del:hover { color: var(--accent); }

.logbox { background: var(--surface); border-top: 1px solid var(--line); }
.logbox summary { padding: 8px 14px; color: var(--muted); cursor: pointer; }
#log { margin: 0; padding: 8px 14px; max-height: 160px; overflow: auto; font-size: 12px; color: var(--muted); white-space: pre-wrap; }

/* ===== 모바일 ===== */
@media (max-width: 640px) {
  .controls {
    top: auto; right: 0; bottom: 0; left: 0; transform: none;
    flex-direction: row; justify-content: space-around;
    background: rgba(20,20,24,.92); padding: 8px;
  }
  .controls .key { flex: 1; font-size: 13px; padding: 10px 4px; }
  /* 접힘: 하단 가로바 대신 우측 하단 작은 토글(◀)만 → 폴더 선택 버튼이 안 가려짐.
     ▶로 오른쪽으로 숨기고, 우측에 남은 ◀를 누르면 다시 펼쳐진다. */
  .controls.collapsed { left: auto; right: 6px; bottom: 6px; }
  .file-panel { width: 100%; max-width: 100%; }
  /* 모바일: 연결 버튼을 가로 꽉 채움 */
  .connect-bar .connect-main { flex-basis: 100%; width: 100%; margin-top: 4px; padding: 9px; }
}
