:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #172026;
  --muted: #65727c;
  --line: #d9e0e5;
  --blue: #2563eb;
  --teal: #0f766e;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 16px 40px rgba(19, 31, 43, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: auto;
  z-index: 2;
}

.brand-row,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  font-weight: 720;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
  font-weight: 720;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-block {
  display: grid;
  gap: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.primary-button,
.ghost-button,
.segment,
.unit-button,
.icon-button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
  transition: background 0.15s ease, border 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.primary-button {
  padding: 0 16px;
  background: var(--teal);
  color: white;
  border-color: var(--teal);
  font-weight: 700;
}

.primary-button:hover {
  background: #0b635d;
}

.ghost-button {
  padding: 0 14px;
  background: #eef2f4;
  color: var(--ink);
  border-color: var(--line);
  font-weight: 650;
}

.ghost-button:hover {
  background: #e3e9ed;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: #eef2f4;
  color: var(--ink);
  border-color: var(--line);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover {
  background: #e3e9ed;
}

.full {
  width: 100%;
}

.unit-list {
  display: grid;
  gap: 8px;
  max-height: 38vh;
  overflow: auto;
  padding-right: 4px;
}

.unit-button {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: #f8fafb;
  color: var(--ink);
  border-color: var(--line);
}

.unit-button:hover,
.unit-button.active {
  background: #e8f3f1;
  border-color: #9fd3cd;
}

.unit-button strong {
  font-size: 14px;
}

.unit-button span {
  color: var(--muted);
  font-size: 12px;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segment {
  border: 0;
  border-right: 1px solid var(--line);
  background: #f8fafb;
  color: var(--ink);
  font-weight: 650;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--blue);
  color: white;
}

.custom-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
}

input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.summary-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: start;
  font-size: 13px;
}

.summary-grid span {
  color: var(--muted);
}

.summary-grid b {
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend {
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.line {
  width: 28px;
  height: 3px;
  border-radius: 999px;
}

.line.original {
  background: var(--blue);
}

.line.shifted {
  background: var(--amber);
}

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

.dot.active {
  background: var(--red);
}

.map-stage {
  position: relative;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

.toast {
  position: absolute;
  left: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100% - 40px));
  padding: 12px 14px;
  background: rgba(23, 32, 38, 0.92);
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 500;
  font-size: 14px;
}

.login-view {
  display: grid;
  min-height: 100vh;
  overflow: auto;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.13), transparent 42%),
    linear-gradient(300deg, rgba(217, 119, 6, 0.12), transparent 46%),
    var(--bg);
}

.login-box {
  display: grid;
  gap: 14px;
  width: min(100%, 360px);
  padding: 26px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

.settings-dialog {
  width: min(760px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(16, 24, 32, 0.34);
}

.settings-dialog form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-grid .wide {
  grid-column: 1 / -1;
}

.token-state {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.active-marker {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  background: var(--red);
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

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

  .sidebar {
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #map {
    height: 52vh;
  }

  .map-stage {
    height: 52vh;
  }

  .custom-range,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid .wide {
    grid-column: auto;
  }
}
