:root {
  color-scheme: light;
  --ink: #141820;
  --muted: #667085;
  --line: #d7dde5;
  --panel: #ffffff;
  --canvas: #f3f6f8;
  --accent: #0f766e;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(243, 246, 248, 0.95), rgba(235, 239, 243, 0.96)),
    repeating-linear-gradient(90deg, rgba(20, 24, 32, 0.04) 0 1px, transparent 1px 84px);
  color: var(--ink);
  font-family:
    Pretendard,
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
}

button,
input,
select {
  min-width: 0;
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.brand-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  overflow: visible;
  filter: drop-shadow(0 10px 14px rgba(15, 23, 42, 0.18));
}

.logo-pin {
  fill: #141820;
}

.logo-tunnel {
  fill: #ffffff;
}

.logo-window {
  fill: #00a84d;
}

.logo-track {
  fill: none;
  stroke: #141820;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.logo-light {
  fill: #ef7c1c;
}

.brand h1 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(26px, 3vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.icon-button,
.text-button,
.line-tab {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.icon-button:hover,
.text-button:hover,
.line-tab:hover {
  transform: translateY(-1px);
  border-color: #9aa4b2;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.control-band {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.line-tabs {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(0, 1.6fr);
  gap: 10px;
}

.line-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 38px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.line-tab span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-tab.is-active {
  background: var(--line-color);
  color: #fff;
  border-color: var(--line-color);
  box-shadow: 0 8px 18px rgba(20, 24, 32, 0.16);
}

.line-tab.is-active .line-dot {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.32);
}

.line-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--line-color);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.line-tab-group {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 9px;
  border: 1px solid #e0e6ee;
  border-radius: 8px;
  background: #f8fafc;
}

