/* =========================================================================
   Stockholm Rental Finder — design system
   Direction: dark editorial "property terminal". A warm ivory serif display
   (Fraunces) against near-black, a single confident amber accent, data set
   in monospace. Grid-breaking card: full-bleed image rail on the left,
   overlapping price tag, generous type scale.
   ========================================================================= */

:root {
  --bg:            #0b0c10;
  --bg-raised:     #14161c;
  --bg-card:       #161922;
  --bg-card-hover: #1b1f2b;
  --line:          #262a35;
  --line-soft:     #1e222c;

  --text:          #f4f1ea;
  --text-dim:      #a7adba;
  --text-faint:    #6b7280;

  --accent:        #f5a524;   /* amber — primary */
  --accent-soft:   rgba(245, 165, 36, 0.14);
  --accent-line:   rgba(245, 165, 36, 0.38);
  --cyan:          #4fd1c5;   /* secondary, for "value"/geo cues */
  --good:          #37d67a;
  --danger:        #ff6b5e;

  --radius:        16px;
  --radius-sm:     10px;
  --shadow:        0 18px 50px -20px rgba(0,0,0,0.75);
  --shadow-lift:   0 28px 70px -24px rgba(0,0,0,0.85);

  --sans: "Space Grotesk", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 82% -8%, rgba(245,165,36,0.08), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(79,209,197,0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

em { font-style: italic; }
.muted { color: var(--text-faint); }
.hidden { display: none !important; }

/* ------------------------------- Top bar -------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: rgba(11,12,16,0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px;
  background: linear-gradient(150deg, var(--accent), #d97706);
  box-shadow: 0 0 0 1px var(--accent-line), 0 8px 24px -6px rgba(245,165,36,0.5);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 10px 13px;
  border: 2px solid #0b0c10; border-bottom: none;
  border-radius: 4px 4px 0 0;
}
.brand-text h1 {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: 22px; letter-spacing: -0.01em; line-height: 1;
}
.brand-text h1 em { color: var(--accent); }
.brand-text p { margin: 5px 0 0; font-size: 12.5px; color: var(--text-dim); }

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.dataset-meta {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--mono); font-size: 12px; color: var(--text-dim);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); box-shadow: 0 0 0 3px rgba(255,255,255,0.03); }
.dot.fresh { background: var(--good); box-shadow: 0 0 10px var(--good); }
.dot.stale { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.dot.busy { background: var(--cyan); animation: pulse 1s var(--ease) infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* --------------------------------- Buttons ------------------------------- */
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 13px;
  border: 1px solid var(--line); background: var(--bg-raised); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: transform .2s var(--ease), border-color .2s var(--ease), background .2s var(--ease);
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent-line); }
.btn:active { transform: translateY(0); }
.btn-refresh { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.refresh-icon { display: inline-block; }
.btn-refresh.busy .refresh-icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; font-size: 12.5px; }
.link-btn:hover { text-decoration: underline; }

/* --------------------------------- Layout -------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 28px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 28px;
  align-items: start;
}

/* --------------------------------- Filters ------------------------------- */
.filters {
  position: sticky; top: 92px;
  /* Scroll the panel itself when its content is taller than the viewport,
     so the bottom filters (municipality list) are always reachable. */
  max-height: calc(100vh - 92px - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 22px;
  padding: 22px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.filters::-webkit-scrollbar { width: 8px; }
.filters::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.filters-head { display: flex; align-items: baseline; justify-content: space-between; }
.filters-head h2 { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; border: none; }
.field-label {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-faint);
}
input[type="search"], input[type="number"], select {
  font-family: var(--sans); font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--text-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); cursor: pointer; user-select: none;
  transition: all .15s var(--ease);
}
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.range-row { display: flex; align-items: center; gap: 8px; }
.range-sep { color: var(--text-faint); }

.toggle { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* source filter */
.source-list { display: flex; flex-direction: column; gap: 4px; }
.source-item { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text-dim); cursor: pointer; padding: 7px 8px; border-radius: 9px; border: 1px solid var(--line-soft); transition: all .15s var(--ease); }
.source-item:hover { color: var(--text); border-color: var(--line); }
.source-item input { accent-color: var(--accent); }
.source-item .src-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--text-faint); }
.source-item.src-qasa .src-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent-line); }
.source-item.src-homeq .src-dot { background: var(--cyan); box-shadow: 0 0 8px rgba(79,209,197,0.5); }
.source-item.src-samtrygg .src-dot { background: #b083ff; box-shadow: 0 0 8px rgba(176,131,255,0.5); }
.source-item .muni-count { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

.muni-list { display: flex; flex-direction: column; gap: 2px; padding-right: 4px; }
.muni-item { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text-dim); cursor: pointer; padding: 5px 4px; border-radius: 7px; }
.muni-item:hover { background: var(--bg-card); color: var(--text); }
.muni-item input { accent-color: var(--accent); }
.muni-item .muni-count { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }

/* --------------------------------- Results ------------------------------- */
.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.results-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.result-count { margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 600; }
.result-count b { color: var(--accent); }
.results-tools { display: flex; align-items: center; gap: 12px; }
.sort-field { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-dim); }
.sort-field select { width: auto; padding: 8px 30px 8px 12px; }

