:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --accent: #2b6cb0;
  --muted: #666;
  --border: #e6e9ef;
}

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

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: #111;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #111;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  color: #111;
  text-decoration: none;
  transition: background 0.2s;
}

.logout-btn:hover {
  background: #f0f6ff;
}

.toolbar-wrapper {
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  position: relative;
}

.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  color: #111;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 1;
}

.toolbar .toolbar-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: #111;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.toolbar .toolbar-item:hover {
  background: #f0f6ff;
}

.toolbar .toolbar-item.active {
  background: #e8f2ff;
  border-color: #b7d1f3;
  color: #1e5394;
}

.toolbar .toolbar-item-primary {
  background: #fff3cd;
  border-color: #ffe69c;
  font-weight: 600;
}

.toolbar .toolbar-item-primary:hover:not(:disabled) {
  background: #ffe8a1;
}

.toolbar .toolbar-item:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.merge-btn {
  background: var(--accent) !important;
  color: white !important;
  border: none !important;
  font-weight: 600 !important;
  animation: slideIn 0.2s ease-out;
  margin: 16px 0;
  padding: 12px 24px;
  border-radius: 6px;
  display: block;
  width: auto;
}

.merge-btn:hover {
  background: #1e5394 !important;
  opacity: 0.9;
}

#mergeButtonContainer,
#mergeButtonContainerBottom {
  margin: 12px 0;
}

@keyframes slideIn {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.content {
  padding: 16px;
}

/* Mobile Responsive */
@media (max-width: 640px) {
  .menu-toggle {
    display: block;
  }

  .toolbar {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 12px;
    gap: 8px;
    display: none;
    width: 100%;
  }

  .toolbar.active {
    display: flex;
  }

  .toolbar .toolbar-item {
    width: 100%;
    text-align: left;
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand {
    font-size: 1rem;
  }
}

/* Products Section Styles */
.products-section {
  padding: 20px;
}

.products-search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  background: var(--card);
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.products-search-bar input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.products-search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.1);
}

.products-search-bar button {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}

.products-search-bar button:hover {
  background: #1e4d7a;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.product-card {
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.product-card.selected {
  border-color: var(--accent);
  background: #f0f6ff;
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.1);
}

.product-card.merged-product {
  border-color: #4caf50;
  background: #e8f5e9;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.product-card.merged-product .status-badge {
  background: #4caf50;
  color: white;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
}

.product-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  z-index: 10;
  accent-color: var(--accent);
}

.product-image {
  width: 100%;
  height: 160px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.product-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.product-info {
  padding: 12px;
}

.product-sku {
  font-weight: 600;
  font-size: 0.875rem;
  color: #111;
  margin-bottom: 4px;
}

.product-name {
  font-size: 0.875rem;
  color: #333;
  margin-bottom: 6px;
  min-height: 2.1em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-price {
  font-weight: 700;
  font-size: 0.95rem;
  color: #2b6cb0;
  margin-bottom: 4px;
}

.product-supplier {
  font-size: 0.75rem;
  color: #666;
}

.product-supplier-with-price {
  font-size: 0.75rem;
  color: #4caf50;
  font-weight: 600;
}

.product-sku {
  font-size: 11px;
  color: #999;
  margin-bottom: 4px;
  font-family: monospace;
}

.product-name {
  font-size: 13px;
  font-weight: 500;
  color: #111;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-supplier {
  font-size: 11px;
  color: #666;
  background: #f5f5f5;
  padding: 3px 6px;
  border-radius: 3px;
  display: inline-block;
}

.product-card.merged .product-supplier {
  background: #4caf50;
  color: white;
}

.status-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  background: #4caf50;
  color: white;
}

.loading, .error, .no-results {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  grid-column: 1 / -1;
}

.error {
  color: #c62828;
  background: #ffebee;
  border-radius: 6px;
}

/* Message Toasts */
.message-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 16px 20px;
  border-radius: 6px;
  font-weight: 500;
  z-index: 999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease;
}

