:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4d;
  --text: #e7edf5;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overscroll-behavior: none;
}

body.sidebar-drawer-open {
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 1fr;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}

#app.admin-open {
  grid-template-columns: 380px 1fr;
}

#sidebar {
  display: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  padding: 0.45rem 0.65rem 0.2rem;
  flex-direction: column;
  min-width: 0;
  font-size: 0.82rem;
}

#app.admin-open #sidebar {
  display: flex;
}

#app.sidebar-collapsed {
  grid-template-columns: 1fr;
}

#app.sidebar-collapsed #sidebar {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sidebar-top header {
  flex: 1;
  min-width: 0;
}

.sidebar-toggle {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  background: rgba(59, 130, 246, 0.15);
  color: var(--text);
}

.sidebar-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#tab-groups.tab-panel.active {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#tab-groups .panel-grow {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}

#tab-groups .dialog-list.scroll-area {
  flex: 0 0 auto;
  max-height: min(28vh, 200px);
  min-height: 56px;
  overflow-y: auto;
}

#tab-map-tab.tab-panel.active {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar-drawer-handle {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1050;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(8, 12, 18, 0.58);
  backdrop-filter: blur(2px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-backdrop.hidden {
  display: none;
}

@media (max-width: 900px) {
  .sidebar-backdrop:not(.hidden) {
    display: block;
  }
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
}

.subtitle {
  margin: 0.05rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0.35rem 0 0.25rem;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.28rem 0.35rem;
  font-size: 0.76rem;
}

.tab.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  color: var(--text);
}

.tab-panel { display: none; }
.tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.panel-grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0;
  border-bottom: none;
}

.panel-grow > *:not(.scroll-area) {
  flex-shrink: 0;
}

.panel-fixed {
  flex-shrink: 0;
  margin-bottom: 0;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.panel-compact {
  padding-top: 0.28rem;
}

.panel-compact:first-child {
  border-top: none;
  padding-top: 0;
}

.panel-compact h2 {
  margin-bottom: 0.28rem;
}

.panel-compact + .panel-compact {
  padding-top: 0.28rem;
}

.scroll-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel h2 {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  flex-shrink: 0;
}

.hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
  flex-shrink: 0;
  line-height: 1.3;
}

.status {
  font-size: 0.74rem;
  color: var(--muted);
  min-height: 1.25em;
  margin: 0;
  padding: 0.2rem 0.35rem;
  border-radius: 5px;
  border: 1px solid transparent;
  white-space: pre-line;
  line-height: 1.25;
}

.status-compact:empty {
  display: none;
  min-height: 0;
  padding: 0;
  margin: 0;
}

.status-compact:not(:empty) {
  margin-top: 0.25rem;
}

.status.status-syncing {
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.08);
}

.status.status-done {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.08);
}

.status.status-error {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.load-banner.sync-banner.sync-error {
  border-color: rgba(239, 68, 68, 0.5);
}

.load-banner.sync-banner.sync-idle {
  border-color: rgba(34, 197, 94, 0.35);
  opacity: 0.92;
}

.load-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  min-width: 220px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.load-banner span {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.load-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.load-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.15s ease;
}

.toast {
  position: absolute;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: rgba(26, 35, 50, 0.95);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

#sidebar button {
  padding: 0.32rem 0.5rem;
  font-size: 0.76rem;
  border-radius: 6px;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.map-actions { margin-top: 0.25rem; }

button {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--accent);
  color: white;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: wait; }

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover { background: rgba(255,255,255,0.05); }

button.secondary.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.2);
  color: var(--text);
}

button.danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger);
  color: white;
}

.filter-label {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  margin: 0 0 0.08rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#sidebar input[type="search"],
#sidebar select {
  width: 100%;
  padding: 0.28rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 0;
  font-size: 0.76rem;
}

input[type="search"], select {
  width: 100%;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 0.5rem;
}

.filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.28rem 0.4rem;
}

.filters-grid .span-2 {
  grid-column: 1 / -1;
}

.filter-field {
  min-width: 0;
}

.filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  margin-top: 0.1rem;
}

.filter-actions button {
  width: 100%;
  padding: 0.3rem 0.35rem;
}

.compact-inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem;
  align-items: center;
}

