:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f0f3ff;
  --text: #172033;
  --muted: #5c667a;
  --border: #e4e7ef;
  --border-strong: #ccd3e0;
  --primary: #244bdb;
  --primary-text: #ffffff;
  --shadow: rgba(15, 23, 42, 0.14);
  --modal-backdrop: rgba(11, 18, 32, 0.48);
  --success-bg: #eaf6ee;
  --success-text: #166534;
  --tisak-bg: #F01616;
  --tisak-soft: #fff1f1;
  --tisak-text: #b00000;
  --inovine-bg: #000235;
  --inovine-soft: #eef5ff;
  --inovine-text: #000235;
  --warning-bg: #fff7ed;
  --warning-text: #9a3412;
  --topbar-padding-y: 16px;
  --topbar-padding-x: 22px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #172033;
  --surface-3: #1e2a44;
  --text: #e5e7eb;
  --muted: #aab4c5;
  --border: #283447;
  --border-strong: #3a4659;
  --primary: #5f7cff;
  --primary-text: #ffffff;
  --shadow: rgba(0, 0, 0, 0.42);
  --modal-backdrop: rgba(0, 0, 0, 0.62);
  --success-bg: #113222;
  --success-text: #8de4ae;
  --tisak-soft: #391414;
  --tisak-text: #ff9b9b;
  --inovine-soft: #1a2444;
  --inovine-text: #cbd8ff;
  --warning-bg: #3b2511;
  --warning-text: #f9c38d;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: calc(var(--topbar-padding-y) + env(safe-area-inset-top)) calc(var(--topbar-padding-x) + env(safe-area-inset-right)) var(--topbar-padding-y) calc(var(--topbar-padding-x) + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-copy {
  min-width: 0;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: clamp(20px, 3.5vw, 24px);
  line-height: 1.15;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.theme-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 850;
  box-shadow: 0 2px 8px var(--shadow);
}

.theme-toggle-icon {
  font-size: 17px;
  line-height: 1;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
}

.panel {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-right: 1px solid var(--border);
  overscroll-behavior: contain;
}

.map-wrap,
#map {
  min-height: 420px;
  height: 100%;
}

#map {
  background: var(--surface-2);
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input,
button {
  font: inherit;
  border-radius: 10px;
}

input {
  min-width: 0;
  flex: 1;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
}

button {
  border: 0;
  min-height: 44px;
  padding: 11px 13px;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 800;
}

button:hover,
a.map-choice:hover {
  filter: brightness(0.95);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
.result-card:focus-visible,
.filter-pill:focus-within {
  outline: 3px solid color-mix(in srgb, var(--primary) 70%, transparent);
  outline-offset: 2px;
}

.provider-filter {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 12px;
}

.filter-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 850;
  cursor: pointer;
  user-select: none;
}

.filter-pill:hover {
  border-color: var(--primary);
}

.filter-pill input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  padding: 0;
  accent-color: var(--primary);
}

.filter-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  line-height: 1;
}

.filter-marker-tisak {
  background: var(--tisak-bg);
}

.filter-marker-inovine {
  background: var(--inovine-bg);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
}

.status {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.results {
  padding-bottom: 4px;
}

.result-card {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  color: inherit;
  cursor: pointer;
  box-shadow: 0 1px 3px var(--shadow);
}

.result-card:hover {
  border-color: var(--primary);
}

.result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.result-title {
  font-weight: 850;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.result-meta {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.directions-choice {
  border: 0;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 850;
}

.directions-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 999px;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-indent: -999px;
  position: relative;
}

.directions-btn::before {
  content: "🧭";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-indent: 0;
}

.directions-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 6px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
}

.badges-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--success-text);
  font-size: 13px;
  font-weight: 750;
}

.provider-badge,
.popup-provider {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 850;
}

.popup-provider {
  margin-bottom: 6px;
}

.provider-badge.provider-tisak,
.popup-provider.provider-tisak {
  background: var(--tisak-soft);
  color: var(--tisak-text);
}

.provider-badge.provider-inovine,
.popup-provider.provider-inovine {
  background: var(--inovine-soft);
  color: var(--inovine-text);
}

.leaflet-container {
  font-family: inherit;
  color: #172033;
}

.leaflet-popup-content {
  width: auto !important;
  margin: 13px 16px;
}

.leaflet-popup-content-wrapper {
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 55px var(--shadow);
}

.leaflet-popup-tip {
  background: var(--surface);
}

.leaflet-control-zoom a,
.leaflet-control-attribution {
  color: #172033;
}

html[data-theme="dark"] .leaflet-tile {
  filter: brightness(0.72) contrast(1.08) saturate(0.82);
}

html[data-theme="dark"] .leaflet-control-zoom a,
html[data-theme="dark"] .leaflet-control-attribution {
  background: #111827;
  color: #e5e7eb;
  border-color: #283447;
}

.popup {
  width: min(430px, calc(100vw - 88px));
  max-width: 430px;
  overflow: visible;
  padding-right: 0;
}

