:root {
  color-scheme: light;
  --bg: #eef3f4;
  --panel: #ffffff;
  --ink: #14232b;
  --soft: #637781;
  --line: #d7e0e3;
  --blue: #176c86;
  --teal: #1b998b;
  --yellow: #d99f2b;
  --red: #c95f4b;
  --shadow: 0 18px 45px rgba(20, 35, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #f8fbfb;
  overflow: auto;
  min-height: 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.workspace.trip-open {
  grid-template-rows: auto auto minmax(320px, 48vh) auto minmax(220px, 1fr);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
  color: var(--soft);
  font-size: 0.82rem;
  font-weight: 800;
  overflow-x: auto;
}

.breadcrumb button,
.breadcrumb span {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
}

.breadcrumb button {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(20, 35, 43, 0.06);
  padding: 16px;
}

.panel-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.05rem;
}

.field,
.field-grid {
  display: grid;
  gap: 7px;
}

.field {
  margin-top: 12px;
}

.field-grid {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.selected-trip-fields {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.field span {
  color: var(--soft);
  font-size: 0.78rem;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.15);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f9fbfb;
  color: var(--ink);
}

.save-action {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.save-status {
  color: var(--soft);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
  min-height: 0.8rem;
  text-align: center;
}

.save-status.ok {
  color: var(--teal);
}

.save-status.warn {
  color: var(--yellow);
}

.save-status.error {
  color: var(--red);
}

.icon-button.saving {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.15);
}

.icon-button.saved {
  border-color: var(--teal);
  background: rgba(27, 153, 139, 0.08);
}

.primary-button,
.secondary-button,
.file-picker span,
.map-control {
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-weight: 750;
  padding: 10px 12px;
}

.secondary-button {
  width: 100%;
  margin-top: 8px;
  border-color: var(--line);
  background: #f8fbfb;
  color: var(--ink);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.file-picker {
  display: block;
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.file-picker span {
  display: block;
  text-align: center;
}

.muted {
  margin: 10px 0 0;
  color: var(--soft);
  font-size: 0.86rem;
}

.crew-list {
  display: grid;
  gap: 9px;
}

.trip-list {
  display: grid;
  margin-top: 8px;
  gap: 8px;
}

.trip-select {
  width: 100%;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #fbfdfd;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.trip-select.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.13);
}

.trip-select.all-trips {
  border-left-color: var(--teal);
}

body:not(.is-trip-open) .sidebar section:nth-of-type(2),
body:not(.is-trip-open) .sidebar section:nth-of-type(3) {
  display: none;
}

.trip-select strong,
.trip-select span {
  display: block;
}

.trip-select span {
  margin-top: 3px;
  color: var(--soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.crew-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 36px;
  gap: 7px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.metric {
  background: #fbfdfd;
  padding: 14px 18px;
}

.metric span,
.leg-meta,
.stop-meta {
  display: block;
  color: var(--soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.map-stage {
  position: relative;
  height: 100%;
  min-height: 0;
  background: #dfeaed;
  overflow: hidden;
}

.workspace:not(.trip-open) .map-stage {
  height: calc(100vh - 52px);
  min-height: 540px;
}

.workspace.trip-open .map-stage {
  height: 100%;
  min-height: 320px;
}

.workspace.trip-open .detail-tabs {
  display: flex;
}

.route-map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container {
  background: #dfeaed;
  color: var(--ink);
  font: inherit;
  overflow: hidden;
}

.leaflet-map-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-pane > svg,
.leaflet-pane > canvas {
  user-select: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  max-width: none !important;
  max-height: none !important;
  border: 0;
}

.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-image-layer,
.leaflet-pane > svg path,
.leaflet-tile-container {
  pointer-events: none;
}

.leaflet-marker-icon.leaflet-interactive,
.leaflet-image-layer.leaflet-interactive,
.leaflet-pane > svg path.leaflet-interactive,
.leaflet-interactive {
  pointer-events: auto;
  cursor: pointer;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
  pointer-events: none;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 800;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.map-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  z-index: 500;
}

.map-summary {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
  padding: 12px;
}

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

.map-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.map-summary-grid div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  padding: 9px;
}

.map-summary-grid span {
  display: block;
  color: var(--soft);
  font-size: 0.72rem;
  font-weight: 800;
}

.map-summary-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 1rem;
  line-height: 1.15;
}

.map-summary-hint {
  margin: 12px 0 0;
  color: var(--soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.map-control {
  background: rgba(255, 255, 255, 0.9);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(20, 35, 43, 0.12);
}

.map-control.active {
  background: var(--blue);
  color: #fff;
}

.zoom-box-control {
  min-width: 92px;
}

.route-map.zoom-box-active,
.route-map.zoom-box-active .leaflet-container {
  cursor: crosshair;
}

.zoom-box-rectangle {
  pointer-events: none;
}

.leaflet-popup-content {
  min-width: 230px;
}

.leaflet-popup {
  position: absolute;
  margin-bottom: 20px;
  text-align: left;
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.leaflet-popup-content {
  margin: 14px 16px;
  line-height: 1.35;
}

.leaflet-popup-tip-container {
  position: absolute;
  left: 50%;
  width: 40px;
  height: 20px;
  margin-left: -20px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 14px;
  height: 14px;
  margin: -7px auto 0;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: var(--shadow);
}

.leaflet-popup-close-button {
  position: absolute;
  top: 4px;
  right: 8px;
  border: 0;
  background: transparent;
  color: var(--soft);
  font-size: 1.2rem;
  line-height: 1;
  text-decoration: none;
  z-index: 1;
}

.trip-count-tooltip {
  border: 0;
  background: transparent;
  box-shadow: none;
  color: #fff;
  font-weight: 950;
  font-size: 0.86rem;
  pointer-events: none;
}

.trip-count-tooltip::before {
  display: none;
}

.map-popup-title {
  margin: 0 0 6px;
  font-weight: 900;
  line-height: 1.18;
}

.map-popup-meta {
  display: block;
  color: var(--soft);
  font-weight: 750;
  margin-bottom: 10px;
}

.map-popup-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-weight: 850;
  padding: 8px 10px;
}

.detail-tabs {
  display: none;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8fbfb;
}

.detail-tab {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 10px;
}

.detail-tab.active {
  background: var(--blue);
  color: #fff;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.72fr) minmax(380px, 1.25fr) minmax(300px, 0.88fr);
  gap: 14px;
  padding: 14px;
  overflow: auto;
}

.workspace:not(.trip-open) .toolbar,
.workspace:not(.trip-open) .detail-tabs,
.workspace:not(.trip-open) .detail-layout {
  display: none;
}

body.is-trip-open .app-shell,
body.is-trip-open .workspace {
  height: auto;
  min-height: 100vh;
  overflow: visible;
}

body.is-trip-open .detail-layout {
  overflow: visible;
  align-items: start;
}

.overview-grid {
  display: grid;
  gap: 8px;
}

.overview-item,
.source-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfd;
  padding: 10px;
}

.source-item {
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.source-item.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.13);
}

.overview-item span,
.source-item span {
  display: block;
  color: var(--soft);
  font-size: 0.76rem;
  font-weight: 750;
}

.overview-item strong,
.source-item strong {
  display: block;
  margin-top: 3px;
}

.source-block {
  margin-top: 16px;
}

.source-list {
  display: grid;
  gap: 8px;
}

.timeline-panel,
.editor-panel {
  min-height: 0;
}

.leg-list {
  display: grid;
  gap: 10px;
}

.leg-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfd;
}

.leg-card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.13);
}

.leg-card button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.leg-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.leg-stops {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.stop-chip {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 8px;
  text-align: left;
}

.stop-chip.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 108, 134, 0.13);
}

.stop-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--yellow);
}

.stop-chip[data-type="marina"] .stop-dot {
  background: var(--teal);
}

.stop-chip[data-type="anchorage"] .stop-dot {
  background: var(--yellow);
}

.stop-chip[data-type="swim"] .stop-dot {
  background: #4d93c7;
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--soft);
  text-align: center;
  padding: 18px;
}

#editorTitle {
  margin-bottom: 8px;
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-rows: auto auto 40vh auto auto;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .detail-tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .detail-layout {
    display: block;
  }

  .detail-layout > .panel {
    display: none;
  }

  .detail-layout[data-active-view="overview"] > [data-panel="overview"],
  .detail-layout[data-active-view="timeline"] > [data-panel="timeline"],
  .detail-layout[data-active-view="editor"] > [data-panel="editor"] {
    display: block;
  }
}

@media (max-width: 560px) {
  .field-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .crew-row {
    grid-template-columns: 1fr 1fr 36px;
  }

  .detail-layout,
  .sidebar {
    padding: 10px;
  }

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