:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #eef3f8;
  --ink: #172033;
  --muted: #667184;
  --line: #d8e0eb;
  --line-strong: #bac6d8;
  --accent: #2367c9;
  --accent-strong: #174e9c;
  --accent-soft: #e5f0ff;
  --ok: #117a51;
  --warn: #9b5a00;
  --danger: #ba3030;
  --shadow: 0 18px 40px rgba(20, 31, 50, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: wait;
  opacity: 0.58;
}

svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.leaflet-container svg {
  width: unset;
  height: unset;
  stroke-width: unset;
  stroke-linecap: unset;
  stroke-linejoin: unset;
  fill: unset;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand > div:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.brand-mark,
.icon-button {
  flex-shrink: 0;
}

.session-link {
  color: var(--muted);
  font-size: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.brand p,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-toolbar,
.form-actions,
.panel-header {
  display: flex;
  gap: 10px;
  align-items: center;
}

.sidebar-toolbar,
.panel-header {
  justify-content: space-between;
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button {
  width: 38px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.route-form,
.invite-form {
  display: grid;
  gap: 12px;
}

.route-form {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.is-hidden {
  display: none !important;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: #29344a;
}

input[type="text"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}

input[type="text"],
select {
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  min-height: 76px;
  padding: 9px 10px;
}

.route-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}

.route-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.route-card:hover,
.route-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(35, 103, 201, 0.12);
}

.route-card strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.route-card span {
  color: var(--muted);
  font-size: 12px;
}

.route-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: #445066;
  font-size: 12px;
  font-weight: 700;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 20px;
  min-width: 0;
  padding: 24px;
}

.route-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.route-hero h2,
.panel h3 {
  margin: 0;
}

.route-hero h2 {
  overflow-wrap: anywhere;
  font-size: 27px;
  line-height: 1.2;
}

.route-description {
  max-width: 820px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(86px, 1fr));
  gap: 10px;
  margin: 0;
}

.stats div {
  min-height: 72px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stats dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats dd {
  margin: 7px 0 0;
  font-size: 18px;
  font-weight: 800;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.workspace-grid[data-role="viewer"],
.workspace-grid[data-role="contributor"] {
  grid-template-columns: minmax(0, 1fr);
}

.photos-panel {
  grid-column: 1 / -1;
}

.viewer-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
}

.viewer-toolbar h3 {
  margin: 0;
  font-size: 20px;
}

.viewer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.segmented-button {
  min-height: 38px;
  padding: 0 12px;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.segmented-button:first-child {
  border-left: 0;
}

.segmented-button.is-selected {
  background: var(--accent);
  color: #fff;
}

.compact-toggle {
  display: inline-flex;
  grid-auto-flow: column;
  grid-template-columns: auto auto;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  white-space: nowrap;
}

.compact-toggle input {
  margin: 0;
}

.viewer-layout {
  display: grid;
  grid-template-columns: minmax(250px, 32%) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(190px, 240px);
  grid-template-areas:
    "side main"
    "scope main";
  gap: 14px;
  min-height: 560px;
  height: min(740px, calc(100vh - 260px));
  min-width: 0;
}

.viewer-layout[data-view-mode="map"] .map-shell,
.viewer-layout[data-view-mode="photo"] .photo-panel {
  grid-area: main;
}

.viewer-layout[data-view-mode="map"] .photo-panel,
.viewer-layout[data-view-mode="photo"] .map-shell {
  grid-area: side;
}

.route-scope {
  grid-area: scope;
}

.map-shell,
.photo-panel,
.route-scope {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.map-shell,
#map {
  height: 100%;
}

.photo-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
}

.photo-panel-header,
.photo-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.photo-panel-header {
  justify-content: space-between;
  flex-wrap: wrap;
}

.photo-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.current-photo-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101727;
  color: #dbe6f5;
  cursor: zoom-in;
}

.viewer-layout[data-view-mode="map"] .current-photo-button {
  min-height: 0;
}

.current-photo-button:disabled {
  cursor: default;
}

.current-photo-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#current-photo-empty {
  color: #b8c6dc;
  font-weight: 800;
}

