:root {
  --fg: #1a1a1a;
  --muted: #6b7280;
  --bg: #fafafa;
  --card: #fff;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-fg: #fff;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.site-header .brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--fg);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  margin-left: -0.5rem;
  border-radius: 6px;
}
.site-header .brand:hover {
  background: var(--bg);
  text-decoration: none;
  color: var(--accent);
}
.site-header nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.site-header form.inline { margin: 0; display: inline; }
.site-header .short { display: none; }

@media (max-width: 640px) {
  .site-header { padding: 0.6rem 0.9rem; gap: 0.5rem; }
  .site-header .brand { font-size: 1.05rem; }
  .site-header nav { gap: 0.5rem; font-size: 0.9rem; }
  .site-header .full,
  .site-header .email-tag { display: none; }
  .site-header .short { display: inline; }
}
.linkish {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0;
}
.linkish:hover { text-decoration: underline; }

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { margin-top: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error {
  background: #fee2e2; color: #991b1b;
  padding: 0.6rem 0.8rem; border-radius: 6px;
}

.form { display: flex; flex-direction: column; gap: 1rem; max-width: 540px; }
.form label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 500; }
.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="search"],
.form select,
.form textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.form textarea { resize: vertical; }

button, .button {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid var(--accent);
  padding: 0.7rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  display: inline-block;
  text-align: center;
}
button:hover, .button:hover { filter: brightness(0.95); text-decoration: none; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.secondary {
  background: #fff;
  color: var(--accent);
}
.actions { display: flex; gap: 0.75rem; align-items: center; }
.actions.stacked { flex-direction: column; align-items: stretch; }
.actions.stacked .cancel { text-align: center; padding-top: 0.25rem; }
.cancel { color: var(--muted); }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.flash.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.search {
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.search input[type="search"] { flex: 1; min-width: 200px; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.search select { padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; }
.search .clear { color: var(--muted); margin-left: 0.25rem; }

.grid {
  list-style: none; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.1s;
}
.card:hover { transform: translateY(-2px); }
.card a { color: var(--fg); display: block; }
.card a:hover { text-decoration: none; }
.card img { width: 100%; height: 240px; object-fit: contain; display: block; background: #f3f4f6; }
.card .no-image {
  width: 100%; height: 240px; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; color: var(--muted); font-size: 0.9rem;
}
.card-body { padding: 0.75rem 1rem 1rem; }
.card-body h3 { margin: 0.4rem 0; font-size: 1.05rem; }
.card-body p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.tag {
  display: inline-block;
  font-size: 0.75rem;
  background: #eef2ff;
  color: #3730a3;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.item-detail {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
  align-items: start;
}
.item-detail img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.item-detail h1 { margin: 0.5rem 0; }
.item-detail .description { white-space: pre-wrap; }

.current-image { display: flex; gap: 1rem; align-items: flex-start; }
.current-image img { max-width: 200px; border-radius: 6px; border: 1px solid var(--border); }
.inline-check { display: flex !important; flex-direction: row !important; align-items: center; gap: 0.4rem; font-weight: normal !important; }

/* Two-column layout for the edit page: large image on the left, fields on the right. */
.form.edit-layout {
  display: grid;
  grid-template-columns: minmax(280px, 480px) 1fr;
  gap: 2rem;
  max-width: 1100px;
  align-items: start;
}
.form.edit-layout .edit-image { display: flex; flex-direction: column; gap: 0.75rem; }
.form.edit-layout .edit-image img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f3f4f6;
}
.form.edit-layout .edit-image .no-image.large {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; color: var(--muted);
  border-radius: 8px; border: 1px solid var(--border);
}
.form.edit-layout .edit-fields { display: flex; flex-direction: column; gap: 1rem; }

/* Click-to-replace overlay on the image. */
.image-drop {
  position: relative;
  display: block;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f3f4f6;
}
.image-drop img,
.image-drop .no-image.large {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
}
.image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  background: rgba(15, 23, 42, 0.55);
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease-in-out;
  pointer-events: none;
}
.image-drop:hover .image-overlay,
.image-drop:focus-within .image-overlay {
  opacity: 1;
}
.image-overlay-text { font-weight: 600; font-size: 1rem; }
.image-overlay .small { color: rgba(255, 255, 255, 0.85); font-size: 0.8rem; }

.image-rotate-bar {
  display: flex;
  gap: 0.5rem;
}
.rotate-edit-btn {
  flex: 1;
  padding: 0.55rem 0.8rem;
  background: #fff;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.rotate-edit-btn:hover:not(:disabled) { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.rotate-edit-btn:disabled { opacity: 0.5; cursor: wait; }
.edit-image img.rotating { opacity: 0.5; }

.take-photo-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}
@media (max-width: 640px) {
  .take-photo-btn { display: inline-flex; }
}

/* Visually hide native file input but keep it focusable for keyboards. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

@media (max-width: 720px) {
  .form.edit-layout { grid-template-columns: 1fr; gap: 1rem; }
  /* On touch devices the overlay can't appear on hover — keep it dimly visible. */
  .image-overlay { opacity: 1; background: linear-gradient(0deg, rgba(15,23,42,0.65) 0%, rgba(15,23,42,0) 50%); justify-content: flex-end; padding-bottom: 0.75rem; }
}

@media (max-width: 640px) {
  .item-detail { grid-template-columns: 1fr; }
}

#scroll-sentinel {
  padding: 2rem 0;
  text-align: center;
}
.center { text-align: center; }
.stats { margin: 0 0 1rem; font-size: 0.95rem; }
.stats strong { color: var(--fg); }