#sidebar input[type="file"] {
  width: 100%;
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 0;
}

#sidebar input[type="file"]::file-selector-button {
  margin-right: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  padding: 0.22rem 0.45rem;
  font-size: 0.72rem;
  cursor: pointer;
}

.compact-inline-row > button {
  white-space: nowrap;
  padding-inline: 0.55rem;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

#sidebar .settings-form {
  gap: 0.45rem;
}

#sidebar .setting-hint {
  font-size: 0.68rem;
  line-height: 1.25;
}

#sidebar .setting-label {
  font-size: 0.78rem;
}

#sidebar .setting-row input[type="number"] {
  padding: 0.28rem 0.4rem;
  font-size: 0.76rem;
}

#sidebar #dialog-search {
  margin-bottom: 0.35rem;
  padding: 0.28rem 0.4rem;
  font-size: 0.76rem;
}

#sidebar .panel {
  margin-bottom: 0.45rem;
  padding-bottom: 0.45rem;
}

#tab-settings.tab-panel.active {
  overflow-y: auto;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.setting-row.setting-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.setting-label {
  font-size: 0.88rem;
  font-weight: 500;
}

.setting-row input[type="number"] {
  width: 100%;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

input[type="file"] {
  width: 100%;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  margin-right: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.bulk-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.35rem;
  padding: 0.35rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.bulk-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.76rem;
  cursor: pointer;
}

.bulk-check input {
  flex-shrink: 0;
}

.dialog-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
}

.dialog-section {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.6rem 0.4rem 0.25rem;
  list-style: none;
}

.dialog-list .empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.5rem;
}

.dialog-item label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.5rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
}

.dialog-item label:hover {
  background: rgba(59, 130, 246, 0.1);
}

.dialog-item input {
  margin-right: 0.4rem;
}

.dialog-title {
  font-size: 0.9rem;
}

#track-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tracks-panel {
  padding-bottom: 0;
  padding-top: 0.25rem;
  min-height: 0;
}

.tracks-panel h2 {
  margin-bottom: 0.2rem;
}

#track-list li {
  border-radius: 6px;
  font-size: 0.78rem;
  border: 1px solid transparent;
}

#track-list li:hover,
#track-list li.active {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.25);
}

.track-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.28rem 0.25rem;
  border-radius: 6px;
}

.track-row:not(.track-row--pending) {
  cursor: pointer;
}

.track-row:not(.track-row--pending):hover {
  background: rgba(59, 130, 246, 0.08);
}

.track-info { flex: 1; min-width: 0; }

.track-info--selectable {
  cursor: pointer;
}

.track-info--selectable:hover .track-name {
  color: var(--accent);
  text-decoration: underline;
}

.track-row--pending .track-info {
  cursor: pointer;
  opacity: 0.72;
}

.track-name {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
  word-break: break-word;
}

#track-list li.active .track-name {
  color: #fbbf24;
  font-weight: 600;
  text-decoration: none;
}

.track-name-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.track-badge {
  display: inline-block;
  font-size: 0.65rem;
  line-height: 1.2;
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.hidden-badge {
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.25);
}

.footer-hide-track {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin: 0.35rem 0 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.footer-hide-track input {
  margin-top: 0.15rem;
}

.track-meta {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  margin-top: 0.08rem;
  line-height: 1.25;
}

.poster-link {
  color: var(--accent);
  text-decoration: none;
}

.poster-link:hover {
  text-decoration: underline;
}

.popup-poster {
  font-size: 0.85rem;
}

.popup-poster .muted,
.muted {
  color: var(--muted);
}

.hidden { display: none !important; }

.sidebar-foot {
  flex-shrink: 0;
  margin: 0.15rem 0 0;
  padding: 0.2rem 0 0.1rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.72rem;
}

.ghost-link {
  background: none;
  border: none;
  color: var(--border);
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  cursor: pointer;
}

.ghost-link:hover {
  color: var(--muted);
  background: none;
}

.area-hint { margin-top: 0.5rem; }

.leaflet-control-layers {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
}

.leaflet-control-layers-expanded {
  padding: 0.4rem 0.6rem !important;
}

.leaflet-control-scale-line {
  background: rgba(26, 35, 50, 0.85) !important;
  border: 1px solid var(--border) !important;
  border-top: none !important;
  color: var(--text) !important;
  padding: 2px 6px 1px !important;
  font-size: 0.75rem !important;
  line-height: 1.2 !important;
}

.leaflet-control-zoom .zoom-level-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  line-height: 22px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text, #333);
  background: var(--panel, #fff);
  border-bottom: 1px solid var(--border, #ccc);
  user-select: none;
  pointer-events: none;
}

#map-area.selecting-area,
#map-area.selecting-area #map {
  cursor: crosshair;
}

#map-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  position: relative;
}

