:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --line: #d8dee7;
  --line-strong: #aab6c5;
  --text: #18202a;
  --muted: #667085;
  --header: #24303d;
  --accent: #0f766e;
  --accent-soft: #e5f3f0;
  --amber: #b45309;
  --danger: #b42318;
  --pin-blue: #2563eb;
  --pin-lime: #84cc16;
  --pin-orange: #f97316;
  --pin-pink: #ec4899;
  --shadow: 0 14px 30px rgba(24, 32, 42, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  min-height: 92px;
  display: grid;
  grid-template-columns: minmax(310px, 0.7fr) minmax(0, 1.7fr);
  gap: 20px;
  align-items: center;
  padding: 14px 24px;
  background: var(--header);
  color: #fff;
  border-bottom: 4px solid var(--accent);
}

.eyebrow {
  margin: 0 0 4px;
  color: #a9bdc8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.title-block {
  min-width: 0;
}

.title-row {
  display: grid;
  grid-template-columns: minmax(98px, 132px) minmax(160px, 220px);
  gap: 10px;
  align-items: center;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.view-tabs button {
  min-height: 32px;
  padding: 5px 12px;
  border-color: rgba(255, 255, 255, 0.38);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 700;
}

.view-tabs button:hover,
.view-tabs button.is-active {
  border-color: #fff;
  background: #fff;
  color: var(--header);
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  flex: none;
  font-size: 24px;
}

#headerAgencySelect,
#headerInstallerSelect {
  width: 100%;
  min-height: 34px;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(132px, 1fr));
  gap: 8px;
  margin: 0;
}

.summary-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
}

.summary-grid dt {
  color: #c0cbd3;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.summary-grid dd {
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 700;
}

.app-main {
  min-height: calc(100vh - 86px);
  display: grid;
  padding: 12px;
}

.workspace {
  min-height: calc(100vh - 110px);
  display: grid;
  grid-template-columns: minmax(540px, clamp(560px, 32vw, 640px)) minmax(0, 1fr);
  grid-template-rows: minmax(560px, calc(100vh - 110px));
  grid-template-areas:
    "list detail";
  gap: 12px;
  overflow: visible;
}

.map-screen {
  min-height: calc(100vh - 110px);
  display: grid;
}

