/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --bg4: #252d3d;
  --border: #2a3348;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;
  --accent: #3b82f6;
  --accent2: #2563eb;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --purple: #8b5cf6;
  --radius: 10px;
  --nav-h: 60px;
}

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

/* ─── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  height: var(--nav-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.navbar-brand { display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.logo { font-size: 1.4rem; }
.brand-name { font-weight: 700; font-size: 1rem; white-space: nowrap; }
.brand-sub { font-size: 0.75rem; color: var(--text3); }

.navbar-tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab:hover { background: var(--bg3); color: var(--text); }
.tab.active {
  background: var(--bg3);
  border-color: var(--accent);
  color: var(--text);
}

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}
.badge-blue { background: var(--accent); }
.badge-gray { background: var(--text3); }

.navbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.scraping-indicator { display: flex; align-items: center; gap: 6px; color: var(--yellow); font-size: 0.8rem; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--yellow);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { filter: brightness(1.1); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--bg4); color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 0.76rem; }

/* ─── Stats bar ──────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  padding: 0 20px;
}
.stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 8px 20px 8px 0;
}
.stat-num { font-size: 1.2rem; font-weight: 700; }
.stat-num.accent { color: var(--accent); }
.stat-label { font-size: 0.72rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; }

/* ─── Filters ────────────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filters-bar select,
.filters-bar input {
  padding: 6px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}
.filters-bar select:focus,
.filters-bar input:focus { border-color: var(--accent); }
.filters-bar input { flex: 1; min-width: 200px; }

/* ─── Main ───────────────────────────────────────────────────────────────────── */
.main { padding: 20px; max-width: 1600px; margin: 0 auto; }

.section { display: none; }
.section.active { display: block; }

