*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: system-ui, sans-serif;
  background: #f0f0f0;
  color: #222;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.4rem; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  background: #222;
  color: #fff;
  text-decoration: none;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}

.btn:hover { background: #444; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn-ghost {
  background: transparent;
  color: #444;
  border: 1px solid #ccc;
}
.btn-ghost:hover { background: #f0f0f0; }

/* Gallery */
.photo-count {
  padding: 0.75rem 1.5rem 0;
  color: #888;
  font-size: 0.85rem;
}

.empty {
  text-align: center;
  padding: 4rem 1rem;
  color: #888;
  font-size: 1.1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  padding-bottom: 5rem; /* room for selection bar */
}

.card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  transition: box-shadow 0.15s;
}

.card.selected {
  box-shadow: 0 0 0 2px #222, 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Checkbox overlay */
.card-select {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 2;
  cursor: pointer;
}

.card-select input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid #ccc;
  border-radius: 4px;
  transition: background 0.1s, border-color 0.1s;
}

.card-select input:checked + .checkbox-mark {
  background: #222;
  border-color: #222;
}

.card-select input:checked + .checkbox-mark::after {
  content: '';
  display: block;
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Thumbnail — clickable */
.card-thumb {
  cursor: pointer;
}

.card-thumb:hover img,
.card-thumb:hover .placeholder {
  opacity: 0.85;
}

.card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}

.placeholder {
  width: 100%;
  height: 200px;
  background: #e8e8e8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 0.85rem;
  transition: opacity 0.15s;
}

.card-footer {
  display: flex;
  align-items: center;
  padding: 0.65rem 0.8rem;
  gap: 0.4rem;
}

.filename {
  font-size: 0.8rem;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* Selection bar */
.selection-bar {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #222;
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 20;
  white-space: nowrap;
}

.selection-bar #selection-count {
  font-size: 0.9rem;
  font-weight: 600;
}

.selection-bar .btn {
  background: rgba(255, 255, 255, 0.15);
}
.selection-bar .btn:hover { background: rgba(255, 255, 255, 0.25); }

.selection-bar #download-selected-btn {
  background: #fff;
  color: #222;
}
.selection-bar #download-selected-btn:hover { background: #e8e8e8; }

/* Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.lightbox-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.85);
}

.lightbox-box {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-close {
  position: absolute;
  top: -2.5rem;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  opacity: 0.8;
}
.lightbox-close:hover { opacity: 1; }

.lightbox-media {
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox-img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}

.lightbox-no-preview {
  color: #ccc;
  font-size: 1rem;
  padding: 3rem 2rem;
}

.lightbox-name {
  color: #ccc;
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-arrow {
  position: relative;
  z-index: 2;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
  align-self: center;
}
.lightbox-arrow:hover { background: rgba(255, 255, 255, 0.3); }

/* Upload form */
form {
  max-width: 480px;
  margin: 2rem auto;
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.form-group { margin-bottom: 1.5rem; }

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="file"] { width: 100%; }

.upload-hint {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: #888;
}

/* Alerts */
.alert {
  max-width: 480px;
  margin: 1rem auto;
  padding: 1rem 1.25rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.alert ul { margin-top: 0.5rem; padding-left: 1.25rem; }
.alert li { margin-top: 0.25rem; }
