/* =============================================
   QuickShare - 메인 스타일시트
   ============================================= */

/* ── 1. CSS 변수 ──────────────────────────────── */
:root {
  --bg:             #f8faff;
  --white:          #ffffff;
  --border:         #e4e9f2;
  --border-focus:   #3b82f6;
  --accent:         #2563eb;
  --accent-light:   #eff6ff;
  --accent-hover:   #1d4ed8;
  --text:           #111827;
  --text-sub:       #4b5563;
  --text-dim:       #9ca3af;
  --red:            #ef4444;
  --sidebar-w:      220px;
  --header-h:       62px;
  --shadow:         0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-hover:   0 4px 16px rgba(37,99,235,0.14), 0 1px 3px rgba(0,0,0,0.06);
}

/* ── 2. 리셋 ──────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── 3. 버튼 ──────────────────────────────────── */
.btn {
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 0.83em;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,0.3); }
.btn-ghost { background: transparent; color: var(--text-sub); border: 1.5px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: #fee2e2; color: var(--red); border: none; }
.btn-danger:hover { background: #fecaca; }

/* ── 4. 헤더 ──────────────────────────────────── */
header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--border);
}

.sidebar-toggle {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  font-size: 1em;
  cursor: pointer;
  color: var(--text-sub);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }

.logo {
  font-size: 1.05em;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  flex-shrink: 0;
}
.logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1em;
}
.search-wrap { flex: 1; max-width: 380px; position: relative; }
.search-icon {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim); font-size: 0.85em; pointer-events: none;
}
.search-bar {
  width: 100%; height: 37px;
  border: 1.5px solid var(--border); border-radius: 9px;
  padding: 0 14px 0 34px;
  font-size: 0.84em; color: var(--text); background: var(--bg);
  outline: none; font-family: inherit; transition: all 0.15s;
}
.search-bar:focus {
  border-color: var(--border-focus); background: var(--white);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}
.search-bar::placeholder { color: var(--text-dim); }
.header-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* ── 5. 앱 레이아웃 ────────────────────────────── */
.app-layout {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

/* ── 6. 사이드바 ────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--border);
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
  overflow-y: auto;
  transition: width 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

/* 사이드바 숨김 */
.sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-title {
  font-size: 0.72em;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── 사이드바 트리 ── */
.sidebar-tree {
  padding: 8px 0 24px;
}

.tree-root {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  font-size: 0.84em;
  font-weight: 600;
  color: var(--text-sub);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 0;
  white-space: nowrap;
}
.tree-root:hover { background: var(--accent-light); color: var(--accent); }
.tree-root.tree-active {
  background: var(--accent-light);
  color: var(--accent);
}

.tree-node { }

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 6px 8px;
  font-size: 0.83em;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 0;
  position: relative;
}
.tree-row:hover { background: var(--accent-light); color: var(--accent); }
.tree-row.tree-active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
}
.tree-row.tree-ancestor {
  color: var(--text);
  font-weight: 600;
}

.tree-toggle {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.6em;
  color: var(--text-dim);
  transition: transform 0.15s;
  border-radius: 4px;
  cursor: pointer;
}
.tree-toggle:hover { background: rgba(37,99,235,0.1); color: var(--accent); }
.toggle-leaf { visibility: hidden; }

.tree-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
  flex: 1;
  min-width: 0;
}
.tree-link:hover { color: inherit; }

.tree-icon { font-size: 0.95em; flex-shrink: 0; }
.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 자식 들여쓰기 */
.tree-children {
  display: none;
  padding-left: 18px;
}
.tree-children.tree-open { display: block; }

/* 열린 토글 아이콘 회전 */
.tree-row.is-open > .tree-toggle .toggle-icon {
  display: inline-block;
  transform: rotate(90deg);
}

/* ── 7. 사이드바 오버레이 (모바일) ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ── 8. 메인 영역 ─────────────────────────────── */
.main-area {
  flex: 1;
  min-width: 0;
  transition: margin-left 0.2s ease;
}

