/* ── 토큰 ───────────────────────────────────────── */
:root {
  --bg: #0e1116;
  --bg-elev: #151a21;
  --bg-soft: #1b212a;
  --line: #262d38;
  --line-soft: #1e242d;
  --text: #e6edf3;
  --text-dim: #8b96a5;
  --text-faint: #5c6674;
  --accent: #5b9cff;
  --accent-soft: rgba(91, 156, 255, 0.14);
  --danger: #ff6b6b;
  --ok: #3ecf8e;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas, "D2Coding", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-elev: #ffffff;
    --bg-soft: #eef1f5;
    --line: #dde2e9;
    --line-soft: #e7ebf0;
    --text: #10151c;
    --text-dim: #5c6874;
    --text-faint: #8b96a3;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --danger: #d92d20;
    --ok: #067647;
  }
}

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

/* hidden 속성이 항상 display 규칙을 이기도록 */
[hidden] { display: none !important; }

html, body { height: 100%; }

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

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ── 로그인 ─────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(91,156,255,0.12), transparent 60%), var(--bg);
}
.gate-card {
  width: min(340px, calc(100vw - 40px));
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 24px;
  display: grid; gap: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.gate-logo { font-size: 24px; font-weight: 700; letter-spacing: 0.14em; text-align: center; }
.gate-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.gate-error { color: var(--danger); font-size: 13px; text-align: center; }

/* ── 공통 컨트롤 ────────────────────────────────── */
input[type="text"], input[type="password"], input[type="search"] {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--text-faint); }

.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px; border: 1px solid transparent;
  background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); border-color: var(--line); }

.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }

.chip {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.chip.muted { background: var(--bg-soft); color: var(--text-faint); }

.hint { color: var(--text-dim); font-size: 12.5px; }

/* ── 레이아웃 ───────────────────────────────────── */
.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: 52px; flex: none;
  display: flex; align-items: center; gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800; letter-spacing: .02em;
}
.brand-name { font-weight: 700; letter-spacing: .08em; }

.search-wrap { position: relative; flex: 1; max-width: 460px; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden auto; max-height: 60vh;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}
.search-results .item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line-soft); }
.search-results .item:last-child { border-bottom: 0; }
.search-results .item:hover { background: var(--bg-soft); }
.search-results .item .sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.search-results .empty { padding: 12px; color: var(--text-faint); }

.top-actions { margin-left: auto; display: flex; gap: 6px; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px 268px 1fr; }
.col { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.col.main { border-right: 0; }
.col.repos { background: var(--bg-elev); }
.col.files { background: color-mix(in srgb, var(--bg-elev) 55%, var(--bg)); }

.col-head {
  height: 40px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line-soft);
}
.col-head h2 {
  font-size: 11px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.inline-form { padding: 10px 12px; display: grid; gap: 7px; border-bottom: 1px solid var(--line-soft); }

/* ── 저장소 / 파일 목록 ─────────────────────────── */
.repo-list, .file-list { list-style: none; overflow-y: auto; flex: 1; padding: 6px; }

.repo-item, .file-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; gap: 9px;
  border: 1px solid transparent;
}
.repo-item:hover, .file-item:hover { background: var(--bg-soft); }
.repo-item.active, .file-item.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

.item-body { min-width: 0; flex: 1; }
.item-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .item-name { font-family: var(--mono); font-size: 13px; }
.item-sub { color: var(--text-faint); font-size: 11.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.item-actions { display: none; gap: 2px; }
.repo-item:hover .item-actions, .file-item:hover .item-actions,
.repo-item.active .item-actions, .file-item.active .item-actions { display: flex; }

.lang-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex: none; background: var(--text-faint);
}

.list-empty { padding: 22px 14px; color: var(--text-faint); font-size: 13px; text-align: center; line-height: 1.6; }

/* ── 메인 패널 ──────────────────────────────────── */
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane-head {
  flex: none; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.pane-head h3 { font-size: 14px; font-weight: 600; }

.toggle { display: flex; align-items: center; gap: 7px; color: var(--text-dim); font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

.detect-bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line-soft);
}
.name-input {
  flex: 1; font-family: var(--mono); font-size: 13px;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  padding: 6px 8px; width: auto;
}
.name-input:hover { border-color: var(--line); }
.name-input.strong { font-size: 14px; font-weight: 600; }

.file-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }

.meta-bar {
  flex: none; padding: 6px 16px;
  color: var(--text-faint); font-size: 12px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; gap: 14px; flex-wrap: wrap;
}

.code-area {
  flex: 1; width: 100%; min-height: 0;
  background: transparent; border: 0; outline: none; resize: none;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  padding: 14px 16px;
  tab-size: 4;
  color: var(--text);
}
.code-area::placeholder { color: var(--text-faint); line-height: 1.9; }

.editor { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.gutter {
  flex: none; width: 52px; overflow: hidden;
  padding: 14px 8px 14px 0;
  text-align: right;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  color: var(--text-faint);
  background: color-mix(in srgb, var(--bg-elev) 60%, var(--bg));
  border-right: 1px solid var(--line-soft);
  user-select: none;
}
.editor-input { padding-left: 12px; }

.paste-pane.dragover { outline: 2px dashed var(--accent); outline-offset: -8px; }

.empty-pane { display: grid; place-items: center; color: var(--text-faint); }

/* ── 토스트 ─────────────────────────────────────── */
.toast-stack { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px; padding: 10px 14px;
  box-shadow: 0 14px 34px rgba(0,0,0,.32);
  font-size: 13px; max-width: 340px;
  animation: pop .16s ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ── 모달 ───────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(0,0,0,.5); }
.modal-card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; width: min(360px, calc(100vw - 40px)); display: grid; gap: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.modal-card h4 { font-size: 15px; }
.modal-card p { color: var(--text-dim); font-size: 13px; line-height: 1.6; word-break: break-all; }

/* ── 좁은 화면 ──────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .col { border-right: 0; border-bottom: 1px solid var(--line); }
  .repo-list, .file-list { max-height: 168px; }
  .search-wrap { max-width: none; }
  .brand-name { display: none; }
}