.popup h3 {
  margin: 0 0 6px;
  font-size: 17px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.popup p {
  margin: 3px 0;
}

.location-note {
  margin-top: 5px !important;
  padding: 6px 8px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 13px;
}

.location-note-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.popup-services {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.popup-services-title {
  margin-bottom: 6px;
  font-weight: 850;
}

.popup-services-list {
  max-height: min(230px, 33dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 8px 4px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.popup-services-list:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.popup-services-empty {
  color: var(--muted);
}

.popup ul {
  margin: 0 0 0 17px;
  padding: 0;
}

.popup li + li {
  margin-top: 3px;
}

.custom-marker-icon,
.tisak-marker-icon,
.inovine-marker-icon {
  background: transparent;
  border: 0;
}

.brand-marker {
  position: relative;
  width: 32px;
  height: 32px;
  border: 2px solid #fff;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.brand-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  z-index: -1;
  width: 11px;
  height: 11px;
  transform: translateX(-50%) rotate(45deg);
  border-radius: 0 0 3px 0;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.20);
}

.tisak-marker {
  background: var(--tisak-bg);
  font-size: 21px;
  line-height: 28px;
  font-family: Arial, Helvetica, sans-serif;
}

.tisak-marker::after {
  background: var(--tisak-bg);
}

.inovine-marker {
  background: var(--inovine-bg);
  font-size: 23px;
  line-height: 27px;
  font-family: Georgia, "Times New Roman", serif;
}

.inovine-marker::after {
  background: var(--inovine-bg);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: var(--modal-backdrop);
}

.modal-backdrop.is-open {
  display: flex;
}

.directions-modal {
  position: relative;
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
}

.directions-modal h2 {
  margin: 0 36px 8px 0;
  font-size: 21px;
}

.directions-modal p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.map-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 900;
  text-decoration: none;
}

.map-choice-apple {
  background: var(--text);
  color: var(--surface);
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .topbar {
    --topbar-padding-y: 12px;
    --topbar-padding-x: 14px;
    align-items: center;
  }

  .topbar p {
    font-size: 13px;
  }

  .layout {
    display: flex;
    flex-direction: column;
  }

  .panel {
    flex: 0 0 auto;
    height: clamp(270px, 42dvh, 380px);
    max-height: 44dvh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px;
  }

  .map-wrap {
    flex: 1 1 auto;
    min-height: 260px;
  }

  .map-wrap,
  #map {
    height: 100%;
  }

  .leaflet-control-zoom a {
    width: 34px;
    height: 34px;
    line-height: 34px;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 10px;
  }

  .topbar h1 {
    font-size: 19px;
  }

  .topbar p {
    display: none;
  }

  .theme-toggle {
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 999px;
  }

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

  .search-row {
    gap: 7px;
  }

  .search-row button {
    flex: 0 0 auto;
  }

  input,
  button {
    font-size: 16px;
  }

  .provider-filter,
  .modal-actions {
    grid-template-columns: 1fr 1fr;
  }

  .filter-pill {
    padding: 9px 8px;
  }

  .result-card {
    padding: 11px;
  }

  .popup {
    width: min(330px, calc(100vw - 72px));
  }

  .popup-services-list {
    max-height: 160px;
  }

  .directions-modal {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .provider-filter,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .panel {
    height: 46dvh;
    max-height: 46dvh;
  }

  .popup {
    width: min(300px, calc(100vw - 64px));
  }
}

@supports not (height: 100dvh) {
  body {
    min-height: 100vh;
  }

  .panel {
    height: 42vh;
  }
}

/* --- Mobile map-first layout: bottom drawer controls --- */
.mobile-panel-toggle,
.mobile-panel-backdrop,
.panel-mobile-header {
  display: none;
}

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
  }

  .topbar {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    right: calc(10px + env(safe-area-inset-right));
    z-index: 820;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: 0 10px 34px var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .topbar h1 {
    margin: 0;
    font-size: clamp(16px, 4.5vw, 19px);
    line-height: 1.15;
  }

  .topbar p {
    display: none;
  }

  .theme-toggle {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 999px;
  }

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

  .layout {
    display: block;
    flex: none;
    height: 100dvh;
    min-height: 100dvh;
  }

  .map-wrap {
    position: fixed;
    inset: 0;
    z-index: 1;
    min-height: 100dvh;
    height: 100dvh;
  }

  #map {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
  }

  .leaflet-top.leaflet-left {
    top: calc(82px + env(safe-area-inset-top));
  }

  .mobile-panel-toggle {
    position: fixed;
    left: 50%;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 850;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 158px;
    min-height: 50px;
    padding: 12px 18px;
    border-radius: 999px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  }

  html.mobile-panel-open .mobile-panel-toggle {
    display: none;
  }

  .mobile-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 880;
    display: block;
    background: rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
  }

  .mobile-panel-backdrop[hidden] {
    display: none;
  }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    height: min(78dvh, 680px);
    max-height: calc(100dvh - 78px - env(safe-area-inset-top));
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-top: 1px solid var(--border);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.26);
    transform: translateY(110%);
    transition: transform 220ms ease;
    overscroll-behavior: contain;
  }

  html.mobile-panel-open .panel {
    transform: translateY(0);
  }

  .panel-mobile-header {
    position: sticky;
    top: -12px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -12px -12px 12px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 22px 22px 0 0;
  }

  .panel-mobile-header::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 46px;
    height: 4px;
    transform: translateX(-50%);
    border-radius: 999px;
    background: var(--border-strong);
  }

  .panel-mobile-header strong {
    padding-top: 8px;
    font-size: 15px;
  }

  .mobile-panel-close {
    width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
  }

  .search-row {
    gap: 8px;
  }

  .search-row button {
    flex: 0 0 auto;
  }

  input,
  button {
    font-size: 16px;
  }

  .provider-filter,
  .modal-actions {
    grid-template-columns: 1fr 1fr;
  }

  .results {
    padding-bottom: 12px;
  }

  .result-card {
    padding: 12px;
  }

  .popup {
    width: min(330px, calc(100vw - 72px));
  }

  .popup-services-list {
    max-height: 160px;
  }

  .directions-modal {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .provider-filter,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .mobile-panel-toggle {
    min-width: 142px;
  }

  .popup {
    width: min(300px, calc(100vw - 64px));
  }
}
