:root {
  --color-primary: #ffce00;
  --color-primary-dark: #f5c400;
  --color-text: #1a1a1a;
  --color-text-light: #666;
  --color-bg: #f5f5f5;
  --color-white: #ffffff;
  --color-danger: #e53935;
  --color-border: #e0e0e0;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  text-decoration: none;
  color: inherit;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
  flex: 1;
}

/* ---------- Navbar ---------- */
.navbar {
  background: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.3rem;
}

.logo-img {
  height: 46px;
  width: auto;
  display: block;
}

.logo {
  font-size: 1.6rem;
}

.brand-name {
  background: var(--color-text);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 6px;
}

nav ul {
  display: flex;
  gap: 20px;
  list-style: none;
}

nav ul li a {
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.2s;
}

nav ul li a:hover, nav ul li a.active {
  background: rgba(255, 255, 255, 0.3);
}

.logout-link {
  color: var(--color-danger);
  cursor: pointer;
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}

.hero h1 {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.hero p {
  color: var(--color-text-light);
  font-size: 1.1rem;
}

.search-box {
  position: relative;
  max-width: 520px;
  margin: 24px auto 0;
}

.search-box .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  opacity: 0.6;
  pointer-events: none;
}

#buscador {
  width: 100%;
  padding: 14px 16px 14px 42px;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: 50px;
  background: var(--color-white);
  color: var(--color-text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#buscador:focus {
  outline: none;
  border-color: var(--color-primary-dark);
  box-shadow: 0 0 0 3px rgba(245, 196, 0, 0.25);
}

/* ---------- Grid de productos ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 24px;
  padding-bottom: 48px;
}

.product-card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.product-image-wrapper {
  background: var(--color-white);
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

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

.product-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-title {
  font-size: 0.95rem;
  color: var(--color-text);
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
}

.product-price {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}

.product-price small {
  font-size: 0.8rem;
  color: var(--color-text-light);
  font-weight: 400;
  margin-left: 4px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary:hover {
  background: #333;
}

.btn-buy {
  background: var(--color-primary);
  color: var(--color-text);
  font-weight: 700;
}

.btn-buy:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: #d5d5d5;
}

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

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

.btn-block {
  width: 100%;
}

.loading-spinner {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px;
  color: var(--color-text-light);
}

/* ---------- Footer ---------- */
.footer {
  background: var(--color-text);
  color: #aaa;
  text-align: center;
  padding: 20px;
  font-size: 0.9rem;
  margin-top: auto;
}

/* ---------- Auth ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ffce00 0%, #f5a623 100%);
  padding: 20px;
}

.auth-card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-header h2 {
  font-size: 1.4rem;
  margin: 8px 0 4px;
}

.auth-header p {
  color: var(--color-text-light);
  font-size: 0.95rem;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
}

.auth-footer a {
  color: var(--color-text);
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* ---------- Formularios ---------- */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary-dark);
}

.error-message {
  background: #fdecea;
  color: var(--color-danger);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-label input {
  width: auto;
}

.ml-connection {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.ml-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
}

.ml-status-badge.connected {
  background: #e8f5e9;
  color: #2e7d32;
}

.ml-status-badge.not-connected {
  background: #fff3e0;
  color: #e65100;
}

.ml-status-badge .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.ml-hint {
  width: 100%;
  color: var(--color-text-light);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* ---------- Panel admin ---------- */
.panel-section {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-top: 32px;
}

.panel-title {
  font-size: 1.3rem;
  margin-bottom: 20px;
}

.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.search-bar input {
  flex: 1;
  padding: 12px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--color-primary-dark);
}

.search-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  padding-bottom: 0;
}

.search-results-info {
  color: var(--color-text-light);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.search-result-badge {
  position: relative;
  top: -8px;
  display: inline-block;
  font-size: 0.7rem;
  background: var(--color-primary);
  color: var(--color-text);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.btn-save {
  margin-top: auto;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.saved-item {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--color-bg);
  border-radius: 8px;
  padding: 12px;
}

.saved-item img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--color-white);
  padding: 4px;
}

.saved-item-info {
  flex: 1;
  min-width: 0;
}

.saved-item-info h4 {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-item-info .saved-price {
  font-weight: 700;
  font-size: 1.05rem;
}

.saved-item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.empty-state {
  color: var(--color-text-light);
  text-align: center;
  padding: 32px;
  border: 2px dashed var(--color-border);
  border-radius: 8px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 18px;
  font-size: 1.8rem;
  color: var(--color-text-light);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--color-text);
}

.modal-content h3 {
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 1.7rem;
  }

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

  .saved-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .saved-item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .navbar-container {
    flex-direction: column;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
  }

  .product-image-wrapper {
    height: 160px;
  }

  .product-price {
    font-size: 1.25rem;
  }

  .panel-section {
    padding: 20px;
  }
}
