@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg:         #0f0f17;
  --surface:    #17172a;
  --card:       #1e1e34;
  --border:     #2e2e50;
  --accent:     #7c6af7;
  --accent2:    #e96af7;
  --success:    #6af7a0;
  --warning:    #f7c26a;
  --info:       #6ac8f7;
  --text:       #e8e8f0;
  --muted:      #8f8fb8;
  --drag-over:  #3a2e70;
  --sel-bg:     rgba(124,106,247,0.22);
  --sel-border: #7c6af7;
  --thumb-size: 250px;
}

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

body {
  font-family: 'Instrument Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-app-region: no-drag;
}

/* ── 타이틀바 ── */
header {
  height: 44px;
  background: var(--bg);
  -webkit-app-region: drag;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px 0 80px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
body.fullscreen header {
  display: none;
}
header h1 {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
}
.dir-path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--muted); opacity: .7;
  max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── 앱 레이아웃 ── */
.app-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

/* ── 사이드바 ── */
aside {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}
.sidebar-nav {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-nav .btn {
  flex: 1;
  justify-content: center;
}
.file-explorer {
  flex: 1;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.file-explorer::-webkit-scrollbar { width: 6px; height: 6px; }
.file-explorer::-webkit-scrollbar-track { background: transparent; }
.file-explorer::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── 메인 콘텐츠 ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 콘텐츠 툴바 ── */
.content-nav {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: none;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #9180ff; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--card); }
.btn-ghost:disabled { color: var(--muted); border-color: var(--border); opacity: .4; cursor: not-allowed; }
.btn-ghost.active { border-color: var(--accent); color: var(--accent); }
.btn-info { background: #0d2535; color: var(--info); border: 1px solid #1a4060; }
.btn-info:hover { background: #132e42; }
.btn-info:disabled { opacity: .4; cursor: not-allowed; }
.btn-info:not(.active) { opacity: .4; }
.sort-group {
  display: flex;
  background: #0d2535;
  border: 1px solid #1a4060;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.sort-btn {
  display: inline-flex; align-items: center;
  padding: 4px 12px; border-radius: 5px; border: none;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.sort-btn:hover { background: #132e42; color: var(--info); }
.sort-btn.active { background: #1a3a4a; color: var(--info); }
.btn-success { background: #1a4a2e; color: var(--success); border: 1px solid #2a6a40; }
.btn-success:hover { background: #204a34; }
.btn-success:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-warning { background: #3a2a10; color: var(--warning); border: 1px solid #5a4020; }
.btn-warning:hover { background: #4a3518; }
.btn-warning:disabled { opacity: .4; cursor: not-allowed; }
.separator { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

/* ── 포맷 바 ── */
#format-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#format-bar label {
  font-size: 14px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
#format-bar input {
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: 13px; padding: 5px 10px; border-radius: 6px; outline: none;
  transition: border-color .15s;
}
#format-bar input:focus { border-color: var(--accent); }
#input-prefix { width: 160px; }
#input-digits { width: 50px; text-align: center; }
.format-sep { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 14px; }
#preview-name {
  font-family: 'JetBrains Mono', monospace; font-size: 13px;
  color: var(--accent2); background: rgba(124,106,247,.1);
  padding: 4px 12px; border-radius: 6px; border: 1px solid rgba(124,106,247,.2);
}
#file-count  { margin-left: auto; font-size: 12px; color: var(--muted); }
#sel-count   { font-size: 12px; color: var(--accent); font-weight: 700; display: none; }
#sel-count.visible { display: inline; }

/* ── 그리드 컨테이너 ── */
#grid-container {
  flex: 1; overflow-y: auto; padding: 20px;
  position: relative;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#grid-container::-webkit-scrollbar { width: 6px; }
#grid-container::-webkit-scrollbar-track { background: transparent; }
#grid-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── 그리드: 고정 열 폭 (--thumb-size) ── */
#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--thumb-size));
  gap: 14px;
  justify-content: start;
}

/* ── 빈 상태 ── */
#empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 16px; color: var(--muted);
}
#empty-state .icon { font-size: 64px; opacity: .3; }
#empty-state p { font-size: 15px; text-align: center; line-height: 1.6; }

/* ── 카드 ── */
.card {
  background: var(--card);
  border: 2px solid transparent;
  border-radius: 12px;
  overflow: hidden;
  cursor: grab;
  transition: border-color .15s, transform .15s, box-shadow .15s, background .15s;
  position: relative;
  width: var(--thumb-size);
}
.card:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.card.selected {
  border-color: var(--sel-border) !important;
  background: var(--sel-bg);
  box-shadow: 0 0 0 1px var(--sel-border), 0 8px 24px rgba(124,106,247,.2);
}
.card.dragging,
.card.multi-dragging { opacity: .3; transform: scale(.96); cursor: grabbing; }
.card.drag-over { border-color: var(--accent) !important; background: var(--drag-over); }
.card.drag-hidden { display: none; }

.card-placeholder {
  border: 2px dashed var(--accent);
  background: rgba(124, 106, 247, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  pointer-events: auto;
}
.card-placeholder-label {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  opacity: 0.8;
}

/* ── 썸네일: 정사각형 + object-fit: contain ── */
.card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #08080f;
  display: block;
}
/* 이미지 로딩 전 shimmer */
.card-thumb:not([src]) {
  background: linear-gradient(90deg, #08080f 25%, #14141f 50%, #08080f 75%);
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s ease-in-out infinite;
}
@keyframes thumb-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.card-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #08080f;
  display: flex; align-items: center; justify-content: center;
  font-size: 52px; opacity: .25;
}

.card-body { padding: 8px 10px; }

.card-num {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  padding: 2px 7px; border-radius: 99px; line-height: 1.6;
  pointer-events: none; z-index: 2;
}
.card-check {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s;
  pointer-events: none; z-index: 2;
}
.card.selected .card-check { opacity: 1; }

.card-name {
  font-size: 11px; color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-new-name {
  font-size: 11px; color: var(--accent2);
  font-family: 'JetBrains Mono', monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}

/* ── Rubber-band 선택 사각형 ── */
#rubber-band {
  position: fixed;
  border: 1.5px solid var(--accent);
  background: rgba(124,106,247,.1);
  border-radius: 3px;
  pointer-events: none;
  display: none;
  z-index: 40;
}

/* ── 다중 드래그 고스트 배지 ── */
#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  display: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px; font-weight: 700;
  font-family: 'Instrument Sans', sans-serif;
  padding: 6px 16px;
  border-radius: 99px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

/* ── 상태바 ── */
footer {
  height: 28px; background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px; flex-shrink: 0;
}
footer span { font-size: 11px; color: var(--muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-dot.ready { background: var(--success); }

/* ── 핀치 크기 힌트 ── */
#thumb-size-hint {
  position: fixed; bottom: 40px; right: 24px;
  background: rgba(124,106,247,.9);
  color: #fff; font-size: 12px; font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  padding: 5px 12px; border-radius: 8px;
  opacity: 0; transition: opacity .2s;
  pointer-events: none; z-index: 500;
}
#thumb-size-hint.show { opacity: 1; }

/* ── 로딩 ── */
#loading {
  display: none; position: fixed; inset: 0;
  background: rgba(15,15,23,.85); backdrop-filter: blur(4px);
  z-index: 100; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
}
#loading.show { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { color: var(--text); font-size: 14px; }

/* ── 카드 호버 원형 로딩바 ── */
.card-hover-loader {
  position: absolute;
  top: calc(var(--thumb-size) / 2);
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}
.card-hover-loader .loader-bg {
  fill: rgba(0, 0, 0, 0.55);
}
.card-hover-loader .loader-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 3;
}
.card-hover-loader .loader-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transform-origin: 24px 24px;
  transform: rotate(-90deg);
  animation: hover-loader-fill 1s linear forwards;
}
@keyframes hover-loader-fill {
  from { stroke-dashoffset: 125.66; }
  to   { stroke-dashoffset: 0; }
}

/* ── 호버 이미지 팝업 ── */
.hover-preview {
  position: fixed;
  display: none;
  visibility: hidden;
  z-index: 8000;
  pointer-events: none;
  background: #0d0d1a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.85), 0 0 0 1px rgba(124,106,247,0.15);
}
.hover-preview img {
  display: block;
  max-width: 840px;
  max-height: 840px;
  width: auto;
  height: auto;
  border-radius: 6px;
  object-fit: contain;
}

/* ── 파일 탐색기 트리 ── */
.tree-root { padding: 6px 0; }

.tree-node { display: flex; flex-direction: column; }

.tree-row {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 0;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
  font-size: 12.5px;
  transition: background .1s;
  position: relative;
}
.tree-row:hover { background: rgba(255,255,255,.05); }
.tree-row.active {
  background: rgba(124,106,247,.18);
  color: #d0c8ff;
}

.tree-chevron {
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--muted);
  transition: transform .15s;
  cursor: pointer;
  border-radius: 3px;
}
.tree-chevron:hover { background: rgba(255,255,255,.08); color: var(--text); }
.tree-chevron.open { transform: rotate(90deg); }
.tree-chevron svg { display: block; pointer-events: none; }

.tree-icon {
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.tree-icon svg { display: block; }

.tree-label {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.4;
}

.tree-children {
  padding-left: 16px;
  border-left: 1px solid rgba(255,255,255,.05);
  margin-left: 15px;
}
.tree-access-error {
  font-size: 11px; color: var(--muted); opacity: .5;
  padding: 2px 8px; font-style: italic;
}

/* ── 폴더 드롭 타겟 하이라이트 ── */
.tree-row.drop-target {
  background: rgba(124,106,247,.35) !important;
  color: #e0d5ff;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── 이동 모달 ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  min-width: 380px; max-width: 480px;
  display: flex; flex-direction: column; gap: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.modal-msg {
  font-size: 14px; color: var(--text); line-height: 1.7;
}
.modal-fields {
  display: flex; flex-direction: column; gap: 10px;
}
.modal-fields label {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; color: var(--muted);
}
.modal-fields input {
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); font-family: 'JetBrains Mono', monospace;
  font-size: 13px; padding: 5px 10px; border-radius: 6px; outline: none;
  transition: border-color .15s; width: 160px;
}
.modal-fields input[type="number"] { width: 70px; text-align: center; }
.modal-fields input:focus { border-color: var(--accent); }
.modal-conflict-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 160px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
}
.modal-conflict-list li {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--warning);
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── 토스트 ── */
#toast {
  position: fixed; bottom: 40px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--success); color: #0a2a1a;
  font-weight: 700; font-size: 14px;
  padding: 12px 24px; border-radius: 12px;
  opacity: 0; transition: all .3s; pointer-events: none; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }