:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #18212f;
  --muted: #637083;
  --line: #d8e0ea;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(24, 33, 47, 0.12);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary-dark);
}

img {
  max-width: 100%;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.72rem 0.8rem;
  background: #fff;
  color: var(--text);
  font: inherit;
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  text-decoration: none;
}

.topbar nav {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-form {
  margin: 0;
}

.topbar nav a,
.link-button {
  padding: 0.55rem 0.75rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
}

.page {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
}

.auth-card,
.panel,
.map-card,
.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card,
.panel {
  padding: clamp(1rem, 3vw, 1.5rem);
}

.auth-card {
  width: min(460px, 100%);
  margin: 4rem auto;
}

.auth-card form,
.panel form,
.grid-form {
  display: grid;
  gap: 1rem;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin: 0 0 1rem;
}

.section-title h1,
.panel h1,
.auth-card h1 {
  margin: 0 0 0.3rem;
}

.section-title p,
.auth-card p {
  margin: 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.55rem;
  padding: 0.68rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.alert {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 6px;
  border: 1px solid #b7e4ce;
  background: #e9f8ef;
  color: #17623a;
}

.alert.error {
  border-color: #f1bbb5;
  background: #fff0ef;
  color: var(--danger);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.map-card {
  overflow: hidden;
}

.map-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}

.map-card > div {
  padding: 1rem;
}

.map-card h2 {
  margin: 0 0 0.25rem;
}

.map-card p {
  margin: 0.25rem 0;
  color: var(--muted);
}

.map-card .actions {
  padding: 0 1rem 1rem;
}

.empty {
  padding: 2rem;
  color: var(--muted);
}

.narrow {
  width: min(720px, 100%);
}

.preview {
  width: min(420px, 100%);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.table-panel {
  display: grid;
  gap: 0.75rem;
}

.user-row {
  display: grid;
  grid-template-columns: 1.2fr 1.5fr 0.8fr 1fr auto auto;
  gap: 0.55rem;
  align-items: center;
}

.map-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1rem;
  align-items: start;
}

.map-viewer {
  position: relative;
  display: grid;
  gap: 0.75rem;
}

.zoom-controls {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  justify-content: flex-end;
}

.editor-toolbar {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
}

.tool {
  min-height: 2.4rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 750;
}

.tool.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.danger-tool {
  color: var(--danger);
}

.zoom-controls .button {
  min-width: 3rem;
}

.map-viewport {
  position: relative;
  height: min(72vh, 760px);
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
}

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

.map-transform {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transform-origin: 0 0;
  will-change: transform;
}

.map-editor {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.map-image {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  user-select: none;
  pointer-events: none;
}

.map-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.map-object {
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}

.map-object.selected {
  filter: drop-shadow(0 0 6px rgba(15, 118, 110, 0.7));
}

.vertex-handle,
.draft-point {
  fill: #ffffff;
  stroke: var(--primary);
  stroke-width: 4;
  cursor: move;
  vector-effect: non-scaling-stroke;
}

.pin {
  position: absolute;
  width: 1.35rem;
  height: 1.35rem;
  transform: translate(-50%, -100%);
  border: 2px solid #fff;
  border-radius: 999px 999px 999px 0;
  background: #e11d48;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  rotate: -45deg;
  cursor: grab;
}

.pin::after {
  content: "";
  position: absolute;
  inset: 0.28rem;
  border-radius: 50%;
  background: #fff;
}

.pin:active {
  cursor: grabbing;
}

.object-panel {
  position: sticky;
  top: 5.5rem;
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.recognition-panel {
  display: grid;
  gap: 0.85rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.recognition-panel h2 {
  margin: 0;
}

.recognition-panel p {
  margin: 0;
  color: var(--muted);
}

.compact {
  gap: 0.65rem;
}

.ai-layer {
  pointer-events: none;
}

.object-panel h2,
.object-panel p {
  margin: 0;
}

.object-panel p {
  color: var(--muted);
}

.coordinate-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.pin-images {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.pin-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .map-workspace,
  .user-row {
    grid-template-columns: 1fr;
  }

  .object-panel {
    position: static;
  }

  .section-title {
    align-items: stretch;
    flex-direction: column;
  }
}
