/* ── Tufte-inspired base ── */
@font-face {
  font-family: 'ET Book';
  src: url('https://cdn.jsdelivr.net/gh/edwardtufte/tufte-css@gh-pages/et-book/et-book-roman-line-figures/et-book-roman-line-figures.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ET Book';
  src: url('https://cdn.jsdelivr.net/gh/edwardtufte/tufte-css@gh-pages/et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ET Book';
  src: url('https://cdn.jsdelivr.net/gh/edwardtufte/tufte-css@gh-pages/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf') format('truetype');
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #fffff8;
  --text: #111;
  --text-light: #555;
  --text-lighter: #888;
  --border: #ddd;
  --border-light: #eee;
  --accent: #333;
  --link: #111;
  --card-hover: #f8f8f2;
  --card-active: #f0f0ea;
  --map-bg: #f2f2ea;
  --marker-border: #fff;
  --glass-bg: rgba(255,255,248,0.65);
  --glass-border: rgba(255,255,255,0.5);
  --glass-shadow: 0 -1px 0 rgba(0,0,0,0.04), 0 -4px 16px rgba(0,0,0,0.08), 0 -16px 48px rgba(0,0,0,0.12);
  --font: 'ET Book', Palatino, 'Palatino Linotype', Georgia, serif;
  --font-size-base: 19px;
  --line-height: 1.6;
  --sidebar-w: 520px;
  --content-max: 55ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --text: #d8d4cc;
    --text-light: #a8a49c;
    --text-lighter: #787470;
    --border: #3a3a36;
    --border-light: #2e2e2a;
    --accent: #d8d4cc;
    --link: #d8d4cc;
    --card-hover: #242420;
    --card-active: #2e2e2a;
    --map-bg: #1a1a18;
    --marker-border: #2a2a26;
    --glass-bg: rgba(26,26,24,0.70);
    --glass-border: rgba(255,255,255,0.08);
    --glass-shadow: 0 -1px 0 rgba(0,0,0,0.15), 0 -4px 16px rgba(0,0,0,0.25), 0 -16px 48px rgba(0,0,0,0.35);
    -webkit-font-smoothing: auto;
  }

}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
html.font-size-small { --font-size-base: 16px; }
html.font-size-large { --font-size-base: 23px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

a { color: var(--link); }
a:hover { color: var(--text-light); }

/* ── Layout ── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  transition: transform 0.3s ease, min-width 0.3s ease, width 0.3s ease;
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
#sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  min-width: 0;
  width: 0;
}

.sidebar-header {
  padding: 1.5rem 1.8rem 0;
  flex-shrink: 0;
}

/* Header row */
.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.2rem;
}

h1 {
  font-size: 1.6rem;
  font-weight: normal;
  font-style: italic;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

/* Lang toggle */
.lang-toggle {
  display: flex;
  gap: 0;
}
.lang-toggle button {
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-lighter);
  font-family: var(--font);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-toggle button:first-child { border-radius: 3px 0 0 3px; }
.lang-toggle button:last-child { border-radius: 0 3px 3px 0; border-left: none; }
.lang-toggle button.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Font size controls */
.font-controls {
  display: flex;
  gap: 0;
}
.font-controls button {
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.2;
}
.font-controls button:first-child { border-radius: 3px 0 0 3px; font-size: 0.65rem; }
.font-controls button:nth-child(2) { border-left: none; border-right: none; font-size: 0.75rem; }
.font-controls button:last-child { border-radius: 0 3px 3px 0; font-size: 0.85rem; }
.font-controls button:hover { background: var(--border-light); }
.font-controls button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.subtitle {
  font-size: 0.75rem;
  color: var(--text-lighter);
  letter-spacing: 0.08em;
  margin-bottom: 1.2rem;
}

/* Search */
.search-wrap {
  margin-bottom: 1rem;
}
.search-wrap input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-wrap input:focus { border-color: var(--text); }
.search-wrap input::placeholder { color: var(--text-lighter); font-style: italic; }

/* Filter sections */
.filter-section {
  margin-bottom: 0.8rem;
}
.filter-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-lighter);
  margin-bottom: 0.35rem;
  display: block;
}
.filter-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-light);
  font-family: var(--font);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: var(--text-light); }
.filter-btn.active {
  box-shadow: inset 0 0 0 3px var(--text);
}

/* Filter toggle (mobile only) */
#filter-toggle {
  display: none;
  width: 100%;
  padding: 0.5rem 0;
  border: none;
  background: transparent;
  color: var(--text-light);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
  text-decoration: underline;
  margin-bottom: 0.4rem;
}

.divider {
  height: 1px;
  background: var(--border-light);
  margin: 0.8rem 0 0.3rem;
}

