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

:root {
  --bg: #ffffff;
  --bg2: #f4f4f5;
  --bg3: #e4e4e7;
  --border: #d4d4d8;
  --text: #18181b;
  --text2: #52525b;
  --text3: #a1a1aa;
  --accent: #2563eb;
  --accent-h: #1d4ed8;
  --danger: #dc2626;
  --danger-h: #b91c1c;
  --success: #16a34a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --nav-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg2);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* NAV */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-brand svg { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-links a {
  text-decoration: none;
  color: var(--text2);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: background .15s, color .15s;
}

.nav-links a:hover, .nav-links a.active { background: var(--bg2); color: var(--text); }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-user {
  font-size: 0.85rem;
  color: var(--text2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-admin { background: #dbeafe; color: #1d4ed8; }
.badge-user  { background: #f0fdf4; color: #15803d; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-h); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)   { background: var(--danger-h); }
.btn-ghost    { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg2); color: var(--text); }
.btn-sm       { padding: 5px 10px; font-size: 0.8rem; }

/* MAIN CONTENT */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.page-header p   { color: var(--text2); margin-top: 4px; font-size: 0.95rem; }
.page-header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ALBUMS GRID */
.albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.album-card {
  display: block;
  text-decoration: none;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
}

.album-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.album-cover {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg3);
  overflow: hidden;
  position: relative;
}

.album-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
}

.album-info {
  padding: 14px 16px;
}

.album-info h3 {
  font-size: 0.975rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text3);
}

/* PHOTOS GRID */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.photo-thumb {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  position: relative;
  cursor: pointer;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .25s;
}

.photo-thumb:hover img { transform: scale(1.05); }

.photo-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity .2s;
}

.photo-thumb:hover .photo-thumb-overlay { opacity: 1; }

/* LIGHTBOX */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox.hidden { display: none; }

.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 80px);
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
}

.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  opacity: .7;
  transition: opacity .15s;
  line-height: 1;
}

.lb-close:hover { opacity: 1; }

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.1);
  border: none;
  color: #fff;
  font-size: 2.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  line-height: 1;
}

.lb-nav:hover { background: rgba(255,255,255,.2); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.7);
  font-size: 0.85rem;
}

/* AUTH PAGE */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
}

.auth-box {
  background: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo h1 { font-size: 1.5rem; font-weight: 700; margin-top: 12px; }
.auth-logo p  { color: var(--text2); font-size: 0.9rem; margin-top: 4px; }

/* FORMS */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* CARDS */
.card {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card + .card { margin-top: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 { font-size: 1.1rem; font-weight: 600; }

/* TABLE */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text2);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--bg2);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 4px;
  color: var(--accent);
}

/* UPLOAD */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text2);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: #eff6ff;
  color: var(--accent);
}

.upload-zone input[type=file] { display: none; }

.upload-zone svg { margin-bottom: 8px; }

.upload-zone p { font-size: 0.9rem; margin-top: 4px; }
.upload-zone small { color: var(--text3); font-size: 0.8rem; }

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.upload-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg3);
  position: relative;
}

.upload-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-thumb .upload-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

/* MESSAGES */
.msg {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.msg-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.msg-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.hidden { display: none !important; }

/* ALBUM ADMIN ITEM */
.album-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.album-item:last-child { border-bottom: none; }

.album-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg3);
  flex-shrink: 0;
}

.album-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.album-item-info { flex: 1; min-width: 0; }

.album-item-info h4 {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-item-info small { color: var(--text3); font-size: 0.8rem; }
.album-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* BACK LINK */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 20px;
  transition: color .15s;
}

.back-link:hover { color: var(--text); }

/* SPINNER */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}

.empty-state svg { opacity: .3; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 480px;
}

.modal h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }

/* RESPONSIVE */
@media (max-width: 640px) {
  main { padding: 20px 16px; }
  .albums-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .photos-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .lb-nav { display: none; }
  nav { padding: 0 16px; gap: 12px; }
  .nav-links { display: none; }
}
