:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --border: #e2e2e6;
  --text: #1b1b1f;
  --muted: #74747c;
  --accent: #e60023;
  --accent-soft: #ffe3e8;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-left h1 { font-size: 18px; margin: 0; }
.topbar-center { flex: 1; max-width: 480px; }
.topbar-center input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 999px;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.small { font-size: 14px; padding: 4px 8px; }

.ghost-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
}
.ghost-btn:hover { background: #ececef; }

.primary-btn {
  background: var(--text);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}
.primary-btn:hover { opacity: 0.85; }

/* ---------- layout ---------- */
.layout {
  display: flex;
  align-items: flex-start;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  padding: 18px 14px;
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.sidebar.collapsed { display: none; }

.sidebar-section { margin-bottom: 22px; }
.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

#rootSelect {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
}

.folder-list { list-style: none; margin: 0; padding: 0; }
.folder-list li {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  color: var(--text);
}
.folder-list li:hover { background: var(--bg); }
.folder-list li.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.folder-list li .count { color: var(--muted); font-size: 12px; }

.active-tag-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  width: fit-content;
}
.active-tag-filter button { background: none; border: none; color: inherit; font-size: 12px; }

.content { flex: 1; padding: 20px; min-width: 0; }

/* ---------- masonry grid ---------- */
.masonry {
  column-count: 5;
  column-gap: 14px;
}
@media (max-width: 1600px) { .masonry { column-count: 4; } }
@media (max-width: 1200px) { .masonry { column-count: 3; } }
@media (max-width: 800px)  { .masonry { column-count: 2; } }
@media (max-width: 500px)  { .masonry { column-count: 1; } }

.card {
  break-inside: avoid;
  margin-bottom: 14px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}
.card img { width: 100%; display: block; background: #eee; }
.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.55), rgba(0,0,0,0) 40%);
  opacity: 0;
  transition: opacity 0.15s ease;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  color: white;
}
.card:hover .card-overlay { opacity: 1; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.card-tag {
  background: rgba(255,255,255,0.9);
  color: #111;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.card-feedback { display: flex; gap: 10px; font-size: 12px; font-weight: 700; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.dialog {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.dialog.wide { max-width: 560px; max-height: 80vh; overflow-y: auto; }
.dialog h2 { margin: 0 0 6px; font-size: 18px; }
.dialog .muted { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }

#nicknameForm, .add-root-form { display: flex; gap: 8px; margin-top: 8px; }
#nicknameForm input, .add-root-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.add-root-form { flex-direction: column; margin-top: 14px; }

.root-table, .tag-manage-list { list-style: none; padding: 0; margin: 0; }
.root-table li, .tag-manage-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.root-table .root-meta { display: flex; flex-direction: column; }
.root-table .root-path { color: var(--muted); font-size: 11px; }
.root-table .root-actions, .tag-manage-list .tag-actions { display: flex; gap: 6px; flex-shrink: 0; }
.root-table .root-actions button, .tag-manage-list .tag-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}
.tag-manage-list input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 6px;
  width: 140px;
}
.tag-manage-list input:hover, .tag-manage-list input:focus { border-color: var(--border); background: var(--bg); }
.tag-manage-list .usage { color: var(--muted); font-size: 12px; }

/* ---------- lightbox ---------- */
.lightbox {
  background: var(--panel);
  border-radius: var(--radius);
  display: flex;
  max-width: 1000px;
  width: 100%;
  max-height: 88vh;
  overflow: hidden;
  position: relative;
}
.close-btn { position: absolute; top: 8px; right: 8px; z-index: 5; background: rgba(255,255,255,0.85); }
.lightbox-image-wrap {
  flex: 1.4;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.lightbox-image-wrap img { max-width: 100%; max-height: 88vh; object-fit: contain; }
.lightbox-info { flex: 1; padding: 20px; overflow-y: auto; }
.lightbox-path { font-size: 12px; color: var(--muted); word-break: break-all; margin-bottom: 16px; }

.feedback-row { display: flex; gap: 10px; margin-bottom: 20px; }
.feedback-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
  font-weight: 700;
}
.feedback-btn.like.active { background: #e7f6ec; border-color: #2fa84f; color: #1c7a37; }
.feedback-btn.dislike.active { background: #fdeaea; border-color: var(--accent); color: var(--accent); }

.tags-heading { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 6px 5px 10px;
  border-radius: 999px;
}
.tag-chip button { background: none; border: none; color: inherit; font-size: 12px; padding: 0 4px; }
.add-tag-form input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}

/* ---------- 이하: Cloudflare Pages 이식하면서 추가된 부분 ---------- */

/* 드라이브 연결 상태 / 공유링크 만료 경고 배너 */
.banner {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.banner[hidden] { display: none; }
.banner.warn  { background: #fff6e5; color: #8a5a00; }
.banner.error { background: #fdeaea; color: var(--accent); }

/* 사이드바 - 연결된 드라이브 정보 */
.library-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
}
.library-name { font-weight: 700; word-break: break-all; }
.library-meta { color: var(--muted); margin-top: 4px; font-size: 11px; }

/* 사이드바 - 태그 목록 */
.tag-list { list-style: none; margin: 8px 0 0; padding: 0; }
.tag-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.tag-list li:hover { background: var(--bg); }
.tag-list li.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tag-list .count { color: var(--muted); font-size: 12px; }
.tag-list .none { color: var(--muted); font-size: 12px; padding: 6px 10px; }

/* 목록 위 상태 줄 (몇 장 / 잘렸는지) */
.status-bar {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.status-bar[hidden] { display: none; }
.status-bar .warn { color: #8a5a00; font-weight: 700; }

/* 썸네일이 도착하기 전 자리를 잡아주는 회색 박스.
   masonry는 이미지 높이를 미리 모르면 로딩 중에 칸이 계속 튀기 때문에 필요하다. */
.card .thumb-wrap {
  position: relative;
  width: 100%;
  background: #ececef;
  min-height: 120px;
}
.card img { transition: opacity 0.2s ease; }
.card img.loading { opacity: 0; }
.card .thumb-fail {
  padding: 24px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
}

.lightbox-actions { margin-top: 20px; }
.lightbox-actions .ghost-btn {
  display: inline-block;
  text-decoration: none;
  color: var(--text);
}

/* 모바일에서는 라이트박스를 세로로 쌓는다 */
@media (max-width: 720px) {
  .lightbox { flex-direction: column; max-height: 92vh; }
  .lightbox-image-wrap { flex: none; max-height: 45vh; }
  .lightbox-image-wrap img { max-height: 45vh; }
  .topbar { flex-wrap: wrap; }
  .topbar-center { order: 3; max-width: none; flex-basis: 100%; }
}

/* 점진 로딩 */
.scroll-sentinel { height: 1px; }
.more-state {
  text-align: center;
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: 13px;
}
.more-state[hidden] { display: none; }
