:root {
  --bg: #f4f1ec;
  --bg-deep: #0c1119;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: #ffffff;
  --surface-muted: rgba(19, 23, 28, 0.06);
  --ink: #151a22;
  --ink-soft: #66707a;
  --line: rgba(18, 25, 33, 0.14);
  --line-strong: rgba(18, 25, 33, 0.24);
  --teal: #17a9a5;
  --blue: #2c67ff;
  --red: #cc4737;
  --amber: #cd8f26;
  --shadow: 0 22px 60px rgba(12, 17, 24, 0.17);
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Inter var", Inter, "Noto Sans SC", "Noto Sans TC", "Noto Sans JP", "Noto Sans KR", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgba(44, 103, 255, 0.07), transparent 42%),
    radial-gradient(circle at 100% 30%, rgba(23, 169, 165, 0.07), transparent 38%),
    radial-gradient(circle at 72% 112%, rgba(205, 143, 38, 0.08), transparent 45%),
    linear-gradient(180deg, #efe8de 0%, var(--bg) 42%, #f4f1ec 100%);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

body.dark {
  --bg: #0f141b;
  --surface: rgba(22, 28, 36, 0.72);
  --surface-strong: #171d26;
  --surface-muted: rgba(244, 247, 255, 0.03);
  --ink: #f3f6fb;
  --ink-soft: #a4adba;
  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.24);
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

.app-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px clamp(16px, 2.8vw, 38px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--bg);
  background: linear-gradient(150deg, var(--teal), var(--blue));
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 12px;
}

.top-actions,
.ip-actions,
.export-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  padding: 24px clamp(16px, 3vw, 40px) 40px;
}

.intro-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--red);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 860px;
  margin-bottom: 12px;
  font-size: clamp(30px, 4.8vw, 56px);
  line-height: 1.05;
}

.lede {
  margin-bottom: 0;
  max-width: 760px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.safety-note {
  border: 1px solid color-mix(in oklab, var(--amber) 42%, var(--line));
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--amber) 12%, transparent);
  padding: 16px;
}

.safety-note strong,
.safety-note span {
  display: block;
}

.safety-note span {
  margin-top: 6px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.atlas-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(300px, 1.3fr) minmax(360px, 470px);
  min-height: 740px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(130deg, color-mix(in oklab, var(--surface) 82%, transparent), color-mix(in oklab, var(--surface) 68%, transparent));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.control-dock,
.preview-ledger {
  position: relative;
  padding: 22px;
  background: var(--surface-strong);
}

.control-dock {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid var(--line);
}

.preview-ledger {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.dock-heading {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.status-dot {
  margin-top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 7px color-mix(in oklab, var(--teal) 24%, transparent);
}

.dock-heading h2,
.ledger-head h2,
.drawer-head h3 {
  margin-bottom: 4px;
  font-size: 19px;
}

.dock-heading p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

.select,
.input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: color-mix(in oklab, var(--surface-strong) 86%, transparent);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select:focus,
.input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--blue) 22%, transparent);
}

.compact {
  min-height: 36px;
  max-width: 150px;
}

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

.ip-box {
  display: grid;
  gap: 10px;
  margin-top: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--teal) 7%, transparent);
}

.inline-message {
  min-height: 18px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--ink);
  transition: transform 0.2s, border-color 0.2s, background 0.2s;
}

.primary-button {
  margin-top: auto;
  min-height: 48px;
  border-color: var(--line-strong);
  background: linear-gradient(120deg, var(--ink), color-mix(in oklab, var(--ink) 86%, var(--blue)));
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.secondary-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.map-stage {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  background: radial-gradient(circle at 18% 15%, rgba(44, 103, 255, 0.14), transparent 45%),
    radial-gradient(circle at 80% 75%, rgba(23, 169, 165, 0.16), transparent 38%),
    radial-gradient(circle at 50% 100%, rgba(205, 143, 38, 0.12), transparent 45%),
    var(--bg);
}

.map-canvas {
  position: relative;
  overflow: hidden;
}

.map-canvas::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(130deg, color-mix(in oklab, var(--bg-deep) 22%, transparent), transparent 62%),
    url("./assets/atlas-canvas.png") center / cover no-repeat;
  opacity: 0.94;
}

.map-canvas::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.09) 0 2px, transparent 2px 48px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.06) 0 2px, transparent 2px 48px);
  mix-blend-mode: soft-light;
  pointer-events: none;
  opacity: 0.33;
}

.pin,
.route {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.pin {
  width: 14px;
  height: 14px;
  border: 3px solid var(--surface-strong);
  border-radius: 50%;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  animation: pulse 2.2s ease-in-out infinite;
}

.pin-a {
  left: 23%;
  top: 34%;
  background: var(--red);
}

.pin-b {
  left: 56%;
  top: 46%;
  background: var(--blue);
}

.pin-c {
  left: 74%;
  top: 25%;
  background: var(--teal);
}

.route {
  height: 2px;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--red), var(--blue), var(--teal));
  opacity: 0.77;
}

.route-a {
  left: 24%;
  top: 36%;
  width: 36%;
  transform: rotate(20deg);
}

.route-b {
  left: 57%;
  top: 47%;
  width: 23%;
  transform: rotate(-28deg);
}

.region-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface-strong) 92%, transparent);
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  min-height: 34px;
  background: var(--surface);
  color: var(--ink-soft);
  white-space: nowrap;
  font-size: 12px;
}

.chip.active {
  color: #fff;
  border-color: var(--ink);
  background: linear-gradient(120deg, #181f29, #2f3b4b);
}

.ledger-head,
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.record-count,
.drawer-head span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: var(--ink-soft);
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.active {
  background: color-mix(in oklab, var(--blue) 10%, transparent);
}

.detail-drawer {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.details-grid {
  display: grid;
  gap: 16px;
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-section h4 {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.field-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(102px, 36%) minmax(0, 1fr);
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.field-row span:first-child {
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.field-row span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  }
}

@media (max-width: 1180px) {
  .atlas-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-stage {
    display: none;
  }
}

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

  .intro-band,
  .top-actions,
  .export-row,
  .ip-actions,
  .ledger-head {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .compact {
    max-width: none;
  }

  .control-dock {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .atlas-panel {
    display: grid;
  }

  .preview-ledger {
    min-width: 0;
  }

  .export-row,
  .ip-actions {
    flex-wrap: wrap;
  }

  .secondary-button {
    flex: 1 1 auto;
  }
}