/* Stats */
.stats-line {
  font-size: 0.7rem;
  color: var(--text-lighter);
  margin-bottom: 0.4rem;
  font-style: italic;
}
.filter-active-label {
  color: var(--text);
  font-style: normal;
  font-weight: bold;
}
.clear-filters-btn {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0.3rem 0.8rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.clear-filters-btn:hover { background: var(--border-light); }

/* ── Breeder list ── */
.breeder-list {
  padding: 0.3rem 0 2.5rem;
}

.breeder-card {
  padding: 0.8rem 1.8rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}
.breeder-card:hover { background: var(--card-hover); }
.breeder-card.active { background: var(--card-active); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.card-info { flex: 1; min-width: 0; }

.card-name-text {
  font-size: 1rem;
  font-weight: normal;
  color: var(--text);
  line-height: 1.3;
}
.card-sub {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.1rem;
  line-height: 1.4;
}

.card-badges {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0.15rem;
}

.badge {
  font-size: 0.55rem;
  font-weight: bold;
  padding: 0.12rem 0.4rem;
  border-radius: 2px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.3;
}
.badge-sztucznie {
  background: #fce4ec;
  color: #991b1b;
  border-color: #fca5a5;
}
.badge-naturalnie {
  background: #e0e0dc;
  color: #222;
  border-color: #bbb;
}
.filter-btn.badge-sztucznie.active {
  box-shadow: inset 0 0 0 3px #991b1b;
}
.filter-btn.badge-naturalnie.active {
  box-shadow: inset 0 0 0 3px #333;
}

/* Line badges */
.card-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.4rem;
}
/* Race badges (saturated) */
.race-carnica {
  background: #dbeafe;
  color: #1e40af;
  border-color: #93c5fd;
}
.race-caucasian {
  background: #fde68a;
  color: #92400e;
  border-color: #fcd34d;
}
.race-amm {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}
.race-cross {
  background: #f3e8ff;
  color: #6b21a8;
  border-color: #d8b4fe;
}
/* Line badges (lighter shade of parent race) */
.badge-line-carnica {
  background: #eff6ff;
  color: #3b82f6;
  border-color: #bfdbfe;
}
.badge-line-caucasian {
  background: #fef9c3;
  color: #b45309;
  border-color: #fde68a;
}
.badge-line-amm {
  background: #f0fdf4;
  color: #22c55e;
  border-color: #bbf7d0;
}
.badge-line-cross {
  background: #faf5ff;
  color: #a855f7;
  border-color: #e9d5ff;
}
.filter-btn.race-carnica.active {
  box-shadow: inset 0 0 0 3px #1e40af;
}
.filter-btn.race-caucasian.active {
  box-shadow: inset 0 0 0 3px #92400e;
}
.filter-btn.race-amm.active {
  box-shadow: inset 0 0 0 3px #166534;
}
.filter-btn.race-cross.active {
  box-shadow: inset 0 0 0 3px #6b21a8;
}

/* Card expanded details */
.card-details {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.85rem;
  line-height: 1.6;
}
.detail-row {
  margin-bottom: 0.4rem;
}
.detail-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-lighter);
  display: block;
}
.detail-value {
  color: var(--text);
}
.detail-value a {
  color: var(--text);
  text-decoration: underline;
}

/* Sidebar footer */
.sidebar-footer {
  position: fixed;
  bottom: -1px;
  left: 0;
  width: var(--sidebar-w);
  padding: 0.3rem 1.8rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg);
  font-size: 0.65rem;
  color: var(--text-lighter);
  display: flex;
  gap: 1rem;
  z-index: 11;
}
.sidebar-footer a {
  color: var(--text-lighter);
  text-decoration: underline;
  transition: color 0.15s;
}
.sidebar-footer a:hover { color: var(--text); }

.kontakt-link {
  margin-left: auto;
  text-decoration: none !important;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 3px;
  vertical-align: middle;
  border: 1px solid var(--border);
}

/* No results */
.no-results {
  padding: 2rem 1.8rem;
  color: var(--text-lighter);
  font-style: italic;
  font-size: 0.9rem;
}

/* ── Sidebar toggle (hidden on desktop) ── */
#sidebar-toggle { display: none; }

/* ── Large font: wider sidebar ── */
html.font-size-large { --sidebar-w: 690px; }

/* ── Map ── */
#map {
  flex: 1;
  height: 100%;
  z-index: 1;
  background: var(--map-bg);
}

/* ── Leaflet overrides ── */
.leaflet-popup-content-wrapper {
  background: var(--bg) !important;
  color: var(--text) !important;
  border-radius: 4px !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08) !important;
  font-family: var(--font) !important;
}
.leaflet-popup-tip { background: var(--bg) !important; }
.leaflet-popup-content {
  margin: 0.8rem 1rem !important;
  font-family: var(--font) !important;
  font-size: 0.85rem !important;
  line-height: 1.5 !important;
}
.leaflet-popup-close-button {
  color: var(--text-lighter) !important;
  font-size: 18px !important;
}
.leaflet-popup-close-button:hover { color: var(--text) !important; }

