:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #f0f3ee;
  --ink: #17201d;
  --muted: #66736f;
  --line: #d7ddd6;
  --teal: #0a6f68;
  --teal-dark: #064c48;
  --berry: #9d2457;
  --amber: #b56b13;
  --blue: #2c637c;
  --green: #52823b;
  --shadow: 0 18px 50px rgba(24, 33, 30, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.navigator,
.detail-panel {
  background: var(--surface);
  border-color: var(--line);
  min-height: 0;
  overflow: auto;
}

.navigator {
  border-right: 1px solid var(--line);
  padding: 18px;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--berry);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.icon-button,
.tool-button,
.close-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-width: 40px;
  height: 40px;
  line-height: 1;
}

.icon-button:hover,
.tool-button:hover,
.close-button:hover {
  background: var(--surface-2);
}

.control-group {
  margin-bottom: 18px;
}

.search-label,
.filter-title {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfcfb;
  color: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.segmented button,
.floor-chip {
  border: 0;
  border-radius: 7px;
  min-height: 36px;
  padding: 7px 9px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.segmented button.active,
.floor-chip.active {
  background: var(--teal);
  color: #fff;
}

.floor-list {
  display: grid;
  gap: 8px;
}

.floor-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  border: 1px solid var(--line);
  background: #fbfcfb;
}

.floor-chip span {
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.8;
}

.route-box {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.route-list {
  margin: 0;
  padding-left: 22px;
}

.route-list li {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.route-list button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
  font-weight: 750;
}

.map-workspace {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 190px;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.current-context {
  font-size: 18px;
  font-weight: 850;
}

.quote-time {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.map-tools {
  display: inline-flex;
  gap: 6px;
}

.map-stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background:
    linear-gradient(45deg, rgba(0,0,0,.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.035) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
  cursor: grab;
  touch-action: none;
}

.map-stage.dragging {
  cursor: grabbing;
}

.map-canvas {
  position: absolute;
  left: 0;
  top: 0;
  --map-scale: 1;
  width: 1200px;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: var(--shadow);
}

.map-canvas img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.pin-layer {
  position: absolute;
  inset: 0;
}

.pin {
  position: absolute;
  width: calc(30px / var(--map-scale));
  height: calc(30px / var(--map-scale));
  transform: translate(-50%, -50%);
  border: calc(2px / var(--map-scale)) solid #fff;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  display: grid;
  place-items: center;
  font-size: calc(11px / var(--map-scale));
  font-weight: 850;
}

.pin[data-type="ai"] { background: var(--berry); }
.pin[data-type="server"] { background: var(--blue); }
.pin[data-type="storage"] { background: var(--green); }
.pin[data-type="power"] { background: var(--amber); }
.pin.visited {
  filter: grayscale(0.7);
  opacity: 0.62;
}

.pin.active {
  outline: calc(4px / var(--map-scale)) solid rgba(10, 111, 104, 0.22);
  width: calc(38px / var(--map-scale));
  height: calc(38px / var(--map-scale));
  z-index: 4;
}

.pin-label {
  position: absolute;
  left: 50%;
  top: calc(34px / var(--map-scale));
  transform: translateX(-50%);
  max-width: calc(120px / var(--map-scale));
  padding: calc(4px / var(--map-scale)) calc(6px / var(--map-scale));
  border-radius: calc(6px / var(--map-scale));
  background: rgba(255,255,255,0.95);
  color: var(--ink);
  border: 1px solid rgba(215,221,214,0.9);
  font-size: calc(11px / var(--map-scale));
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0,0,0,.12);
  pointer-events: none;
}

.company-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 320px);
  gap: 12px;
  overflow-x: auto;
  padding: 14px 18px 18px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.company-card {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
  text-align: left;
}

.company-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(10,111,104,.14);
}

.company-card h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.company-card p {
  margin: 0;
  color: #33403c;
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.stock-pill {
  justify-self: start;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
  background: #edf6f4;
  color: var(--teal-dark);
}

.stock-pill.down {
  background: #f8ecec;
  color: #9b2d2d;
}

.stock-pill.neutral {
  background: #f0f1ec;
  color: #4d554f;
}

.detail-panel {
  position: relative;
  border-left: 1px solid var(--line);
  padding: 18px;
}

.close-button {
  position: sticky;
  top: 0;
  float: right;
  z-index: 3;
  font-size: 24px;
}

.detail-kicker {
  color: var(--berry);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.detail-panel h2 {
  margin: 8px 0 8px;
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

.detail-booth {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.detail-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.detail-section p {
  margin: 0;
  color: #33403c;
  line-height: 1.62;
}

.stock-box {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.stock-price {
  font-size: 28px;
  font-weight: 850;
}

.stock-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.visited-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.visited-row input {
  width: 18px;
  height: 18px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
}

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

  .detail-panel {
    position: fixed;
    right: 12px;
    top: 82px;
    bottom: 12px;
    width: min(390px, calc(100vw - 24px));
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    transform: translateX(calc(100% + 24px));
    transition: transform 0.18s ease;
    z-index: 10;
  }

  .detail-panel.open {
    transform: translateX(0);
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .navigator {
    position: sticky;
    top: 0;
    z-index: 8;
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  h1 {
    font-size: 24px;
  }

  .map-workspace {
    min-height: 78vh;
    grid-template-rows: auto 56vh 178px;
  }

  .topbar {
    height: auto;
    min-height: 64px;
    padding: 10px 12px;
  }

  .company-strip {
    grid-auto-columns: minmax(236px, 280px);
    padding: 12px;
  }

  .detail-panel {
    top: 10px;
    bottom: 10px;
    left: 10px;
    right: 10px;
    width: auto;
  }
}