.load-fill-pulse {
  width: 40% !important;
  animation: load-pulse 1.2s ease-in-out infinite;
}

@keyframes load-pulse {
  0% { margin-left: 0; width: 30%; }
  50% { margin-left: 35%; width: 45%; }
  100% { margin-left: 70%; width: 30%; }
}

.map-hint {
  position: absolute;
  bottom: 4.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  text-align: center;
  background: rgba(26, 35, 50, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  max-width: min(420px, 90%);
  pointer-events: none;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

.map-hint span {
  display: block;
}

.map-top-bar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: calc(100% - 24px);
  pointer-events: none;
}

.map-top-bar > * {
  pointer-events: auto;
}

.map-search {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
  max-width: 360px;
}

.map-search-field {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(26, 35, 50, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.2rem 0.35rem 0.2rem 0.65rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.map-search-field:focus-within {
  border-color: var(--accent);
}

.map-search-field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.86rem;
  padding: 0.35rem 0;
  outline: none;
}

.map-search-field input::placeholder {
  color: var(--muted);
}

.map-search-field input::-webkit-search-cancel-button {
  cursor: pointer;
}

.map-search-submit {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.map-search-submit:hover {
  background: rgba(59, 130, 246, 0.35);
}

.map-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: rgba(26, 35, 50, 0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-height: min(50vh, 320px);
  overflow-y: auto;
  z-index: 1100;
}

.map-search-results.hidden {
  display: none;
}

.map-search-results li {
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.35;
  cursor: pointer;
  border-bottom: 1px solid rgba(45, 58, 79, 0.6);
}

.map-search-results li:last-child {
  border-bottom: none;
}

.map-search-results li:hover,
.map-search-results li.active {
  background: rgba(59, 130, 246, 0.15);
}

.map-search-results .result-title {
  display: block;
  color: var(--text);
  font-weight: 600;
}

.map-search-results .result-meta {
  display: block;
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.74rem;
}

.map-search-results .result-empty {
  cursor: default;
  color: var(--muted);
}

.map-search-results .result-empty:hover {
  background: transparent;
}

.map-status {
  flex-shrink: 0;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  line-height: 1.35;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.map-status.loading #map-status-text::before {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  margin-right: 0.4rem;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: map-status-spin 0.7s linear infinite;
  vertical-align: -0.1em;
}

@keyframes map-status-spin {
  to { transform: rotate(360deg); }
}

.measure-label {
  position: absolute;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: rgba(26, 35, 50, 0.92);
  border: 1px solid #fbbf24;
  color: #fde68a;
  border-radius: 8px;
  padding: 0.4rem 0.55rem 0.4rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  white-space: nowrap;
  max-width: min(96vw, 520px);
}

.measure-clear-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 6px;
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.measure-clear-btn:hover {
  background: rgba(251, 191, 36, 0.28);
}

.measure-vertex {
  background: none;
  border: none;
}

.measure-vertex span {
  display: block;
  width: 14px;
  height: 14px;
  margin: 2px;
  border-radius: 50%;
  background: #fbbf24;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  cursor: grab;
}

.measure-vertex.selected span {
  width: 16px;
  height: 16px;
  margin: 1px;
  background: #fff;
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.55);
}

.leaflet-dragging .measure-vertex span {
  cursor: grabbing;
}

.measure-segment-label {
  background: none;
  border: none;
}

.measure-segment-label span {
  display: inline-block;
  transform: translate(-50%, -50%);
  padding: 0.12rem 0.38rem;
  border-radius: 4px;
  background: rgba(26, 35, 50, 0.88);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fde68a;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

#map-area.measuring #map {
  cursor: crosshair;
}

#map-area.selecting-area #map {
  cursor: crosshair;
}

#map {
  flex: 1;
  min-height: 0;
  background: #2a3544;
}