.leaflet-control-zoom a {
  background: var(--bg) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--border-light) !important; }

.leaflet-control-attribution {
  background: rgba(255,255,248,0.8) !important;
  font-size: 9px !important;
}

/* ── Custom markers ── */
.marker-pin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--marker-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform 0.2s ease;
  cursor: pointer;
}
.marker-pin:hover {
  transform: scale(1.4);
}
.marker-pin.selected {
  transform: scale(1.5);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.2);
}

/* Popup content */
.popup-title {
  font-size: 1rem;
  font-weight: normal;
  margin-bottom: 0.1rem;
}
.popup-business {
  font-size: 0.75rem;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 0.6rem;
}
.popup-row {
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  color: var(--text);
  line-height: 1.4;
}
.popup-row a {
  color: var(--text);
  text-decoration: underline;
}
.popup-badges {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.popup-lines {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.3rem;
  font-style: italic;
}

/* ── Bottom sheet (mobile) ── */
/* Receding background when sheet is open */
#app {
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
              border-radius 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
#app.sheet-open {
  transform: scale(0.94);
  border-radius: 14px;
  overflow: hidden;
}

.sheet-dim-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  backdrop-filter: blur(40px) saturate(180%);
  border-top: 0.5px solid var(--glass-border);
  border-radius: 14px 14px 0 0;
  padding: 0.6rem 1.4rem 2rem;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  box-shadow: var(--glass-shadow);
  z-index: 101;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}
.bottom-sheet.visible {
  transform: translateY(0);
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.15rem;
}
.sheet-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  color: var(--text-lighter);
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  font-family: var(--font);
}
.sheet-close:hover { color: var(--text); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Responsive: Mobile ── */
@media (max-width: 900px) {
  :root { --sidebar-w: 100%; }

  body { height: auto; overflow-x: hidden; overflow-y: auto; }
  #app { flex-direction: column; height: auto; max-width: 100vw; overflow-x: hidden; }

  #sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    border-right: none;
    overflow: visible;
  }

  #map { display: none; }

  .sidebar-header { padding: 1.2rem 1.2rem 0; }
  .breeder-card { padding: 0.8rem 1.2rem; }

  h1 { font-size: 1.4rem; }

}

@media (max-width: 480px) {
  .sidebar-header { padding: 1rem 1rem 0; }
  .breeder-card { padding: 0.7rem 1rem; }
  .header-row { flex-wrap: wrap; }
  .header-controls { width: 100%; justify-content: flex-end; margin-top: 0.3rem; }
}

/* ── Dark mode badge overrides (must come last to win specificity) ── */
@media (prefers-color-scheme: dark) {
  .badge-sztucznie { background: #2e1818; color: #c07070; border-color: #3e2424; }
  .badge-naturalnie { background: #242422; color: #8a8680; border-color: #3a3a36; }
  .filter-btn.badge-sztucznie.active { box-shadow: inset 0 0 0 3px #c07070; }
  .filter-btn.badge-naturalnie.active { box-shadow: inset 0 0 0 3px #8a8680; }

  .race-carnica { background: #1a2238; color: #6a90c8; border-color: #243050; }
  .race-caucasian { background: #2e2416; color: #b89848; border-color: #3e3420; }
  .race-amm { background: #162a20; color: #58a880; border-color: #223828; }
  .race-cross { background: #241838; color: #a080c8; border-color: #302448; }

  .badge-line-carnica { background: #1a2440; color: #6a9fe0; border-color: #253050; }
  .badge-line-caucasian { background: #332818; color: #d0a850; border-color: #443820; }
  .badge-line-amm { background: #182e24; color: #5cc490; border-color: #243e30; }
  .badge-line-cross { background: #281a40; color: #b490e0; border-color: #382a50; }

  .filter-btn.race-carnica.active { box-shadow: inset 0 0 0 3px #6a90c8; }
  .filter-btn.race-caucasian.active { box-shadow: inset 0 0 0 3px #b89848; }
  .filter-btn.race-amm.active { box-shadow: inset 0 0 0 3px #58a880; }
  .filter-btn.race-cross.active { box-shadow: inset 0 0 0 3px #a080c8; }

  .filter-active-label { color: var(--text); }

  .font-controls button { color: #787470; border-color: #3a3a36; }
  .font-controls button.active { background: #787470; color: var(--bg); border-color: #787470; }
  .font-controls button:hover { background: #2e2e2a; }

  .leaflet-popup-content-wrapper {
    background: var(--bg) !important;
    border-color: var(--border) !important;
  }
  .leaflet-popup-tip { background: var(--bg) !important; }
}