/* ── 9. 브레드크럼 ────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 28px;
  font-size: 0.82em;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}
.crumb-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.crumb-link:hover { text-decoration: underline; }
.crumb-sep { color: var(--text-dim); }
.crumb-current { color: var(--text); font-weight: 600; }

/* ── 10. 통계 카드 ────────────────────────────── */
.stats { display: flex; gap: 14px; padding: 20px 28px; }
.stat-card {
  background: var(--white); border-radius: 14px;
  border: 1px solid var(--border); padding: 14px 18px; flex: 1;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1em; flex-shrink: 0;
}
.si-blue   { background: #eff6ff; }
.si-green  { background: #f0fdf4; }
.si-purple { background: #faf5ff; }
.si-orange { background: #fff7ed; }
.stat-val { font-size: 1.3em; font-weight: 700; color: var(--text); letter-spacing: -0.03em; line-height: 1; }
.stat-label { font-size: 0.7em; color: var(--text-dim); font-weight: 500; margin-top: 3px; }

/* ── 11. 메인 래퍼 ────────────────────────────── */
.main-wrap { padding: 20px 28px 40px; }

/* ── 12. 섹션 헤더 ────────────────────────────── */
.section-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 14px;
}
.section-left { display: flex; align-items: center; gap: 10px; }
.section-title { font-size: 0.9em; font-weight: 700; color: var(--text); }
.count-pill {
  font-size: 0.72em; font-weight: 600;
  background: var(--accent-light); color: var(--accent);
  padding: 2px 9px; border-radius: 20px;
}
.selected-count {
  font-size: 0.72em; font-weight: 600;
  background: #fef9c3; color: #92400e;
  padding: 2px 9px; border-radius: 20px;
}

/* ── 13. 그리드 ───────────────────────────────── */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 13px; margin-bottom: 28px;
}
.file-card {
  background: var(--white); border-radius: 13px;
  border: 1px solid var(--border); padding: 16px;
  cursor: pointer; transition: all 0.2s;
  position: relative; box-shadow: var(--shadow);
}
.file-card:hover { box-shadow: var(--shadow-hover); border-color: #bfdbfe; transform: translateY(-2px); }
.card-icon { font-size: 2em; margin-bottom: 11px; display: block; }
.card-name {
  font-size: 0.8em; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 5px;
}
.card-meta { font-size: 0.7em; color: var(--text-dim); }
.card-del {
  position: absolute; top: 10px; right: 10px; opacity: 0;
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 0.8em; transition: all 0.15s;
  background: var(--bg); color: var(--text-dim);
}
.file-card:hover .card-del { opacity: 1; }
.card-del:hover { background: #fee2e2; color: var(--red); }

/* ── 14. 테이블 ───────────────────────────────── */
.table-wrap {
  background: var(--white); border-radius: 14px;
  border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 11px 18px; text-align: left;
  font-size: 0.7em; font-weight: 700; color: var(--text-dim);
  letter-spacing: 0.07em; text-transform: uppercase;
  background: #fafbff; border-bottom: 1px solid var(--border);
}
thead th.sortable { cursor: pointer; user-select: none; white-space: nowrap; transition: background 0.12s, color 0.12s; }
thead th.sortable:hover { background: #eef2ff; color: var(--accent); }
tbody tr { transition: background 0.1s; cursor: pointer; }
tbody tr:hover { background: var(--accent-light); }
tbody tr.dir-row:hover { background: #fefce8; }
tbody td {
  padding: 11px 18px; font-size: 0.84em;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.drag-over { background: #dbeafe !important; outline: 2px dashed var(--accent); }

.fname-cell { display: flex; align-items: center; gap: 10px; }
.ficon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1em; flex-shrink: 0; cursor: grab;
}
.ficon:active { cursor: grabbing; }
.fi-blue   { background: #dbeafe; }
.fi-green  { background: #dcfce7; }
.fi-orange { background: #ffedd5; }
.fi-purple { background: #ede9fe; }
.fi-gray   { background: var(--bg); border: 1px solid var(--border); }
.fi-yellow { background: #fef9c3; }

.fname { font-weight: 600; color: var(--text); }
.flink { color: inherit; text-decoration: none; }
.flink:hover { color: var(--accent); }
.td-sub { color: var(--text-dim); font-size: 0.83em; }

/* ── 15. 배지 ─────────────────────────────────── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 0.7em; font-weight: 700; }
.b-blue   { background: #dbeafe; color: #1d4ed8; }
.b-green  { background: #dcfce7; color: #15803d; }
.b-orange { background: #ffedd5; color: #c2410c; }
.b-purple { background: #ede9fe; color: #6d28d9; }
.b-gray   { background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); }
.b-yellow { background: #fef9c3; color: #92400e; }

/* ── 16. 액션 버튼 ────────────────────────────── */
.action-btns { display: flex; align-items: center; gap: 6px; opacity: 0; transition: opacity 0.15s; }
tbody tr:hover .action-btns { opacity: 1; }
.del-btn { color: #fca5a5; cursor: pointer; transition: color 0.15s; font-size: 1.2em; }
.del-btn:hover { color: var(--red); }
.move-btn { color: var(--text-dim); cursor: pointer; transition: color 0.15s; font-size: 1.1em; }
.move-btn:hover { color: var(--accent); }
.rename-btn { color: var(--text-dim); cursor: pointer; transition: color 0.15s; font-size: 1.1em; }
.rename-btn:hover { color: #f59e0b; }

/* ── 17. 빈 상태 ──────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-icon { font-size: 3em; margin-bottom: 14px; opacity: 0.4; }
.empty-text { font-size: 0.88em; }

/* ── 18. 정렬 아이콘 ──────────────────────────── */
.sort-icon { display: inline-block; margin-left: 4px; font-size: 0.8em; color: var(--text-dim); transition: color 0.12s; }
.sort-icon.active { color: var(--accent); font-weight: 700; }

/* ── 19. 모달 ─────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
  align-items: center; justify-content: center;
}
.modal-backdrop.active { display: flex; }
.modal-box {
  background: var(--white); border-radius: 16px;
  padding: 28px; width: 380px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  display: flex; flex-direction: column; gap: 16px;
}
.modal-title { font-size: 1em; font-weight: 700; color: var(--text); }
.modal-label { font-size: 0.8em; color: var(--text-sub); font-weight: 600; margin-bottom: -8px; }
.modal-input {
  width: 100%; height: 40px;
  border: 1.5px solid var(--border); border-radius: 9px;
  padding: 0 14px; font-size: 0.88em;
  color: var(--text); font-family: inherit; outline: none;
  transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.modal-select {
  width: 100%; height: 40px;
  border: 1.5px solid var(--border); border-radius: 9px;
  padding: 0 14px; font-size: 0.88em;
  color: var(--text); font-family: inherit; outline: none;
  background: var(--white); cursor: pointer;
}
.modal-select:focus { border-color: var(--border-focus); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; }

/* ── 20. 기타 ─────────────────────────────────── */
#file-input { display: none; }
.row-selected { background: #eff6ff !important; }
.col-check { width: 40px; }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: white;
  padding: 10px 22px; border-radius: 10px;
  font-size: 0.84em; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
  z-index: 400;
}
.toast.show { opacity: 1; }

/* ── 21. 반응형 ───────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    z-index: 150;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
  }
  .stats {
    flex-wrap: wrap;
  }
  .stats .stat-card {
    min-width: calc(50% - 7px);
  }
}