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

:root {
  --sidebar-width: 360px;
  --header-height: 64px;
  --red: #d32f2f;
  --red-light: #ffebee;
  --red-dark: #b71c1c;
  --green: #388e3c;
  --blue: #1565c0;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-600: #757575;
  --gray-800: #424242;
  --gray-900: #212121;
  --bg-surface: #ffffff;
  --bg-body: #ffffff;
  --text-on-header: #ffffff;
  --btn-primary-hover: #0d47a1;
  --header-bg: #212121;
  color-scheme: light;
}

html[data-theme="dark"] {
  --red: #ef5350;
  --red-light: #4e1a1a;
  --red-dark: #c62828;
  --green: #66bb6a;
  --blue: #42a5f5;
  --gray-100: #1e1e1e;
  --gray-200: #2c2c2c;
  --gray-300: #3a3a3a;
  --gray-600: #9e9e9e;
  --gray-800: #cccccc;
  --gray-900: #e0e0e0;
  --bg-surface: #121212;
  --bg-body: #0e0e0e;
  --text-on-header: #e0e0e0;
  --btn-primary-hover: #1976d2;
  --header-bg: #1e1e1e;
  color-scheme: dark;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--gray-900);
  background: var(--bg-body);
  height: 100vh;
  overflow: hidden;
}

/* Header */
#header {
  height: var(--header-height);
  background: var(--header-bg);
  color: var(--text-on-header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  z-index: 1000;
}

#header .stats {
  flex: 1;
  text-align: right;
}

.header-icon-link,
.header-info {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  padding: 4px;
}

html[data-theme="dark"] .header-icon-link,
html[data-theme="dark"] .header-info {
  color: rgba(224, 224, 224, 0.6);
}

.header-icon-link:hover,
.header-info:hover {
  color: var(--text-on-header);
}

#header .header-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

#header h1 {
  font-size: 1.2rem;
  font-weight: 600;
}

#header .subtitle {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.7;
}

.stats {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

html[data-theme="dark"] .stats {
  color: rgba(224, 224, 224, 0.85);
}

.stats strong {
  color: #ffcdd2;
}

.stats-short {
  display: none;
}

.stats-date {
  display: block;
  font-size: 0.75rem;
  opacity: 0.6;
}

/* Main layout */
#main {
  display: flex;
  height: calc(100vh - var(--header-height));
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--gray-300);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#sidebar.has-more-content::after {
  content: '\2304';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--gray-500);
  background: linear-gradient(transparent, var(--bg-surface) 40%);
  padding: 12px 0 4px;
  pointer-events: none;
}

#search-box {
  padding: 12px;
  border-bottom: 1px solid var(--gray-300);
}

.search-wrapper {
  position: relative;
}

#search-input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
  background: var(--bg-surface);
  color: var(--gray-900);
}

#search-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.15);
}

.search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--gray-600);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.search-clear:hover {
  color: var(--gray-900);
  background: var(--gray-200);
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
}

#authority-detail {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.hidden {
  display: none !important;
}

/* Authority list */
.authority-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  transition: background 0.15s;
}

.authority-item:hover {
  background: var(--gray-200);
}

.authority-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.authority-type {
  font-size: 0.75rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.authority-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

.inaccessible-count {
  font-size: 0.85rem;
  font-weight: 600;
}

.accessible-count {
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
}

.authority-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.authority-bar-row .inaccessible-bar {
  flex: 1;
}

.inaccessible-bar {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
}

.inaccessible-bar-fill {
  height: 100%;
  background: var(--red);
  border-radius: 3px;
}


/* Private notice */
.privaat-notice {
  font-size: 0.85rem;
  color: var(--gray-600);
  font-style: italic;
}

/* Back button */
.back-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--gray-100);
  border: none;
  border-bottom: 1px solid var(--gray-300);
  cursor: pointer;
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  color: var(--blue);
  font-weight: 500;
}

.back-btn:hover {
  background: var(--gray-200);
}

/* Authority detail */
.detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.detail-header h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.detail-header .authority-type {
  margin-bottom: 8px;
}

.detail-stats {
  display: flex;
  gap: 16px;
  margin: 12px 0;
}

.detail-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.detail-bar-row .inaccessible-bar {
  flex: 1;
}

