/* ==========================================================================
   Apartamente București — design system
   Pattern: Marketplace/Directory · Style: Data-Dense Dashboard
   Wordmark: Cinzel · UI: Inter (tabular numerals for all figures)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

/* --- Tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Brand — trust teal + professional blue */
  --brand-50:  #f0fdfa;
  --brand-100: #ccfbf1;
  --brand-200: #99f6e4;
  --brand-400: #2dd4bf;
  --brand-500: #14b8a6;
  --brand-600: #0f766e;
  --brand-700: #115e59;
  --brand-900: #134e4a;
  --accent-600: #0369a1;

  /* Neutrals */
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #fbfcfd;
  --surface-sunken:#eef1f4;
  --text:          #0f172a;
  --text-muted:    #55637a;
  --text-subtle:   #78849b;
  --border:        #e2e6ec;
  --border-strong: #c9d0da;

  --primary:       var(--brand-600);
  --primary-hover: var(--brand-700);
  --on-primary:    #ffffff;
  --primary-soft:  var(--brand-50);
  --ring:          color-mix(in srgb, var(--brand-600) 45%, transparent);

  --positive:      #047857;
  --positive-soft: #ecfdf5;
  --negative:      #b91c1c;
  --negative-soft: #fef2f2;
  --warning:       #b45309;

  /* Elevation — layered, low-opacity, premium rather than heavy */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 2px 4px rgba(16, 24, 40, .04), 0 8px 16px -4px rgba(16, 24, 40, .08);
  --shadow-lg: 0 4px 8px rgba(16, 24, 40, .04), 0 24px 48px -12px rgba(16, 24, 40, .18);

  /* Geometry */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* Motion */
  --dur-fast: 120ms;
  --dur: 180ms;
  --ease: cubic-bezier(.2, .8, .3, 1);

  --header-h: 64px;
  --sidebar-w: 312px;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg:            #0b0f14;
  --surface:       #131920;
  --surface-2:     #172029;
  --surface-sunken:#0f151b;
  --text:          #e8edf4;
  --text-muted:    #9fb0c3;
  --text-subtle:   #7b8ba0;
  --border:        #232d39;
  --border-strong: #33404f;

  --primary:       var(--brand-500);
  --primary-hover: var(--brand-400);
  --on-primary:    #04211f;
  --primary-soft:  rgba(20, 184, 166, .12);
  --ring:          color-mix(in srgb, var(--brand-400) 55%, transparent);

  --positive:      #34d399;
  --positive-soft: rgba(52, 211, 153, .12);
  --negative:      #f87171;
  --negative-soft: rgba(248, 113, 113, .12);
  --warning:       #fbbf24;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
}

/* --- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv05' 1, 'ss01' 1;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Every figure in the UI is compared column-wise — tabular avoids jitter. */
.num, .price, input[type='number'] { font-variant-numeric: tabular-nums; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-pill); border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* The skip link must become visible when a keyboard user reaches it. */
a.visually-hidden:focus {
  position: fixed; top: 10px; left: 10px; z-index: 999;
  width: auto; height: auto; margin: 0; padding: 10px 16px;
  clip: auto; overflow: visible;
  background: var(--primary); color: var(--on-primary);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-weight: 600;
}

/* --- Header -------------------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  height: var(--header-h);
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--r-md);
  background: linear-gradient(140deg, var(--brand-500), var(--brand-700));
  color: #fff;
}
.brand-name {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 17px; font-weight: 700; letter-spacing: .04em;
  white-space: nowrap;
}
.brand-sub { display: block; font-family: 'Inter', sans-serif; font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-subtle); }

.header-search { flex: 1; min-width: 0; max-width: 720px; }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* --- Controls ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-sunken); border-color: var(--text-subtle); }
.btn:active { transform: translateY(1px); }
.btn[aria-pressed='true'] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.btn-primary {
  background: var(--primary); border-color: var(--primary); color: var(--on-primary);
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-sunken); border-color: transparent; }

.btn-icon { width: 40px; padding: 0; }

.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }

input[type='text'], input[type='number'], input[type='search'], select {
  width: 100%; min-height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
select { padding-right: 30px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378849b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input::placeholder { color: var(--text-subtle); }

/* --- Smart search -------------------------------------------------------- */
.smart {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  padding: 4px 4px 4px 14px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.smart:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.smart svg { flex-shrink: 0; color: var(--text-subtle); }
.smart input {
  flex: 1; min-width: 0; min-height: 36px;
  border: none; background: transparent; padding: 0;
}
.smart input:focus { box-shadow: none; }
.smart .btn { min-height: 36px; border-radius: var(--r-pill); }

/* --- Layout -------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 24px;
  max-width: 1680px;
  margin: 0 auto;
  padding: 20px;
  align-items: start;
}

.sidebar {
  position: sticky; top: calc(var(--header-h) + 20px);
  max-height: calc(100vh - var(--header-h) - 40px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.sidebar-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-size: 14px; font-weight: 600; }

/* --- Filter groups ------------------------------------------------------- */
.fgroup { border-bottom: 1px solid var(--border); }
.fgroup:last-child { border-bottom: none; }
.fgroup > summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 13px 16px;
  font-size: 13px; font-weight: 600; letter-spacing: .01em;
  cursor: pointer; list-style: none;
  transition: background var(--dur) var(--ease);
}
.fgroup > summary::-webkit-details-marker { display: none; }
.fgroup > summary:hover { background: var(--surface-sunken); }
.fgroup > summary .chev { color: var(--text-subtle); transition: transform var(--dur) var(--ease); }
.fgroup[open] > summary .chev { transform: rotate(180deg); }
.fgroup-body { padding: 4px 16px 16px; display: grid; gap: 12px; }

