:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --ok: #15803d;
  --border: #e5e3dc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Auth ---------- */
.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 100vh;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-card h1 { margin: 0 0 8px; font-size: 22px; }
.hint { color: var(--muted); margin: 0 0 24px; }

#auth-form { display: flex; flex-direction: column; gap: 12px; }
#code {
  width: 100%;
  font-size: 20px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafaf7;
}
#code:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font-size: 16px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
button.small { font-size: 13px; padding: 6px 10px; }

.status { margin-top: 16px; min-height: 1.5em; font-size: 14px; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { font-size: 14px; color: var(--muted); }
.who strong { color: var(--ink); }

/* ---------- App layout ---------- */
.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 20px;
}
@media (min-width: 900px) {
  .app-main { grid-template-columns: minmax(320px, 1fr) 2fr; align-items: start; }
}

.upload-card, .gallery-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.upload-card h2, .gallery-card h2 { margin: 0 0 12px; font-size: 17px; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: #eff4ff;
}
.dropzone p { margin: 4px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Queue ---------- */
.queue { margin-top: 16px; }
#queue-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
#queue-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: #fafaf7;
  border-radius: 6px;
  font-size: 13px;
}
#queue-list li .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#queue-list li .meta { color: var(--muted); white-space: nowrap; }
.queue-actions { display: flex; gap: 8px; }

/* ---------- Log ---------- */
.log { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.log h3 { font-size: 14px; margin: 0 0 8px; }
#log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  max-height: 160px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#log-list li { padding: 2px 0; }
#log-list li.ok { color: var(--ok); }
#log-list li.err { color: var(--danger); }

/* ---------- Gallery ---------- */
.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.gallery-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.gallery { display: flex; flex-direction: column; gap: 20px; }

.group h3 {
  font-size: 15px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.group h3 .count { color: var(--muted); font-weight: normal; font-size: 13px; }
.group h3 button { font-size: 13px; padding: 6px 10px; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #eee;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb input[type="checkbox"] {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--accent);
}
.thumb.selected { outline: 3px solid var(--accent); outline-offset: -3px; }

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

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  padding: 0;
  line-height: 1;
}
.lightbox-delete {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  align-items: center;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 14px;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 500;
}
.tab.active {
  background: #eef2ff;
  color: var(--accent);
  border-color: #c7d2fe;
}

/* ---------- Admin: create code form ---------- */
.create-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.create-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.create-form input {
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafaf7;
}
.create-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.new-code-result {
  margin-top: 16px;
  padding: 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
}
.code-display {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}
.code-display code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  letter-spacing: 0.1em;
  text-align: center;
  user-select: all;
}

/* ---------- Admin: codes table ---------- */
.codes-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.codes-table th, .codes-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
.codes-table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.codes-table tr.expired td { color: var(--muted); }
.codes-table .badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

/* ---------- Admin view: single column layout ---------- */
@media (min-width: 900px) {
  .admin-view { grid-template-columns: 1fr 1fr; }
}
