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

:root {
  --brand: #6c47ff;
  --brand-dark: #5535e0;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --danger: #ef4444;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1rem;
}

.center-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1rem;
  gap: 1.5rem;
  max-width: 460px;
}

/* Logo */
.logo-block { text-align: center; }
.logo {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--brand), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}
.logo.small { font-size: 1.2rem; }
.tagline { color: var(--muted); margin-top: 0.25rem; font-size: 0.95rem; }

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card h2 { font-size: 1.25rem; margin-bottom: 0.4rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.hidden { display: none !important; }

/* Forms */
label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--text); }
.optional { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="password"], input[type="email"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--brand); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; width: 100%; margin-top: 0.5rem; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: #f3f4f6; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e9eaec; }
.btn-small { padding: 0.4rem 0.85rem; font-size: 0.85rem; width: auto; margin-top: 0; }

/* Error / hint */
.error { color: var(--danger); font-size: 0.88rem; margin-top: 0.5rem; min-height: 1.2rem; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 0.4rem; }

/* Success card */
.success-icon { font-size: 3rem; margin-bottom: 0.75rem; }

/* ── Gallery header ── */
.gallery-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.view-count { font-size: 0.82rem; color: var(--muted); }

/* ── Manage panel ── */
.manage-panel {
  background: #f0eeff;
  border-bottom: 1px solid #d8d0ff;
  padding: 1.25rem 0;
}
.manage-panel h3 { font-size: 1rem; margin-bottom: 1rem; color: var(--brand-dark); }
.manage-section { margin-bottom: 1.25rem; }
.manage-section:last-child { margin-bottom: 0; }

.upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--brand);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.upload-label:hover { background: #ede9ff; }

.upload-progress { margin-top: 0.75rem; }
.progress-bar { background: var(--border); border-radius: 99px; height: 6px; overflow: hidden; margin-bottom: 0.3rem; }
.progress-fill { height: 100%; background: var(--brand); width: 0; transition: width 0.2s; }

.row-input { display: flex; gap: 0.5rem; align-items: center; }
.row-input input { margin-bottom: 0; flex: 1; }

/* ── Media grid ── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px 0;
}
@media (min-width: 500px) { .media-grid { grid-template-columns: repeat(4, 1fr); } }

.media-cell {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #e5e7eb;
  cursor: pointer;
}
.media-cell img, .media-cell video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.media-cell:hover img, .media-cell:hover video { transform: scale(1.03); }

.video-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  pointer-events: none;
}

.delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  z-index: 2;
}
.delete-btn:active { background: #b91c1c; }

.gallery-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
  text-align: center;
  padding: 0.5rem 1rem 0;
}

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

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-media { max-width: 90vw; max-height: 85vh; display: flex; align-items: center; justify-content: center; }
.lightbox-media img, .lightbox-media video { max-width: 90vw; max-height: 85vh; object-fit: contain; border-radius: 6px; }
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav.prev { left: 1rem; }
.lightbox-nav.next { right: 1rem; }
.lightbox-caption { position: absolute; bottom: 1rem; color: rgba(255,255,255,0.6); font-size: 0.85rem; }

/* ── Admin panel ── */
.result-section { margin-bottom: 1.5rem; }
.result-section label { font-size: 0.85rem; font-weight: 700; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.badge { background: #fef3c7; color: #92400e; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 99px; font-weight: 600; }
.qr-wrap { display: flex; justify-content: center; margin: 0.5rem 0; }
.qr-wrap img { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }
.code-display {
  font-family: 'Courier New', monospace;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: center;
  color: var(--brand-dark);
}
.code-display.small { font-size: 0.85rem; letter-spacing: 0; word-break: break-all; }
.result-actions { display: flex; gap: 0.75rem; margin: 1rem 0; }
.result-actions .btn { width: auto; flex: 1; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

@media print {
  .btn, .result-actions, hr, #generate-another { display: none !important; }
}