.line-tab-heading {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.line-tab-grid {
  display: grid;
  gap: 6px;
}

.line-tab-group.is-numbered .line-tab-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.line-tab-group.is-other .line-tab-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.line-tab.is-number {
  min-height: 34px;
  padding: 0 6px;
  font-size: 15px;
  font-weight: 900;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(190px, 1.5fr) minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.section-heading select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.section-heading select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.text-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #c5ccd6;
  transition: background 160ms ease;
}

.switch span::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  content: "";
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

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

.metric strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: 24px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-section {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-heading select {
  width: 136px;
  flex: 0 0 auto;
}

.map-section {
  padding: 0;
}

.map-section .section-heading {
  margin: 0;
  padding: 16px 16px 12px;
}

.map-canvas {
  width: 100%;
  height: clamp(420px, 58dvh, 700px);
  overflow: hidden;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: #e6edf3;
}

.leaflet-container {
  font: inherit;
  overflow: hidden;
  touch-action: pan-x pan-y;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  border: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
}

.leaflet-tile-loaded {
  visibility: inherit;
}

.leaflet-map-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.train-popup {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

.train-popup strong {
  color: var(--ink);
  font-size: 14px;
}

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

.track-board {
  display: grid;
  gap: 12px;
}

.line-strip {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--line-color);
  border-radius: 8px;
  background: #fff;
}

.line-strip.is-empty {
  background: rgba(255, 255, 255, 0.62);
}

.strip-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.strip-label strong {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strip-label span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.route-track {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}

.route-track-inner {
  position: relative;
  width: max(100%, var(--track-width));
  min-height: 140px;
  padding: 0 18px;
}

.route-rail {
  position: absolute;
  top: 42px;
  right: 18px;
  left: 18px;
  height: 10px;
  border-radius: 999px;
  background: #edf2f7;
  box-shadow: inset 0 0 0 1px rgba(20, 24, 32, 0.08);
}

.route-rail::before {
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: var(--line-color);
  content: "";
  opacity: 0.82;
}

.route-rail::after {
  position: absolute;
  top: 50%;
  right: -2px;
  left: -2px;
  height: 18px;
  border-right: 3px solid var(--line-color);
  border-left: 3px solid var(--line-color);
  content: "";
  transform: translateY(-50%);
}

.route-endpoints {
  position: absolute;
  right: 14px;
  bottom: 0;
  left: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.route-endpoints span {
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-markers {
  position: absolute;
  inset: 0 18px 24px;
}

.train-pin {
  --status-bg: #eef2f6;
  --status-color: var(--line-color);
  --status-text: #344054;
  position: absolute;
  top: calc(18px + var(--stack) * 32px);
  left: calc(var(--pos) * 1%);
  display: grid;
  justify-items: center;
  width: 104px;
  gap: 5px;
  transform: translateX(-50%);
}

.train-pin.status-arrive {
  --status-bg: #dcfce7;
  --status-color: #16a34a;
  --status-text: #166534;
}

.train-pin.status-depart {
  --status-bg: #e0f2fe;
  --status-color: #0284c7;
  --status-text: #075985;
}

.train-pin.status-enter {
  --status-bg: #fef3c7;
  --status-color: #f59e0b;
  --status-text: #92400e;
}

.train-pin-dot {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--status-color);
  box-shadow: 0 4px 12px rgba(20, 24, 32, 0.18);
}

.train-pin-dot::after {
  width: 7px;
  height: 7px;
  border-radius: inherit;
  background: #fff;
  content: "";
}

.train-pin-label {
  display: grid;
  max-width: 104px;
  gap: 3px;
  padding: 5px 7px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 5px 14px rgba(20, 24, 32, 0.1);
  text-align: center;
}

.train-pin-label strong,
.train-pin-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.train-pin-label strong {
  color: #111827;
  font-size: 12px;
}

.pin-detail {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.train-pin-label .pin-status {
  flex: 0 0 auto;
  justify-self: center;
  min-height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--status-bg);
  color: var(--status-text);
  font-size: 10px;
  font-weight: 900;
  line-height: 18px;
}

.pin-meta {
  min-width: 0;
}

.train-pin-label span:not(.pin-status) {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.no-train {
  display: grid;
  min-width: 220px;
  min-height: 72px;
  place-items: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: #eef2f6;
  color: #344054;
  font-size: 11px;
  font-weight: 800;
}

.badge.status-arrive {
  background: #dcfce7;
  color: #166534;
}

.badge.status-depart {
  background: #e0f2fe;
  color: #075985;
}

.badge.status-enter {
  background: #fef3c7;
  color: #92400e;
}

.badge.status-last {
  background: #fee2e2;
  color: var(--danger);
}

.empty-state {
  padding: 34px 16px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #141820;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

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

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

  .map-canvas {
    height: clamp(360px, 58dvh, 560px);
  }

  .line-strip {
    grid-template-columns: 1fr;
  }

  .route-track {
    padding-top: 2px;
  }
}

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

  .topbar {
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0 12px;
  }

  .brand-logo {
    width: 42px;
    height: 42px;
  }

  .brand {
    gap: 10px;
  }

  .brand h1 {
    font-size: 24px;
  }

  .brand p {
    margin-top: 4px;
    font-size: 12px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .control-band {
    gap: 10px;
    padding: 12px;
  }

  .line-tabs {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .line-tab-group {
    gap: 6px;
    padding: 8px;
  }

  .line-tab-heading {
    font-size: 10px;
  }

  .line-tab-group.is-numbered .line-tab-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .line-tab-group.is-other .line-tab-grid {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .line-tab-group.is-other .line-tab {
    flex: 0 0 auto;
    min-width: 88px;
  }

  .line-tab {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .line-tab.is-number {
    min-height: 32px;
    font-size: 14px;
  }

  .control-grid {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 8px;
  }

  .control-grid .field:first-child {
    grid-column: 1 / -1;
  }

  .api-field {
    grid-column: 1 / 2;
  }

  .switch {
    grid-column: 1 / -1;
    justify-content: flex-start;
    min-height: 34px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
    margin: 10px 0;
  }

  .metric {
    padding: 10px;
  }

  .metric strong {
    font-size: 19px;
  }

  .metric span {
    font-size: 11px;
  }

  .field input {
    min-height: 38px;
  }

  .board-section {
    margin-top: 10px;
    padding: 12px;
  }

  .map-section {
    padding: 0;
  }

  .map-section .section-heading {
    padding: 12px;
  }

  .section-heading {
    gap: 8px;
    align-items: flex-start;
    flex-direction: column;
    margin-bottom: 10px;
  }

  .section-heading h2 {
    font-size: 17px;
  }

  .section-heading select {
    width: 100%;
  }

  .section-heading .text-button,
  .control-grid .text-button {
    min-height: 38px;
  }

  .map-canvas {
    height: clamp(320px, 52dvh, 430px);
  }

  .line-strip {
    gap: 8px;
    padding: 10px;
  }

  .strip-label {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .route-track-inner {
    min-height: 146px;
    padding: 0 14px;
  }

  .route-rail {
    top: 38px;
    right: 14px;
    left: 14px;
    height: 9px;
  }

  .route-markers {
    inset: 0 14px 22px;
  }

  .train-pin {
    top: calc(18px + var(--stack) * 32px);
    width: 92px;
  }

  .train-pin-dot {
    width: 22px;
    height: 22px;
  }

  .train-pin-label {
    max-width: 92px;
    padding: 4px 6px;
  }

  .train-pin-label strong {
    font-size: 11px;
  }

  .train-pin-label span:not(.pin-status) {
    font-size: 9px;
  }

  .train-pin-label .pin-status {
    min-height: 17px;
    padding: 0 5px;
    font-size: 9px;
    line-height: 17px;
  }

  .no-train {
    min-width: 100%;
    min-height: 68px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
  }
}