#map .leaflet-container {
  width: 100% !important;
  height: 100% !important;
  background: #2a3544;
  touch-action: none;
}

.track-footer {
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 0.65rem 1rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0px));
  font-size: 0.88rem;
}

.track-footer:empty {
  display: none;
}

.track-footer .footer-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.track-footer .footer-meta {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.track-footer .footer-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.track-footer .stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.track-footer .stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.track-footer .stat-value {
  font-size: 0.95rem;
  font-weight: 500;
}

.track-footer.highlighted {
  border-top-color: #fbbf24;
  box-shadow: 0 -2px 12px rgba(251, 191, 36, 0.15);
}

.footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.footer-btn {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.92);
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.toolbar-spacer {
  flex: 1;
  min-width: 0.5rem;
}

.toolbar-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.toolbar-btn.active {
  background: rgba(59, 130, 246, 0.25);
  border-color: var(--accent);
}

.map-tool-hint {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  margin: 0;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  background: rgba(15, 20, 25, 0.88);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 18, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(360px, calc(100vw - 2rem));
  padding: 1.25rem;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.login-modal-card {
  width: min(400px, calc(100vw - 2rem));
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  animation: login-modal-in 0.18s ease-out;
}

@keyframes login-modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.35rem 1.35rem 0.25rem;
}

.login-modal-heading h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-modal-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.4;
}

.login-modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.login-modal-close:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  color: var(--text);
}

.login-modal-form {
  padding: 1rem 1.35rem 1.35rem;
}

.login-field {
  display: block;
}

.login-field-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.login-field input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-field input[type="password"]:focus {
  outline: none;
  border-color: rgba(59, 130, 246, 0.65);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.login-submit {
  width: 100%;
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 10px;
}

.login-error {
  margin: 0.75rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.login-error.hidden {
  display: none;
}

.modal-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.sync-log-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.sync-log-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
  flex-shrink: 0;
}

.sync-log-dot.active {
  background: #3ecf8e;
  opacity: 1;
  animation: sync-log-pulse 1.4s ease-in-out infinite;
}

@keyframes sync-log-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.65; }
}