.list-pane,
.map-pane,
.detail-pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.list-pane {
  grid-area: list;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.detail-pane {
  grid-area: detail;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.map-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.map-screen .map-pane {
  min-height: 0;
}

.toolbar {
  display: grid;
  grid-template-columns:
    minmax(132px, 1.4fr)
    minmax(76px, 0.85fr)
    minmax(84px, 0.95fr)
    minmax(76px, 0.85fr)
    54px;
  gap: 6px;
  align-items: end;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

label {
  min-width: 0;
  display: grid;
  gap: 5px;
}

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

input,
select,
button {
  min-height: 36px;
  border-radius: 6px;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}

button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

button:disabled {
  cursor: default;
  color: #a6afba;
  background: #eef1f4;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 1px;
}

.result-bar {
  min-height: 44px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.is-error {
  color: var(--danger);
  font-weight: 700;
}

.map-toolbar {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.map-filter-bar {
  display: grid;
  grid-template-columns: minmax(140px, 240px) minmax(160px, 280px) 72px;
  gap: 8px;
  align-items: end;
}

.map-actions {
  display: grid;
  grid-template-columns: 82px minmax(160px, 1fr) 64px 64px;
  gap: 8px;
  align-items: end;
}

.radius-field {
  min-width: 0;
}

.map-status {
  min-height: 20px;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.map-status strong {
  color: var(--text);
  font-size: 13px;
}

.map-canvas {
  position: relative;
  min-height: 320px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(216, 222, 231, 0.5) 1px, transparent 1px),
    linear-gradient(rgba(216, 222, 231, 0.5) 1px, transparent 1px),
    #eef3f6;
  background-size: 48px 48px;
  touch-action: none;
}

.map-screen .map-canvas {
  min-height: 520px;
}

.map-canvas:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: -3px;
}

.map-tiles,
.map-radius-layer,
.map-markers {
  position: absolute;
  inset: 0;
}

.map-tiles img {
  position: absolute;
  width: 256px;
  height: 256px;
  user-select: none;
}

.radius-circle {
  position: absolute;
  border: 2px solid rgba(15, 118, 110, 0.75);
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.12);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.radius-origin {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(24, 32, 42, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.map-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 2px 8px rgba(24, 32, 42, 0.32);
  cursor: pointer;
  transform: translate(-50%, -100%) rotate(-45deg);
}

.map-marker::after {
  position: absolute;
  inset: 4px;
  content: "";
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
}

.map-marker:hover,
.map-marker.is-selected {
  z-index: 2;
  box-shadow: 0 0 0 4px rgba(24, 32, 42, 0.18), 0 3px 10px rgba(24, 32, 42, 0.34);
}

.map-marker.visit-within-3,
.legend-dot.visit-within-3 {
  background: var(--pin-blue);
}

.map-marker.visit-within-6,
.legend-dot.visit-within-6 {
  background: var(--pin-lime);
}

.map-marker.visit-within-12,
.legend-dot.visit-within-12 {
  background: var(--pin-orange);
}

.map-marker.visit-over-12,
.legend-dot.visit-over-12 {
  background: var(--pin-pink);
}

.map-zoom {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  display: grid;
  gap: 6px;
}

.map-zoom button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  background: rgba(255, 255, 255, 0.96);
  font-weight: 700;
}

.map-attribution {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 3;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.84);
  color: #3e4d5f;
  font-size: 11px;
  text-decoration: none;
}

.map-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.map-legend div {
  min-width: 0;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  border-right: 1px solid var(--line);
}

.map-legend div:last-child {
  border-right: 0;
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.map-legend dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pager {
  display: grid;
  grid-template-columns: 36px 88px 36px;
  gap: 6px;
  align-items: center;
  text-align: center;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf1f5;
  color: #3e4d5f;
  font-size: 12px;
  font-weight: 700;
}

.list-pane tbody tr {
  cursor: pointer;
}

.list-pane tbody tr:hover {
  background: #f7faf9;
}

.list-pane tbody tr.is-selected {
  background: var(--accent-soft);
}

.list-pane table {
  min-width: 0;
  table-layout: fixed;
}

.list-pane th,
.list-pane td {
  padding: 7px 6px;
  font-size: 12px;
}

.list-pane th {
  font-size: 11px;
}

.list-pane th:nth-child(1),
.list-pane td:nth-child(1) {
  width: 36%;
}

.list-pane th:nth-child(2),
.list-pane td:nth-child(2) {
  width: 16%;
}

.list-pane th:nth-child(3),
.list-pane td:nth-child(3) {
  width: 16%;
}

.list-pane th:nth-child(4),
.list-pane td:nth-child(4) {
  width: 18%;
}

.list-pane th:nth-child(5),
.list-pane td:nth-child(5) {
  width: 14%;
}

.empty-row td {
  padding: 28px 10px;
  color: var(--muted);
  text-align: center;
}

.detail-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.detail-head .eyebrow {
  color: var(--accent);
}

.detail-head h2 {
  font-size: 19px;
  word-break: break-word;
}

.detail-head p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.detail-head p:last-child span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-head p:last-child strong {
  margin-right: 4px;
  color: #3e4d5f;
}

.store-profile {
  max-height: 210px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  overflow: auto;
  border-bottom: 1px solid var(--line);
}

.store-profile div {
  min-width: 0;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.store-profile div.is-wide {
  grid-column: 1 / -1;
}

.store-profile dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.store-profile dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.history-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.history-head h3 {
  margin: 0;
  color: #3e4d5f;
  font-size: 14px;
}

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

.detail-wrap table {
  min-width: 640px;
  table-layout: fixed;
}

.detail-wrap th:nth-child(1),
.detail-wrap td:nth-child(1) {
  width: 90px;
}

.detail-wrap th:nth-child(2),
.detail-wrap td:nth-child(2) {
  width: 112px;
}

.detail-wrap th:nth-child(3),
.detail-wrap td:nth-child(3) {
  width: 70px;
}

.detail-wrap th:nth-child(4),
.detail-wrap td:nth-child(4) {
  width: 58px;
}

.detail-wrap th:nth-child(5),
.detail-wrap td:nth-child(5) {
  width: 70px;
}

.detail-wrap th:nth-child(6),
.detail-wrap td:nth-child(6) {
  width: 62px;
}

.detail-wrap th:nth-child(7),
.detail-wrap td:nth-child(7) {
  width: 120px;
}

.login-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 32, 42, 0.72);
}

.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.login-box h1 {
  font-size: 21px;
}

.login-box button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 1320px) {
  .app-header {
    grid-template-columns: minmax(300px, 0.7fr) minmax(0, 1.7fr);
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(112px, 1fr));
  }

  .workspace {
    min-height: calc(100vh - 110px);
    overflow: visible;
    grid-template-columns: minmax(520px, 540px) minmax(0, 1fr);
    grid-template-rows: minmax(540px, calc(100vh - 110px));
    grid-template-areas:
      "list detail";
  }

  .detail-pane {
    min-height: 360px;
  }
}

@media (max-width: 980px) {
  .app-header {
    grid-template-columns: 1fr;
  }

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

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      "list"
      "detail";
  }
}

@media (max-width: 760px) {
  .app-header {
    padding: 14px;
  }

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

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

  .toolbar label:first-child {
    grid-column: 1 / -1;
  }

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

  .map-filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .radius-field {
    grid-column: 1 / -1;
  }

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

  #clearButton {
    grid-column: 1 / -1;
  }

  #mapFilterClearButton {
    grid-column: 1 / -1;
  }

  .store-profile {
    grid-template-columns: 1fr;
  }

  .result-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .pager {
    align-self: end;
  }
}
