:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --surface-2:      #ffffff;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-vanzare: #2a78d6;
  --series-adoptie: #eb6834;
  --series-3:       #1baf7a;
  --series-4:       #eda100;
  --series-5:       #e87ba4;
  --series-6:       #008300;
  --series-7:       #4a3aa7;
  --series-8:       #e34948;

  --good: #0ca30c;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --surface-2:      #212120;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

    --series-vanzare: #3987e5;
    --series-adoptie: #d95926;
    --series-3:       #199e70;
    --series-4:       #c98500;
    --series-5:       #d55181;
    --series-6:       #008300;
    --series-7:       #9085e9;
    --series-8:       #e66767;
    --good: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --surface-2:      #212120;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);

  --series-vanzare: #3987e5;
  --series-adoptie: #d95926;
  --series-3:       #199e70;
  --series-4:       #c98500;
  --series-5:       #d55181;
  --series-6:       #008300;
  --series-7:       #9085e9;
  --series-8:       #e66767;
  --good: #0ca30c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1400px; margin: 0 auto; padding: 0 20px 60px; }

/* Header */
.app-header { padding: 28px 0 16px; }
.app-header h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.01em; }
.app-header p { margin: 0; color: var(--text-secondary); font-size: 14px; }

/* KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.kpi-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.kpi-tile .kpi-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.kpi-tile .kpi-value { font-size: 24px; font-weight: 600; line-height: 1.1; }
.kpi-tile .kpi-value.c-vanzare { color: var(--series-vanzare); }
.kpi-tile .kpi-value.c-adoptie { color: var(--series-adoptie); }

/* Filter bar */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--page);
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.filter-bar .field { display: flex; flex-direction: column; gap: 4px; }
.filter-bar label { font-size: 11px; color: var(--text-muted); }
.filter-bar select, .filter-bar input[type="text"], .filter-bar input[type="number"] {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
}
.filter-bar select[multiple] { min-width: 130px; height: 32px; }
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--text-primary); color: var(--page); font-weight: 600; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.price-range { display: flex; gap: 6px; align-items: center; }
.price-range input { width: 84px; }
.btn-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.btn-reset:hover { color: var(--text-primary); border-color: var(--text-primary); }
.result-count { margin-left: auto; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

/* Tabs */
.view-tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 14px;
  border-bottom: 1px solid var(--border);
}
.view-tabs button {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 16px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.view-tabs button.active { color: var(--text-primary); border-bottom-color: var(--series-vanzare); font-weight: 600; }

.view-panel { display: none; }
.view-panel.active { display: block; }

/* Map */
#map { width: 100%; height: 620px; border-radius: 12px; border: 1px solid var(--border); }
.map-legend {
  display: flex;
  gap: 18px;
  align-items: center;
  margin: 10px 2px;
  font-size: 13px;
  color: var(--text-secondary);
}
.map-legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.map-legend .dot-vanzare { background: var(--series-vanzare); }
.map-legend .dot-adoptie { background: var(--series-adoptie); }
.leaflet-popup-content { font-family: system-ui, -apple-system, sans-serif; }
.popup-card { width: 200px; }
.popup-card img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; margin-bottom: 6px; background: var(--grid); }
.popup-card .p-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.popup-card .p-meta { font-size: 12px; color: #52514e; margin-bottom: 6px; }
.popup-card a { font-size: 12px; color: #2a78d6; text-decoration: none; font-weight: 600; }

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.chart-card h3 { font-size: 14px; margin: 0 0 2px; font-weight: 600; }
.chart-card .chart-sub { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }
.chart-card canvas { max-height: 280px; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card.wide canvas { max-height: 220px; }
.charts-grid-spaced { margin-top: 16px; }
.chart-empty { color: var(--text-muted); font-size: 13px; padding: 40px 0; text-align: center; margin: 0; }
.hidden { display: none !important; }

/* Legend for tip (vanzare/adoptie) reused across charts */
.mini-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.mini-legend span { display: inline-flex; align-items: center; gap: 5px; }
.mini-legend .sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* Listing cards */
.listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.listing-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text-primary);
}
.listing-card .thumb { width: 100%; height: 150px; object-fit: cover; background: var(--grid); }
.listing-card .thumb.image-error { visibility: hidden; }
.listing-card .body { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.listing-card .tag {
  align-self: flex-start;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border-radius: 5px;
  color: #fff;
}
.listing-card .tag.vanzare { background: var(--series-vanzare); }
.listing-card .tag.adoptie { background: var(--series-adoptie); }
.listing-card .title { font-size: 13px; font-weight: 600; line-height: 1.3; margin: 2px 0; }
.listing-card .price { font-size: 15px; font-weight: 700; }
.listing-card .meta { font-size: 12px; color: var(--text-secondary); }

.load-more-wrap { display: flex; justify-content: center; margin-top: 18px; }
.load-more-wrap button {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

footer.app-footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  #map { height: 440px; }
  .app-header h1 { font-size: 21px; }
}

/* Header top row + theme toggle */
.header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.theme-toggle {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px; height: 40px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.freshness-line { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); }

.kpi-row-fresh { margin-top: -6px; }
.kpi-row-fresh .kpi-tile { border-style: dashed; }

/* Istoric tab */
.istoric-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
#panel-istoric canvas { max-height: 340px; }
#panel-istoric .charts-grid canvas { max-height: 220px; }
.scrape-info { font-size: 13px; color: var(--text-secondary); line-height: 1.9; }
.scrape-info b { color: var(--text-primary); }

/* Description modal */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  background: var(--surface-1);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  border: 1px solid var(--border);
}
.modal-close {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 14px;
  z-index: 2;
}
.modal-img { width: 100%; height: 220px; object-fit: cover; background: var(--grid); display: block; }
.modal-body { padding: 16px 18px 20px; }
.modal-body h3 { margin: 8px 0 4px; font-size: 17px; }
.modal-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.modal-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-line;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 14px;
  max-height: 40vh;
  overflow-y: auto;
}
.modal-body a {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--series-vanzare);
  text-decoration: none;
}

/* Description peek button on listing cards */
.listing-card { position: relative; }
.desc-peek-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  border-radius: 7px;
  width: 30px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
}
.map-popup-desc-btn {
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: 1px solid rgba(11,11,11,0.15);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  margin-left: 6px;
}
