:root {
  --bg: #edf3f1;
  --surface: #ffffff;
  --surface-soft: #f6faf8;
  --ink: #10201d;
  --muted: #65736f;
  --line: #d8e2de;
  --brand: #123f3a;
  --brand-2: #0e7c72;
  --brand-3: #e8f3f0;
  --accent: #c69a31;
  --danger: #b23b33;
  --warn: #b8860f;
  --ok: #247a5a;
  --info: #2d6f8f;
  --shadow: 0 18px 42px rgba(16, 32, 29, 0.1);
  --shadow-soft: 0 8px 22px rgba(16, 32, 29, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(14, 124, 114, 0.12), transparent 30rem),
    radial-gradient(circle at top right, rgba(198, 154, 49, 0.1), transparent 28rem),
    linear-gradient(180deg, #f8fbfa 0, var(--bg) 20rem);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #17534c 0%, var(--brand) 100%);
  color: #fff;
  font-weight: 750;
  padding: 0.78rem 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

button:hover {
  background: linear-gradient(180deg, #1b6158 0%, #144b44 100%);
  box-shadow: 0 10px 24px rgba(20, 33, 29, 0.12);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #f4f8f6;
  color: var(--brand);
  border: 1px solid #cddbd5;
  box-shadow: none;
}

button.secondary:hover {
  background: #e6efeb;
}

.file-action {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0.78rem 1rem;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 750;
  cursor: pointer;
}

.file-action.secondary {
  background: #f4f8f6;
  border: 1px solid #cddbd5;
}

.file-action input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

button.danger {
  background: linear-gradient(180deg, #c64a40 0%, var(--danger) 100%);
  color: #fff;
}

.export-grid button {
  background: linear-gradient(180deg, #25665e 0%, #174e44 100%);
}

.export-grid button.secondary {
  background: #f4f8f6;
  color: var(--brand);
}

.export-grid button.danger {
  background: linear-gradient(180deg, #c64a40 0%, var(--danger) 100%);
}

button:disabled {
  opacity: 0.5;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1rem;
  background: rgba(251, 253, 252, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--info);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 5vw, 2rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0.4rem;
  font-size: 1.15rem;
}

.role-switch {
  min-width: 8.75rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.role-switch select {
  margin-top: 0.25rem;
}

.tabbar {
  position: sticky;
  top: 73px;
  z-index: 19;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.7rem 0.85rem;
  background: rgba(242, 247, 245, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.tabbar::-webkit-scrollbar {
  display: none;
}

.tab {
  min-width: max-content;
  min-height: 42px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  padding: 0.58rem 0.85rem;
  box-shadow: none;
}

.tab.active {
  background: linear-gradient(180deg, #17534c 0%, var(--brand) 100%);
  color: #fff;
  border-color: var(--brand);
}

.tab[disabled] {
  color: #8b9692;
  background: #edf2f0;
  cursor: not-allowed;
}

.role-notice {
  padding: 0.65rem 1rem;
  background: #fff8e8;
  border-bottom: 1px solid #ead6a4;
  color: #6f4b00;
  font-weight: 750;
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.section-band,
.data-form {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 1rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--brand-2);
}

.export-grid,
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
}

.metric-grid {
  display: grid;
  gap: 1rem;
}

.metric-group {
  padding: 1rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-group h3 {
  margin: 0 0 0.75rem;
  color: var(--brand);
  font-size: 1rem;
}

.metric-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.sync-panel {
  display: grid;
  gap: 0.85rem;
}

.sync-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
}

.sync-overview article,
.issue {
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.sync-overview strong,
.issue strong {
  display: block;
  color: var(--brand);
}

.sync-overview span,
.issue span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.sync-filter {
  max-width: 22rem;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.sync-status {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.metric {
  min-height: 96px;
  padding: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, var(--surface-soft) 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--brand-2);
}

.metric:nth-child(4n + 2)::before {
  background: var(--info);
}

.metric:nth-child(4n + 3)::before {
  background: var(--accent);
}

.metric:nth-child(4n + 4)::before {
  background: var(--ok);
}

.metric strong {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--brand);
  font-size: 1.8rem;
  line-height: 1.05;
}

.metric span {
  color: var(--muted);
  font-size: 0.85rem;
}

.section-band {
  margin-top: 1rem;
  padding: 1rem;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.section-title h2 {
  position: relative;
  padding-left: 0.75rem;
}

.section-title h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18rem;
  bottom: 0.18rem;
  width: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.section-title span {
  color: var(--muted);
  font-size: 0.85rem;
}

.map-wrap {
  width: 100%;
  overflow: hidden;
  background: #eaf0ed;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  aspect-ratio: 16 / 10;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65), var(--shadow-soft);
}

#siteMap,
canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#siteMap {
  min-height: 320px;
  background: #d8e4df;
}

.site-marker {
  background: transparent;
  border: 0;
}

.site-marker span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.38);
}

.site-marker.has-logtag span {
  position: relative;
  border-width: 4px;
  font-weight: 950;
  box-shadow: 0 0 0 3px rgba(198, 154, 49, 0.52), 0 2px 9px rgba(0, 0, 0, 0.38);
}

.site-marker.has-logtag span::after {
  content: "T";
  position: absolute;
  right: -8px;
  top: -8px;
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  color: #10201d;
  font-size: 0.58rem;
  font-weight: 950;
}

.trap-marker {
  background: transparent;
  border: 0;
}

.trap-marker span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 6px;
  background: #c69a31;
  color: #10201d;
  font-size: 0.72rem;
  font-weight: 950;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.34);
}

.map-fallback {
  display: grid;
  min-height: 320px;
  place-items: center;
  padding: 1rem;
  color: var(--muted);
  font-weight: 800;
}

.detail-open {
  overflow: hidden;
}

.detail-sheet[hidden] {
  display: none;
}

.detail-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  align-items: end;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: rgba(11, 22, 20, 0.48);
  box-shadow: none;
}

.detail-panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(86vh, 920px);
  margin: 0 auto;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 18px 18px 0 0;
  background: linear-gradient(180deg, #ffffff 0%, #f6faf8 100%);
  box-shadow: 0 -18px 50px rgba(7, 16, 14, 0.28);
}

.detail-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.detail-header h2 {
  margin: 0;
  font-size: 1.45rem;
}

.detail-close {
  min-height: 42px;
}

.detail-content {
  padding: 1rem;
}

.detail-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid color-mix(in srgb, var(--status-color) 28%, var(--line));
  border-left: 6px solid var(--status-color);
  border-radius: 8px;
  background: color-mix(in srgb, var(--status-color) 10%, #ffffff);
}

.detail-status span,
.detail-status strong {
  font-weight: 850;
}

.detail-grid {
  display: grid;
  gap: 0.85rem;
}

.detail-card {
  padding: 0.95rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.detail-card h3 {
  margin: 0 0 0.75rem;
  color: var(--brand);
  font-size: 1rem;
}

.detail-card dl {
  display: grid;
  gap: 0.55rem;
  margin: 0;
}

.detail-card dl div {
  display: grid;
  grid-template-columns: minmax(8rem, 0.45fr) 1fr;
  gap: 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #edf3f0;
}

.detail-card dl div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.detail-card dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.detail-card dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-weight: 700;
}

.detail-photos {
  margin-top: 0.85rem;
}

.photo-strip {
  display: grid;
  grid-auto-columns: minmax(132px, 168px);
  grid-auto-flow: column;
  gap: 0.7rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.photo-strip figure {
  margin: 0;
}

.photo-strip img,
.photo-missing {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7efeb;
  object-fit: cover;
}

.photo-missing {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 850;
}

.photo-strip figcaption {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.leaflet-control-layers {
  border: 1px solid rgba(20, 33, 29, 0.12) !important;
  border-radius: 8px !important;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16) !important;
}

.leaflet-control-layers-toggle {
  width: 38px !important;
  height: 38px !important;
  background-size: 22px 22px !important;
}

.leaflet-control-layers-expanded {
  max-width: min(230px, calc(100vw - 4rem));
  padding: 0.55rem 0.65rem !important;
  font-size: 0.88rem;
}

.leaflet-control-layers label {
  margin: 0.25rem 0;
  color: var(--ink);
  font-size: 0.88rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 10px rgba(16, 32, 29, 0.04);
}

.dot {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: 0.35rem;
  border-radius: 99px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.ok {
  background: var(--ok);
}

.warn {
  background: var(--warn);
}

.critical {
  background: var(--danger);
}

.muted {
  background: #7d8581;
}

.data-form {
  padding: 1rem;
  border-top: 4px solid var(--brand-2);
}

.form-head,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-head {
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.form-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 1rem -1rem -1rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

label {
  display: block;
  color: #53625e;
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  margin-top: 0.25rem;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: #fcfefd;
  color: var(--ink);
  padding: 0.72rem 0.78rem;
  box-shadow: inset 0 1px 0 rgba(20, 33, 29, 0.03);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 48px;
  margin-top: 0.25rem;
  border: 1px solid #cbd8d4;
  border-radius: 8px;
  background: #fcfefd;
  color: var(--ink);
  padding: 0.72rem 0.78rem;
  cursor: pointer;
}

.check-field input {
  width: 1.35rem;
  min-height: 1.35rem;
  margin: 0;
  accent-color: var(--brand);
  box-shadow: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-2);
  outline: 3px solid rgba(15, 118, 110, 0.14);
  background: #fff;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

input:invalid,
select:invalid,
textarea:invalid {
  border-color: #c27c74;
}

.wide {
  grid-column: 1 / -1;
}

.autosave-note {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.autosave-note::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.4rem;
  border-radius: 999px;
  background: var(--ok);
}

.warning-box {
  margin-top: 1rem;
  padding: 0.8rem;
  border-left: 4px solid var(--danger);
  border-radius: 8px;
  background: #fff2ef;
  color: #7a271a;
  font-weight: 750;
}

.issue-list {
  display: grid;
  gap: 0.65rem;
}

.issue.warn {
  border-left: 4px solid var(--warn);
}

.issue.info {
  border-left: 4px solid var(--info);
}

.history-list {
  display: grid;
  gap: 0.75rem;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.95rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfa 100%);
  box-shadow: var(--shadow-soft);
}

.history-item header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.history-item dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 0.7rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.history-item dt {
  font-weight: 850;
}

.history-item dd {
  margin: 0;
}

.pill {
  align-self: start;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 850;
  box-shadow: 0 3px 10px rgba(16, 32, 29, 0.12);
}

.role-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfa 100%);
}

.role-card ul {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
}

#toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: linear-gradient(180deg, #174e44 0%, #102b27 100%);
  color: #fff;
  opacity: 0;
  transform: translateY(0.8rem);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

dialog {
  width: min(520px, calc(100% - 2rem));
  border: 0;
  border-radius: 8px;
  padding: 1rem;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

video {
  width: 100%;
  border-radius: 8px;
  background: #000;
}

@media (min-width: 720px) {
  .toolbar {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-header {
    align-items: flex-start;
  }

  .role-switch {
    min-width: 7.5rem;
  }

  .section-title {
    display: block;
  }

  .form-head,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-actions button,
  .form-actions .file-action,
  .form-head button {
    width: 100%;
  }

  .history-item header {
    display: block;
  }

  .history-item .pill {
    display: inline-block;
    margin-top: 0.5rem;
  }

  .leaflet-top.leaflet-right {
    top: 0.55rem;
    right: 0.55rem;
  }

  .leaflet-control-layers-expanded {
    max-width: 180px;
    font-size: 0.8rem;
  }

  .leaflet-control-layers-toggle {
    width: 34px !important;
    height: 34px !important;
    background-size: 19px 19px !important;
  }

  .detail-panel {
    max-height: 90vh;
  }

  .detail-header {
    align-items: flex-start;
  }

  .detail-header .detail-close {
    padding-inline: 0.75rem;
  }

  .detail-card dl div {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .photo-strip {
    grid-auto-columns: minmax(118px, 42vw);
  }
}

@media (min-width: 980px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