.field { display: grid; gap: 6px; }
.field > label, .field-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Segmented control — rooms, tri-state toggles */
.seg { display: flex; background: var(--surface-sunken); border-radius: var(--r-md); padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-height: 34px; padding: 0 6px;
  border: none; border-radius: 7px; background: transparent;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.seg-yes[aria-pressed='true'] { color: var(--positive); }
.seg-no[aria-pressed='true'] { color: var(--negative); }

/* Checkbox rows with counts */
/* The label is the real touch target — the 17px box inside it is only the
   visual. Kept at 44px on coarse pointers per Apple HIG / Material. */
.check {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 0 6px; margin: 0 -6px;
  border-radius: var(--r-sm); cursor: pointer;
  font-size: 14px;
  transition: background var(--dur) var(--ease);
}
.check:hover { background: var(--surface-sunken); }
.check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.check .count { margin-left: auto; font-size: 12px; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.check.is-empty { opacity: .45; }

.scroll-list { max-height: 232px; overflow-y: auto; padding-right: 4px; }

/* Price histogram behind the range inputs */
.histogram { display: flex; align-items: flex-end; gap: 2px; height: 40px; margin-bottom: 2px; }
.histogram span {
  flex: 1; min-height: 2px; border-radius: 2px 2px 0 0;
  background: var(--brand-200); transition: background var(--dur) var(--ease);
}
[data-theme='dark'] .histogram span { background: color-mix(in srgb, var(--brand-500) 35%, transparent); }
.histogram span.in { background: var(--primary); }

/* --- Toolbar ------------------------------------------------------------- */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.result-count { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.result-count small { display: block; font-size: 13px; font-weight: 400; color: var(--text-muted); letter-spacing: 0; }
.toolbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.toolbar-right select { width: auto; min-width: 176px; }

.viewtoggle { display: flex; gap: 2px; background: var(--surface-sunken); padding: 3px; border-radius: var(--r-md); }
.viewtoggle button {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: none; border-radius: 7px; background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.viewtoggle button[aria-pressed='true'] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* Active filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 6px 0 11px;
  background: var(--primary-soft); color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 500;
}
.chip button {
  display: grid; place-items: center; width: 20px; height: 20px;
  border: none; border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.chip button:hover { background: color-mix(in srgb, var(--primary) 20%, transparent); }
.chip-understood { background: var(--surface); color: var(--text-muted); border-color: var(--border); }

/* --- Result grid --------------------------------------------------------- */
.results { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.results[data-view='list'] { grid-template-columns: 1fr; }

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.card-media { position: relative; aspect-ratio: 4 / 3; background: var(--surface-sunken); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 400ms var(--ease); }
.card:hover .card-media img { transform: scale(1.04); }
.card-media .placeholder { display: grid; place-items: center; height: 100%; color: var(--text-subtle); }

.card-price {
  position: absolute; left: 10px; bottom: 10px;
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 6px 11px; border-radius: var(--r-md);
  background: rgba(9, 14, 20, .82);
  color: #fff; backdrop-filter: blur(6px);
  font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.card-price small { font-size: 11px; font-weight: 500; opacity: .8; }

.card-fav {
  position: absolute; top: 8px; right: 8px;
  display: grid; place-items: center; width: 36px; height: 36px;
  border: none; border-radius: 50%;
  background: rgba(9, 14, 20, .55); color: #fff; cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.card-fav:hover { background: rgba(9, 14, 20, .8); }
.card-fav[aria-pressed='true'] { color: #fb7185; }
.card-fav[aria-pressed='true'] svg { fill: currentColor; }

.card-dup {
  position: absolute; top: 8px; left: 8px;
  padding: 4px 9px; border-radius: var(--r-pill);
  background: rgba(9, 14, 20, .68); color: #fff;
  font-size: 11px; font-weight: 600; backdrop-filter: blur(6px);
}

/* Count bubble on the header favourites button */
#btn-favs { position: relative; }
#btn-favs[aria-pressed='true'] { color: #fb7185; }
#btn-favs[aria-pressed='true'] svg { fill: currentColor; }
.fav-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary);
  border-radius: var(--r-pill);
  font-size: 10px; font-weight: 700; line-height: 1;
}
/* Author display rules beat the UA's [hidden] { display:none } — restate it. */
.fav-badge[hidden] { display: none; }

.card-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; flex: 1; }
.card-title {
  font-size: 14.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-loc { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-muted); }
.card-loc svg { flex-shrink: 0; color: var(--text-subtle); }

.specs { display: flex; flex-wrap: wrap; gap: 5px; }
.spec {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--r-sm);
  background: var(--surface-sunken); color: var(--text-muted);
  font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
}
.spec-yes { background: var(--positive-soft); color: var(--positive); }
.spec-dist { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.spec-dist svg { width: 11px; height: 11px; }
.spec-no  { background: var(--negative-soft); color: var(--negative); }

.card-foot {
  display: flex; align-items: center; gap: 8px;
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-subtle);
}
.source-tag {
  padding: 2px 7px; border-radius: var(--r-sm);
  background: var(--surface-sunken); color: var(--text-muted);
  font-weight: 600; font-size: 11px; letter-spacing: .02em;
}
.sqm { margin-left: auto; font-variant-numeric: tabular-nums; }

/* List view */
.results[data-view='list'] .card { flex-direction: row; }
.results[data-view='list'] .card-media { width: 260px; flex-shrink: 0; aspect-ratio: auto; }
.results[data-view='list'] .card-body { padding: 14px 16px; }
.results[data-view='list'] .card-title { -webkit-line-clamp: 1; font-size: 15.5px; }

/* Compact table view */
.results[data-view='table'] { gap: 0; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.results[data-view='table'] .card {
  flex-direction: row; align-items: center; gap: 12px;
  border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  padding: 8px 12px; transform: none !important;
}
.results[data-view='table'] .card:hover { background: var(--surface-sunken); box-shadow: none; }
.results[data-view='table'] .card-media { width: 64px; height: 48px; aspect-ratio: auto; border-radius: var(--r-sm); }
.results[data-view='table'] .card-price { position: static; background: none; color: var(--text); backdrop-filter: none; padding: 0; font-size: 15px; }
.results[data-view='table'] .card-fav, .results[data-view='table'] .card-dup { position: static; }
.results[data-view='table'] .card-body { flex-direction: row; align-items: center; gap: 12px; padding: 0; }
.results[data-view='table'] .card-foot { border: none; padding: 0; margin: 0; }
.results[data-view='table'] .card-title { -webkit-line-clamp: 1; }

/* --- Skeletons ----------------------------------------------------------- */
.sk { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.sk-media { aspect-ratio: 4 / 3; }
.sk-line { height: 12px; border-radius: var(--r-sm); margin: 10px 14px; }
.sk-line.short { width: 55%; }
.shimmer {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, color-mix(in srgb, var(--surface-sunken) 60%, var(--surface)) 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* --- Empty / error states ------------------------------------------------ */
.state {
  grid-column: 1 / -1;
  display: grid; place-items: center; gap: 14px;
  padding: 64px 24px; text-align: center;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
}
.state h3 { font-size: 17px; }
.state p { margin: 0; color: var(--text-muted); max-width: 46ch; }
.state-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* --- Pagination ---------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 28px 0 8px; }
.page-info { font-size: 14px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* --- Modal --------------------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(9, 14, 20, .55);
  backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}
.modal.open { opacity: 1; visibility: visible; }
.modal-panel {
  width: min(980px, 100%); max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(.97) translateY(8px);
  transition: transform var(--dur) var(--ease);
}
.modal.open .modal-panel { transform: none; }
.modal-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
/* grid-template-columns must be minmax(0,1fr) and children min-width:0, or a
   wide child (gallery, table, long chip row) pushes past the panel and clips. */
.modal-body {
  overflow-y: auto; padding: 18px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px;
}
.modal-body > * { min-width: 0; }
.modal-foot { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); }

/* Fixed height + min-height:0 on the children: without it a tall source photo
   keeps its intrinsic size and pushes through the rest of the modal. */
.gallery { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; height: 340px; overflow: hidden; }
.gallery.is-single { grid-template-columns: 1fr; }
.gallery img {
  width: 100%; height: 100%; min-height: 0; min-width: 0;
  object-fit: cover; display: block;
  border-radius: var(--r-md); background: var(--surface-sunken);
}
.gallery-side { display: grid; grid-template-rows: 1fr 1fr; gap: 8px; min-height: 0; }
.gallery-side:has(img:only-child) { grid-template-rows: 1fr; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
.kv div { padding: 10px 12px; background: var(--surface-sunken); border-radius: var(--r-md); }
.kv dt { font-size: 11px; font-weight: 500; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .05em; }
.kv dd { margin: 3px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

.section-title { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.desc { font-size: 14.5px; line-height: 1.65; color: var(--text-muted); white-space: pre-wrap; max-height: 260px; overflow-y: auto; }

/* Source spec values can be a single very long unbroken string (URLs, JSON);
   fixed layout + wrapping keeps them inside the panel instead of stretching it. */
.attr-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 13.5px; }
.attr-table td {
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere; word-break: break-word;
}
.attr-table tr:last-child td { border-bottom: none; }
.attr-table td:first-child { color: var(--text-subtle); width: 45%; }
.attr-table td:last-child { font-weight: 500; }

/* --- Drawer (mobile filters) --------------------------------------------- */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(9, 14, 20, .5); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}
.scrim.open { opacity: 1; visibility: visible; }

.mobile-bar { display: none; }

/* --- Toast --------------------------------------------------------------- */
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-radius: var(--r-md);
  background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: toast-in var(--dur) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* --- Compare bar --------------------------------------------------------- */
.compare-bar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 70; display: none; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-pill); box-shadow: var(--shadow-lg);
}
.compare-bar.show { display: flex; }
.compare-count { font-size: 14px; font-weight: 600; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 1180px) {
  :root { --sidebar-w: 280px; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }

  /* Filters become a bottom sheet on touch layouts. */
  .sidebar {
    position: fixed; inset: auto 0 0 0; z-index: 70;
    max-height: 86vh; border-radius: var(--r-xl) var(--r-xl) 0 0;
    transform: translateY(101%);
    transition: transform 240ms var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar::before {
    content: ''; display: block; width: 40px; height: 4px; margin: 10px auto 0;
    background: var(--border-strong); border-radius: var(--r-pill);
  }
  .sidebar-head { top: 14px; }

  .mobile-bar {
    position: sticky; top: var(--header-h); z-index: 40;
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
  }
  .mobile-bar .btn { flex: 1; }
  .mobile-bar select { flex: 1; }

  .brand-sub { display: none; }
  .toolbar-right .desktop-only { display: none; }
  .results[data-view='list'] .card { flex-direction: column; }
  .results[data-view='list'] .card-media { width: 100%; aspect-ratio: 4 / 3; }
  .gallery { grid-template-columns: 1fr; max-height: none; }
  .gallery-side { grid-template-columns: 1fr 1fr; grid-template-rows: none; }
}

.btn-only-icon { display: none; }

@media (max-width: 640px) {
  .app-header { padding: 0 12px; gap: 10px; }
  .brand-name { display: none; }
  /* Give the query the full width; the submit button becomes an arrow. */
  .smart .btn-label { display: none; }
  .smart .btn-only-icon { display: block; }
  .smart .btn { width: 40px; padding: 0; }
  .layout { padding: 12px; }
  .results { grid-template-columns: 1fr; gap: 12px; }
  .modal { padding: 0; }
  .modal-panel { width: 100%; max-height: 100vh; height: 100%; border-radius: 0; }
  .result-count { font-size: 17px; }
  .toolbar { gap: 8px; }
  /* Keep the filter sheet clear of the home indicator / browser chrome. */
  .sidebar { padding-bottom: env(safe-area-inset-bottom, 0); }
  .compare-bar { left: 12px; right: 12px; transform: none; justify-content: space-between; }
}

/* --- Reduced motion ------------------------------------------------------ */
@media (pointer: coarse) {
  .check { min-height: 44px; }
  .seg button { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
  .card:hover .card-media img { transform: none; }
}

@media print {
  .app-header, .sidebar, .toolbar-right, .pagination, .compare-bar { display: none; }
  .layout { grid-template-columns: 1fr; }
}
