:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #65716b;
  --line: #d8ded9;
  --paper: #fbfbf8;
  --panel: rgba(255, 255, 255, 0.92);
  --field: #f5f7f4;
  --green: #2f6f55;
  --green-strong: #225641;
  --rose: #b35663;
  --rose-soft: #fff0f1;
  --blue: #315f86;
  --shadow: 0 18px 42px rgba(28, 38, 33, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #dde5dd;
}

.leaflet-control-container {
  font-family: inherit;
}

.app-header {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 10px;
  pointer-events: none;
}

.app-header > * {
  pointer-events: auto;
}

.app-header > div:first-child {
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(216, 222, 217, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.kicker {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.header-actions,
.card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 300px minmax(420px, 560px);
  justify-content: space-between;
  gap: 14px;
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto 24px;
  pointer-events: none;
}

.map-panel {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid rgba(216, 222, 217, 0.94);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.overview {
  align-self: start;
  max-height: calc(100vh - 142px);
  padding: 14px;
  overflow: auto;
}

.overview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.timeline-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.timeline-item {
  min-width: 0;
}

.timeline-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.timeline-drag-handle {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--muted);
  cursor: grab;
  font-size: 16px;
  font-weight: 900;
  touch-action: none;
}

.timeline-drag-handle:active {
  cursor: grabbing;
}

.timeline-item.dragging .timeline-row {
  opacity: 0.55;
}

.timeline-item.drop-target .timeline-button,
.timeline-item.drop-target .timeline-drag-handle {
  border-color: var(--rose);
  box-shadow: 0 0 0 3px rgba(179, 86, 99, 0.16);
}

.timeline-button {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 58px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  min-height: 54px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  text-align: left;
}

.timeline-button:hover {
  border-color: var(--green);
}

.timeline-order-actions {
  display: none;
  grid-template-columns: 1fr;
  gap: 6px;
}

.timeline-order-button {
  min-width: 44px;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.timeline-order-button:disabled {
  opacity: 0.35;
}

.timeline-pin {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.timeline-time {
  color: var(--green);
  font-size: 13px;
  font-weight: 850;
  line-height: 1.15;
}

.timeline-name {
  display: block;
  overflow-wrap: anywhere;
  font-weight: 800;
  line-height: 1.25;
}

.timeline-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.map-hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.planner {
  min-width: 0;
  max-height: calc(100vh - 142px);
  padding: 14px;
  overflow: auto;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding-bottom: 10px;
}

.toolbar h2 {
  font-size: 24px;
  line-height: 1.1;
}

.toolbar p {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.status-line {
  min-height: 28px;
  color: var(--muted);
  font-size: 13px;
}

.stop-list {
  display: grid;
  gap: 14px;
}

.stop-card {
  padding: 15px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stop-card.active-stop {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 111, 85, 0.14);
}

.card-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.place-line label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.place-input {
  min-height: 48px;
  font-size: 24px;
  font-weight: 850;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 111, 85, 0.14);
  background: #fff;
}

.grid-fields {
  display: grid;
  grid-template-columns: 132px minmax(150px, 1fr);
  gap: 11px;
  margin-top: 14px;
}

.grid-fields .wide {
  grid-column: 1 / -1;
}

.location-actions,
.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-self: end;
}

.advanced-coordinates {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(245, 247, 244, 0.72);
  padding: 9px 10px;
}

.advanced-coordinates summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}

.coordinate-grid {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  margin-top: 10px;
}

.grid-fields label,
.text-fields label {
  display: grid;
  gap: 7px;
}

.text-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 11px;
  margin-top: 11px;
}

.photo-section {
  margin-top: 14px;
}

.photo-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 10px;
}

.photo-head h3 {
  font-size: 16px;
}

.photo-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 96px;
  border: 1.5px dashed #9eaaa3;
  border-radius: 8px;
  background: #f8faf7;
  color: var(--muted);
  text-align: center;
  font-weight: 750;
}

.drop-zone.dragging {
  border-color: var(--green);
  background: #edf7f1;
  color: var(--green-strong);
}

.drop-zone input {
  display: none;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 9px;
  margin-top: 11px;
}

