/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --verde:    #00c853;
  --verde2:   #00e676;
  --azul:     #1565c0;
  --azul2:    #1976d2;
  --amarillo: #ffd600;
  --rojo:     #e53935;
  --naranja:  #ff6f00;
  --fondo:    #f0f4ff;
  --card:     #ffffff;
  --texto:    #1a1a2e;
  --gris:     #6b7280;
  --radio:    18px;
  --sombra:   0 4px 24px rgba(0,0,0,.12);
}

/* ── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, var(--azul) 0%, #6a1b9a 100%);
  color: #fff;
  padding: 20px 16px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
header::before {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Ccircle cx='30' cy='30' r='28'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.logo { font-size: 2.4rem; margin-bottom: 4px; }
header h1 { font-size: 1.7rem; font-weight: 900; letter-spacing: -0.5px; }
header p  { font-size: .95rem; opacity: .85; margin-top: 4px; }

/* ── Main layout ────────────────────────────────────────────────────────── */
main { max-width: 520px; margin: 0 auto; padding: 20px 16px 80px; }

/* ── Card base ──────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 22px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 1.05rem; font-weight: 800;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

/* ── Upload zone ────────────────────────────────────────────────────────── */
#upload-zone {
  border: 3px dashed #bbc8e6;
  border-radius: 16px;
  padding: 36px 16px;
  text-align: center;
  cursor: pointer;
  transition: all .25s;
  background: #f7f9ff;
  position: relative;
}
#upload-zone:hover, #upload-zone.dragover {
  border-color: var(--azul2);
  background: #e8f0fe;
  transform: scale(1.01);
}
#upload-zone .zone-icon  { font-size: 3.2rem; }
#upload-zone .zone-title { font-size: 1.1rem; font-weight: 800; margin: 8px 0 4px; color: var(--azul); }
#upload-zone .zone-sub   { font-size: .85rem; color: var(--gris); }
#file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

/* ── Camera buttons ─────────────────────────────────────────────────────── */
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1; padding: 13px 8px;
  border: none; border-radius: 12px;
  font-size: .95rem; font-weight: 800;
  cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(.96); }
.btn-camera { background: linear-gradient(135deg, var(--verde) 0%, var(--verde2) 100%); color: #fff; }
.btn-gallery { background: linear-gradient(135deg, var(--naranja) 0%, #ff8f00 100%); color: #fff; }
.btn-buscar {
  width: 100%; padding: 16px;
  font-size: 1.15rem; font-weight: 900;
  background: linear-gradient(135deg, var(--azul) 0%, #6a1b9a 100%);
  color: #fff; border-radius: 14px;
  box-shadow: 0 4px 16px rgba(21,101,192,.4);
}
.btn-buscar:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Preview image ──────────────────────────────────────────────────────── */
#preview-wrap {
  display: none;
  margin-top: 16px;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--sombra);
}
#preview-wrap img {
  width: 100%; display: block;
  max-height: 260px; object-fit: contain;
  background: #000;
}
#btn-clear {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,.55); color: #fff;
  border: none; border-radius: 50%;
  width: 34px; height: 34px; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Loader ─────────────────────────────────────────────────────────────── */
#loader {
  display: none;
  flex-direction: column; align-items: center; gap: 14px;
  padding: 30px 0;
}
.spinner {
  width: 56px; height: 56px;
  border: 5px solid #dde3f5;
  border-top-color: var(--azul);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 1rem; font-weight: 700; color: var(--azul); text-align: center; }
.loader-dots::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%,20%  { content: ''; }
  40%     { content: '.'; }
  60%     { content: '..'; }
  80%,100%{ content: '...'; }
}

/* ── Cromo info card ────────────────────────────────────────────────────── */
#cromo-info { display: none; }
.cromo-badge {
  background: linear-gradient(135deg, #1565c0 0%, #6a1b9a 100%);
  color: #fff; border-radius: 14px;
  padding: 16px 18px; margin-bottom: 16px;
}
.cromo-nombre { font-size: 1.45rem; font-weight: 900; }
.cromo-meta   { font-size: .85rem; opacity: .85; margin-top: 4px; }
.cromo-tag {
  display: inline-block;
  background: rgba(255,255,255,.18);
  border-radius: 20px; padding: 3px 10px;
  margin: 4px 4px 0 0; font-size: .8rem; font-weight: 700;
}
.confianza-alta   { background: var(--verde); }
.confianza-media  { background: var(--naranja); }
.confianza-baja   { background: var(--rojo); }

/* ── Stats precio ───────────────────────────────────────────────────────── */
#precios-stats { display: none; }
.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 18px;
}
.stat-box {
  background: var(--fondo);
  border-radius: 12px; padding: 14px 8px;
  text-align: center;
}
.stat-box .stat-label { font-size: .72rem; color: var(--gris); font-weight: 700; text-transform: uppercase; }
.stat-box .stat-val   { font-size: 1.3rem; font-weight: 900; margin-top: 4px; }
.stat-min  .stat-val { color: var(--verde); }
.stat-med  .stat-val { color: var(--azul2); }
.stat-max  .stat-val { color: var(--rojo); }