.detail-bar-pct {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.detail-stat {
  flex: 1;
  text-align: center;
}

.detail-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.red { color: var(--red); }
.green { color: var(--green); }

.detail-stat-label {
  font-size: 0.75rem;
  color: var(--gray-600);
  margin-top: 2px;
}

.detail-contact {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-top: 8px;
}

.detail-contact div {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.detail-contact svg {
  flex-shrink: 0;
}

.detail-contact a {
  color: var(--blue);
  text-decoration: none;
}

.detail-contact a:hover {
  text-decoration: underline;
}

.detail-actions {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
}

.detail-actions .btn {
  display: block;
  width: 100%;
  text-align: center;
}

.stop-list {
  list-style: none;
}

.stop-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.85rem;
}

.stop-item:hover {
  background: var(--gray-200);
}

.stop-name {
  font-weight: 500;
}

.stop-town {
  color: var(--gray-600);
  font-size: 0.8rem;
}

/* Map */
#map {
  flex: 1;
  z-index: 1;
}

/* Stop marker (divIcon reset) */
.stop-marker {
  background: none;
  border: none;
}

/* Cluster overrides */
.marker-cluster-small {
  background-color: rgba(211, 47, 47, 0.2);
}
.marker-cluster-small div {
  background-color: rgba(211, 47, 47, 0.6);
  color: #ffffff;
}
.marker-cluster-medium {
  background-color: rgba(211, 47, 47, 0.3);
}
.marker-cluster-medium div {
  background-color: rgba(211, 47, 47, 0.7);
  color: #ffffff;
}
.marker-cluster-large {
  background-color: rgba(211, 47, 47, 0.4);
}
.marker-cluster-large div {
  background-color: rgba(211, 47, 47, 0.8);
  color: #ffffff;
}

/* Popup */
.stop-popup {
  min-width: 260px;
}

.stop-popup h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.stop-popup .btn {
  font-size: 0.8rem;
  padding: 4px 10px;
  margin-top: 8px;
}

.popup-sv-link {
  display: inline-block;
  margin: 8px 0 4px;
  color: var(--blue);
  text-decoration: none;
  font-size: 0.8rem;
}

.popup-sv-link:hover {
  text-decoration: underline;
}

.popup-btn-full {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 8px;
}

dl.popup-details {
  margin: 0 0 4px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0;
  font-size: 0.8rem;
}

dl.popup-details dt,
dl.popup-details dd {
  padding: 2px 0;
  border-bottom: 1px solid var(--gray-200);
  margin: 0;
}

dl.popup-details dt:last-of-type,
dl.popup-details dd:last-of-type {
  border-bottom: none;
}

dl.popup-details dt {
  color: var(--gray-600);
  font-weight: 500;
  padding-right: 12px;
}

.popup-icon {
  vertical-align: -2px;
  margin-right: 2px;
}

dl.popup-details dd {
  text-align: right;
  word-break: break-word;
}

.stop-popup:focus {
  outline: none;
}

.popup-privaat {
  font-size: 0.8rem;
  color: var(--gray-600);
  font-style: italic;
  margin-top: 8px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--blue);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-800);
}

.btn-secondary:hover {
  background: var(--gray-300);
}

.btn-danger {
  background: var(--red);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--red-dark);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-content {
  background: var(--bg-surface);
  border-radius: 12px;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-300);
}

.modal-header h2 {
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-600);
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--gray-900);
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.field-group {
  margin-bottom: 12px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.field-label-row label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin: 0;
}

.copy-field-btn {
  background: none;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.7rem;
  color: var(--blue);
  cursor: pointer;
  transition: background 0.15s;
}

.copy-field-btn:hover {
  background: var(--gray-100);
}

.email-field {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  background: var(--bg-surface);
  color: var(--gray-900);
}

.email-field:focus {
  outline: none;
  border-color: var(--blue);
}

.email-field[readonly] {
  background: var(--gray-100);
  color: var(--gray-800);
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-300);
}

.btn-full {
  display: block;
  width: 100%;
  text-align: center;
}

.btn-disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Info modal */
.modal-info {
  max-width: 520px;
}

.info-body p {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--gray-800);
  margin-bottom: 12px;
}

.info-body h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 16px 0 6px;
  color: var(--gray-900);
}

.info-body ul {
  list-style: none;
  padding: 0;
  margin-bottom: 12px;
}

.info-body li {
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 4px 0;
  border-bottom: 1px solid var(--gray-200);
}

.info-body li:last-child {
  border-bottom: none;
}

#welcome-modal ul {
  list-style: none;
  padding: 0;
}

#welcome-modal li {
  border-bottom: none;
  padding: 8px 0;
  position: relative;
  margin-bottom: 8px;
  text-align: center;
}

#welcome-modal li::after {
  content: '\2193';
  display: block;
  text-align: center;
  color: var(--gray-500);
  font-size: 1rem;
  margin-top: 8px;
}

.info-body a {
  color: var(--blue);
  text-decoration: none;
}

.info-body a:hover {
  text-decoration: underline;
}