.btn-cheapest {
  font-family: var(--sans); font-weight: 600; font-size: 13px; cursor: pointer;
  color: var(--good); background: rgba(55,214,122,0.08); border: 1px solid rgba(55,214,122,0.4);
  padding: 9px 15px; border-radius: 10px; display: inline-flex; align-items: center; gap: 7px;
  transition: transform .18s var(--ease), background .18s var(--ease), box-shadow .18s var(--ease);
}
.btn-cheapest:hover { transform: translateY(-1px); background: rgba(55,214,122,0.16); }
.btn-cheapest.active { background: var(--good); color: var(--bg); border-color: var(--good); box-shadow: 0 8px 20px -8px rgba(55,214,122,0.7); }

/* list / map view toggle */
.view-toggle { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.view-btn { font-family: var(--sans); font-weight: 600; font-size: 13px; color: var(--text-dim); background: none; border: none; cursor: pointer; padding: 7px 15px; border-radius: 8px; transition: all .18s var(--ease); }
.view-btn:hover { color: var(--text); }
.view-btn.active { background: var(--accent); color: var(--bg); }

/* map */
.map-wrap { display: flex; flex-direction: column; gap: 10px; }
#map { height: min(72vh, 760px); width: 100%; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); background: var(--bg-raised); z-index: 1; }
.map-hint { margin: 0; font-size: 12.5px; color: var(--text-faint); }
.leaflet-container { background: #0e1016; font-family: var(--sans); }
/* dark-ish popup */
.leaflet-popup-content-wrapper { background: var(--bg-card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lift); }
.leaflet-popup-tip { background: var(--bg-card); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 0; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-dim); }
.map-pop { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px 12px; }
.map-pop-img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; margin: -10px -12px 4px; width: calc(100% + 24px); }
.map-pop-price { font-family: var(--mono); font-size: 16px; color: var(--accent); }
.map-pop-meta { font-size: 13px; color: var(--text); }
.map-pop-area { font-size: 12.5px; color: var(--cyan); font-weight: 600; }
.map-pop-src { font-family: var(--mono); font-size: 10.5px; display: inline-block; width: fit-content; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); }
.map-pop-src.src-qasa { color: var(--accent); border-color: var(--accent-line); }
.map-pop-src.src-homeq { color: var(--cyan); border-color: rgba(79,209,197,0.4); }
.map-pop-src.src-samtrygg { color: #c4a2ff; border-color: rgba(176,131,255,0.4); }
.map-pop-link { font-weight: 600; font-size: 13px; color: var(--bg); background: var(--accent); text-decoration: none; padding: 7px 12px; border-radius: 8px; text-align: center; margin-top: 2px; }
.map-pop-link:hover { filter: brightness(1.08); }

/* -------------------------------- Cards ---------------------------------- */
.cards { display: flex; flex-direction: column; gap: 18px; }

.card {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .3s var(--ease), border-color .3s var(--ease), box-shadow .3s var(--ease);
  opacity: 0; transform: translateY(14px);
  animation: rise .5s var(--ease) forwards;
}
@keyframes rise { to { opacity: 1; transform: translateY(0); } }
.card:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--shadow-lift); }

/* Left image rail */
.card-media { position: relative; background: var(--bg-raised); min-height: 236px; }
.card-media .main-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  cursor: zoom-in; transition: transform .5s var(--ease);
}
.card:hover .card-media .main-img { transform: scale(1.04); }
.card-media .no-img {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-family: var(--mono); font-size: 12px; text-align: center; padding: 20px;
}
.price-tag {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(11,12,16,0.86); backdrop-filter: blur(6px);
  border: 1px solid var(--accent-line); border-radius: 10px;
  padding: 8px 12px; box-shadow: 0 8px 20px -8px rgba(0,0,0,0.8);
}
.price-tag .amount { font-family: var(--mono); font-weight: 500; font-size: 18px; color: var(--accent); line-height: 1; }
.price-tag .per { font-size: 11px; color: var(--text-dim); }
.price-tag .breakdown { font-size: 10px; color: var(--text-faint); margin-top: 4px; white-space: nowrap; }