/* ── Anuncios list ──────────────────────────────────────────────────────── */
.anuncio-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--fondo); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
  text-decoration: none; color: inherit;
  transition: transform .15s, box-shadow .15s;
  border: 2px solid transparent;
}
.anuncio-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
  border-color: var(--azul2);
}
.anuncio-img {
  width: 58px; height: 58px; border-radius: 10px;
  object-fit: cover; flex-shrink: 0;
  background: #dde3f5;
}
.anuncio-img-placeholder {
  width: 58px; height: 58px; border-radius: 10px;
  background: linear-gradient(135deg, #dde3f5 0%, #c3d0f0 100%);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
}
.anuncio-body { flex: 1; min-width: 0; }
.anuncio-titulo {
  font-size: .9rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.anuncio-fuente-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.fuente-badge {
  font-size: .7rem; font-weight: 800; padding: 2px 8px;
  border-radius: 20px; color: #fff;
}
.fuente-Wallapop    { background: #13c1ac; }
.fuente-eBay        { background: #e53238; }
.fuente-Milanuncios { background: #ff6600; }
.anuncio-estado { font-size: .72rem; color: var(--gris); }
.anuncio-precio {
  font-size: 1.2rem; font-weight: 900;
  color: var(--azul); flex-shrink: 0;
}

/* ── Enlaces de búsqueda ────────────────────────────────────────────────── */
.enlace-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--fondo); border-radius: 14px;
  padding: 16px; margin-bottom: 10px;
  text-decoration: none; color: inherit;
  border: 2.5px solid transparent;
  transition: all .2s;
}
.enlace-item:hover, .enlace-item:active {
  border-color: var(--c, var(--azul2));
  background: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
}
.enlace-emoji { font-size: 2rem; flex-shrink: 0; }
.enlace-body  { flex: 1; min-width: 0; }
.enlace-titulo { font-size: 1rem; font-weight: 800; color: var(--c, var(--azul)); }
.enlace-desc   { font-size: .78rem; color: var(--gris); margin-top: 2px; }
.enlace-arrow  { font-size: 1.3rem; color: var(--c, var(--azul)); flex-shrink: 0; font-weight: 900; }

/* ── Sin resultados ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 24px 16px; color: var(--gris);
}
.empty-state .empty-icon { font-size: 2.5rem; }
.empty-state p { margin-top: 8px; font-size: .9rem; }

/* ── Error ──────────────────────────────────────────────────────────────── */
.error-box {
  background: #fde8e8; border: 2px solid #f5c6c6;
  border-radius: 12px; padding: 16px;
  color: var(--rojo); font-weight: 700;
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px;
}
.error-box .err-icon { font-size: 1.4rem; flex-shrink: 0; }

/* ── Historial ──────────────────────────────────────────────────────────── */
#historial-section { display: none; }
.historial-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid #edf0f9;
}
.historial-item:last-child { border-bottom: none; }
.hist-avatar {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--azul) 0%, #6a1b9a 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.hist-thumb {
  width: 44px; height: 44px;
  object-fit: cover; display: block;
  border-radius: 10px; flex-shrink: 0;
}
.hist-info { flex: 1; min-width: 0; }
.hist-nombre { font-weight: 800; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-album  { font-size: .75rem; color: var(--gris); }
.hist-precio { font-weight: 900; color: var(--azul); font-size: .95rem; }

/* ── Bottom nav ─────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-top: 1px solid #e5e9f5;
  display: flex; box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}
.nav-item {
  flex: 1; padding: 10px 4px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  font-size: .7rem; font-weight: 700; color: var(--gris);
  transition: color .2s;
}
.nav-item .nav-icon { font-size: 1.4rem; }
.nav-item.active { color: var(--azul); }

/* ── Tabs sections ──────────────────────────────────────────────────────── */
.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Toast ──────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1a1a2e; color: #fff;
  padding: 12px 22px; border-radius: 24px;
  font-size: .9rem; font-weight: 700;
  opacity: 0; transition: all .3s; pointer-events: none;
  white-space: nowrap; z-index: 999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive tweaks ──────────────────────────────────────────────────── */
@media (max-width: 380px) {
  header h1 { font-size: 1.4rem; }
  .cromo-nombre { font-size: 1.2rem; }
  .stats-grid { gap: 7px; }
  .stat-box .stat-val { font-size: 1.1rem; }
}