.sync-log-card {
  width: min(720px, calc(100vw - 1.5rem));
  max-height: min(82vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.sync-log-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sync-log-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.sync-log-summary {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.sync-log-view {
  flex: 1;
  min-height: 240px;
  max-height: 52vh;
  overflow: auto;
  padding: 0.65rem 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  background: rgba(0, 0, 0, 0.22);
}

.sync-log-line {
  display: flex;
  gap: 0.55rem;
  padding: 0.12rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.sync-log-line:last-child {
  border-bottom: none;
}

.sync-log-ts {
  flex: 0 0 auto;
  color: var(--muted);
  white-space: nowrap;
}

.sync-log-msg {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.sync-log-line.kind-error .sync-log-msg {
  color: #ff8a8a;
}

.sync-log-line.kind-done .sync-log-msg {
  color: #8fd9a8;
}

.sync-log-line.kind-system .sync-log-msg {
  color: #9ec5ff;
}

.sync-log-line.kind-progress .sync-log-msg {
  color: #b8c4ce;
}

.sync-log-line.kind-telethon .sync-log-msg {
  color: #7eb8da;
  font-size: 0.74rem;
}

.sync-log-line.kind-wait .sync-log-msg {
  color: #ffb86b;
  font-size: 0.74rem;
}

.sync-log-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.sync-log-hint {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  opacity: 0.85;
}

.sync-log-autoscroll {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.sync-log-updated {
  text-align: right;
}

.sync-log-stale {
  color: #ffb86b !important;
}

.modal-card input[type="password"] {
  width: 100%;
  margin-top: 0.75rem;
}

.track-popup .leaflet-popup-content {
  margin: 0.65rem 0.75rem;
  line-height: 1.45;
}

.track-popup-inner strong {
  display: block;
  margin-bottom: 0.35rem;
}

.track-popup-stats {
  font-size: 0.85rem;
  color: var(--text);
}

.track-popup-stats div {
  margin-top: 0.15rem;
}

#track-list li.active {
  background: rgba(251, 191, 36, 0.12);
  border-radius: 6px;
}

@media (max-width: 900px) {
  #app,
  #app.admin-open,
  #app.sidebar-collapsed,
  #app:not(.admin-open) {
    display: block;
    grid-template-columns: unset;
    grid-template-rows: unset;
    height: 100dvh;
    max-height: 100dvh;
  }

  #map-area {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
  }

  #map {
    flex: 1 1 0;
    height: 0;
    min-height: 0;
    width: 100%;
    position: relative;
  }

  #sidebar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 1100;
    width: auto;
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 12px));
    height: auto;
    padding: 0.35rem 0.85rem max(0.35rem, env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
    transform: translateY(105%);
    transition: transform 0.28s ease;
  }

  #app.admin-open:not(.sidebar-collapsed) #sidebar {
    display: flex;
    transform: translateY(0);
  }

  .sidebar-drawer-handle {
    display: block;
    flex-shrink: 0;
    width: 42px;
    height: 4px;
    margin: 0.15rem auto 0.55rem;
    border-radius: 999px;
    background: rgba(139, 156, 179, 0.55);
  }

  #tab-groups .dialog-list.scroll-area {
    max-height: min(24dvh, 160px);
  }

  .map-top-bar {
    left: 8px;
    right: 8px;
    transform: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    max-width: none;
  }

  .map-search {
    max-width: none;
    min-width: 0;
    flex: none;
    width: 100%;
  }

  .map-search-field input {
    font-size: 16px;
    min-height: 40px;
  }

  .map-search-submit {
    width: 40px;
    height: 40px;
  }

  .map-toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.3rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 100%;
    padding: 0.3rem 0.4rem;
  }

  .map-toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar-spacer {
    display: none;
  }

  .toolbar-btn {
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    padding: 0.45rem 0.65rem;
    font-size: 0.78rem;
  }

  .map-status {
    align-self: center;
    max-width: 100%;
    white-space: normal;
    text-align: center;
    font-size: 0.72rem;
    line-height: 1.3;
  }

  .map-tool-hint {
    top: calc(var(--map-chrome-top, 108px) + env(safe-area-inset-top, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.35;
  }

  .load-banner {
    top: calc(var(--map-chrome-top, 108px) + env(safe-area-inset-top, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    min-width: 0;
    max-width: none;
  }

  #map-area.has-map-status {
    --map-chrome-top: 168px;
  }

  #map-area:not(.has-map-status) {
    --map-chrome-top: 120px;
  }

  .leaflet-top.leaflet-left,
  .leaflet-top.leaflet-right {
    top: calc(var(--map-chrome-top, 108px) + env(safe-area-inset-top, 0px));
  }

  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }

  .leaflet-control-layers-toggle {
    width: 36px !important;
    height: 36px !important;
  }

  .leaflet-bottom.leaflet-left,
  .leaflet-bottom.leaflet-right {
    margin-bottom: max(6px, env(safe-area-inset-bottom, 0px));
  }

  .track-footer {
    max-height: min(42dvh, 320px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0.55rem 0.75rem;
    padding-bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
    font-size: 0.82rem;
  }

  .track-footer .footer-title {
    font-size: 0.92rem;
    word-break: break-word;
  }

  .track-footer .footer-meta {
    font-size: 0.76rem;
    word-break: break-word;
  }

  .track-footer .footer-stats {
    gap: 0.35rem 0.85rem;
  }

  .track-footer .stat-value {
    font-size: 0.88rem;
  }

  .footer-actions {
    flex-direction: column;
  }

  .footer-btn {
    width: 100%;
    min-height: 44px;
  }

  .toast {
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    text-align: center;
    font-size: 0.82rem;
  }

  .measure-label {
    bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    white-space: normal;
    text-align: center;
    font-size: 0.82rem;
    justify-content: center;
  }

  .map-hint {
    bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
  }

  input[type="search"],
  select,
  .login-field input[type="password"] {
    font-size: 16px;
  }

  button {
    min-height: 44px;
  }

  .modal {
    align-items: flex-end;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .login-modal-card {
    width: 100%;
    max-width: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  #track-list li {
    font-size: 0.84rem;
  }

  .track-meta {
    font-size: 0.72rem;
    line-height: 1.35;
  }

  .track-row {
    padding: 0.55rem 0.35rem;
  }

  .track-visible {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }
}
