/* ============================================================
   Portal Inmobiliario · estilos (modo claro + oscuro)
   ============================================================ */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e5e8ee;
  --text: #1b2430;
  --text-muted: #6a7686;
  --accent: #2f5fd0;
  --accent-strong: #244cad;
  --accent-soft: #eaf0fd;
  --price: #12203a;
  --whatsapp: #25d366;
  --whatsapp-dark: #1da851;
  --venta: #0a7d55;
  --venta-bg: #e4f5ee;
  --alquiler: #2f5fd0;
  --alquiler-bg: #eaf0fd;
  --tasacion: #b4690e;
  --tasacion-bg: #fbf0df;
  --shadow: 0 1px 3px rgba(20, 30, 48, .07), 0 1px 2px rgba(20, 30, 48, .04);
  --shadow-hover: 0 12px 30px rgba(20, 30, 48, .13);
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #161d26;
  --surface-2: #1c2530;
  --border: #29323e;
  --text: #e8ecf1;
  --text-muted: #97a3b2;
  --accent: #5e8bf0;
  --accent-strong: #7aa0f4;
  --accent-soft: #1b2740;
  --price: #f1f5fb;
  --venta: #46d19b;
  --venta-bg: #123227;
  --alquiler: #7aa0f4;
  --alquiler-bg: #17233c;
  --tasacion: #e6ad4e;
  --tasacion-bg: #2f2513;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-hover: 0 12px 30px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.container { max-width: 1160px; margin: 0 auto; padding: 0 16px; }