/* ─── Grid ───────────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

/* ─── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.card-img {
  width: 100%; height: 180px;
  background: var(--bg3);
  position: relative;
  overflow: hidden;
}
.card-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.card-img-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
  background: var(--bg3);
  color: var(--text3);
}
.card-badges {
  position: absolute; top: 8px; left: 8px;
  display: flex; gap: 4px; flex-wrap: wrap;
}

/* ─── Badge portal ───────────────────────────────────────────────────────────── */
.badge-portal {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-portal.boe { background: #1d4ed8; color: #fff; }
.badge-portal.aeat { background: #7c3aed; color: #fff; }
.badge-portal.sareb { background: #0f766e; color: #fff; }

.badge-ocupacion {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
}
.badge-ocupacion.libre { background: #065f46; color: #6ee7b7; }
.badge-ocupacion.ocupado { background: #7f1d1d; color: #fca5a5; }
.badge-ocupacion.desconocido { background: #374151; color: #9ca3af; }
.badge-cargas {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #7f1d1d;
  color: #fca5a5;
  border: 1px solid #ef4444;
}

.card-body {
  padding: 14px;
  flex: 1;
  display: flex; flex-direction: column; gap: 8px;
}
.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-location { font-size: 0.78rem; color: var(--text2); }
.card-prices {
  display: flex; flex-direction: column; gap: 3px;
  margin-top: 2px;
}
.price-main { font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.price-tasacion { font-size: 0.85rem; color: var(--text2); font-weight: 500; }
.price-puja { font-size: 0.78rem; color: var(--text2); }
.price-deposit { font-size: 0.78rem; color: var(--text2); }
.card-dates { font-size: 0.78rem; color: var(--text2); line-height: 1.5; }
.card-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.75rem; color: var(--text3);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: auto;
}
.distancia {
  font-size: 0.72rem;
  background: var(--bg4);
  color: var(--text2);
  padding: 2px 7px;
  border-radius: 99px;
  white-space: nowrap;
}
.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg3);
}
.card-actions .btn { text-align: center; }
.card-actions .btn-wide { grid-column: 1 / -1; }

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text2);
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state .hint { font-size: 0.82rem; color: var(--text3); margin-top: 6px; }

/* ─── Detalle ────────────────────────────────────────────────────────────────── */
.detalle-view {
  max-width: 900px;
  margin: 0 auto;
}

.detalle-back {
  margin-bottom: 20px;
}

.detalle-header {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.detalle-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; }
.detalle-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }

.detalle-prices {
  display: flex; gap: 24px; flex-wrap: wrap;
}
.price-block { display: flex; flex-direction: column; gap: 2px; }
.price-block .label { font-size: 0.72rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.05em; }
.price-block .value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.price-block .value.small { font-size: 1rem; color: var(--text); }

.detalle-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.gallery img {
  width: 100%; height: 150px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s;
}
.gallery img:hover { transform: scale(1.03); }

/* Info grid */
.info-grid {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.info-grid h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text3); margin-bottom: 14px; }
.info-table { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; }
.info-row { display: flex; flex-direction: column; gap: 2px; }
.info-row .k { font-size: 0.72rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.03em; }
.info-row .v { font-size: 0.88rem; color: var(--text); word-break: break-word; }
.info-row .v a { color: var(--accent); text-decoration: none; }
.info-row .v a:hover { text-decoration: underline; }
.info-row.full { grid-column: 1 / -1; }

/* Maps iframe */
.maps-frame {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.maps-frame iframe { display: block; width: 100%; height: 320px; border: none; }

/* ─── Lightbox ───────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 4px; }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--bg4);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  z-index: 9999;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar { flex-wrap: wrap; height: auto; padding: 10px; gap: 8px; }
  .navbar-tabs { width: 100%; overflow-x: auto; }
  .stats-bar { flex-wrap: wrap; padding: 8px 12px; }
  .main { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  .info-table { grid-template-columns: 1fr; }
}

/* ─── Condiciones de subasta ─────────────────────────────────────────────────── */
.condiciones-box {
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.condiciones-box h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 10px;
}
.condiciones-text {
  font-size: 0.85rem;
  white-space: pre-wrap;
  color: var(--text);
  font-family: inherit;
  line-height: 1.7;
  margin: 0;
}
.badge-puja-doc {
  font-size: 0.7rem;
  background: var(--accent);
  color: #000;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 600;
}

/* ─── MultiSelect ─────────────────────────────────────────────────────────── */
.multiselect { position: relative; min-width: 160px; }
.ms-trigger {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-size: 0.82rem; cursor: pointer; user-select: none;
  min-height: 34px; gap: 4px; white-space: nowrap; overflow: hidden;
}
.ms-trigger:hover { border-color: var(--accent); }
.ms-arrow { flex-shrink: 0; opacity: 0.6; font-size: 0.7rem; }
.ms-label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ms-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 200;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 0; min-width: 190px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
/* Ocultar el checkbox nativo */
.ms-dropdown input[type=checkbox] { display: none; }
/* Fila del item */
.ms-dropdown label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px; font-size: 0.82rem; color: var(--text2);
  cursor: pointer; transition: background 0.1s, color 0.1s;
}
.ms-dropdown label:hover { background: var(--bg3); color: var(--text); }
/* Checkmark a la derecha — oculto por defecto */
.ms-dropdown label .ms-check {
  width: 16px; height: 16px; border-radius: 4px;
  border: 1.5px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; color: transparent; background: transparent;
  transition: all 0.15s;
}
/* Cuando el checkbox está checked, colorear el checkmark */
.ms-dropdown input[type=checkbox]:checked + .ms-check-row .ms-check,
.ms-dropdown label.ms-checked .ms-check {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.ms-selected-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.ms-tag {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 0.7rem; font-weight: 500;
}
.ms-tag .ms-remove { cursor: pointer; opacity: 0.75; font-size: 0.75rem; margin-left: 2px; }
.ms-tag .ms-remove:hover { opacity: 1; }

/* ─── Fecha progress ──────────────────────────────────────────────────────── */
.fecha-progress { margin: 6px 0; }
.fecha-bar-labels { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text2); margin-bottom: 4px; }
.fecha-bar-track { height: 4px; background: var(--bg4); border-radius: 2px; overflow: hidden; }
.fecha-bar-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
.fecha-bar-remaining { font-size: 0.7rem; margin-top: 3px; text-align: right; }

/* ─── Card actions rows ───────────────────────────────────────────────────── */
.card-actions-row { display: flex; gap: 6px; margin-bottom: 4px; }
.card-actions-row .btn { flex: 1; }