.info-copyright {
  text-align: center;
  color: var(--gray-600);
  font-size: 0.8rem;
  margin-top: 16px;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--header-bg);
  color: var(--text-on-header);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 3000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

/* Loading overlay */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--gray-600);
  font-size: 0.9rem;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.authority-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  background: var(--gray-100);
}

.stop-item:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  background: var(--gray-100);
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  position: static;
}

/* Article page */
.page-body {
  height: auto;
  overflow: visible;
  background: var(--bg-body);
}

.page-header {
  height: var(--header-height);
  background: var(--header-bg);
  color: var(--text-on-header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
}

.page-header a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s;
}

.page-header a:hover {
  color: var(--text-on-header);
}

.page-header a:focus-visible {
  outline: 2px solid var(--text-on-header);
  outline-offset: 2px;
}

.page-header h1 {
  font-size: 1.2rem;
  font-weight: 600;
}

.page-container {
  max-width: 740px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-container h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gray-900);
  margin: 40px 0 12px;
  padding-top: 8px;
  border-top: 2px solid var(--gray-200);
}

.page-container h2:first-of-type {
  border-top: none;
  margin-top: 24px;
}

.page-container h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-900);
  margin: 24px 0 8px;
}

.page-container p {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--gray-800);
  margin-bottom: 12px;
}

.page-container .intro {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--gray-800);
}

.page-container .updated-date {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: -8px;
}

.page-container ul,
.page-container ol {
  margin: 0 0 16px 20px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--gray-800);
}

.page-container li {
  margin-bottom: 4px;
}

.page-container table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.9rem;
}

.page-container th,
.page-container td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-200);
}

.page-container th {
  font-weight: 600;
  color: var(--gray-900);
  background: var(--gray-100);
  border-bottom: 2px solid var(--gray-300);
}

.page-container td {
  color: var(--gray-800);
}

.page-container a {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-color: rgba(21, 101, 192, 0.3);
  text-underline-offset: 2px;
}

.page-container a:hover {
  text-decoration-color: var(--blue);
}

.page-container a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.page-container .sources-list {
  list-style: none;
  margin-left: 0;
  padding: 0;
}

.page-container .sources-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 0;
}

.page-container .sources-list li:last-child {
  border-bottom: none;
}

/* Stat highlight */
.stat-highlight {
  color: var(--red);
}

/* Conclusions list */
.conclusions-list {
  list-style: none;
  margin-left: 0;
  padding: 0;
}

.conclusions-list li {
  position: relative;
  padding: 8px 0 8px 24px;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 0;
}

.conclusions-list li:last-child {
  border-bottom: none;
}

.conclusions-list li::before {
  content: "\2192";
  position: absolute;
  left: 0;
  color: var(--red);
  font-weight: 600;
}

.info-link {
  display: block;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0;
  text-decoration: none;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}

.info-link:hover {
  background: var(--gray-200);
  border-color: var(--blue);
}

.info-link:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* Theme toggle */
#theme-toggle {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  padding: 4px;
}

html[data-theme="dark"] #theme-toggle {
  color: rgba(224, 224, 224, 0.6);
}

#theme-toggle:hover {
  color: var(--text-on-header);
}

/* Leaflet dark mode overrides */
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
  background: var(--bg-surface);
  color: var(--gray-900);
}

html[data-theme="dark"] .leaflet-bar a {
  background-color: var(--bg-surface);
  color: var(--gray-900);
  border-bottom-color: var(--gray-300);
}

html[data-theme="dark"] .leaflet-bar a:hover {
  background-color: var(--gray-200);
}

html[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(18, 18, 18, 0.8);
  color: var(--gray-600);
}

html[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--gray-600);
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  #main {
    flex-direction: column;
  }

  #sidebar {
    height: auto;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--gray-300);
  }

  #sidebar-content {
    display: none;
  }

  #sidebar.sidebar-list-visible {
    max-height: 100%;
  }

  #sidebar.sidebar-list-visible #sidebar-content {
    display: block;
    overflow-y: auto;
  }

  #sidebar.sidebar-detail-visible {
    height: 40vh;
  }

  #map {
    flex: 1;
    min-height: 0;
  }

  #header h1 {
    font-size: 1rem;
  }

  .stats {
    font-size: 0.8rem;
  }

  .stats-full {
    display: none;
  }

  .stats-short {
    display: inline;
  }

  .stats-date {
    display: none;
  }

  #header .subtitle {
    display: none;
  }

  .page-container {
    padding: 24px 16px 48px;
  }

  .page-container table {
    font-size: 0.8rem;
  }

  .page-container th,
  .page-container td {
    padding: 8px;
  }
}