.message-toast.success {
  background: #e8f5e9;
  color: #2e7d32;
}

.message-toast.error {
  background: #ffebee;
  color: #c62828;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.message-toast.error {
  animation: slideIn 0.3s ease-out, slideOut 0.3s ease-in 15s forwards;
}

.message-toast.success {
  animation: slideIn 0.3s ease-out, slideOut 0.3s ease-in 6s forwards;
}

/* Modal styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  min-width: 400px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-content h2 {
  margin: 0;
  color: #333;
  font-size: 1.125rem;
}

.close-modal-btn {
  background: transparent;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.close-modal-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 12px 0;
}

.checklist-item {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  margin: 4px 0;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.checklist-item.pending {
  background-color: #e8f4f8;
  color: #0066cc;
}

.checklist-item.running {
  background-color: #fffacd;
  color: #cc9900;
}

.checklist-item.completed {
  background-color: #d4edda;
  color: #155724;
}

.checklist-item.error {
  background-color: #f8d7da;
  color: #721c24;
}

.checklist-icon {
  margin-right: 8px;
  font-weight: bold;
  min-width: 16px;
  display: inline-block;
  font-size: 0.875rem;
}

.checklist-item.running .checklist-icon {
  animation: spin 1s linear infinite;
}

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

.status-text {
  margin-top: 12px;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 4px;
  font-size: 13px;
  font-family: monospace;
  color: #666;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Pagination styling */
.pagination-info {
  text-align: center;
  padding: 15px;
  color: #666;
  font-size: 14px;
  font-weight: 500;
}

.pagination-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 15px;
  flex-wrap: wrap;
}

.pagination-btn {
  background: white;
  border: 1px solid #ddd;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  color: #333;
  min-width: 40px;
  text-align: center;
}

.pagination-btn:hover:not(.active) {
  background: #f0f6ff;
  border-color: #2b6cb0;
  color: #2b6cb0;
}

.pagination-btn.active {
  background: #2b6cb0;
  color: white;
  border-color: #2b6cb0;
  font-weight: 600;
}

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

@media (max-width: 640px) {
  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .products-search-bar {
    flex-direction: column;
  }

  .products-search-bar button {
    width: 100%;
  }

}

/* Merge Modal Styling */
.merge-modal {
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

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

.merge-header h2 {
  margin: 0;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  color: #333;
}

.merge-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.products-comparison {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  grid-column: 1 / 2;
}

.product-comparison-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  text-align: center;
}

.comp-image {
  width: 100%;
  height: 120px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.comp-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.comp-info {
  padding: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.merge-selections {
  display: flex;
  flex-direction: column;
  gap: 16px;
  grid-column: 2 / 3;
}

.selection-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selection-group label {
  font-weight: 600;
  color: #111;
}

.selection-group select,
.selection-group input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

#imagesCheckboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.image-checkbox {
  position: relative;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 1;
}

.image-checkbox input {
  display: none;
}

.image-checkbox img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.2s;
}

.image-checkbox input:checked + img {
  opacity: 0.6;
  border: 2px solid var(--accent);
}

.stock-summary {
  max-height: 150px;
  overflow-y: auto;
}

.stock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.stock-table th {
  background: #f5f5f5;
  padding: 6px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--border);
}

.stock-table td {
  padding: 6px;
  border: 1px solid var(--border);
}

.merge-preview {
  background: #f9f9f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
}

.merge-preview h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
}

.preview-item {
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.preview-item strong {
  display: block;
  color: #666;
  margin-bottom: 2px;
}

.merge-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.cancel-btn,
.submit-btn {
  padding: 10px 20px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
}

.cancel-btn {
  background: white;
  color: #111;
  border: 1px solid var(--border);
}

.cancel-btn:hover {
  background: #f0f0f0;
}

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

.submit-btn:hover {
  background: #1e5394;
}
