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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
}

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

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

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

h1 { font-size: 1.4rem; margin-bottom: 16px; }
h2 { font-size: 1.15rem; margin-bottom: 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; color: var(--text-muted); }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-muted);
}

input[type="url"],
input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 12px;
  background: var(--card-bg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { background: #93c5fd; cursor: not-allowed; }
.btn.small { padding: 6px 12px; font-size: 0.8rem; background: var(--border); color: var(--text); }
.btn.small:hover { background: #cbd5e1; }
.btn.full-width { width: 100%; margin-top: 16px; }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }
.status { color: var(--text-muted); font-size: 0.85rem; margin-top: 8px; }

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.top-bar h1 { margin-bottom: 0; }

/* Scanner */
#scanner-region {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  background: #000;
  min-height: 200px;
}

.manual-input {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.manual-input input { flex: 1; margin-bottom: 0; }

/* Product card */
.prod-img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.meta { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 4px; }
.desc {
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 12px;
  line-height: 1.4;
}

.badge {
  display: block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  background: #dcfce7;
  color: var(--success);
  margin-bottom: 10px;
  margin-top: 10px;
  text-align: center;
}

/* Chips */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.chip {
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  border: 2px solid var(--border);
  background: var(--card-bg);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover { border-color: var(--primary); }
.chip.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Search results */
.search-results {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  margin-bottom: 8px;
}
.search-results li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: #f1f5f9; }

/* Selected tags */
.selected-tag-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
  margin-top: 10px;
  border: 1px solid lightgray;
  padding: 6px;
  border-radius: 6px;
}

.selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  background: #e0e7ff;
  color: var(--primary-dark);
  font-weight: 600;
}
.selected-tag .remove {
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  margin-left: 2px;
}

/* Product select list */
#product-select-list {
  list-style: none;
}
#product-select-list li {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--card-bg);
}
#product-select-list li:hover { border-color: var(--primary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--radius);
  background: #1e293b;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 9999;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* Quantity */
.quantity-section {
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.quantity-section h3 {
  margin: 0;
  white-space: nowrap;
}
.quantity-section input[type="number"] {
  width: 100px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--card-bg);
  color: var(--text);
  text-align: center;
  margin-bottom: 0;
  -moz-appearance: textfield;
}
.quantity-section input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.quantity-section input[type="number"]::-webkit-inner-spin-button,
.quantity-section input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* AI skip notice */
#ai-skip-notice {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#ai-skip-notice p { margin: 0; }

/* AI skip notice buttons */
.ai-skip-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* LLM fallback button */
.btn-llm {
  background: #f59e0b;
  color: #fff;
  margin-bottom: 12px;
}
.btn-llm:hover {
  background: #d97706;
}

/* Product screen image uploads */
#prod-img-upload-section { margin-bottom: 12px; }
#prod-img-upload-section .form-group { margin-bottom: 10px; }

/* Not-found actions */
.not-found-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.not-found-actions .btn { flex: 1; }

/* Create form */
.create-form { margin-top: 12px; }
.create-form .form-group { margin-bottom: 12px; position: relative; }

.create-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--card-bg);
  resize: vertical;
}

.create-form input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--card-bg);
}

.create-form input[type="file"] {
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.form-row .form-group { margin-bottom: 0; }

/* Autocomplete */
.autocomplete-wrapper { position: relative; }
.autocomplete-results {
  list-style: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  margin-top: -10px;
}
.autocomplete-results li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.autocomplete-results li:last-child { border-bottom: none; }
.autocomplete-results li:hover { background: #f1f5f9; }

/* Image preview */
.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.image-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Duplicate warning */
.duplicate-warning {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.duplicate-warning .dup-title { font-weight: 600; margin-bottom: 8px; }
.duplicate-warning .dup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #fcd34d;
  gap: 8px;
}
.duplicate-warning .dup-item:last-child { border-bottom: none; }
.duplicate-warning .dup-info { flex: 1; font-size: 0.85rem; }
.duplicate-warning .dup-actions { display: flex; gap: 6px; flex-shrink: 0; }
.duplicate-warning .btn-dismiss {
  margin-top: 8px;
  width: 100%;
}

/* Login form */
.login-form { margin-bottom: 16px; }

/* Settings toggle link */
.settings-toggle {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 16px;
  text-decoration: underline;
  cursor: pointer;
}

/* Collapsible settings */
.collapsible-settings {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}

/* Logout button */
.btn-logout {
  background: var(--danger) !important;
  color: #fff !important;
}
.btn-logout:hover { background: #b91c1c !important; }

.top-bar-buttons { display: flex; gap: 6px; }

/* AI loading */
#ai-loading p {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-style: italic;
}
