:root {
  --bg: #ffffff;
  --text: #111827; /* gray-900 */
  --muted: #6b7280; /* gray-500 */
  --primary: #2563eb; /* blue-600 */
  --primary-contrast: #ffffff;
  --surface: #f3f4f6; /* gray-100 */
  --border: #e5e7eb; /* gray-200 */
  --success: #16a34a; /* green-600 */
  --warning: #f59e0b; /* amber-500 */
}

* {
  box-sizing: border-box;
}
html,
body {
  min-height: 100%;
}
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Noto Sans, Ubuntu, Cantarell, Helvetica Neue, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
}
.title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.1;
}

.container {
  padding: 16px;
  padding-bottom: 17vh;
}

.search {
  position: sticky;
  top: calc(52px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding-bottom: 10px;
  margin-bottom: 10px;
  z-index: 5;
}
.search input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stat-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.stat-number {
  font-weight: 700;
  font-size: 18px;
}
.stat-label {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
}
.tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.card {
  position: relative;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 12px;
  border-radius: 12px;
  overflow: hidden;
  min-height: 110px;
}
.card:active {
  transform: scale(0.98);
}
.card-title {
  font-weight: 600;
  font-size: 14px;
  z-index: 2;
  position: relative;
}
.card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.card.has-photo {
  background: #ecfdf5; /* green-50 */
  border-color: #86efac; /* green-300 */
}
.card.has-photo .card-badge {
  background: #dcfce7;
  border-color: #86efac;
  color: var(--success);
}

.thumb-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.25;
}
.thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 60%,
    rgba(0, 0, 0, 0.35)
  );
}
.card .card-title {
  color: var(--text);
}
.card.has-photo .card-title {
  color: #064e3b;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}
.btn-secondary {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.gallery-actions {
  margin-bottom: 12px;
}
.grid-gallery .card {
  min-height: 110px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1000;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}
.modal-content {
  position: relative;
  width: min(560px, calc(100vw - 24px));
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  padding: 14px;
}
.modal-title {
  margin: 0 0 10px;
  font-size: 18px;
}
.modal-body {
  max-height: 85vh;
  overflow: auto;
}
.modal-preview {
  width: 100%;
  /* Allow the image to define its own aspect ratio to fit the screen */
  aspect-ratio: auto;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  /* Do not hide overflow in modal so full image can be viewed */
  overflow: visible;
  position: relative;
}
.modal-preview::before {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 600;
  background: repeating-linear-gradient(
    45deg,
    #f9fafb,
    #f9fafb 14px,
    #f3f4f6 14px,
    #f3f4f6 28px
  );
}
.modal-preview.has-image::before {
  content: "";
  background: transparent;
}
/* Ensure the image in modal fits within the viewport without cropping */
.modal-preview .thumb {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 0;
}
.modal-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.modal .error {
  color: #b00020;
  margin-top: 8px;
}

.thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}
.thumb-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}
.thumb-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(17, 24, 39, 0.75);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 6px 8px;
  font-size: 12px;
}

.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;
}

/* Prevent background scroll when modal open */
body.no-scroll {
  overflow: hidden;
  height: 100vh;
}

/* Desktop refinements */
@media (min-width: 1024px) {
  .title {
    font-size: 18px;
  }
  .stat-number {
    font-size: 20px;
  }
}
