:root {
  --border: #d8dde6;
  --ink: #172033;
  --muted: #647083;
  --panel: #ffffff;
  --bg: #f4f6f8;
  --accent: #1466d9;
  --accent-soft: rgba(20, 102, 217, 0.12);
  --danger: #c23934;
  --ok: #1f7a4d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  height: 100vh;
  overflow: hidden;
}

.map-workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.toolbar button,
#saveButton {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

.toolbar button:hover,
#saveButton:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#saveButton {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 18px;
  background: #fbfcfe;
  border-bottom: 1px solid var(--border);
}

.metric {
  min-width: 0;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.metric strong {
  display: block;
  font-size: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-frame {
  flex: 1;
  overflow: auto;
  background: #e8ebef;
  position: relative;
}

.map-stage {
  position: relative;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  padding: 18px;
}

#mapImage {
  display: block;
  width: 1000px;
  max-width: none;
  background: #fff;
  box-shadow: 0 2px 12px rgba(22, 30, 46, 0.18);
  cursor: crosshair;
  user-select: none;
}

.selection-box {
  position: absolute;
  border: 3px solid var(--danger);
  border-radius: 50%;
  background: rgba(194, 57, 52, 0.08);
  pointer-events: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 6px rgba(194, 57, 52, 0.16);
}

.side-panel {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  background: var(--panel);
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.segment-list {
  display: grid;
  gap: 7px;
  max-height: 34vh;
  overflow: auto;
}

.segment-item {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.segment-item:hover,
.segment-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.segment-item strong {
  display: block;
  font-size: 13px;
}

.segment-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1f5;
  color: #3f4b5f;
  font-size: 12px;
  white-space: nowrap;
}

.status-badge.done {
  background: #e6f4ee;
  color: var(--ok);
}

.status-badge.blocked {
  background: #fff2e5;
  color: #a15300;
}

.detail-form {
  display: grid;
  gap: 12px;
  padding: 16px 14px 22px;
}

.form-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.segment-code {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
}

h2 {
  margin: 8px 0 0;
  font-size: 18px;
  line-height: 1.3;
}

.save-state {
  color: var(--ok);
  font-size: 12px;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  color: #334055;
}

.check-grid {
  display: grid;
  gap: 8px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.contractor-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.updated-info {
  margin: 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .map-workspace,
  .side-panel {
    height: auto;
    overflow: visible;
  }

  .map-frame {
    height: 58vh;
  }

  .side-panel {
    border-top: 1px solid var(--border);
  }

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