:root {
  --bg: #e8ede8;
  --panel: #f5f8f5;
  --ink: #243229;
  --muted: #536557;
  --line: #c7d3c8;
  --accent: #2f6b44;
  --accent-soft: rgba(47, 107, 68, 0.18);
  --danger: #a13232;
  --shadow: 0 8px 24px rgba(19, 34, 23, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(120deg, #e4ebe4 0%, #eef3ee 45%, #dfe8df 100%);
}

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

.hidden {
  display: none !important;
}

.topbar {
  height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 248, 245, 0.92);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  font-size: 1.2rem;
  font-weight: 700;
}

.topbar p {
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 2px;
}

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

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

input[type="search"],
input[type="text"],
input[type="date"],
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

button,
.button-link,
.file-like {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 11px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.button-link:hover,
.file-like:hover {
  border-color: var(--accent);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button.danger {
  border-color: #d8adad;
  color: var(--danger);
}

button.ghost {
  background: #f4f7f4;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  height: calc(100% - 72px);
}

.map-shell {
  position: relative;
  min-width: 0;
  background: #dbe4db;
}

.map-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}

.map-viewport.point-mode {
  cursor: crosshair;
}

.map-viewport.dragging {
  cursor: grabbing;
}

.map-content {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  user-select: none;
}

.map-rotator {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: center center;
}

#mapImage {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
  pointer-events: none;
}

#overlaySvg {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
}

.zone-polygon {
  fill: rgba(64, 132, 86, 0.2);
  stroke: rgba(28, 82, 46, 0.74);
  stroke-width: 2;
  transition: fill 120ms ease, stroke-width 120ms ease, stroke 120ms ease;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
}

.zone-polygon:hover,
.zone-polygon.focused {
  fill: rgba(52, 120, 77, 0.32);
  stroke: rgba(19, 68, 39, 0.98);
  stroke-width: 3.5;
}

.zone-polygon.selected-zone {
  fill: rgba(65, 141, 92, 0.42);
  stroke: rgba(11, 59, 33, 1);
  stroke-width: 4.5;
  filter: drop-shadow(0 0 8px rgba(39, 121, 73, 0.45));
}

.zone-polygon.muted {
  fill: rgba(68, 109, 80, 0.12);
  stroke: rgba(44, 79, 57, 0.38);
}

.zone-label {
  font-weight: 700;
  font-family: Arial, Helvetica, sans-serif;
  fill: #202124;
  stroke: rgba(255, 255, 255, 0.97);
  paint-order: stroke;
  text-anchor: middle;
  dominant-baseline: middle;
  letter-spacing: 0.01em;
  pointer-events: none;
  user-select: none;
}

.zone-label-admin {
  fill: #1c2f42;
  stroke: rgba(252, 254, 255, 0.98);
}

.zone-label.selected-zone-label {
  fill: #0e4f2c;
  stroke: rgba(255, 255, 255, 1);
  font-weight: 800;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.95));
}

.zone-label.muted {
  opacity: 0.55;
}

.photo-point-meta {
  font-size: 0.8rem;
  color: #325347;
}

