@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@300;400;500&display=swap');

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

:root {
  --bg: #0c0c0e;
  --surface: #141416;
  --s2: #1c1c1f;
  --border: #252528;
  --text: #f2f0eb;
  --muted: #5a5a60;
  --accent: #e8c96d;
  --adim: rgba(232, 201, 109, 0.1);
  --danger: #e8695a;
  --success: #5ec98a;
  --r: 10px;
}

body {
  font-family: 'Geist', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { text-decoration: none; }
button, input, select, textarea { font-family: 'Geist', sans-serif; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(12, 12, 14, .94);
  backdrop-filter: blur(12px);
  z-index: 20;
}
.logo {
  font-family: 'Instrument Serif', serif;
  font-size: 1.35rem;
  letter-spacing: -.02em;
  color: var(--text);
}
.logo em { color: var(--accent); font-style: italic; }
.nav { display: flex; align-items: center; gap: 1.5rem; }
.nav a { color: var(--muted); font-size: .85rem; transition: color .2s; }
.nav a:hover { color: var(--text); }
.nav a.on { color: var(--accent); }
.nav-user {
  font-size: .78rem;
  color: var(--muted);
  padding: .3rem .7rem;
  border: 1px solid var(--border);
  border-radius: 20px;
}
.nav-role {
  font-size: .68rem;
  background: var(--adim);
  color: var(--accent);
  border: 1px solid rgba(232, 201, 109, .2);
  padding: .15rem .5rem;
  border-radius: 10px;
  margin-left: .3rem;
}

/* ── Form controls ───────────────────────────────────────────────────────── */
input[type=text],
input[type=email],
input[type=password],
input[type=date],
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .875rem;
  padding: .55rem .9rem;
  border-radius: var(--r);
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select {
  appearance: none;
  cursor: pointer;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235a5a60' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
}
textarea { resize: vertical; }
label { font-size: .75rem; color: var(--muted); display: block; margin-bottom: .3rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border-radius: var(--r);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 400;
  transition: all .15s;
  border: none;
  padding: .6rem 1.1rem;
}
.btn-primary { background: var(--accent); color: #000; font-weight: 500; }
.btn-primary:hover { opacity: .85; }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.btn-ghost:hover { border-color: var(--text); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: .85; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .1);
  color: rgba(255, 255, 255, .7);
  font-size: .72rem;
  padding: .25rem .7rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
}
.pill:hover { background: rgba(255, 255, 255, .14); color: white; }
.pill.active { border-color: var(--accent); color: var(--accent); background: var(--adim); }
.pill.danger { color: var(--danger); border-color: rgba(232, 105, 90, .3); }
.pill.danger:hover { background: rgba(232, 105, 90, .15); }
.pill-sm { font-size: .68rem; padding: .15rem .55rem; }

/* ── Tags ────────────────────────────────────────────────────────────────── */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--adim);
  border: 1px solid rgba(232, 201, 109, .2);
  color: var(--accent);
  font-size: .72rem;
  padding: .15rem .55rem;
  border-radius: 20px;
}
.tag-chip.pub { background: rgba(94, 201, 138, .1); border-color: rgba(94, 201, 138, .25); color: var(--success); }
.tag-chip.shr { background: rgba(100, 160, 255, .1); border-color: rgba(100, 160, 255, .25); color: #64a0ff; }

.tag-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: .35rem .5rem;
  min-height: 40px;
  cursor: text;
  transition: border-color .2s;
}
.tag-input-wrap:focus-within { border-color: var(--accent); }
.tag-input-wrap input {
  background: none;
  border: none;
  outline: none;
  font-size: .85rem;
  color: var(--text);
  padding: .1rem .2rem;
  min-width: 80px;
  flex: 1;
  width: auto;
}
.tc-remove {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
  padding: 0;
  opacity: .6;
}
.tc-remove:hover { opacity: 1; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.vbadge { font-size: .65rem; padding: .15rem .5rem; border-radius: 20px; font-weight: 500; }
.vbadge.public  { background: rgba(94, 201, 138, .15); color: var(--success); }
.vbadge.private { background: rgba(90, 90, 96, .2); color: var(--muted); }

/* ── Masonry gallery ─────────────────────────────────────────────────────── */
.gallery { padding: 1.5rem 2rem; columns: 4 220px; column-gap: 10px; }

.gitem {
  break-inside: avoid;
  margin-bottom: 10px;
  border-radius: var(--r);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  position: relative;
}
.gitem img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform .35s cubic-bezier(.25, .46, .45, .94);
}
.gitem:hover img { transform: scale(1.04); }

.goverlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.85) 0%, rgba(0,0,0,.1) 55%, transparent 100%);
  opacity: 0;
  transition: opacity .2s;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: .8rem;
  pointer-events: none;
}
.gitem:hover .goverlay { opacity: 1; }

.go-title {
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: .15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: white;
}
.go-meta { font-size: .7rem; color: rgba(255,255,255,.5); }
.go-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .35rem; }
.go-tag {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.7);
  font-size: .65rem;
  padding: .1rem .4rem;
  border-radius: 20px;
}

/* Select mode */
.gitem .sel-check {
  position: absolute;
  top: .6rem;
  left: .6rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  border: 2px solid rgba(255,255,255,.4);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  color: white;
  transition: all .15s;
}
.select-mode .gitem .sel-check { display: flex; }
.gitem.selected .sel-check { background: var(--accent); border-color: var(--accent); color: #000; }
.gitem.selected img { transform: scale(.96); }

/* ── Skeletons + spinner ─────────────────────────────────────────────────── */
.skeleton {
  break-inside: avoid;
  margin-bottom: 10px;
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

#sentinel { height: 1px; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
  padding: .9rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 57px;
  background: rgba(12, 12, 14, .93);
  backdrop-filter: blur(12px);
  z-index: 19;
}
.search-wrap { position: relative; }
.search-wrap .icon {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: .85rem;
}
.search-wrap input {
  padding-left: 2rem;
  width: 200px;
  transition: border-color .2s, width .2s;
  border-radius: 20px;
}
.search-wrap input:focus { width: 240px; }
.filter-sep { width: 1px; height: 18px; background: var(--border); }
.filter-count { font-size: .78rem; color: var(--muted); margin-left: auto; }
.fselect { width: auto; padding: .42rem 1.8rem .42rem .7rem; border-radius: 20px; font-size: .8rem; }

.active-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .5rem 2rem;
  border-bottom: 1px solid var(--border);
}
.active-tags:empty { display: none; }

/* ── Tag dropdown ────────────────────────────────────────────────────────── */
.tag-dd { position: relative; }
.tag-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: .75rem;
  min-width: 220px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.tag-panel.open { display: block; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .72rem;
  padding: .18rem .6rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
}
.tag-pill:hover, .tag-pill.sel { border-color: var(--accent); color: var(--accent); }

/* ── Bulk bar ─────────────────────────────────────────────────────────────── */
.bulk-bar {
  display: none;
  align-items: center;
  gap: 1rem;
  padding: .75rem 2rem;
  background: var(--adim);
  border-bottom: 1px solid rgba(232, 201, 109, .2);
}
.bulk-bar.show { display: flex; }
.bulk-count { font-size: .85rem; color: var(--accent); font-weight: 500; }

/* ── Lightbox ────────────────────────────────────────────────────────────── */
.lb {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.94);
  z-index: 100;
  backdrop-filter: blur(6px);
  animation: fadeIn .15s;
}
.lb.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lb-layout { display: flex; width: 100%; height: 100%; }