/* thumbnail strip */
.thumbs { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; }
.thumbs .thumb {
  width: 42px; height: 42px; border-radius: 8px; object-fit: cover; cursor: pointer;
  border: 1.5px solid rgba(255,255,255,0.35); box-shadow: 0 4px 10px -3px rgba(0,0,0,0.7);
  transition: transform .18s var(--ease), border-color .18s var(--ease);
}
.thumbs .thumb:hover { transform: translateY(-2px); border-color: var(--accent); }
.thumbs .thumb-more {
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 12px; color: var(--text);
  background: rgba(11,12,16,0.82); width: 42px; height: 42px; border-radius: 8px; cursor: pointer;
  border: 1.5px solid rgba(255,255,255,0.25);
}

/* Right body */
.card-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.card-address { min-width: 0; }
.card-address h3 {
  margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-address .locality { color: var(--text-dim); font-size: 13.5px; margin-top: 3px; }
.card-address .locality .muni { color: var(--cyan); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.03em;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--text-dim); white-space: nowrap;
}
.badge.first { color: var(--good); border-color: rgba(55,214,122,0.4); background: rgba(55,214,122,0.08); }
.badge.furn { color: var(--cyan); border-color: rgba(79,209,197,0.4); background: rgba(79,209,197,0.08); }
.badge.source { font-weight: 600; }
.badge.source.src-qasa { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.badge.source.src-homeq { color: var(--cyan); border-color: rgba(79,209,197,0.4); background: rgba(79,209,197,0.08); }
.badge.source.src-samtrygg { color: #c4a2ff; border-color: rgba(176,131,255,0.4); background: rgba(176,131,255,0.1); }

.specs { display: flex; flex-wrap: wrap; gap: 22px; padding: 4px 0; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.spec { display: flex; flex-direction: column; gap: 2px; }
.spec .v { font-family: var(--mono); font-size: 16px; color: var(--text); }
.spec .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.spec .v.cyan { color: var(--cyan); }

.card-desc {
  color: var(--text-dim); font-size: 13.5px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: auto; }
.card-foot .posted { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.btn-view {
  font-family: var(--sans); font-weight: 600; font-size: 13px; text-decoration: none;
  color: var(--bg); background: var(--accent); padding: 9px 16px; border-radius: 9px;
  display: inline-flex; align-items: center; gap: 7px; transition: transform .2s var(--ease), filter .2s var(--ease);
}
.btn-view:hover { transform: translateY(-1px); filter: brightness(1.08); }

/* -------------------------------- Empty / pager -------------------------- */
.empty { text-align: center; padding: 70px 20px; }
.empty-title { font-family: var(--serif); font-size: 22px; margin: 0 0 8px; }
.pager { display: flex; justify-content: center; padding: 8px 0 40px; }
.btn-more { padding: 12px 26px; }

/* skeletons */
.skeleton { position: relative; overflow: hidden; background: var(--bg-card); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.card.skeleton { min-height: 236px; }

/* -------------------------------- Lightbox ------------------------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(6,7,10,0.94); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 88vw; max-height: 86vh; border-radius: 12px; box-shadow: var(--shadow-lift); }
.lb-close { position: absolute; top: 22px; right: 26px; font-size: 34px; line-height: 1; color: var(--text); background: none; border: none; cursor: pointer; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 44px; color: var(--text); background: rgba(20,22,28,0.6); border: 1px solid var(--line);
  width: 56px; height: 56px; border-radius: 50%; cursor: pointer; transition: background .2s var(--ease);
}
.lb-nav:hover { background: var(--accent); color: var(--bg); }
.lb-prev { left: 3vw; } .lb-next { right: 3vw; }
.lb-counter { position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); font-family: var(--mono); font-size: 13px; color: var(--text-dim); }

/* --------------------------------- Toast --------------------------------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-raised); border: 1px solid var(--accent-line); color: var(--text);
  padding: 13px 20px; border-radius: 12px; box-shadow: var(--shadow-lift);
  font-size: 13.5px; z-index: 110; opacity: 0; transition: all .3s var(--ease); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* -------------------------------- Responsive ----------------------------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; padding: 18px; gap: 18px; }
  /* On stacked/mobile layout the panel flows normally — the whole page
     scrolls, so it must not be a short internal scroll box. */
  .filters { position: static; max-height: none; overflow: visible; }
  .card { grid-template-columns: 260px minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px 18px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .card { grid-template-columns: 1fr; }
  .card-media { min-height: 210px; }
  .brand-text p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto; }
  /* Cards start at opacity:0 for the entrance animation; with animations
     disabled they must be forced visible or they'd never appear. */
  .card { opacity: 1 !important; transform: none !important; }
}
