:root {
  color-scheme: light;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --bg: #eef3f7;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-muted: #f7fafc;
  --text: #17212b;
  --text-soft: #526172;
  --line: #d5dee8;
  --line-strong: #b8c5d4;
  --shadow: 0 18px 44px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 10px 26px rgba(15, 23, 42, 0.08);
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --success: #16a34a;
  --warning: #f97316;
  --danger: #dc2626;
  --muted: #9ca3af;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.1), transparent 24%),
    radial-gradient(circle at top right, rgba(22, 163, 74, 0.08), transparent 18%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

button,
input,
select,
textarea,
.legend,
.panel-card,
.toolbar {
  min-width: 0;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 12px;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  border-color: transparent;
  color: #fff;
}

button.success {
  background: var(--success);
  border-color: transparent;
  color: #fff;
}

button.danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

button.compact {
  min-height: 40px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
}

body > .toolbar,
body > main {
  width: min(1240px, calc(100vw - 24px));
  margin-left: auto;
  margin-right: auto;
}

.toolbar {
  flex: 0 0 auto;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
  margin-top: max(8px, env(safe-area-inset-top));
  margin-bottom: 10px;
  padding: 0.8rem 0.95rem;
  border: 1px solid rgba(213, 222, 232, 0.9);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
}

.toolbar h1 {
  margin: 0;
  font-size: clamp(1.05rem, 0.96rem + 0.45vw, 1.35rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.75rem;
}

.icon-toggle,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  font-weight: 600;
  font-size: 1.35rem;
}

.icon-toggle {
  cursor: pointer;
  position: relative;
}

.icon-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.icon-toggle:has(input:checked) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.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;
}

main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.map-shell {
  position: relative;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(213, 222, 232, 0.9);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-add-button {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 850;
  width: min(280px, calc(100% - 32px));
  margin-inline: auto;
  box-shadow: var(--shadow-soft);
}

.bench-list-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1100;
  width: min(430px, calc(100% - 24px));
  max-height: min(620px, calc(100% - 24px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0.9rem;
  padding: 0.95rem;
  border: 1px solid rgba(213, 222, 232, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.global-history-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1110;
  width: min(480px, calc(100% - 24px));
  max-height: min(680px, calc(100% - 24px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.9rem;
  padding: 0.95rem;
  border: 1px solid rgba(213, 222, 232, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.bench-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.bench-list-title {
  display: grid;
  gap: 0.22rem;
  min-width: 0;
}

.bench-list-header h2 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.bench-list-count {
  color: var(--text-soft);
  font-size: 0.78rem;
  line-height: 1.15;
}

.compact-square {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border-radius: 10px;
  font-size: 1.15rem;
}

.bench-sort {
  display: grid;
  gap: 0.35rem;
  color: var(--text-soft);
  font-size: 0.85rem;
}

.bench-sort select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 16px;
}

.bench-list {
  display: grid;
  gap: 0.7rem;
  overflow: auto;
  padding: 0.05rem 0.2rem 0.1rem 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.bench-list-item {
  display: grid;
  align-items: stretch;
  width: 100%;
  min-height: 78px;
  padding: 0.78rem 0.85rem;
  text-align: left;
  border-radius: 14px;
  border-color: rgba(203, 213, 225, 0.95);
  background: #ffffff;
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.06);
}

.bench-list-item:hover {
  transform: none;
  border-color: var(--line-strong);
}

.bench-list-main {
  display: grid;
  align-content: center;
  gap: 0.5rem;
  min-width: 0;
}

.bench-list-topline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.bench-list-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 1.45rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.bench-list-topline strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.18;
}

.bench-list-details {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.38rem 0.5rem;
  color: var(--text-soft);
  font-size: 0.8rem;
  line-height: 1.2;
}

.bench-list-status,
.bench-list-date,
.bench-list-photo {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  white-space: nowrap;
}

.bench-list-status {
  gap: 0.36rem;
  padding: 0.18rem 0.52rem 0.18rem 0.34rem;
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid rgba(213, 222, 232, 0.9);
}

.bench-list-date {
  padding: 0.18rem 0.52rem;
  background: #f8fafc;
  border: 1px solid rgba(226, 232, 240, 0.95);
}

.bench-list-item.is-overdue .bench-list-date {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.bench-list-photo {
  order: -1;
  padding: 0.16rem 0.42rem;
  color: #155e75;
  background: #ecfeff;
  border: 1px solid #bae6fd;
}

.bench-list-photo.is-missing {
  color: #64748b;
  background: #f8fafc;
  border-color: #e2e8f0;
}

.bench-list-empty {
  margin: 0;
  padding: 1rem 0.75rem;
  color: var(--text-soft);
  font-size: 0.86rem;
}

.bench-list-item .dot {
  width: 0.68rem;
  height: 0.68rem;
  margin-right: 0;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.05);
}

.legend {
  position: absolute;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 500;
  max-width: min(300px, calc(100% - 24px));
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(213, 222, 232, 0.78);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  pointer-events: none;
}

.map-shell.is-admin .legend {
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px);
}

.legend h2 {
  margin: 0 0 0.55rem;
  font-size: 0.86rem;
  line-height: 1.1;
}

.legend ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem 0.7rem;
}

.legend li {
  display: flex;
  align-items: center;
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.2;
  white-space: nowrap;
}

.location-accuracy-note {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 650;
  max-width: min(220px, calc(100% - 92px));
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(191, 219, 254, 0.9);
  border-radius: 999px;
  background: rgba(239, 246, 255, 0.86);
  color: #1e3a8a;
  font-size: 0.74rem;
  line-height: 1.15;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.dot {
  width: 0.68rem;
  height: 0.68rem;
  display: inline-block;
  flex: 0 0 auto;
  border-radius: 999px;
  margin-right: 0.4rem;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.good { background: var(--success); }
.ok { background: var(--warning); }
.to_check { background: var(--warning); }
.repair { background: var(--danger); }
.removed { background: var(--muted); }
.inactive { background: #6b7280; }

.bench-marker-icon {
  background: transparent;
  border: 0;
}

.bench-marker-pin {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #fff;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.18), 0 5px 16px rgba(15, 23, 42, 0.18);
}

.bench-marker-icon.is-moving .bench-marker-pin {
  background: #facc15 !important;
  border-color: #111827;
  color: #111827;
  box-shadow:
    0 0 0 6px rgba(250, 204, 21, 0.35),
    0 0 0 12px rgba(37, 99, 235, 0.18),
    0 10px 24px rgba(15, 23, 42, 0.28);
}

.bench-marker-icon.is-inactive .bench-marker-pin {
  opacity: 0.82;
  filter: grayscale(0.25);
}

.bench-marker-number {
  display: block;
  width: 100%;
  overflow: hidden;
  text-align: center;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.28);
  user-select: none;
}

.bench-marker-icon.is-missing-photo .bench-marker-pin {
  border-style: dashed;
}

.bench-marker-photo-missing {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 8px;
  height: 8px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
}

.leaflet-municipalityMask-pane,
.leaflet-municipalityBoundary-pane {
  pointer-events: none;
  will-change: transform;
}

.bench-marker-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
}

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

.leaflet-control-layers {
  position: relative;
  z-index: 650;
  border: 1px solid rgba(184, 197, 212, 0.9);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.leaflet-top,
.leaflet-bottom {
  z-index: 700;
}

.editor-panel,
.bench-list-panel,
.global-history-panel,
.position-edit-bar {
  z-index: 1200;
}

.leaflet-popup-content-wrapper {
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.leaflet-popup {
  max-width: calc(100vw - 16px);
}

.leaflet-popup-content {
  width: min(520px, calc(100vw - 56px));
  min-width: min(360px, calc(100vw - 56px));
  max-width: min(520px, calc(100vw - 56px));
  margin: 1rem;
}

.popup-card,
.popup-editor {
  display: grid;
  gap: 0.55rem;
}

.photo-field {
  display: grid;
  gap: 0.55rem;
}

.photo-remove-note {
  color: #991b1b;
  font-size: 0.82rem;
  line-height: 1.35;
}

.photo-preview,
.popup-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-muted);
}

.popup-photo {
  max-height: 220px;
}

.popup-header {
  display: grid;
  gap: 0.2rem;
}

.popup-header strong {
  font-size: 1rem;
  line-height: 1.3;
}

.popup-header small {
  color: var(--text-soft);
}

.popup-meta,
.popup-notes {
  display: grid;
  gap: 0.35rem;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

.popup-editor label {
  display: grid;
  gap: 0.32rem;
  font-size: 0.9rem;
  color: var(--text-soft);
}

.inspection-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0.45rem;
}

.popup-editor input,
.popup-editor select,
.popup-editor textarea,
#fieldName,
#fieldNamePreset,
#fieldInspection,
#fieldStatus,
#fieldActive,
#fieldImage,
#fieldNotes {
  width: 100%;
  font-size: 16px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  background: var(--surface-strong);
  color: var(--text);
}

.popup-editor textarea,
#fieldNotes {
  min-height: 82px;
  resize: vertical;
}

.popup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.popup-actions button {
  width: 100%;
}

.popup-move {
  display: grid;
  gap: 0.55rem;
  padding: 0.7rem;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.popup-move small {
  color: var(--text-soft);
}

.popup-position-preview {
  display: block;
  word-break: break-word;
}

.popup-overdue {
  border-radius: 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.6rem 0.7rem;
  font-size: 0.83rem;
  line-height: 1.4;
}

.editor-panel {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(920px, calc(100% - 24px));
  max-height: calc(100% - 28px);
  z-index: 900;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.panel-card {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(213, 222, 232, 0.95);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.15rem;
  backdrop-filter: blur(12px);
}

.position-edit-bar {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1000;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.85rem;
  width: min(760px, calc(100% - 24px));
  padding: 0.8rem;
  border: 1px solid rgba(184, 197, 212, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.position-edit-text {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.position-edit-text strong,
.position-edit-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.position-edit-text span {
  color: var(--text-soft);
  font-size: 0.86rem;
}

.position-edit-actions {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.55rem;
}

.panel-card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  line-height: 1.3;
}

#benchForm {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

#benchForm label {
  display: grid;
  gap: 0.38rem;
  font-size: 0.92rem;
  color: var(--text-soft);
}

.full-width {
  grid-column: 1 / -1;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.1rem;
  padding-top: 0.15rem;
}

.history-section {
  display: grid;
  gap: 0.6rem;
  padding: 0.75rem;
  border: 1px solid rgba(213, 222, 232, 0.95);
  border-radius: 14px;
  background: rgba(248, 250, 252, 0.9);
}

.history-header,
.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.history-header h3 {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.2;
}

.history-header span {
  color: var(--text-soft);
  font-size: 0.78rem;
}

.history-list {
  display: grid;
  gap: 0.48rem;
  max-height: 190px;
  overflow: auto;
  overscroll-behavior: contain;
}

.history-item {
  display: grid;
  gap: 0.3rem;
  padding: 0.58rem 0.62rem;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 12px;
  background: #fff;
}

.history-item-top strong {
  font-size: 0.84rem;
  line-height: 1.25;
}

.history-item-top span,
.history-item small,
.history-empty {
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.25;
}

.history-empty {
  margin: 0;
}

.history-changes {
  display: grid;
  gap: 0.24rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-changes li {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.25;
}

.history-changes b {
  max-width: 55%;
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-history-list {
  display: grid;
  gap: 0.62rem;
  overflow: auto;
  padding-right: 0.1rem;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.global-history-item {
  display: grid;
  gap: 0.38rem;
  padding: 0.72rem;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.05);
  cursor: pointer;
}

.global-history-item:hover {
  border-color: var(--line-strong);
}

.global-history-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
}

.global-history-top strong {
  overflow: hidden;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.global-history-top .dot {
  margin-right: 0;
}

@media (max-width: 960px) {
  body > .toolbar,
  body > main {
    width: min(100vw - 16px, 100%);
  }

  .legend ul {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .toolbar {
    align-items: center;
    gap: 0.55rem;
    padding: 0.68rem 0.72rem;
  }

  .controls {
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 0.42rem;
  }

  .icon-toggle,
  .icon-button {
    width: 40px;
    height: 40px;
    min-height: 40px;
    border-radius: 10px;
  }

  #map {
    border-radius: 20px;
  }

  .editor-panel {
    width: calc(100% - 12px);
    bottom: 6px;
    max-height: calc(100% - 12px);
  }

  .panel-card {
    border-radius: 18px;
    padding: 0.9rem;
  }

  #benchForm {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  #benchForm label,
  .popup-editor label {
    font-size: 0.84rem;
  }

  #benchForm .photo-field {
    grid-column: 1 / -1;
  }

  .photo-field {
    gap: 0.42rem;
  }

  .photo-preview {
    max-height: 112px;
  }

  .popup-photo {
    max-height: 150px;
  }

  .popup-editor textarea,
  #fieldNotes {
    min-height: 64px;
  }

  .popup-editor input,
  .popup-editor select,
  .popup-editor textarea,
  #fieldName,
  #fieldNamePreset,
  #fieldInspection,
  #fieldStatus,
  #fieldActive,
  #fieldImage,
  #fieldNotes {
    min-height: 40px;
    border-radius: 10px;
    padding: 0.52rem 0.62rem;
  }

  .panel-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }

  .panel-actions button {
    width: 100%;
  }

  .position-edit-bar {
    grid-template-columns: 1fr;
    width: calc(100% - 12px);
    bottom: max(6px, env(safe-area-inset-bottom));
    gap: 0.6rem;
  }

  .position-edit-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .position-edit-actions button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .toolbar {
    margin-top: max(8px, env(safe-area-inset-top));
    margin-bottom: 8px;
    padding: 0.7rem 0.75rem;
    border-radius: 16px;
  }

  .toolbar h1 {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
  }

  main {
    min-height: 0;
  }

  #map {
    border-radius: 18px;
  }

  .legend {
    left: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    max-width: calc(100% - 16px);
    padding: 0.55rem 0.62rem;
    border-radius: 12px;
  }

  .bench-list-panel {
    top: 8px;
    right: 8px;
    width: calc(100% - 16px);
    max-height: calc(100% - 16px);
    gap: 0.72rem;
    padding: 0.7rem;
  }

  .global-history-panel {
    top: 8px;
    right: 8px;
    width: calc(100% - 16px);
    max-height: calc(100% - 16px);
    gap: 0.72rem;
    padding: 0.7rem;
  }

  .bench-list {
    gap: 0.62rem;
    padding-right: 0;
  }

  .bench-list-item {
    min-height: 82px;
    padding: 0.72rem;
    border-radius: 13px;
  }

  .bench-list-topline strong {
    font-size: 0.94rem;
  }

  .bench-list-details {
    flex-wrap: nowrap;
    gap: 0.28rem;
    overflow-x: auto;
    padding-bottom: 0.02rem;
    font-size: 0.72rem;
    scrollbar-width: none;
  }

  .bench-list-details::-webkit-scrollbar {
    display: none;
  }

  .bench-list-status,
  .bench-list-date,
  .bench-list-photo {
    flex: 0 0 auto;
    min-height: 23px;
  }

  .bench-list-photo {
    padding-inline: 0.38rem;
  }

  .bench-list-date {
    padding-inline: 0.42rem;
  }

  .legend h2 {
    margin-bottom: 0.4rem;
    font-size: 0.78rem;
  }

  .legend ul {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem 0.55rem;
  }

  .legend li {
    font-size: 0.74rem;
  }

  .leaflet-popup-content {
    min-width: 0;
    max-width: calc(100vw - 40px);
    margin: 0.85rem;
  }

  .popup-actions button {
    min-height: 40px;
    padding: 0.52rem 0.58rem;
  }

  .popup-move {
    padding: 0.65rem;
  }
}