.lb-img-side {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  position: relative;
  min-width: 0;
}
.lb-img-side img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--r);
  animation: scaleIn .2s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes scaleIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.lb-nav {
  position: absolute;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: white;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.lb-nav:hover { background: rgba(255,255,255,.2); }
.lb-close { top: 1rem; left: 1rem; }
.lb-prev { top: 50%; left: 1rem; transform: translateY(-50%); }
.lb-next { top: 50%; right: 1rem; transform: translateY(-50%); }

.lb-meta {
  width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.lbm-head { padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); }
.lbm-title {
  font-family: 'Instrument Serif', serif;
  font-size: 1.1rem;
  font-weight: 400;
  margin-bottom: .5rem;
  word-break: break-word;
}
.lbm-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.lbm-body { flex: 1; padding: 1.1rem 1.4rem; display: flex; flex-direction: column; gap: 1rem; }

.meta-field label { font-size: .72rem; color: var(--muted); margin-bottom: .3rem; }
.meta-value { font-size: .875rem; line-height: 1.5; }
.meta-value.dim { color: var(--muted); font-style: italic; font-size: .82rem; }
.meta-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.meta-dates { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ── Edit panel ──────────────────────────────────────────────────────────── */
.edit-panel { display: none; padding: 1.1rem 1.4rem; flex-direction: column; gap: .85rem; border-top: 1px solid var(--border); }
.edit-panel.open { display: flex; }
.ef { display: flex; flex-direction: column; gap: .3rem; }
.ef-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.ef-btns { display: flex; gap: .6rem; margin-top: .2rem; }
.ef-btns .btn { flex: 1; justify-content: center; padding: .55rem; }

.vis-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.vis-toggle button {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .8rem;
  padding: .45rem .75rem;
  cursor: pointer;
  transition: all .15s;
}
.vis-toggle button.on { background: var(--adim); color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem;
  max-width: 400px;
  width: 90%;
  animation: scaleIn .18s ease;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}
.modal h3 { font-family: 'Instrument Serif', serif; font-size: 1.15rem; font-weight: 400; }
.modal-btns { display: flex; gap: .6rem; }
.modal-btns .btn { flex: 1; justify-content: center; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .65rem 1.1rem;
  border-radius: var(--r);
  font-size: .82rem;
  opacity: 0;
  transform: translateY(6px);
  transition: all .2s;
  pointer-events: none;
  z-index: 300;
  max-width: 280px;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  text-align: center;
  gap: .9rem;
}
.empty-icon { font-size: 2.5rem; opacity: .2; }
.empty h2 { font-family: 'Instrument Serif', serif; font-size: 1.4rem; font-weight: 400; color: var(--muted); }
.empty p { font-size: .85rem; color: var(--muted); }
.empty a { color: var(--accent); font-size: .875rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: .875rem; }
.tbl th {
  text-align: left;
  font-size: .72rem;
  color: var(--muted);
  font-weight: 400;
  padding: .5rem 1rem;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tbl td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: var(--s2); }
.tbl-actions { display: flex; gap: .4rem; }

/* ── Stats ───────────────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  padding: 1.5rem 2rem;
}
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 1.25rem 1.5rem; }
.stat-value { font-family: 'Instrument Serif', serif; font-size: 2rem; font-weight: 400; }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 2rem; }
.tab {
  font-size: .875rem;
  padding: .85rem 1rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.on { display: block; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .gallery { columns: 2 140px; padding: 1rem; }
  .filters { padding: .75rem 1rem; top: 53px; }
  header { padding: 1rem 1.25rem; }
  .lb-layout { flex-direction: column; }
  .lb-meta { width: 100%; max-height: 50vh; border-left: none; border-top: 1px solid var(--border); }
  .lb-img-side { min-height: 45vh; padding: 1.5rem 1rem; }
  .lb-prev, .lb-next { display: none; }
  .stats { padding: 1rem; }
  .tabs { padding: 0 1rem; }
  .tbl th, .tbl td { padding: .6rem .75rem; }
  .bulk-bar { flex-wrap: wrap; gap: .5rem; }
}
