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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-2: #242424;
  --border: #2a2a2a;
  --accent: #e8e8e8;
  --muted: #888;
  --tag-bg: #252525;
  --error: #c0392b;
  --radius: 8px;
  --sidebar-w: 280px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--bg);
  color: var(--accent);
  font-family: var(--font);
  min-height: 100vh;
}

/* ── Login ── */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 2rem; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 1.25rem;
}
.login-box h2 { font-size: 1.4rem; font-weight: 600; }
.login-box form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-box input {
  padding: 0.65rem 0.9rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--accent); font-size: 1rem; outline: none;
}
.login-box input:focus { border-color: #555; }
.login-box button {
  padding: 0.65rem; background: var(--accent); color: #000; border: none;
  border-radius: var(--radius); font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-box button:hover { opacity: 0.85; }
.error { color: var(--error); font-size: 0.875rem; }

/* ── Home ── */
.home-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; }
.home-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 2rem; width: 100%; max-width: 600px;
}
.home-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.home-head h1 { font-size: 1.3rem; font-weight: 700; }
.home-user { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; color: var(--muted); }
.home-user a { color: var(--muted); text-decoration: none; }
.home-user a:hover { color: var(--accent); }
.home-subtitle { font-size: 0.9rem; color: var(--muted); margin-bottom: 1.5rem; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.library-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  padding: 1.5rem 1rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; color: var(--accent);
  transition: border-color 0.15s, transform 0.1s;
}
.library-card:hover { border-color: #555; transform: translateY(-2px); }
.library-icon { font-size: 2rem; }
.library-name { font-size: 0.9rem; font-weight: 600; text-align: center; }
.empty-msg { color: var(--muted); font-size: 0.9rem; grid-column: 1/-1; text-align: center; padding: 2rem; }

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

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--surface); z-index: 2;
}
.sidebar-head h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em; }
.sidebar-actions { display: flex; gap: 0.8rem; }
.sidebar-link { font-size: 0.78rem; color: var(--muted); text-decoration: none; }
.sidebar-link:hover { color: var(--accent); }

.nav-item {
  display: flex; align-items: center; gap: 0.4rem; width: 100%; text-align: left;
  padding: 0.5rem 0.75rem; background: none; border: none; color: var(--accent);
  font-size: 0.88rem; font-family: var(--font); cursor: pointer; border-radius: 6px;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--surface-2); font-weight: 600; }
.nav-all { margin: 0.6rem 0.6rem 0.2rem; width: calc(100% - 1.2rem); }

.folder-tree { padding: 0 0.6rem 1rem; }
.folder-item { white-space: nowrap; overflow: hidden; }
.folder-name { overflow: hidden; text-overflow: ellipsis; }
.caret { display: inline-block; width: 14px; font-size: 0.7rem; color: var(--muted); cursor: pointer; }
.caret-spacer { display: inline-block; width: 14px; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar input[type="search"] {
  flex: 0 1 360px; padding: 0.55rem 0.9rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--accent);
  font-size: 0.9rem; outline: none;
}
.topbar input[type="search"]:focus { border-color: #555; }
.result-count { font-size: 0.82rem; color: var(--muted); }
.active-filter { font-size: 0.82rem; color: var(--accent); margin-left: auto; }

/* ── Grid ── */
.grid {
  flex: 1; overflow-y: auto; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem; padding: 1.5rem; align-content: start;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: #555; transform: translateY(-2px); }
.thumb-wrap {
  position: relative; width: 100%; padding-bottom: 100%; overflow: hidden; background: var(--bg);
}
.thumb-wrap img {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; display: block;
}
.no-thumb {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; color: var(--muted); background: var(--bg);
}
.badge-video {
  position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,0.7); color: #fff;
  font-size: 0.7rem; padding: 2px 6px; border-radius: 4px;
}
.card-info { padding: 0.6rem 0.7rem; }
.card-name { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 0.68rem; color: var(--muted); margin-top: 0.2rem; }

.loading, .empty { text-align: center; padding: 3rem; color: var(--muted); }

/* ── Tags ── */
.tag {
  font-size: 0.72rem; padding: 0.22rem 0.55rem; background: var(--tag-bg);
  border-radius: 4px; color: var(--accent); display: inline-block;
}
.tag.clickable { cursor: pointer; }
.tag.clickable:hover { background: #333; }

/* ── Lightbox ── */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.lb-close {
  position: absolute; top: 1.2rem; right: 1.5rem; font-size: 1.8rem;
  background: none; border: none; color: var(--accent); cursor: pointer; z-index: 2;
}
.lb-content {
  display: flex; gap: 1.5rem; max-width: 1400px; max-height: 90vh; width: 100%;
}
.lb-media {
  flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0;
}
.lb-media img, .lb-media video {
  max-width: 100%; max-height: 86vh; object-fit: contain; border-radius: var(--radius);
}
.lb-info {
  width: 300px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; overflow-y: auto; max-height: 86vh;
  display: flex; flex-direction: column; gap: 1rem;
}
.lb-info h3 { font-size: 1rem; font-weight: 600; word-break: break-word; }
.lb-meta { font-size: 0.82rem; color: var(--muted); }
.lb-palette { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.swatch { width: 28px; height: 28px; border-radius: 5px; border: 1px solid var(--border); }
.lb-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lb-annotation { font-size: 0.82rem; color: var(--muted); font-style: italic; }
.lb-download {
  margin-top: auto; padding: 0.65rem; background: var(--accent); color: #000;
  text-align: center; border-radius: var(--radius); text-decoration: none;
  font-size: 0.88rem; font-weight: 600;
}
.lb-download:hover { opacity: 0.85; }

/* ── Responsive ── */
@media (max-width: 800px) {
  .sidebar { display: none; }
  .lb-content { flex-direction: column; }
  .lb-info { width: 100%; max-height: none; }
}