.photo-tile {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.photo-preview-button {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.remove-photo {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 30px;
  min-height: 30px;
  border-radius: 999px;
  border: 0;
  background: rgba(23, 32, 28, 0.78);
  color: #fff;
  font-weight: 900;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.map-link,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 850;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.primary-button:hover {
  background: var(--green-strong);
}

.secondary-button,
.ghost-button {
  background: rgba(255, 255, 255, 0.86);
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: var(--rose-soft);
  border-color: #f0c8cd;
  color: var(--rose);
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--field);
  border-color: var(--line);
  color: var(--ink);
}

.map-link {
  background: #eef5fb;
  border-color: #caddeb;
  color: var(--blue);
}

.map-link[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.45;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.stop-marker-shell {
  background: transparent;
  border: 0;
}

.stop-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 24px rgba(23, 32, 28, 0.28);
  font-size: 15px;
  font-weight: 950;
}

.stop-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 12px;
  height: 12px;
  background: var(--green);
  transform: translateX(-50%) rotate(45deg);
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
}

.stop-marker.active {
  background: #b35663;
}

.stop-marker.active::after {
  background: #b35663;
}

.leaflet-popup-content {
  display: grid;
  gap: 4px;
  min-width: 130px;
  margin: 12px 14px;
  color: var(--ink);
  font-family: inherit;
}

.leaflet-popup-content span {
  color: var(--green);
  font-weight: 850;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(12, 18, 15, 0.84);
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: min(1100px, 100%);
  max-height: min(82vh, 900px);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  object-fit: contain;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 26px;
  font-weight: 800;
}

.lightbox-caption {
  align-self: start;
  margin-top: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 750;
}

body.lightbox-open {
  overflow: hidden;
}

body.panels-collapsed .layout {
  display: none;
}

body.panels-collapsed .app-header {
  width: min(560px, calc(100% - 20px));
  margin-left: 10px;
}

body.panels-collapsed .app-header > div:first-child {
  padding: 10px 12px;
}

body.panels-collapsed h1 {
  font-size: 22px;
}

body.panels-collapsed .subtitle,
body.panels-collapsed .kicker {
  display: none;
}

@media (max-width: 940px) {
  #map {
    position: relative;
    inset: auto;
    z-index: 1;
    width: 100%;
    height: min(68vh, 620px);
    min-height: 420px;
  }

  body {
    background: var(--paper);
  }

  .app-header,
  .layout {
    width: min(100% - 20px, 1180px);
  }

  .app-header {
    position: relative;
    z-index: 2;
    display: grid;
    align-items: start;
    gap: 8px;
    padding: 10px 0 8px;
    pointer-events: auto;
  }

  .app-header > div:first-child {
    width: 100%;
    max-width: none;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .kicker,
  .subtitle {
    display: none;
  }

  h1 {
    font-size: 20px;
  }

  .layout {
    position: relative;
    z-index: 2;
    grid-template-columns: 1fr;
    margin-top: 0;
  }

  .overview,
  .planner {
    max-height: none;
  }

  .map-panel {
    background: #fff;
    backdrop-filter: none;
    box-shadow: 0 8px 22px rgba(28, 38, 33, 0.08);
  }

  .planner {
    margin-bottom: 28px;
  }

  .toolbar,
  .photo-head,
  .card-top {
    display: grid;
  }

  .card-actions {
    justify-content: start;
  }

  .map-hint {
    display: none;
  }

  .overview {
    padding: 10px;
  }

  .planner {
    padding: 12px;
  }
}

@media (max-width: 540px) {
  .header-actions {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .header-actions > * {
    flex: 0 0 auto;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button,
  .map-link,
  .icon-button {
    min-height: 34px;
    padding: 0 11px;
    font-size: 13px;
  }

  .grid-fields,
  .location-actions,
  .coordinate-grid {
    grid-template-columns: 1fr;
  }

  .stop-card {
    padding: 13px;
  }

  .place-input {
    font-size: 21px;
  }

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

  .timeline-button {
    grid-template-columns: 26px 52px minmax(0, 1fr);
    min-height: 50px;
  }

  .timeline-row {
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 7px;
  }

  .timeline-drag-handle {
    display: none;
  }

  .timeline-order-actions {
    display: grid;
  }

  .timeline-drag-handle {
    min-height: 50px;
  }

  .lightbox {
    padding: 14px;
  }

  .lightbox-close {
    top: 10px;
    right: 10px;
  }
}
