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

:root {
  --primary: #1a1a2e;
  --accent: #e94560;
  --accent-hover: #d63851;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --error: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* PIN Page */
.pin-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}

.pin-page h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.pin-page p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.pin-inputs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.pin-inputs input {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
  background: var(--card);
}

.pin-inputs input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 160px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 16px;
  font-size: 13px;
  min-width: auto;
}

.error-message {
  color: var(--error);
  font-size: 14px;
  margin-top: 12px;
  min-height: 20px;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Form Page */
.form-page {
  display: none;
}

.form-page.active {
  display: block;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.form-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 20px;
  background: var(--primary);
  color: white;
}

.save-status {
  font-size: 13px;
  color: var(--text-secondary);
  transition: opacity 0.3s;
}

.save-status.saving {
  color: var(--accent);
}

.save-status.saved {
  color: var(--success);
}

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

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card);
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

/* Toggle switch */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle.active {
  background: var(--accent);
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle.active::after {
  transform: translateX(20px);
}

/* Tags input */
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  min-height: 44px;
  align-items: center;
  cursor: text;
}

.tags-container:focus-within {
  border-color: var(--accent);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 13px;
  background: var(--bg);
  border-radius: 16px;
  color: var(--text);
}

.tag-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

.tags-input {
  border: none;
  outline: none;
  font-size: 14px;
  flex: 1;
  min-width: 80px;
  padding: 4px 0;
  background: transparent;
}

/* Options list (Versus) */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.option-row input {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--card);
}

.option-row input:focus {
  border-color: var(--accent);
}

.option-row .remove-option {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.option-row .remove-option:hover {
  background: var(--bg);
  color: var(--error);
}

.add-option-btn {
  align-self: flex-start;
  padding: 8px 16px;
  font-size: 14px;
  border: 1px dashed var(--border);
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.add-option-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Image Gallery */
.image-gallery {
  margin-bottom: 20px;
}

.image-gallery label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.image-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  cursor: grab;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.image-item:active {
  cursor: grabbing;
}

.image-item.dragging {
  opacity: 0.5;
  border-color: var(--accent);
}

.image-item.drag-over {
  border-color: var(--accent);
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-item .delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(0,0,0,0.6);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.image-item:hover .delete-btn {
  opacity: 1;
}

.image-item .order-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.6);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-add {
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
  color: var(--text-secondary);
  gap: 4px;
}

.image-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.image-add .plus-icon {
  font-size: 28px;
  line-height: 1;
}

.image-add span {
  font-size: 12px;
}

.image-uploading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-uploading .spinner {
  border-color: rgba(0,0,0,0.15);
  border-top-color: var(--accent);
  margin: 0;
}

/* Submit area */
.submit-area {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Responsive */
@media (max-width: 480px) {
  .container {
    padding: 16px 12px;
  }

  .pin-inputs input {
    width: 42px;
    height: 50px;
    font-size: 20px;
  }

  .image-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  gap: 16px;
}

.loading-overlay .spinner {
  width: 32px;
  height: 32px;
  border-color: rgba(0,0,0,0.1);
  border-top-color: var(--accent);
  margin: 0;
}

.loading-overlay p {
  color: var(--text-secondary);
  font-size: 15px;
}

.hidden {
  display: none !important;
}

/* Category dropdown */
.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Read-only field */
.readonly-field {
  padding: 10px 14px;
  font-size: 15px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
