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

html, body, #app {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

/* ── Top bar ── */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #ddd;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  border-radius: 6px;
  padding: 3px 6px;
  margin: 0 -2px;
  transition: background 0.15s;
}
.app-brand:hover { background: #f0f0f0; }

.app-logo {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.app-title {
  font-weight: 600;
  font-size: 15px;
  color: #333;
  white-space: nowrap;
}

.sep { width: 1px; height: 24px; background: #ddd; margin: 0 2px; }
.sep.flex { flex: 1; width: auto; height: 0; background: none; }

.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}

.btn:hover:not(:disabled) { background: #f5f5f5; border-color: #aaa; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.active { background: #e8f0fe; border-color: #4285f4; color: #1a73e8; }
.btn.primary-btn { background: #1a73e8; border-color: #1a73e8; color: #fff; }
.btn.primary-btn:hover:not(:disabled) { background: #1557b0; }
.btn.danger-btn { border-color: #d93025; color: #d93025; }
.btn.danger-btn:hover { background: #fce8e6; }

.select-sm {
  height: 32px;
  padding: 0 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}

.snap-label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 13px;
  cursor: pointer;
}

.name-input {
  height: 32px;
  padding: 0 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 13px;
  width: 160px;
}

/* ── Map ── */

#map {
  position: absolute;
  top: 48px; left: 0; right: 0; bottom: 0;
}

/* When trim panel visible, shrink map bottom */
.has-trim-panel #map {
  bottom: 80px;
}

/* ── Trim panel ── */

#trim-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 80px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border-top: 1px solid #ddd;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trim-info {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: #333;
}

.trim-of { color: #666; }
.trim-pts { color: #888; font-size: 12px; }

.trim-range-wrap {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}

.trim-track {
  position: absolute;
  left: 9px; right: 9px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
}

.trim-track-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: #1a73e8;
  border-radius: 2px;
}

.trim-range {
  position: absolute;
  width: 100%;
  height: 4px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
  z-index: 2;
}

.trim-range::-webkit-slider-runnable-track { background: transparent; }
.trim-range::-moz-range-track             { background: transparent; height: 4px; }
.trim-range::-moz-range-progress          { background: transparent; }

.trim-range::-webkit-slider-thumb {
  pointer-events: all;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1a73e8;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: grab;
  margin-top: -7px;
}
.trim-range:active::-webkit-slider-thumb {
  cursor: grabbing;
  box-shadow: 0 2px 8px rgba(26,115,232,0.4);
}

.trim-range::-moz-range-thumb {
  pointer-events: all;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1a73e8;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: grab;
}

/* ── Import page inline trim ── */

.import-trim {
  flex: 1;
  min-width: 120px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.import-trim .trim-range-wrap {
  flex: 1;
}

.import-trim-label {
  font-size: 11px;
  color: #bbb;
  white-space: nowrap;
  min-width: 44px;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s;
}

.import-trim-label:first-child { text-align: right; }
.import-trim-label:last-child  { text-align: left; }
.import-trim-label.active      { color: #d93025; }

/* ── Modal ── */

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

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 360px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal h2 { font-size: 18px; font-weight: 600; }
.modal p  { color: #444; }

.share-url-row {
  display: flex;
  gap: 8px;
}

.share-url-input {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 13px;
  background: #f8f8f8;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Toast ── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 3000;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  background: #333;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
  animation: toast-in 0.2s ease;
}

.toast.warning { background: #f57c00; }
.toast.error   { background: #d93025; }
.toast.success { background: #188038; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── View-only badge ── */

.view-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: #f1f3f4;
  border: 1px solid #ddd;
  border-radius: 12px;
  font-size: 11px;
  color: #555;
  font-weight: 500;
  white-space: nowrap;
}

.route-name-display {
  font-size: 13px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Route info card ── */

#route-card {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 999;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 190px;
  max-width: 260px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}


.card-header {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}

.card-icon {
  font-size: 32px;
  line-height: 1.1;
  flex-shrink: 0;
}

.card-icon-trigger {
  font-size: 32px;
  line-height: 1;
  flex-shrink: 0;
  background: none;
  border: 1.5px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px 3px;
  transition: border-color 0.15s, background 0.15s;
}

.card-icon-trigger:hover {
  border-color: #ccc;
  background: #f5f5f5;
}

.card-title-text {
  font-size: 14px;
  font-weight: 600;
  color: #222;
  line-height: 1.3;
  word-break: break-word;
  padding-top: 6px;
}

.card-title-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  background: #fafafa;
}

.card-title-input:focus {
  outline: none;
  border-color: #4285f4;
  background: #fff;
}

.card-emoji-popup {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 1500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  overflow: hidden;
}

.card-stats {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  line-height: 1.5;
}

.card-label {
  color: #888;
  font-size: 12px;
  flex-shrink: 0;
}

.card-value {
  color: #222;
  font-size: 12px;
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-description {
  color: #444;
  font-size: 12px;
  line-height: 1.5;
  border-top: 1px solid #eee;
  padding-top: 8px;
  word-break: break-word;
}

.card-desc-input {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
  background: #fafafa;
  margin-top: 2px;
  line-height: 1.5;
}

.card-desc-input:focus {
  outline: none;
  border-color: #4285f4;
  background: #fff;
}

/* ── Leaflet handle overrides ── */
.route-handle {
  cursor: grab;
}
.route-handle:active {
  cursor: grabbing;
}

/* ── Timestamp popup ── */
.ts-popup { font-size: 13px; line-height: 1.75; min-width: 170px; }
.ts-popup-time { font-weight: 600; color: #1a1a1a; }
.ts-popup-coords { color: #555; font-size: 12px; font-variant-numeric: tabular-nums; }
.ts-popup-dist    { color: #188038; font-size: 12px; font-variant-numeric: tabular-nums; }
.ts-popup-elapsed { color: #1a73e8; font-size: 12px; font-variant-numeric: tabular-nums; }
