:root {
  --bg: #eef3ee;
  --surface: #ffffff;
  --ink: #17221b;
  --muted: #667468;
  --line: #d6ded4;
  --green: #25563f;
  --green-dark: #163927;
  --yellow: #f4c95d;
  --rust: #b85d3b;
  --blue: #34699a;
  --shadow: 0 12px 32px rgba(23, 34, 27, 0.12);
}

* {
  box-sizing: border-box;
}

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

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

.hidden,
[hidden] {
  display: none !important;
}

button,
.capture-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.capture-button.disabled {
  opacity: 0.48;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: rgba(238, 243, 238, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.section-head p,
.photo-meta {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 10px;
  background: #dbe6dc;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.active {
  background: #d8f1df;
  color: #155b2d;
}

.status-pill.error {
  background: #f7ded8;
  color: #85351f;
}

.app-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 32, 25, 0.42);
}

.app-dialog {
  width: min(460px, 100%);
  border: 2px solid var(--green);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(20, 32, 25, 0.22);
  padding: 18px;
}

.app-dialog h2 {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 22px;
}

.app-dialog-message {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
}

.app-dialog-message p {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.45;
}

.app-dialog-form {
  display: grid;
  gap: 12px;
}

.app-dialog-form label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.app-dialog-form input,
.app-dialog-form select {
  font-size: 18px;
  font-weight: 800;
}

.dialog-error {
  margin: 0;
  border: 1px solid rgba(184, 93, 59, 0.55);
  border-radius: 8px;
  background: #fff0ea;
  color: #9a3517;
  padding: 10px;
  font-size: 15px;
  font-weight: 900;
}

.app-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.app-dialog-actions button {
  min-height: 54px;
  font-size: 18px;
  font-weight: 900;
}

.app-dialog-actions button:only-child {
  grid-column: 1 / -1;
}

.app-dialog-actions .danger {
  border-color: rgba(184, 93, 59, 0.55);
  background: #fff0ea;
  color: #9a3517;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.work-panel {
  order: 1;
}

.photo-panel {
  order: 2;
}

.controls-panel {
  order: 3;
}

.export-panel {
  order: 4;
}

.map-section {
  order: 5;
}

.panel,
.map-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.form-grid,
.stats-grid,
.action-grid,
.photo-actions {
  display: grid;
  gap: 10px;
}

.form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 11px 12px;
}

input[readonly],
select:disabled {
  background: #eef3ee;
  color: var(--ink);
  opacity: 1;
}

.route-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.endpoint-field {
  display: block;
  margin-top: 12px;
}

.endpoint-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.day-grid {
  grid-template-columns: 220px minmax(0, 1fr);
}

.day-list {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.day-chip {
  min-width: 148px;
  flex: 0 0 auto;
  display: grid;
  align-content: center;
  gap: 2px;
  text-align: left;
}

.day-chip.active {
  background: #e6f1e8;
  border-color: var(--green);
  color: var(--green-dark);
}

.day-chip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.action-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.icon {
  min-width: 20px;
  font-weight: 900;
  text-align: center;
}

.stats-grid {
  margin-top: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8faf7;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head.inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.map-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6f1;
  aspect-ratio: 16 / 9;
  min-height: 280px;
}

#routeMap {
  width: 100%;
  height: 100%;
  display: block;
}

.map-grid line {
  stroke: #dce5db;
  stroke-width: 1;
}

