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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #f5f5f5;
  color: #333;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 12px 40px;
}

header {
  padding: 16px 0 12px;
  border-bottom: 1px solid #ddd;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 { font-size: 1.3rem; }
header h1 a { color: inherit; text-decoration: none; }

a { color: #2563eb; }

button, .btn {
  background: #2563eb;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:active, .btn:active { opacity: 0.8; }
button.secondary { background: #6b7280; }
button.danger { background: #dc2626; }
button.small { padding: 4px 10px; font-size: 0.8rem; }

/* Filter bar */
#filter-bar {
  background: white;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 120px;
}

.filter-group label {
  font-size: 0.75rem;
  color: #666;
  text-transform: capitalize;
}

.filter-group select {
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
  background: white;
}

#filter-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

#filter-actions button { padding: 4px 12px; font-size: 0.8rem; background: #6b7280; }
#result-count { font-size: 0.85rem; color: #666; }

/* Items grid */
#items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.item-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: box-shadow 0.15s;
}

.item-card:active { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }

.item-thumb { height: 160px; overflow: hidden; background: #eee; }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.no-photo { height: 100%; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 0.85rem; }

.item-info { padding: 10px; }
.item-fields { display: flex; flex-direction: column; gap: 2px; }
.item-fields .field { font-size: 0.85rem; }
.item-fields .field strong { color: #666; }
.item-qr { font-size: 0.75rem; color: #999; margin-top: 6px; font-family: monospace; word-break: break-all; }

/* Pagination */
#pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 16px;
}

#pagination button { background: #e5e7eb; color: #333; padding: 6px 12px; }
#pagination button.active { background: #2563eb; color: white; }

/* Item detail */
.back-link {
  display: inline-block;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.edit-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.85rem;
  color: #2563eb;
}

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.photo-gallery img, .item-photo {
  width: 100%;
  border-radius: 6px;
  cursor: pointer;
}

.field-table {
  width: 100%;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.field-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
}

.field-table .field-key {
  font-weight: 600;
  color: #666;
  width: 30%;
  text-transform: capitalize;
}

.item-meta {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: #999;
}

.empty { text-align: center; padding: 40px; color: #999; }

/* Admin styles */
.admin-header {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-header a { font-size: 0.85rem; }

#login-form {
  max-width: 300px;
  margin: 60px auto;
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#login-form h2 { margin-bottom: 16px; font-size: 1.1rem; }
#login-form input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  margin-bottom: 10px;
}

.admin-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.admin-nav button.active { background: #1d4ed8; }

/* Scanner */
#scanner-container {
  max-width: 400px;
  margin: 0 auto;
}

#scanner-container video {
  width: 100%;
  border-radius: 8px;
}

#qr-reader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

/* Item form */
.item-form {
  background: white;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 4px;
  text-transform: capitalize;
}

/* Private field indicators */
.private-badge {
  display: inline-block;
  font-size: 0.65rem;
  color: #92400e;
  background: #fef3c7;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 6px;
  text-transform: none;
  vertical-align: middle;
  font-weight: 500;
}

.private-field-summary {
  color: #92400e;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.field-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.field-row .form-group { flex: 1; }

.photo-upload {
  margin-top: 16px;
}

.photo-upload input[type="file"] {
  display: none;
}

.photo-upload .photo-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.photo-preview .photo-thumb {
  position: relative;
  width: 80px;
  height: 80px;
}

.photo-preview .photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.photo-preview .photo-thumb .delete-photo {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #dc2626;
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

/* Datalist / autocomplete styling */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 150px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.autocomplete-list div {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

.autocomplete-list div:hover, .autocomplete-list div.selected {
  background: #e5e7eb;
}

.field-manager {
  background: white;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 16px;
}

.field-manager h3 { margin-bottom: 8px; font-size: 0.95rem; }

.field-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field-tag {
  background: #e5e7eb;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Field cards in field management */
.field-card {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 8px;
}

.field-card-header {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-card-header:hover { background: #f0f1f3; border-radius: 8px; }

.field-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: capitalize;
}

.field-card-body {
  padding: 0 12px 12px;
  border-top: 1px solid #e5e7eb;
}

/* Option chips in field management */
.option-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.option-chip {
  background: #dbeafe;
  color: #1e40af;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.option-chip-x {
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.6;
}

.option-chip-x:hover { opacity: 1; }

/* Option chips in item form */
.form-option-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.form-option-chip {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.form-option-chip:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}

.form-option-chip.active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.form-option-chip.active .form-option-chip-x { color: rgba(255,255,255,0.7); }
.form-option-chip.active .form-option-chip-x:hover { color: white; }

.form-option-chip-x {
  font-size: 0.9rem;
  line-height: 1;
  margin-left: 2px;
  color: #9ca3af;
  cursor: pointer;
}

.form-option-chip-x:hover { color: #dc2626; }

.form-option-add {
  background: white;
  color: #2563eb;
  border-style: dashed;
  font-weight: bold;
  font-size: 0.9rem;
  padding: 2px 8px;
}

.form-option-add:hover {
  background: #eff6ff;
  border-color: #2563eb;
}

/* Sticky dictation controls */
#stt-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  background: white;
  padding: 8px 0;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show { opacity: 1; }

.admin-item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-item-row {
  background: white;
  padding: 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.admin-item-row .item-summary {
  font-size: 0.9rem;
}

.admin-item-row .item-summary .qr {
  font-family: monospace;
  font-size: 0.8rem;
  color: #999;
}

/* QR code displays */
.qr-code-display {
  margin-top: 10px;
  text-align: center;
}

.qr-code-display canvas {
  border-radius: 6px;
  background: white;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.admin-item-qr {
  flex-shrink: 0;
  border-radius: 4px;
}

.item-checkbox {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #2563eb;
}

.admin-item-row {
  gap: 10px;
}

/* Speech-to-text controls */
@keyframes stt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#stt-stop-btn {
  animation: stt-pulse 1.5s ease-in-out infinite;
}

/* Venmo overlay */
#venmo-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.venmo-overlay-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.venmo-link {
  display: inline-block;
  background: #008CFF;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.venmo-link:active {
  opacity: 0.8;
}

/* Sold items in admin list */
.admin-item-row.sold-row {
  opacity: 0.6;
}

.sold-badge {
  background: #dc2626;
  color: white;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Photo lightbox */
#photo-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 20px;
}

#photo-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
