:root {
  color-scheme: light;
  --bg: #eef2f0;
  --panel: #ffffff;
  --text: #16211d;
  --muted: #65716d;
  --line: #d9e0dc;
  --green: #1f8a5b;
  --green-2: #dff3e8;
  --yellow: #c98d19;
  --red: #b63b3b;
  --shadow: 0 14px 42px rgba(27, 42, 35, 0.14);
  --field: #ffffff;
  --button: #f8faf9;
  --status-bg: rgba(255, 255, 255, 0.92);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111715;
  --panel: #1a2420;
  --text: #eef5f1;
  --muted: #a5b3ad;
  --line: #30413a;
  --green: #36c57e;
  --green-2: #173426;
  --yellow: #e0ab3d;
  --red: #ff7676;
  --shadow: 0 14px 42px rgba(0, 0, 0, 0.35);
  --field: #121a17;
  --button: #223029;
  --status-bg: rgba(26, 36, 32, 0.94);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  height: 100%;
  min-height: 100%;
  position: relative;
}

body.embed #clearButton,
body.embed #exportButton,
body.embed .file-button {
  display: none;
}

body.embed .workspace {
  height: 100vh;
}

body.embed .map-panel,
body.embed .stat,
body.embed .panel-section {
  box-shadow: none;
}

.topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 800;
  width: auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 62%, transparent);
  backdrop-filter: blur(22px) saturate(1.35);
  box-shadow: var(--shadow);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

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

h1 {
  font-size: 20px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  min-width: 0;
}

.button,
.icon-button {
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--text);
  border-radius: 999px;
  min-height: 36px;
}

.toolbar-toggle {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  gap: 3px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  padding: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.toolbar-toggle span {
  padding: 0 7px 0 5px;
}

.toolbar-toggle button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  min-height: 28px;
  padding: 0 8px;
}

.toolbar-toggle button.is-active {
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  color: var(--text);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--line) 76%, transparent),
    0 2px 8px rgba(0, 0, 0, 0.08);
}

:root[data-theme="dark"] .toolbar-toggle button.is-active {
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.button {
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

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

.button.secondary {
  border-color: transparent;
  background: transparent;
}

.file-button input {
  display: none;
}

.icon-button {
  width: 34px;
  font-weight: 800;
}

.icon-button.danger {
  color: var(--red);
}

.workspace {
  display: block;
  position: relative;
  height: 100vh;
  padding: 0;
  min-height: 0;
  overflow: hidden;
}

.map-panel {
  background: var(--panel);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  position: relative;
  min-height: 0;
  height: 100%;
}

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

:root[data-theme="dark"] #map {
  background: #111b23;
}

:root[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) saturate(0.72) brightness(0.82) contrast(1.08);
}

:root[data-theme="dark"] .leaflet-control-zoom a,
:root[data-theme="dark"] .leaflet-control-attribution {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
}

.leaflet-interactive:focus {
  outline: none;
}

.map-status {
  position: absolute;
  left: 56px;
  bottom: 14px;
  z-index: 500;
  background: var(--status-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.1);
}

.map-status:empty {
  display: none;
}

.map-create-modal {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 650;
  width: min(340px, calc(100% - 24px));
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.side-panel {
  position: absolute;
  top: 94px;
  right: 12px;
  z-index: 700;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 106px);
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition:
    transform 160ms ease,
    opacity 160ms ease;
}

.side-panel.is-collapsed {
  transform: translateX(calc(100% - 104px));
}

.side-panel.is-collapsed .stats-grid,
.side-panel.is-collapsed .panel-section {
  display: none;
}

.drawer-toggle {
  align-self: flex-end;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0 12px;
  font: inherit;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat,
.panel-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(27, 42, 35, 0.08);
}

.stat {
  padding: 10px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  font-size: 26px;
  line-height: 1.1;
}

.panel-section {
  padding: 12px;
}

.section-header,
.visit-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.visit-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 10px;
}

.map-item-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-item-form-title {
  font-weight: 800;
  font-size: 14px;
}

.map-item-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.media-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
  color: var(--text);
  background: #fff;
  background: var(--field);
  min-width: 0;
}

textarea {
  resize: vertical;
}

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

.country-summary {
  color: var(--muted);
  margin-top: 8px;
  font-size: 13px;
}

.visit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.visit-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--panel) 94%, var(--bg));
}

.visit-photo-frame {
  background: var(--green-2);
  min-height: 86px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.visit-photo-frame img {
  width: 100%;
  height: 150px;
  display: block;
  object-fit: cover;
}

.visit-photo-frame video,
.visit-photo-frame iframe,
.item-popup video,
.item-popup iframe,
.item-popup img {
  width: 100%;
  max-height: 180px;
  border: 0;
  border-radius: 6px;
  object-fit: cover;
}

.media-embed {
  min-height: 260px;
}

.item-popup {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.item-popup-meta {
  color: var(--muted);
  font-size: 12px;
}

.visit-card-body {
  padding: 10px;
}

.visit-card h3 {
  font-size: 15px;
}

.visit-meta {
  color: var(--muted);
  font-size: 12px;
}

.visit-card p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

.delete-button {
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
}

.leaflet-popup-content {
  margin: 10px;
}

.popup-photo {
  width: 180px;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  margin-bottom: 8px;
}

@media (max-width: 900px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    align-items: center;
    flex-direction: row;
    gap: 8px;
    padding: 8px;
    overflow: visible;
    background: color-mix(in srgb, var(--panel) 62%, transparent);
    backdrop-filter: blur(22px) saturate(1.35);
  }

  .eyebrow {
    display: none;
  }

  .topbar > div:first-child {
    flex: 0 0 calc(40% - 4px);
    min-width: 0;
  }

  h1 {
    font-size: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    flex: 0 0 calc(60% - 4px);
    justify-content: flex-start;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: none;
    flex-wrap: nowrap;
    min-width: 0;
    padding: 1px;
  }

  .topbar-actions > :first-child {
    margin-left: auto;
  }

  .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  .toolbar-toggle {
    flex: 0 0 auto;
    min-height: 32px;
    border-radius: 999px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    font-size: 11px;
  }

  .toolbar-toggle span {
    display: none;
  }

  .toolbar-toggle button {
    min-height: 24px;
    border-radius: 999px;
    padding: 0 7px;
  }

  .toolbar-toggle button.is-active {
    background: color-mix(in srgb, var(--panel) 78%, transparent);
    box-shadow:
      inset 0 0 0 1px color-mix(in srgb, var(--line) 76%, transparent),
      0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .topbar .button.secondary {
    flex: 0 0 auto;
    min-height: 32px;
    border-radius: 999px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    padding: 0 9px;
    font-size: 0;
  }

  .topbar .button.secondary::before {
    content: attr(data-short);
    font-size: 12px;
  }

  .map-create-modal {
    max-height: calc(100vh - 96px);
    overflow-y: auto;
  }

  .workspace {
    height: 100vh;
    overflow: hidden;
  }

  body.embed .workspace {
    height: 100vh;
  }

  .side-panel {
    top: auto;
    bottom: 12px;
    right: 12px;
    width: min(340px, calc(100% - 24px));
    max-height: 44vh;
  }

  .map-panel {
    height: 100%;
  }

  .side-panel.is-collapsed {
    transform: translateX(calc(100% - 104px));
  }
}

@media (max-width: 520px) {
  .stats-grid,
  .split {
    grid-template-columns: 1fr;
    display: grid;
    width: 100%;
  }
}