/* ---------- Navbar ---------- */
.nav {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 62px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.brand-mark svg { width: 19px; height: 19px; fill: currentColor; }
.brand span b { color: var(--accent); }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { padding: 8px 12px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.nav-links a:hover { background: var(--surface-2); color: var(--text); }
.nav-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  display: grid; place-items: center; transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 19px; height: 19px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; cursor: pointer; font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 10px; transition: background .15s, transform .05s, box-shadow .15s;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-strong); }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-wa { background: var(--whatsapp); color: #fff; }
.btn-wa:hover { background: var(--whatsapp-dark); }
.btn-wa svg { width: 17px; height: 17px; fill: currentColor; }

/* ---------- Hero + buscador ---------- */
.hero {
  background: radial-gradient(1200px 300px at 50% -80px, var(--accent-soft), transparent),
              var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 30px 0 22px;
}
.hero h1 { margin: 0 0 4px; font-size: clamp(22px, 3.4vw, 32px); letter-spacing: -.03em; }
.hero p { margin: 0 0 18px; color: var(--text-muted); }

.search {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
  display: grid; gap: 10px;
  grid-template-columns: 1.6fr 1fr 1fr 1fr auto;
}
.search .field { display: flex; flex-direction: column; gap: 4px; }
.search label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding-left: 2px; }
.input, .select {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%236a7686'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 34px; }
.search .search-btn { align-self: end; }
.search .search-btn .btn { height: 44px; width: 100%; }

/* ---------- Toolbar de resultados ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 22px 0 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 17px; }
.toolbar h2 b { color: var(--accent); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-toggle button { border: 0; background: var(--surface); color: var(--text-muted); padding: 9px 11px; cursor: pointer; display: grid; place-items: center; }
.view-toggle button.active { background: var(--accent-soft); color: var(--accent); }
.view-toggle button svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Grilla de resultados ---------- */
.results { display: grid; gap: 16px; }
.results.grid { grid-template-columns: repeat(3, 1fr); }

/* ---------- Tarjeta (horizontal) ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-columns: 320px 1fr;
  transition: box-shadow .18s, transform .18s;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }

.card-media { position: relative; background: var(--surface-2); aspect-ratio: 4 / 3; overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-media .ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--border); }
.card-media .ph svg { width: 54px; height: 54px; fill: currentColor; }

.badge {
  position: absolute; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
}
.badge-op { left: 10px; top: 10px; color: #fff; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.badge-photos { right: 10px; bottom: 10px; color: #fff; background: rgba(0,0,0,.6); }
.badge-photos svg { width: 13px; height: 13px; fill: currentColor; }

.card-media .arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.9); color: #1b2430; display: grid; place-items: center;
  opacity: 0; transition: opacity .15s;
}
.card:hover .arrow { opacity: 1; }
.arrow.prev { left: 8px; } .arrow.next { right: 8px; }
.arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.card-body { padding: 15px 16px; display: flex; flex-direction: column; }
.op-tag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; align-self: flex-start; }
.op-venta { color: var(--venta); background: var(--venta-bg); }
.op-alquiler { color: var(--alquiler); background: var(--alquiler-bg); }
.op-tasacion { color: var(--tasacion); background: var(--tasacion-bg); }

.price { font-size: 23px; font-weight: 800; color: var(--price); letter-spacing: -.02em; margin: 8px 0 2px; }
.price small { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.card-title { font-size: 16px; font-weight: 700; margin: 4px 0 2px; }
.card-addr { color: var(--text-muted); font-size: 14px; }
.features { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0; color: var(--text); font-size: 13.5px; }
.features span { display: inline-flex; align-items: center; gap: 5px; }
.features svg { width: 16px; height: 16px; fill: var(--text-muted); }
.card-desc { color: var(--text-muted); font-size: 13.5px; margin: 0 0 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.agency { display: flex; align-items: center; gap: 8px; min-width: 0; }
.agency-logo { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.agency-name { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-actions { display: flex; gap: 8px; flex: none; }
.card-actions .btn { padding: 9px 13px; }

/* ---------- Estados ---------- */
.state { text-align: center; padding: 60px 20px; color: var(--text-muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: var(--radius); height: 240px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 40px; }
.footer .container { padding: 26px 16px; color: var(--text-muted); font-size: 13.5px; text-align: center; }

/* ============================================================
   Página de detalle
   ============================================================ */
.detail { padding: 22px 0 40px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 14px; margin-bottom: 14px; }
.back:hover { color: var(--text); }
.gallery { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.gallery-main { position: relative; aspect-ratio: 16 / 10; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.gallery-main img { width: 100%; height: 100%; object-fit: cover; }
.gallery-side { display: grid; grid-template-rows: 1fr 1fr; gap: 10px; }
.gallery-side img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.thumbs img { width: 92px; height: 68px; object-fit: cover; border-radius: 9px; cursor: pointer; border: 2px solid transparent; flex: none; }
.thumbs img.active { border-color: var(--accent); }

.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; margin-top: 22px; }
.detail-main h1 { margin: 8px 0 2px; font-size: 26px; letter-spacing: -.02em; }
.detail-price { font-size: 30px; font-weight: 800; color: var(--price); margin: 12px 0; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.fact { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.fact .k { font-size: 12px; color: var(--text-muted); }
.fact .v { font-weight: 700; margin-top: 2px; }
.section-title { font-size: 18px; margin: 22px 0 8px; }
.prose { color: var(--text); white-space: pre-line; }
.contact-card { position: sticky; top: 78px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.contact-card .lbl { font-size: 13px; color: var(--text-muted); }
.contact-card .agency-title { font-size: 18px; font-weight: 800; margin: 4px 0; }

/* La inmobiliaria dentro de la tarjeta ahora es un link */
a.agency { text-decoration: none; border-radius: 8px; transition: opacity .15s; }
a.agency:hover { opacity: .75; }

/* ============================================================
   Perfil público de inmobiliaria
   ============================================================ */
.agency-cover {
  height: 230px; background-size: cover; background-position: center;
  border-bottom: 1px solid var(--border);
}
.agency-head {
  display: flex; align-items: flex-end; gap: 18px;
  margin-top: -56px; position: relative; z-index: 1; padding-bottom: 8px;
}
.agency-avatar {
  width: 116px; height: 116px; border-radius: 18px; object-fit: cover;
  border: 4px solid var(--surface); box-shadow: var(--shadow); flex: none; background: var(--surface-2);
}
.agency-head-info { flex: 1; min-width: 0; padding-bottom: 6px; }
.agency-head-info h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.agency-loc { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }
.agency-head-actions { flex: none; padding-bottom: 8px; }

.agency-body { display: grid; grid-template-columns: 1fr 330px; gap: 26px; margin: 22px 0 42px; }
.agency-aside .contact-card { top: 78px; }
.agency-links { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.agency-link { padding: 9px 0; border-bottom: 1px solid var(--border); color: var(--text); font-size: 14px; }
.agency-link:last-child { border-bottom: 0; }
.agency-link:hover { color: var(--accent); }
.agency-map { margin-top: 14px; }
.agency-map iframe { width: 100%; height: 220px; border: 0; border-radius: 12px; display: block; }

/* ============================================================
   Directorio de inmobiliarias
   ============================================================ */
.ag-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  transition: box-shadow .18s, transform .18s;
}
.ag-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.ag-card-cover { height: 92px; background-size: cover; background-position: center; }
.ag-card-body { padding: 0 16px 16px; }
.ag-card-logo {
  width: 60px; height: 60px; border-radius: 13px; object-fit: cover;
  border: 3px solid var(--surface); margin-top: -30px; position: relative; display: block; background: var(--surface-2);
}
.ag-card-name { font-weight: 700; font-size: 17px; margin-top: 10px; color: var(--text); }
.ag-card-loc { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.ag-card-count { color: var(--accent); font-size: 13px; font-weight: 600; margin-top: 8px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 980px) {
  .results.grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .contact-card { position: static; }
  .gallery { grid-template-columns: 1fr; }
  .gallery-side { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .agency-body { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .nav-links { display: none; }
  .search { grid-template-columns: 1fr 1fr; }
  .search .search-btn { grid-column: 1 / -1; }
  .card { grid-template-columns: 1fr; }
  .card-media { aspect-ratio: 16 / 10; }
  .results.grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .agency-head { flex-wrap: wrap; margin-top: -44px; }
  .agency-avatar { width: 92px; height: 92px; }
  .agency-head-actions { width: 100%; padding-bottom: 0; }
  .agency-head-actions .btn { width: 100%; }
}