.current-photo-caption {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.current-photo-caption strong,
.current-photo-caption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-scope {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

.scope-list {
  display: grid;
  gap: 7px;
  min-height: 0;
  overflow: auto;
}

.scope-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.scope-button:hover,
.scope-button.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(35, 103, 201, 0.12);
}

.scope-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.scope-main strong,
.scope-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-main strong {
  font-size: 13px;
}

.scope-count {
  display: grid;
  place-items: center;
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.photo-group-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(12, 24, 42, 0.28);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.photo-group-marker.is-selected {
  background: #101727;
  box-shadow: 0 0 0 4px rgba(35, 103, 201, 0.22), 0 8px 20px rgba(12, 24, 42, 0.32);
}

.map-photo-thumb {
  overflow: hidden;
  border: 2px solid #ffffff;
  border-radius: 8px;
  background: #101727;
  box-shadow: 0 8px 20px rgba(12, 24, 42, 0.28);
}

.map-photo-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.map-photo-thumb.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(35, 103, 201, 0.28), 0 8px 20px rgba(12, 24, 42, 0.28);
}

.map-photo-more {
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #101727;
  box-shadow: 0 8px 20px rgba(12, 24, 42, 0.28);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.endpoint-marker {
  display: grid;
  place-items: center;
}

.endpoint-marker span {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(12, 24, 42, 0.24);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.endpoint-marker-start span {
  background: var(--ok);
}

.endpoint-marker-end span {
  background: var(--danger);
}

.panel {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border-top: 1px solid var(--line);
}

.photos-panel {
  min-height: 380px;
}

.upload-block {
  display: grid;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.upload-block:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.file-drop {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 74px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #f8fbff;
  cursor: pointer;
}

.file-drop:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop svg {
  width: 24px;
  height: 24px;
  color: var(--accent-strong);
}

.file-drop span {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
}

.progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-alt);
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ok);
  transition: width 180ms ease;
}

.segment-summary {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding-top: 4px;
}

.mini-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mini-header strong {
  font-size: 13px;
}

.segment-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.segment-item {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.segment-item:first-child {
  border-top: 0;
}

.segment-item > div:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.segment-item strong,
.segment-item span {
  overflow-wrap: anywhere;
}

.segment-item strong {
  font-size: 13px;
}

.segment-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.member-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.member-item:first-child {
  border-top: 0;
}

.member-item strong,
.member-item span {
  overflow-wrap: anywhere;
}

.member-item div {
  display: grid;
  gap: 3px;
}

.member-item strong {
  font-size: 13px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.photo-card {
  position: relative;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.photo-card .photo-preview {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  cursor: zoom-in;
  aspect-ratio: 4 / 3;
}

.photo-card .photo-delete {
  position: absolute;
  right: 6px;
  top: 6px;
  background: var(--surface);
}

.danger-button {
  color: var(--danger);
}

.danger-fill,
.danger-fill:hover {
  background: var(--danger);
}

.confirm-dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.confirm-dialog::backdrop {
  background: rgba(10, 15, 25, 0.55);
}

.confirm-dialog h3 {
  margin-top: 0;
}

.confirm-dialog p,
.upload-errors,
#upload-progress-text,
.access-notice {
  overflow-wrap: anywhere;
}

.confirm-dialog .form-actions {
  margin-top: 20px;
  justify-content: flex-end;
}

.upload-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.upload-errors {
  max-height: 180px;
  overflow: auto;
  padding-left: 20px;
  font-size: 13px;
  color: var(--danger);
}

.file-drop:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.access-notice {
  padding: 12px 0;
  color: var(--danger);
  border-bottom: 1px solid var(--line);
}

.member-item select {
  width: 150px;
}

.panel-header {
  flex-wrap: wrap;
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-card p {
  margin: 0;
  overflow: hidden;
  color: #465268;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.photo-meta .chip {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 34px;
  height: 34px;
}

.photo-dialog {
  width: min(980px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #0c111b;
  color: #fff;
}

.photo-dialog::backdrop {
  background: rgba(5, 10, 18, 0.7);
}

.photo-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 140px);
  object-fit: contain;
  background: #0c111b;
}

.photo-dialog p {
  margin: 0;
  padding: 12px 16px 16px;
  color: #d9e2f2;
}

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(12, 17, 27, 0.78);
  color: #fff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.status-ok {
  color: var(--ok);
}

.status-warn {
  color: var(--warn);
}

.status-danger {
  color: var(--danger);
}

@media (max-width: 1180px) {
  .route-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .viewer-layout {
    grid-template-columns: minmax(240px, 40%) minmax(0, 1fr);
  }

  .workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .photos-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .route-list {
    max-height: 340px;
  }

  .route-hero {
    grid-template-columns: 1fr;
  }

  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .viewer-controls {
    justify-content: flex-start;
  }

  .viewer-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 390px 340px 260px;
    grid-template-areas:
      "main"
      "side"
      "scope";
    height: auto;
    min-height: 0;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .member-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .member-item > div:first-child {
    grid-column: 1 / -1;
  }
  .sidebar,
  .workspace {
    padding: 16px;
  }

  .sidebar-toolbar {
    align-items: stretch;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .form-actions {
    flex-direction: column-reverse;
  }

  .route-hero h2 {
    font-size: 22px;
  }

  .viewer-controls,
  .segmented-control,
  .compact-toggle,
  .viewer-controls select {
    width: 100%;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
