:root {
  --paper: #f6f3ec;
  --paper-elevated: #ffffff;
  --paper-muted: #ece7dc;
  --border: #ddd6c7;
  --border-strong: #c7beab;
  --ink: #16181d;
  --ink-muted: #5f636b;
  --ink-subtle: #8b8f96;

  --accent-pin: #d4542f;
  --accent-walk: #158052;
  --accent-car: #2563eb;
  --accent-scooter: #0284c7;
  --accent-bike: #d97706;
  --accent-transit: #7c3aed;
  --accent-other: #475569;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-soft: 0 6px 24px rgba(22, 24, 29, 0.08);
  --shadow-float: 0 10px 30px rgba(22, 24, 29, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.studio-shell {
  display: grid;
  grid-template-columns: 400px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--paper);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #faf8f3 0%, var(--paper) 100%);
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 12px;
}

.brand-mark svg {
  width: 32px;
  height: 32px;
  display: block;
}

.brand-header h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.date-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-chip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
}

.field-chip span {
  font-size: 0.64rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-subtle);
}

.field-chip input,
.field-chip select {
  border: none;
  background: transparent;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink);
  outline: none;
  width: 100%;
}

.utc-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 9px;
  font-size: 0.72rem;
}

.mono-pill {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: #16181d;
  color: #f6f3ec;
}

.utc-hint {
  color: var(--ink-muted);
  font-family: "IBM Plex Mono", monospace;
}

/* Tool Bar */
.tool-bar {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--paper-elevated);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.tool-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-0.5px);
}

.tool-btn.active {
  background: #16181d;
  color: #fff;
  border-color: #16181d;
}

.tool-btn.subtle {
  margin-left: auto;
  background: transparent;
  color: var(--ink-muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-pin {
  background: var(--accent-pin);
}

.dot-move {
  background: var(--accent-walk);
}

/* Saved Places */
.saved-places-bar {
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: #f1ede4;
}

.section-mini-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--ink-muted);
  font-size: 0.68rem;
  cursor: pointer;
  text-decoration: underline;
}

.saved-places-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.place-chip {
  border: 1px solid var(--border);
  background: var(--paper-elevated);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.place-chip:hover {
  border-color: var(--accent-pin);
  color: var(--accent-pin);
}

/* Timeline Scroll */
.timeline-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  margin: auto 8px;
  padding: 24px 18px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.55);
}

.empty-state h3 {
  margin: 0 0 6px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.02rem;
}

.empty-state p {
  margin: 0 0 14px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

.seg-card {
  position: relative;
  background: var(--paper-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  box-shadow: 0 2px 6px rgba(22, 24, 29, 0.03);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.seg-card:hover {
  border-color: var(--border-strong);
}

.seg-card.selected {
  border-color: #16181d;
  box-shadow: 0 4px 14px rgba(22, 24, 29, 0.09);
}

.seg-card.kind-move {
  background: #fbfaf7;
  border-left: 4px solid var(--move-color, var(--accent-walk));
}

.seg-card.kind-stationary {
  border-left: 4px solid var(--accent-pin);
}

.seg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.pin-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-pin);
  color: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.move-badge {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--move-color, var(--accent-walk));
  color: #fff;
  font-size: 0.76rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.name-input {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  padding: 3px 6px;
  border-radius: 6px;
  outline: none;
}

.name-input:hover,
.name-input:focus {
  background: var(--paper);
  border-color: var(--border);
}

.activity-select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--paper-elevated);
  border-radius: 7px;
  padding: 4px 7px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  outline: none;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-subtle);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--paper-muted);
  color: var(--ink);
}

.icon-btn.danger:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.time-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}

.time-input {
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 6px;
  padding: 4px 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  color: var(--ink);
  outline: none;
}

.time-sep {
  color: var(--ink-subtle);
  font-size: 0.75rem;
}

.dur-chip {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.71rem;
  color: var(--ink-muted);
}

.seg-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.69rem;
  color: var(--ink-muted);
}

