:root {
  color-scheme: light;
  --navy: #173f5f;
  --navy-2: #102f47;
  --blue: #2878b5;
  --gray: #cbd1d6;
  --yellow: #f5c84c;
  --green: #40a66a;
  --red: #c74c4c;
  --ink: #16212a;
  --muted: #66727c;
  --surface: #ffffff;
  --background: #edf2f4;
  --border: #d9e0e4;
  --shadow: 0 14px 40px rgb(16 47 71 / 14%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--background); }

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #e7f0f3 0, var(--background) 220px);
  min-height: 100vh;
}

button, select, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  color: white;
  background: var(--navy);
  box-shadow: 0 6px 20px rgb(16 47 71 / 18%);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 4vw, 32px); }
h2 { margin-bottom: 4px; }
h3 { margin-bottom: 4px; }

.eyebrow {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  opacity: .78;
}

.network-badge {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgb(255 255 255 / 14%);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.network-badge.offline { background: #9f2d2d; }

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 28px) 36px;
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(150px, 220px) 1fr;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toolbar label { font-weight: 800; }
.toolbar select {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #b8c3ca;
  border-radius: 10px;
  background: white;
}

.progress-summary {
  justify-self: end;
  display: grid;
  text-align: right;
}
.progress-summary span { color: var(--muted); font-size: 13px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 4px;
  color: #48545e;
  font-size: 13px;
  font-weight: 700;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; border: 1px solid rgb(0 0 0 / 18%); }
.dot-gray { background: var(--gray); }
.dot-yellow { background: var(--yellow); }
.dot-green { background: var(--green); }

.share-card {
  margin: 0 0 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.share-card h2 { margin: 0; font-size: 18px; }
.share-card p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.share-blocks { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-top: 14px; }
.share-block { padding: 13px; border: 1px solid var(--border); border-radius: 12px; background: #f8fbfc; }
.share-block h3 { margin: 0; font-size: 15px; }
.share-block p { margin-top: 3px; }
.share-batches { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.share-batches button { min-height: 36px; padding: 0 10px; border: 0; border-radius: 9px; color: white; background: var(--blue); font-weight: 800; font-size: 12px; }
.share-history { flex-basis: 100%; color: var(--muted); font-size: 12px; }
.share-batches button:disabled { opacity: .55; cursor: not-allowed; }
.share-block.incomplete { opacity: .72; }
.share-notice { min-height: 18px; }
.share-notice.error { color: var(--red); font-weight: 700; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.logged-in-user { font-size: 12px; font-weight: 800; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); display: grid; gap: 10px; padding: 28px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.login-card h1 { margin: 0; color: var(--navy); }
.login-card > p:not(.eyebrow):not(.notice) { margin-bottom: 10px; color: var(--muted); }
.login-card label { font-weight: 800; }
.login-card input { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid #b8c3ca; border-radius: 10px; }
.admin-button { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.13); color: #fff; border-radius: 10px; padding: 9px 12px; font: inherit; font-weight: 800; cursor: pointer; }
.admin-dialog { max-width: 820px; }
.admin-login, .review-form { display: grid; gap: 10px; margin-top: 18px; }
.admin-login label, .review-form label { font-weight: 800; }
.admin-login > div { display: flex; gap: 8px; }
.admin-login input, .review-form textarea { width: 100%; border: 1px solid #cbd6df; border-radius: 10px; padding: 12px; font: inherit; }
.review-form textarea { min-height: 110px; resize: vertical; }
.admin-period-controls { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; margin-top: 18px; padding: 12px; border-radius: 12px; background: #eef4f7; text-align: center; }
.admin-period-controls span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.admin-summary { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); gap: 10px; margin: 14px 0; }
.admin-summary article { padding: 12px; border: 1px solid #d8e0e6; border-radius: 12px; background: #fff; }
.admin-summary strong, .admin-summary span { display: block; }
.admin-summary strong { font-size: 22px; color: var(--navy); }
.admin-summary span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.admin-list-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 18px 0 10px; }
.admin-list-heading h3, .admin-list-heading p { margin: 0; }
.admin-list-heading p { color: var(--muted); font-size: 13px; }
.admin-list-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 7px; }
.danger-button { border: 0; border-radius: 9px; padding: 10px 12px; background: #b9412d; color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.admin-target-list { display: grid; gap: 9px; }
.admin-target { border: 1px solid #d8e0e6; border-left: 5px solid #8896a1; border-radius: 10px; padding: 12px; background: #fff; }
.admin-target.status-valid { border-left-color: #26a269; }
.admin-target.status-late { border-left-color: #df5e43; }
.admin-target.status-repeat_requested { border-left-color: #e87919; }
.admin-target header { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.admin-target h4, .admin-target p { margin: 0; }
.admin-target p { margin-top: 3px; color: var(--muted); font-size: 13px; }
.admin-status { display: inline-block; border-radius: 999px; padding: 4px 8px; background: #edf2f5; color: #425466; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-valid .admin-status { color: #157347; background: #dcf4e5; }
.status-late .admin-status { color: #a93220; background: #fde6e1; }
.status-repeat_requested .admin-status { color: #a54c00; background: #fff0dc; }
.admin-slot-list { display: grid; gap: 4px; margin: 10px 0; font-size: 13px; }
.admin-slot-list a { color: #1b6da8; }
.admin-target details { margin-top: 8px; color: var(--muted); font-size: 13px; }
.admin-history { display: grid; gap: 4px; padding-top: 8px; }
.admin-target button { margin-top: 10px; }
.cycle-summary { color: #a54c00; }

.map-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: white;
  box-shadow: var(--shadow);
}

.map-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.map-heading p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.site-plan-viewport {
  position: relative;
  height: min(70vh, 820px);
  min-height: 460px;
  overflow: auto;
  overscroll-behavior: contain;
  background: #f7faf9;
  touch-action: auto;
}

.site-plan-host {
  position: relative;
  width: 1320px;
  min-height: 880px;
  padding: 18px;
}

.site-plan-host svg {
  display: block;
  width: 1280px;
  height: auto;
  filter: saturate(.75);
}

.site-plan-host svg text { pointer-events: none; user-select: none; }
.site-plan-host svg .site-unit {
  fill: var(--gray) !important;
  transition: fill .2s ease, filter .2s ease, opacity .2s ease;
}
.site-plan-host svg .site-unit.inactive { pointer-events: none; opacity: .64; }
.site-plan-host svg .site-unit.active-unit {
  pointer-events: auto;
  cursor: pointer;
  opacity: 1;
  stroke: #0c273a !important;
  stroke-width: 1.4px !important;
  filter: drop-shadow(0 0 2px white) drop-shadow(0 0 4px #1b6b9b);
}
.site-plan-host svg .active-unit.status-empty { fill: var(--gray) !important; }
.site-plan-host svg .active-unit.status-partial { fill: var(--yellow) !important; }
.site-plan-host svg .active-unit.status-complete { fill: var(--green) !important; }
.site-plan-host svg .active-unit:focus { outline: none; stroke: #e74848 !important; stroke-width: 2px !important; }
.site-plan-host svg .site-unit.under-construction {
  opacity: 1;
  stroke: #e56f00 !important;
  stroke-width: 2.25px !important;
  stroke-dasharray: 3 1.5;
  filter: drop-shadow(0 0 1px white) drop-shadow(0 0 3px rgba(229, 111, 0, .9));
}

.construction-mark {
  border: 1px solid #bb5700;
  border-radius: 3px !important;
  background: repeating-linear-gradient(135deg, #f49328 0 3px, #ffe1a8 3px 6px);
}
.construction-summary { color: #985000; font-size: 13px; }
.construction-summary.mapping-issue { color: var(--red); }
.road-summary { color: #087e42; font-size: 13px; }
.road-icon-key {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 3px;
  vertical-align: -2px;
  border: 2px solid #8a8f93;
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px white;
}

.site-plan-host svg .road-checkpoint { cursor: pointer; outline: none; }
.site-plan-host svg .road-checkpoint .road-scan {
  fill: rgb(255 255 255 / 88%);
  stroke: #8a8f93;
  stroke-width: 1.2px;
  stroke-dasharray: 2 1;
}
.site-plan-host svg .road-checkpoint .road-camera { fill: #8a8f93; }
.site-plan-host svg .road-checkpoint.status-complete .road-scan { stroke: #00a957; }
.site-plan-host svg .road-checkpoint.status-complete .road-camera { fill: #00a957; }
.site-plan-host svg .road-checkpoint:focus .road-scan { stroke: #173f5f; stroke-width: 2px; }

.loading {
  display: grid;
  place-items: center;
  min-height: 460px;
  color: var(--muted);
}

.primary-button, .secondary-button, .icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  font-weight: 800;
}
.primary-button { padding: 0 16px; color: white; background: var(--blue); }
.primary-button:disabled { cursor: not-allowed; opacity: .5; }
.secondary-button { padding: 0 14px; color: var(--navy); background: #e8f0f5; }
.secondary-button.dark { color: white; background: #344652; }
.full-width { width: 100%; }
.icon-button {
  width: 44px;
  padding: 0;
  color: var(--navy);
  background: #e8eef2;
  font-size: 28px;
}
.icon-button.light { color: white; background: rgb(255 255 255 / 16%); }

dialog {
  border: 0;
  padding: 0;
}
dialog::backdrop { background: rgb(10 24 34 / 62%); backdrop-filter: blur(3px); }

.sheet-dialog {
  width: min(680px, calc(100vw - 20px));
  max-height: 92vh;
  margin: auto auto 0;
  padding: 14px 16px 24px;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 50px rgb(0 0 0 / 24%);
}
.sheet-handle { width: 44px; height: 5px; margin: 0 auto 14px; border-radius: 99px; background: #c6ced3; }
.dialog-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.dialog-header p { margin-bottom: 0; color: var(--muted); }

.unit-status-banner {
  display: grid;
  gap: 3px;
  margin: 16px 0;
  padding: 13px 14px;
  border-left: 6px solid var(--gray);
  border-radius: 10px;
  background: #f1f4f6;
}
.unit-status-banner.status-partial { border-color: var(--yellow); background: #fff8dc; }
.unit-status-banner.status-complete { border-color: var(--green); background: #e7f6ed; }
.unit-status-banner span { color: var(--muted); font-size: 13px; }

.photo-slots { display: grid; gap: 12px; }
.photo-slot {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
}
.photo-slot p { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.photo-preview {
  position: relative;
  grid-column: 1 / -1;
  overflow: hidden;
  border-radius: 10px;
  background: #dce3e7;
}
.photo-preview img { display: block; width: 100%; max-height: 210px; object-fit: cover; }
.upload-indicator {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: white;
  background: rgba(3, 16, 25, .58);
  backdrop-filter: blur(2px);
}
.upload-indicator[hidden], .photo-preview[hidden] { display: none !important; }
.upload-ring {
  --upload-progress: 0deg;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: conic-gradient(#36a7ec var(--upload-progress), rgba(255, 255, 255, .3) 0);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
}
.upload-ring::before {
  content: "";
  grid-area: 1 / 1;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: white;
}
.upload-ring span {
  z-index: 1;
  grid-area: 1 / 1;
  color: var(--navy);
  font-weight: 900;
  font-size: 14px;
}
.upload-indicator strong { text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.slot-number {
  float: left;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: 9px;
  border-radius: 50%;
  color: white;
  background: var(--navy);
  font-weight: 850;
}
.notice { min-height: 20px; margin: 12px 2px 0; color: var(--muted); font-size: 13px; }
.notice.error { color: var(--red); font-weight: 700; }

.camera-dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  overflow: hidden;
  color: white;
  background: #071018;
}
.camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  height: 84px;
  padding: 12px 16px;
  background: #0d1d28;
}
.camera-header h2 { margin: 0; }
.camera-stage {
  position: relative;
  display: grid;
  place-items: center;
  height: calc(100dvh - 190px);
  overflow: hidden;
  background: black;
}
.camera-stage video, .camera-stage img { width: 100%; height: 100%; object-fit: contain; }
.camera-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .42;
  background-image:
    linear-gradient(to right, transparent 33.15%, rgb(255 255 255 / 72%) 33.35%, rgb(255 255 255 / 72%) 33.55%, transparent 33.75%),
    linear-gradient(to right, transparent 66.15%, rgb(255 255 255 / 72%) 66.35%, rgb(255 255 255 / 72%) 66.55%, transparent 66.75%),
    linear-gradient(to bottom, transparent 33.15%, rgb(255 255 255 / 72%) 33.35%, rgb(255 255 255 / 72%) 33.55%, transparent 33.75%),
    linear-gradient(to bottom, transparent 66.15%, rgb(255 255 255 / 72%) 66.35%, rgb(255 255 255 / 72%) 66.55%, transparent 66.75%);
}
.camera-stage video[hidden] ~ .camera-grid { display: none; }
.camera-error { max-width: 520px; margin: 20px; padding: 18px; border-radius: 12px; background: #612828; line-height: 1.5; }
.camera-actions { min-height: 106px; padding: 14px 16px; text-align: center; background: #0d1d28; }
.shutter-button {
  width: 74px;
  height: 74px;
  border: 7px solid #dce6eb;
  border-radius: 50%;
  color: transparent;
  background: transparent;
  box-shadow: 0 0 0 3px rgb(5 17 25 / 52%), inset 0 0 0 2px rgb(5 17 25 / 28%);
}
.preview-actions { display: flex; justify-content: center; gap: 12px; }
.photo-size { margin: 8px 0 0; color: #b8c6cf; font-size: 12px; }

@media (orientation: landscape) and (max-height: 650px) {
  .camera-dialog {
    position: fixed;
    inset: 0;
    margin: 0;
    background: #000;
  }
  .camera-header {
    position: absolute;
    z-index: 2;
    inset: 0 0 auto;
    height: auto;
    min-height: 70px;
    padding: 10px 16px 18px;
    background: linear-gradient(to bottom, rgb(3 12 18 / 72%), transparent);
  }
  .camera-header .eyebrow { font-size: 10px; }
  .camera-header h2 { font-size: clamp(20px, 3vw, 28px); }
  .camera-stage { height: 100dvh; background: #000; }
  .camera-stage video, .camera-stage img { object-fit: cover; }
  .camera-actions {
    position: absolute;
    z-index: 2;
    right: 0;
    bottom: 0;
    left: 0;
    min-height: 92px;
    padding: 12px 16px 14px;
    background: linear-gradient(to top, rgb(3 12 18 / 72%), transparent);
  }
  .shutter-button {
    width: 68px;
    height: 68px;
    border-width: 6px;
  }
  .preview-actions { gap: 10px; }
  .preview-actions .primary-button, .preview-actions .secondary-button { min-height: 40px; padding: 8px 14px; }
  .photo-size { margin-top: 4px; }
}

@media (max-width: 640px) {
  .topbar { padding: 14px; }
  .network-badge { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  main { padding: 12px 8px 24px; }
  .toolbar { grid-template-columns: auto 1fr; }
  .progress-summary { grid-column: 1 / -1; justify-self: stretch; text-align: left; padding-top: 8px; border-top: 1px solid var(--border); }
  .map-heading { align-items: flex-start; }
  .map-heading .secondary-button { max-width: 130px; }
  .site-plan-viewport { height: 67vh; min-height: 430px; }
  .share-card { padding: 14px; }
  .topbar-actions { gap: 7px; }
  .logged-in-user { display: none; }
  .admin-button { padding: 8px 9px; font-size: 12px; }
  .admin-summary { grid-template-columns: repeat(2, 1fr); }
  .admin-list-heading { align-items: start; }
  .admin-list-actions { justify-content: start; }
  .photo-slot { grid-template-columns: 1fr; }
  .photo-slot .primary-button { width: 100%; }
}
