/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:     #111318;
  --card:   #1c1f27;
  --border: #2a2d38;
  --text:   #e2e5ec;
  --muted:  #7a8094;
  --accent: #4f9eff;
  --accent2: #3ecf8e;
  --danger: #ef4444;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
  --radius: 10px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ── App layout ─────────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title-row { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
  margin-bottom: 0;
}

.sidebar-header h1 span { color: var(--accent); }

.btn-logout {
  background: none; border: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 2px 4px;
  border-radius: 5px; line-height: 1; text-decoration: none;
  transition: color .15s;
}
.btn-logout:hover { color: var(--danger); text-decoration: none; }

.btn-sync {
  width: 100%;
  padding: 8px 12px;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .3px;
  transition: opacity .15s;
}
.btn-sync:hover { opacity: .85; }
.btn-sync:disabled { opacity: .4; cursor: default; }

.btn-classify {
  display: block;
  width: 100%;
  padding: 7px 12px;
  margin-top: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.btn-classify:hover { background: var(--border); color: var(--text); text-decoration: none; }

/* ── AI filter section ──────────────────────────────────────────────────────── */
.ai-filter-section {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
}
.ai-filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ai-filter-label { font-size: .75rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }

.btn-analyze {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: .72rem;
  padding: 3px 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-analyze:hover { background: var(--border); color: var(--text); }

.ai-cat-btns { display: flex; gap: 4px; flex-wrap: wrap; }

.ai-cat-btn {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.ai-cat-btn:hover { background: rgba(255,255,255,.05); color: var(--text); }
.ai-cat-btn.active { background: rgba(79,158,255,.15); border-color: var(--accent); color: var(--accent); }

.sidebar-stats {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Nav tabs ───────────────────────────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Nav tree ───────────────────────────────────────────────────────────────── */
.nav-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-tree::-webkit-scrollbar { width: 4px; }
.nav-tree::-webkit-scrollbar-track { background: transparent; }
.nav-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-group { user-select: none; }

.nav-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: .84rem;
  transition: background .1s;
}
.nav-group-header:hover { background: rgba(255,255,255,.04); }

.nav-group-header .arrow {
  width: 12px;
  font-size: .7rem;
  color: var(--muted);
  transition: transform .2s;
  flex-shrink: 0;
}
.nav-group.open > .nav-group-header .arrow { transform: rotate(90deg); }

.nav-group-header .cnt {
  margin-left: auto;
  font-size: .72rem;
  color: var(--muted);
  font-weight: 400;
}

.nav-children { display: none; }
.nav-group.open > .nav-children { display: block; }

.nav-item {
  display: flex;
  align-items: center;
  padding: 5px 16px 5px 36px;
  cursor: pointer;
  color: var(--muted);
  font-size: .82rem;
  transition: background .1s, color .1s;
  border-radius: 0;
  gap: 8px;
}
.nav-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav-item.active { background: rgba(79,158,255,.12); color: var(--accent); }
.nav-item .cnt { margin-left: auto; font-size: .72rem; }

.nav-loading, .nav-empty {
  padding: 20px 16px;
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
}

/* ── Main content ───────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--card);
}

.content-header h2 { font-size: 1rem; font-weight: 600; }
.content-header .subtitle { color: var(--muted); font-size: .82rem; }
.content-header .photo-count { margin-left: auto; color: var(--muted); font-size: .82rem; }

/* ── Photo grid ─────────────────────────────────────────────────────────────── */
.grid-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.grid-wrap::-webkit-scrollbar { width: 6px; }
.grid-wrap::-webkit-scrollbar-track { background: transparent; }
.grid-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

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

.photo-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  cursor: pointer;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  transition: transform .15s, box-shadow .15s;
}
.photo-card:hover { transform: scale(1.02); box-shadow: var(--shadow); z-index: 1; }

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--border);
}

.photo-card-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 20px 8px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  opacity: 0;
  transition: opacity .2s;
  font-size: .72rem;
  color: rgba(255,255,255,.9);
}
.photo-card:hover .photo-card-overlay { opacity: 1; }
.photo-card-overlay .date { display: block; }
.photo-card-overlay .loc { color: rgba(255,255,255,.65); }

/* ── Pagination ─────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.page-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: .82rem;
  transition: background .1s, border-color .1s;
}
.page-btn:hover { background: var(--border); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: .3; cursor: default; }

/* ── Loading / empty states ─────────────────────────────────────────────────── */
.state-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--muted);
  font-size: .9rem;
}
.state-msg .icon { font-size: 3rem; opacity: .4; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Lightbox ───────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.93);
  z-index: 1000;
  display: none;
  flex-direction: column;
}
.lightbox.open { display: flex; }

.lightbox-toolbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  flex-shrink: 0;
}

.lb-btn {
  background: rgba(255,255,255,.08);
  border: none;
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-btn:hover { background: rgba(255,255,255,.16); }

.lb-title { flex: 1; font-size: .88rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-counter { font-size: .82rem; color: var(--muted); flex-shrink: 0; }

.lightbox-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.lb-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.lb-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
}

.lb-nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,.5);
  border: none;
  color: #fff;
  width: 48px; height: 80px;
  font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  transition: background .15s;
  z-index: 2;
}
.lb-nav:hover { background: rgba(255,255,255,.15); }
.lb-nav.prev { left: 12px; }
.lb-nav.next { right: 12px; }
.lb-nav:disabled { opacity: .2; cursor: default; }

.lb-info-panel {
  width: 260px;
  min-width: 260px;
  background: var(--card);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lb-info-row { }
.lb-info-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.lb-info-value { font-size: .88rem; color: var(--text); }

.lb-spinner {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.3);
}

/* ── Sync overlay ───────────────────────────────────────────────────────────── */
.sync-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}

.sync-dialog {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 420px;
  max-width: 90vw;
}
.sync-dialog h3 { margin-bottom: 20px; font-size: 1rem; }

.progress-bar-wrap {
  background: var(--bg);
  border-radius: 6px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width .4s;
  width: 0%;
}

.sync-msg { font-size: .83rem; color: var(--muted); margin-bottom: 20px; min-height: 1.2em; }
.sync-actions { display: flex; justify-content: flex-end; }
.btn-close-sync {
  padding: 8px 18px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: .85rem;
}
.btn-close-sync:hover { background: var(--border); }

/* ── Welcome / setup ────────────────────────────────────────────────────────── */
.welcome {
  display: flex; align-items: center; justify-content: center;
  height: 100%; flex-direction: column; gap: 16px; padding: 40px;
  text-align: center;
}
.welcome h2 { font-size: 1.4rem; }
.welcome p  { color: var(--muted); max-width: 480px; line-height: 1.7; }
.welcome .btn-setup {
  padding: 12px 28px;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  margin-top: 8px;
}
.welcome .btn-setup:hover { opacity: .85; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; max-height: 40vh; }
  .lb-info-panel { display: none; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