.photo-marker {
  fill: #d26f2c;
  stroke: #fff4e8;
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

.photo-marker-label {
  fill: #17130c;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.photo-marker-name {
  fill: #202124;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  stroke: rgba(255, 255, 255, 0.95);
  paint-order: stroke;
  pointer-events: none;
}

.photo-marker-group {
  cursor: pointer;
}

.photo-marker-group.selected-zone-marker .photo-marker {
  fill: #e2551f;
  stroke: #fff;
  filter: drop-shadow(0 0 8px rgba(226, 85, 31, 0.65));
}

.photo-marker-group.selected-zone-marker .photo-marker-name {
  font-weight: 800;
  fill: #111;
}

.photo-marker-group.muted {
  opacity: 0.42;
}

.photo-marker.active {
  fill: #e84f24;
  stroke: #fff;
}

.map-shell.overlays-hidden .zone-polygon {
  opacity: 0;
  pointer-events: none;
}

.map-shell.overlays-hidden .zone-label {
  opacity: 0;
}

.map-shell.overlays-hidden .photo-marker-group {
  opacity: 0;
  pointer-events: none;
}

.tooltip {
  position: absolute;
  display: none;
  transform: translate(12px, 12px);
  background: rgba(15, 30, 20, 0.92);
  color: #f5f7f5;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 30;
}

.detail-drawer {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

.drawer-empty,
.drawer-content {
  padding: 16px;
}

.drawer-empty h2 {
  margin-bottom: 8px;
}

.drawer-empty p {
  color: var(--muted);
}

.drawer-header {
  margin-bottom: 12px;
}

.drawer-header h2 {
  font-size: 1.3rem;
}

.drawer-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.zone-summary {
  color: #344638;
  margin-bottom: 14px;
}

.detail-drawer section {
  margin-top: 14px;
}

.detail-drawer h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 7px;
  color: var(--muted);
}

.bullet-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.photo-card {
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(17, 32, 22, 0.1);
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.photo-meta {
  padding: 8px;
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
}

.photo-date {
  color: var(--muted);
}

.tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  background: var(--accent-soft);
  color: #1f4f30;
  border: 1px solid #9fbea8;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 10, 0.86);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 80;
}

.lightbox figure {
  position: relative;
  display: inline-block;
  margin: 0;
  max-width: min(92vw, 1180px);
}

.lightbox img {
  max-width: 100%;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.lightbox figcaption {
  color: #f4f5f4;
  margin-top: 8px;
  font-size: 0.92rem;
}

.lightbox-topinfo {
  position: static;
  width: min(92%, 760px);
  margin: 0 auto 10px;
  background: rgba(14, 20, 16, 0.82);
  color: #f4f6f4;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 10px;
  padding: 9px 12px;
  text-align: center;
  z-index: 110;
  pointer-events: auto;
}

.lightbox-top-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.lightbox-top-meta {
  margin-top: 5px;
  font-size: 0.92rem;
  color: #d9e2db;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 2rem;
  line-height: 1;
  color: #ecf0ec;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.35);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  z-index: 120;
}

.lightbox-side {
  position: absolute;
  top: 70px;
  bottom: 0;
  width: 32%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  z-index: 85;
}

.lightbox-side span {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 2rem;
  line-height: 46px;
  text-align: center;
  color: #ecf0ec;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.35);
  opacity: 0.7;
}

.lightbox-side:hover span {
  opacity: 1;
}

.lightbox-side-prev {
  left: 0;
  justify-content: flex-start;
  padding-left: 14px;
}

.lightbox-side-next {
  right: 0;
  justify-content: flex-end;
  padding-right: 14px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  height: calc(100% - 72px);
}

.admin-sidebar {
  overflow: auto;
  display: grid;
  gap: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(17, 32, 22, 0.08);
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.panel label {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  font-size: 0.86rem;
}

.inline-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.zone-select {
  width: 100%;
  margin-top: 8px;
}

.hint {
  color: var(--muted);
  font-size: 0.84rem;
}

#polygonOutput {
  width: 100%;
  margin-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
}

input[type="file"] {
  margin-top: 8px;
}

#importInput {
  display: none;
}

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

.upload-target-card {
  margin-top: 8px;
  border: 1px solid #9fbea8;
  background: #edf5ef;
  border-radius: 9px;
  padding: 8px;
  display: grid;
  gap: 2px;
}

.upload-target-label {
  font-size: 0.76rem;
  color: #3f5d49;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.upload-target-name {
  font-weight: 700;
  color: #214d31;
}

.upload-target-meta {
  font-size: 0.8rem;
  color: #4f6658;
}

.upload-target-card.draft {
  border-color: #d6b48f;
  background: #fcf4ea;
}

.upload-target-card.draft .upload-target-name {
  color: #7d4a1f;
}

.upload-target-card.draft .upload-target-meta {
  color: #8a5f3f;
}

.upload-target-card.missing {
  border-color: #d9b0b0;
  background: #fbefef;
}

.upload-target-card.missing .upload-target-name {
  color: #8f2e2e;
}

.upload-target-card.missing .upload-target-meta {
  color: #8b4e4e;
}

.upload-queue {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.upload-queue-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.upload-queue-item-size {
  color: var(--muted);
  white-space: nowrap;
}

.photo-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.photo-item.point-target {
  border-color: #d28d2c;
  box-shadow: 0 0 0 2px rgba(210, 141, 44, 0.2);
}

.photo-item img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
}

.photo-item button {
  padding: 5px 7px;
}

.photo-item-summary {
  display: grid;
  gap: 4px;
}

.photo-item-title {
  font-weight: 600;
}

.photo-item-date {
  font-size: 0.82rem;
  color: var(--muted);
}

.photo-edit-fields {
  display: grid;
  gap: 6px;
}

.photo-edit-fields input {
  width: 100%;
}

.photo-item-actions {
  display: grid;
  gap: 6px;
}

.photo-edit-panel {
  margin-top: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.panel-map {
  position: relative;
  min-width: 0;
  padding: 0;
}

.status-strip {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(30, 48, 37, 0.9);
  color: #f5f7f5;
  font-size: 0.8rem;
  padding: 5px 9px;
  border-radius: 6px;
}

.admin-map .zone-polygon {
  fill: rgba(67, 121, 165, 0.18);
  stroke: rgba(31, 74, 109, 0.82);
}

.admin-map .zone-polygon.focused {
  fill: rgba(67, 121, 165, 0.3);
  stroke: rgba(14, 56, 94, 0.96);
}

.admin-map .zone-polygon.selected-zone {
  fill: rgba(63, 129, 184, 0.42);
  stroke: rgba(13, 65, 111, 1);
  stroke-width: 4.5;
  filter: drop-shadow(0 0 8px rgba(54, 120, 173, 0.5));
}

.admin-map .zone-polygon.muted {
  fill: rgba(59, 95, 130, 0.12);
  stroke: rgba(35, 62, 86, 0.38);
}

.admin-map .zone-label.zone-label-admin.selected-zone-label {
  fill: #0b3b63;
  stroke: rgba(255, 255, 255, 1);
  font-weight: 800;
  filter: drop-shadow(0 0 6px rgba(230, 242, 254, 0.95));
}

.admin-map .zone-label.zone-label-admin.muted {
  opacity: 0.52;
}

.admin-map .photo-marker-group.selected-zone-marker .photo-marker {
  fill: #2d85d0;
  stroke: #f4fbff;
  filter: drop-shadow(0 0 8px rgba(45, 133, 208, 0.68));
}

.admin-map .photo-marker-group.selected-zone-marker .photo-marker-name {
  fill: #0a3557;
  font-weight: 800;
}

.draft-polygon {
  fill: rgba(221, 142, 61, 0.22);
  stroke: rgba(172, 102, 29, 0.95);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
}

.draft-point {
  fill: #c06d1b;
  stroke: #fff;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: move;
}

@media (max-width: 1180px) {
  .map-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 42%;
  }

  .detail-drawer {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .admin-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .admin-sidebar {
    max-height: 44vh;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .topbar-actions input {
    grid-column: 1 / -1;
  }

  .map-layout {
    height: calc(100% - 112px);
  }

  .admin-layout {
    height: calc(100% - 112px);
  }
}
