:root {
  --bg: #000000;
  --panel: #05070b;
  --panel-2: #090d14;
  --line: #1f2937;
  --text: #edf4ff;
  --muted: #93a4bc;
  --accent: #38bdf8;
  --selected: #fb7185;
  --rect: #f97316;
  --map-width: 58%;
  --map-height: 55vh;
  --mobile-side-height: 45vh;
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
#app { display: flex; flex-direction: column; }
button, input, select { font: inherit; }
button, select, input[type="text"], input[type="number"] {
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  min-height: 34px;
  padding: 6px 9px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.active { border-color: var(--selected); color: var(--selected); }
button.primary { border-color: #2563eb; background: #102555; }
button.icon-btn { width: 34px; min-width: 34px; padding: 0; font-weight: 900; }
.toolbar-icon-btn {
  position: relative;
  width: 36px;
  min-width: 36px;
  padding: 0;
  color: var(--text);
}
.toolbar-icon-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 17px;
  height: 17px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.toolbar-icon-btn[data-icon="load"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M7 2h2v6.59l2.3-2.3 1.4 1.41L8 12.41 3.3 7.7l1.4-1.41L7 8.59zM2 13h12v1H2z'/%3E%3C/svg%3E"); }
.toolbar-icon-btn[data-icon="markers"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M4.5 2a2.5 2.5 0 0 1 2.45 3.02L10 8.07V6.5a2.5 2.5 0 1 1 1.5 2.29l-3.1-3.1A2.5 2.5 0 1 1 4.5 2Zm0 1.5a1 1 0 1 0 0 2 1 1 0 0 0 0-2Zm8 2a1 1 0 1 0 0 2 1 1 0 0 0 0-2ZM4 10a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm0 1.5a.5.5 0 1 0 0 1 .5.5 0 0 0 0-1Z'/%3E%3C/svg%3E"); }
.toolbar-icon-btn[data-icon="settings"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='m9.6 1 .25 1.66a5.5 5.5 0 0 1 1.29.74l1.53-.7 1.1 1.9-1.28 1.05c.08.29.12.59.12.9s-.04.61-.12.9l1.28 1.05-1.1 1.9-1.53-.7a5.5 5.5 0 0 1-1.29.74L9.6 15H7.4l-.25-1.66a5.5 5.5 0 0 1-1.29-.74l-1.53.7-1.1-1.9 1.28-1.05A3.6 3.6 0 0 1 4.4 8c0-.31.04-.61.12-.9L3.24 6.05l1.1-1.9 1.53.7a5.5 5.5 0 0 1 1.29-.74L7.4 1zm-1.6 4a3 3 0 1 0 0 6 3 3 0 0 0 0-6Zm0 1.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Z'/%3E%3C/svg%3E"); }
.icon-only {
  position: relative;
}
.icon-only::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M3.23 4.29 4.29 3.23 8 6.94l3.71-3.71 1.06 1.06L9.06 8l3.71 3.71-1.06 1.06L8 9.06l-3.71 3.71-1.06-1.06L6.94 8 3.23 4.29Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M3.23 4.29 4.29 3.23 8 6.94l3.71-3.71 1.06 1.06L9.06 8l3.71 3.71-1.06 1.06L8 9.06l-3.71 3.71-1.06-1.06L6.94 8 3.23 4.29Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.hidden { display: none !important; }
label { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; color: var(--muted); }
input[type="file"] { width: 100%; color: var(--muted); }
input[type="range"] { width: 220px; }
input[type="color"] { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #0b1220; }
#topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #080b10 0%, #020304 100%);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 1200;
}
.group { display: flex; align-items: center; gap: 8px; padding-right: 10px; border-right: 1px solid var(--line); flex-wrap: wrap; }
.group:last-child { border-right: 0; }
.action-group { flex: 0 0 auto; }
#status { color: var(--muted); margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.group > button { flex: 0 0 auto; }
.filter-control { position: relative; display: inline-flex; align-items: center; min-width: 0; }
.filter-control input, .filter-control > button:first-child { padding-right: 34px; }
.filter-control > button:first-child:empty::before { content: "\00a0"; }
.filter-control .inside-x {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  border: 0;
  line-height: 1;
  font-weight: 900;
}
.filter-control .inside-x:hover { background: #172033; color: white; }
#dateRange {
  width: min(336px, 38vw);
  min-width: 0;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
#timeFilterBtn { min-width: 112px; text-align: left; }
#main { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: var(--map-width) 7px 1fr; overflow: hidden; }
#mapPane { min-width: 260px; position: relative; }
#map { width: 100%; height: 100%; background: #1f2937; }
#divider { background: #1f2a3d; cursor: col-resize; border-left: 1px solid #0b1220; border-right: 1px solid #0b1220; }
#divider:hover { background: var(--accent); }
#sidePane { min-width: 360px; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); overflow: hidden; }
#tableWrap { overflow: auto; flex: 1; }
#tableStatus {
  flex: 0 0 auto;
  padding: 8px 12px 10px;
  border-top: 1px solid rgba(31, 41, 55, 0.9);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  padding: 8px 9px;
  background: #0b1220;
  color: #dbeafe;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: white; background: #111c31; }
thead th.sorted { color: var(--accent); }
tbody td { height: 34px; padding: 6px 9px; border-bottom: 1px solid #1e293b; color: #dbeafe; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #172033; }
tbody tr.selected { outline: 2px solid var(--selected); outline-offset: -2px; background: #331118; }
.spacer-row td { padding: 0; border: 0; height: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 22px; text-align: center; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { display: none !important; }
.leaflet-tooltip.gpx-tooltip {
  background: #ffffff;
  color: #06080b;
  border: 1px solid #06080b;
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
  border-radius: 10px;
  padding: 8px 10px;
}
.tooltip-date { font-size: 14px; font-weight: 700; line-height: 1.2; }
.tooltip-time { font-size: 11px; line-height: 1.1; margin-top: 2px; opacity: 0.72; }
.gpx-canvas { position: absolute; pointer-events: auto; }
.leaflet-dragging .gpx-canvas, .rect-draw-mode .gpx-canvas { pointer-events: none; }
.leaflet-container.rect-draw-mode { cursor: crosshair; }
.map-action-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-action-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(3, 6, 10, 0.94);
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(0,0,0,.34);
}
.map-action-btn::before {
  content: "";
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.map-action-btn[data-icon="rect"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='black' stroke-width='1.5' stroke-dasharray='2 1.5' d='M2.75 2.75h10.5v10.5H2.75z'/%3E%3C/svg%3E"); }
.map-action-btn[data-icon="close"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M3.23 4.29 4.29 3.23 8 6.94l3.71-3.71 1.06 1.06L9.06 8l3.71 3.71-1.06 1.06L8 9.06l-3.71 3.71-1.06-1.06L6.94 8 3.23 4.29Z'/%3E%3C/svg%3E"); }
.map-action-btn[data-icon="legend"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M2.5 4A1.5 1.5 0 0 1 4 2.5h8A1.5 1.5 0 0 1 13.5 4v1.5H2.5zm0 3h11v2h-11zm0 3.5H6V12H2.5zm4.5 0h6.5V12H7z'/%3E%3C/svg%3E"); }
.map-action-btn[data-icon="measure"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='black' d='M10.82 2.12 13.88 5.18 5.18 13.88 2.12 10.82zm.18 2.12-.88-.88-1.06 1.06.88.88zm-2.12 2.12L8 5.48 6.94 6.54l.88.88zm-2.12 2.12-.88-.88-1.06 1.06.88.88zm-2.12 2.12-.88-.88-.88.88.88.88z'/%3E%3C/svg%3E"); }
.map-action-btn > span { display: none; }
.map-action-btn.active {
  border-color: var(--selected);
  color: var(--selected);
  background: rgba(54, 16, 27, 0.92);
}
.map-action-btn.hidden { display: none; }
.rect-outline {
  cursor: grab;
}
.rect-outline.dragging {
  cursor: grabbing;
}
.rect-handle {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: rgba(249, 115, 22, 0.92);
  border: 2px solid rgba(255, 237, 213, 0.96);
  box-shadow: 0 0 0 1px rgba(255,255,255,.18), 0 6px 18px rgba(0,0,0,.34);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.58);
  z-index: 5000;
}
.modal-backdrop.visible { display: flex; }
.modal {
  width: min(590px, calc(100vw - 28px));
  max-height: min(780px, calc(100vh - 28px));
  overflow: hidden;
  background: linear-gradient(180deg, #07090d 0%, #020304 100%);
  border: 1px solid #172033;
  border-radius: 16px;
  box-shadow: 0 28px 90px rgba(0,0,0,.55);
}
.modal.wide { width: min(720px, calc(100vw - 28px)); }
.marker-modal { width: min(760px, calc(100vw - 28px)); }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 15px; border-bottom: 1px solid #172033; }
.modal-foot { border-bottom: 0; border-top: 1px solid #172033; justify-content: flex-end; }
.modal-title { font-size: 16px; font-weight: 800; }
.modal-body { padding: 14px 15px; display: grid; gap: 13px; overflow: auto; }
.marker-modal .modal-body { overflow: auto; }
.modal-head button, .modal-foot button { background: #0a1018; }
.modal-close {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  color: var(--muted);
}
.modal-close:hover {
  color: var(--text);
  background: #121a25;
}
.form-row { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; min-width: 0; }
.form-row > label:first-child { min-width: 112px; }
.form-row > .size-row { min-width: 0; }
.form-row > input[type="color"] { flex: 0 0 auto; }
.muted { color: var(--muted); font-size: 13px; }
.size-row { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; }
.size-row input[type="range"] { width: min(320px, 40vw); flex: 1 1 auto; }
.value-pill { min-width: 56px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.style-preview {
  width: 100%;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: radial-gradient(circle at center, rgba(20,28,40,.95) 0 18%, rgba(6,10,16,.96) 18% 100%);
}
.file-list { display: grid; gap: 8px; }
.file-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #0b1220; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-row { justify-content: flex-start; }
.check-row label { color: var(--text); }
.split-row { justify-content: space-between; flex-wrap: wrap; }
.column-menu {
  position: fixed;
  z-index: 7000;
  min-width: 220px;
  display: none;
  background: #0d1627;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 20px 52px rgba(0,0,0,.55);
  padding: 8px;
}
.column-menu.visible { display: grid; gap: 4px; }
.column-menu label { display: flex; justify-content: space-between; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; }
.column-menu label:hover { background: #172033; }
.time-picker-shell { display: grid; gap: 12px; justify-items: center; }
.time-readouts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.time-readouts button { min-width: 120px; font-variant-numeric: tabular-nums; }
.time-mode { display: flex; gap: 8px; justify-content: center; }
.clock-face {
  position: relative;
  width: min(390px, 88vw);
  height: min(390px, 88vw);
  border-radius: 50%;
  background: radial-gradient(circle at center, #111c31 0 62%, #0b1220 63% 100%);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 48px rgba(0,0,0,.28), 0 18px 44px rgba(0,0,0,.3);
  touch-action: none;
}
.clock-tick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 14px;
  margin-left: -1px;
  margin-top: calc(-50% + 18px);
  border-radius: 999px;
  background: rgba(219, 234, 254, 0.22);
  transform-origin: 50% calc(50% - 18px);
}
.clock-tick.major {
  height: 22px;
  background: rgba(219, 234, 254, 0.5);
}
.clock-hand {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: var(--clock-hand-length, 36%);
  background: var(--accent);
  transform-origin: 50% 100%;
  border-radius: 999px;
  box-shadow: 0 0 18px rgba(56,189,248,.4);
}
.clock-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(56,189,248,.55);
}
.clock-label {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 40px;
  height: 34px;
  padding: 0 4px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: #dbeafe;
  background: transparent;
  border: 1px solid transparent;
}
.clock-label:hover { border-color: var(--accent); background: #0f2238; }
.clock-label.active { background: var(--accent); color: #04101c; font-weight: 800; }
.flatpickr-day.today {
  border-color: var(--accent);
  color: var(--accent);
}
.legend-panel {
  min-width: 168px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(4, 7, 11, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #dbeafe;
  box-shadow: 0 14px 28px rgba(0,0,0,.34);
}
.legend-bar {
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  margin-bottom: 7px;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.legend-date-btn {
  padding: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}
.legend-date-btn:hover {
  color: white;
  border: 0;
  text-decoration: underline;
}
.legend-date-input {
  position: fixed;
  left: -9999px;
  top: -9999px;
}
.measure-tooltip {
  background: rgba(255, 255, 255, 0.98);
  color: #06080b;
  border: 1px solid rgba(6, 8, 11, 0.82);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(0,0,0,.2);
}
.measure-path {
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (max-width: 850px) {
  html, body, #app { overflow: auto; }
  #main { height: auto; min-height: 0; display: flex; flex-direction: column; }
  #mapPane { height: var(--map-height); min-height: 0; }
  #divider { height: 7px; cursor: row-resize; }
  #sidePane { height: var(--mobile-side-height); min-height: 0; flex: 0 0 auto; }
  #topbar {
    align-items: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 12px;
  }
  .group { width: auto; min-width: max-content; border-right: 0; padding-right: 0; flex-wrap: nowrap; }
  .group > button { min-width: max-content; }
  .filter-control, .filter-control > input, .filter-control > button:first-child { width: auto; }
  #dateRange { width: 280px; }
  #timeFilterBtn { min-width: 104px; }
  #status { margin-left: 0; width: auto; min-width: max-content; }
  .form-row { flex-wrap: wrap; }
  input[type="range"] { width: 190px; }
  #tableWrap { height: 100%; min-height: 0; }
}