/* Tag chips on item detail page */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0 0; }
.chip {
  display: inline-block;
  font-size: 0.8rem;
  background: #f3f4f6;
  color: var(--fg);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* Bulk upload picker */
#bulk-progress { margin-top: 1rem; max-width: 540px; }
#bulk-progress progress { width: 100%; height: 1.1rem; }
#bulk-preview:not(:empty) { padding: 0.4rem 0; }

/* Drafts annotation page */
.draft-filters {
  display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 1rem;
}
.draft-filters a {
  padding: 0.35rem 0.8rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--fg);
}
.draft-filters a:hover { text-decoration: none; background: var(--bg); }
.draft-filters a.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.drafts-bulk-bar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.75rem; margin-bottom: 1rem;
  position: sticky; top: 0; z-index: 5;
}
.drafts-bulk-bar select { padding: 0.45rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; font: inherit; }
.drafts-bulk-bar button { padding: 0.45rem 0.8rem; font-size: 0.9rem; }

.drafts-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.draft-row {
  display: grid;
  grid-template-columns: 28px 120px 1fr;
  gap: 0.75rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.75rem;
  align-items: start;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.draft-row.removing { opacity: 0; transform: translateX(20px); pointer-events: none; }
.draft-select { padding-top: 0.4rem; }
.draft-thumb { position: relative; width: 120px; }
.draft-thumb img {
  width: 120px;
  height: auto;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
  background: #f3f4f6;
  display: block;
  cursor: zoom-in;
}

#zoom-preview {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  pointer-events: none;
  padding: 2rem;
}
#zoom-preview[hidden] {
  display: none;
}
#zoom-preview img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}
.draft-thumb img.rotating { opacity: 0.5; }
.draft-thumb .no-image.small {
  width: 120px; height: 120px; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; color: var(--muted); font-size: 0.8rem; border-radius: 6px;
}
.rotate-bar {
  position: absolute;
  bottom: 4px; left: 4px; right: 4px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.rotate-btn {
  pointer-events: auto;
  width: 28px; height: 28px;
  padding: 0;
  background: rgba(15, 23, 42, 0.6);
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rotate-btn:hover:not(:disabled) { background: rgba(15, 23, 42, 0.85); }
.rotate-btn:disabled { opacity: 0.4; cursor: wait; }
.draft-form { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.draft-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem 0.75rem;
}
.draft-grid label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; font-weight: 500; }
.draft-grid label.span-2 { grid-column: 1 / -1; }
.draft-grid input[type="text"],
.draft-grid select,
.draft-grid textarea {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  width: 100%;
}
.draft-grid textarea { resize: vertical; }
.draft-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.draft-actions button { padding: 0.4rem 0.75rem; font-size: 0.9rem; }
.draft-actions .detect-btn { background: #fff; color: var(--accent); border-color: var(--accent); }
.draft-actions .detect-btn:disabled { opacity: 0.6; cursor: wait; }

.discard-link {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: lowercase;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
}
.discard-link:hover { color: var(--danger); text-decoration: underline; }
.discard-link:disabled { opacity: 0.5; cursor: wait; }
.save-status { font-size: 0.8rem; transition: opacity 0.3s; }
.save-status.saved { color: #166534; }
.save-status.error { color: var(--danger); }

@media (max-width: 720px) {
  .draft-row { grid-template-columns: 28px 1fr; }
  .draft-thumb { grid-column: 2; }
  .draft-form { grid-column: 1 / -1; }
  .draft-grid { grid-template-columns: 1fr; }
}