.seg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--paper-elevated);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 0.71rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.mini-btn:hover {
  border-color: #16181d;
}

.mini-btn.active {
  background: #16181d;
  color: #fff;
  border-color: #16181d;
}

.mini-btn.route-btn {
  background: #eef6f1;
  border-color: #b7dec7;
  color: #0e633f;
}

.mini-btn.route-btn:hover {
  background: #ddf0e5;
}

.between-connector {
  display: flex;
  justify-content: center;
  margin: -3px 0;
}

.insert-move-btn {
  border: 1px dashed var(--border-strong);
  background: var(--paper);
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 3px 11px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
}

.insert-move-btn:hover {
  border-color: var(--accent-walk);
  color: var(--accent-walk);
  background: #eef6f1;
}

/* Sticky Export Footer */
.export-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--paper-elevated);
  display: flex;
  gap: 8px;
}

.primary-btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  background: #16181d;
  color: #fff;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.14s ease;
}

.primary-btn:hover {
  opacity: 0.9;
}

.secondary-btn {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.secondary-btn:hover {
  background: var(--paper-muted);
}

/* Map Stage */
.map-stage {
  position: relative;
  height: 100vh;
  width: 100%;
}

#map {
  height: 100%;
  width: 100%;
}

.map-search-wrap {
  position: absolute;
  top: 14px;
  left: 56px;
  z-index: 600;
  width: min(370px, calc(100% - 76px));
}

.search-box {
  display: flex;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(22, 24, 29, 0.12);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.83rem;
  color: var(--ink);
  outline: none;
}

.search-box button {
  border: none;
  background: #16181d;
  color: #fff;
  padding: 0 14px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.search-results {
  margin: 6px 0 0;
  padding: 4px;
  list-style: none;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  max-height: 270px;
  overflow-y: auto;
}

.search-results li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-results li:hover {
  background: var(--paper);
}

.search-results strong {
  font-size: 0.82rem;
}

.search-results span {
  font-size: 0.71rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-mode-banner {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 500;
  background: rgba(22, 24, 29, 0.88);
  color: #f6f3ec;
  backdrop-filter: blur(8px);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  box-shadow: var(--shadow-soft);
  pointer-events: none;
}

.draw-hud {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: rgba(22, 24, 29, 0.94);
  color: #fff;
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  padding: 11px 14px;
  box-shadow: var(--shadow-float);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
}

.draw-hud-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.draw-hud-info strong {
  font-size: 0.82rem;
}

.draw-hud-info span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  color: #cbd5e1;
}

.draw-hud-actions {
  display: flex;
  gap: 6px;
}

.hud-btn {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hud-btn.primary {
  background: #34c759;
  color: #0b2413;
  border-color: #34c759;
}

.map-controls-bottom {
  position: absolute;
  bottom: 22px;
  right: 16px;
  z-index: 500;
  display: flex;
  gap: 6px;
}

.map-pill-btn,
.map-pill-select {
  border: 1px solid rgba(22, 24, 29, 0.14);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  outline: none;
}

/* Custom Leaflet Markers */
.custom-pin-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-pin);
  border: 2.5px solid #fff;
  color: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.custom-pin-marker.selected {
  transform: scale(1.16);
  box-shadow: 0 0 0 4px rgba(212, 84, 47, 0.35), 0 4px 12px rgba(0, 0, 0, 0.4);
}

.vertex-handle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid #16181d;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 24, 29, 0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(820px, 100%);
  max-height: 86vh;
  background: var(--paper-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
}

.modal-sub {
  margin: 2px 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-close {
  border: none;
  background: var(--paper-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

.xml-code {
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  background: #14171c;
  color: #e2e8f0;
  flex: 1;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: #16181d;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  box-shadow: var(--shadow-float);
}

@media (max-width: 900px) {
  .studio-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 48vh 52vh;
  }

  .sidebar {
    height: 48vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-stage {
    height: 52vh;
  }

  .map-mode-banner {
    display: none;
  }
}