#routePath {
  stroke: var(--green);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-path {
  stroke: rgba(37, 86, 63, 0.34);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-path.active {
  stroke: var(--green);
  stroke-width: 8;
}

.track-dot {
  fill: var(--green-dark);
}

.photo-dot.before {
  fill: var(--blue);
  opacity: 0.55;
}

.photo-dot.during {
  fill: var(--rust);
  opacity: 0.55;
}

.photo-dot.active {
  opacity: 1;
}

.photo-label {
  fill: #fff;
  font-size: 24px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.empty-map {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

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

.photo-actions {
  grid-template-columns: 1fr 1fr;
}

.photo-point-control {
  margin-bottom: 12px;
}

.photo-point-control > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 8px;
  font-size: 32px;
  font-weight: 900;
}

.segmented input[value="BP"] + span,
.segmented input[value="EP"] + span {
  border-width: 2px;
}

.segmented input:checked + span {
  background: #e6f1e8;
  border-color: var(--green);
  color: var(--green-dark);
}

.interval-meter {
  display: grid;
  grid-template-columns: 74px minmax(0, 180px);
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.interval-meter span {
  margin-bottom: 0;
}

.interval-meter small {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.interval-meter input:disabled {
  opacity: 0.55;
}

.interval-meter:has(input:not(:disabled)) {
  border-left: 4px solid var(--green);
  padding-left: 8px;
}

.capture-button {
  min-height: 86px;
  font-size: 32px;
  line-height: 1.1;
}

.capture-button > span {
  margin-bottom: 0;
  color: inherit;
  font-size: inherit;
  font-weight: 900;
}

.capture-button.before {
  border-color: rgba(52, 105, 154, 0.4);
  background: #eef5fb;
  color: #214c73;
}

.capture-button.during {
  border-color: rgba(184, 93, 59, 0.4);
  background: #fbf0ea;
  color: #864123;
}

.capture-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.check-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  padding: 10px;
}

.check-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  margin-bottom: 8px;
}

.check-head h3 {
  margin: 0 0 2px;
  font-size: 15px;
}

.check-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check-head strong {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #e6f1e8;
  color: var(--green-dark);
  padding: 6px 10px;
  font-size: 13px;
}

.check-list {
  display: grid;
  gap: 6px;
}

.check-row {
  display: grid;
  grid-template-columns: minmax(84px, 1fr) 86px 86px;
  gap: 6px;
  align-items: center;
}

.check-row.header {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.check-row.required {
  border: 2px solid rgba(37, 86, 63, 0.28);
  border-radius: 8px;
  background: #eef5ee;
  padding: 4px;
}

.check-name {
  font-weight: 800;
}

.check-row.required .check-name {
  color: var(--green-dark);
  font-size: 18px;
  font-weight: 900;
}

.check-status {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--muted);
  font-size: 17px;
  font-weight: 900;
}

.check-status.ok {
  border-color: rgba(37, 86, 63, 0.35);
  background: #e6f1e8;
  color: var(--green-dark);
}

.check-status.missing {
  border-color: rgba(184, 93, 59, 0.55);
  background: #fff0ea;
  color: #9a3517;
}

.photo-list-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.photo-list {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.photo-list.empty {
  display: block;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fbfcfa;
  font-weight: 700;
}

.photo-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.photo-card img {
  width: 112px;
  height: 92px;
  object-fit: cover;
  border-radius: 6px;
  background: #d6ded4;
}

.photo-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.remove-photo {
  width: 32px;
  min-height: 32px;
  padding: 0;
}

.map-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--green);
  font-weight: 800;
}

#summaryText {
  min-height: 150px;
  margin-top: 12px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

@media (max-width: 820px) {
  .app-header {
    align-items: flex-start;
  }

  .form-grid,
  .action-grid,
  .stats-grid,
  .photo-list {
    grid-template-columns: 1fr 1fr;
  }

  .day-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .app-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 20px;
  }

  .form-grid,
  .action-grid,
  .stats-grid,
  .route-actions,
  .segmented,
  .interval-meter,
  .photo-actions,
  .photo-list {
    grid-template-columns: 1fr;
  }

  .check-row {
    grid-template-columns: minmax(74px, 1fr) 76px 76px;
  }

  .interval-meter small {
    grid-column: 1;
  }

  .map-wrap {
    aspect-ratio: 4 / 5;
    min-height: 360px;
  }

  .capture-button {
    min-height: 86px;
    font-size: 32px;
  }

  .photo-card {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .photo-card img {
    width: 96px;
    height: 86px;
  }
}
