:root {
  --blue: #427bca;
  --blue-dark: #3569b5;
  --orange: #e9963e;
  --gray: #a9a9a9;
  --navy: #1d3461;
  --text: #172033;
  --muted: #667085;
  --border: #dde3ea;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --green: #22a06b;
  --yellow: #f5b84b;
  --red: #dc3545;
  --shadow: 0 12px 28px rgba(29, 52, 97, .08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Montserrat", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn,
.tool-btn {
  border: 1px solid var(--border);
  background: white;
  color: var(--navy);
  border-radius: 8px;
  min-height: 36px;
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  display: inline-grid;
  place-items: center;
  font-weight: 700;
}

.tool-btn {
  padding: 0 12px;
  font-size: .76rem;
  font-weight: 700;
}

.tool-btn.active,
.icon-btn:hover,
.tool-btn:hover {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.page-shell {
  padding: 1.5rem;
  max-width: 1680px;
  margin: 0 auto;
}

.overview-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: stretch;
  max-width: 1680px;
  margin: 0 auto 18px;
}

.map-frame,
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.workspace {
  max-width: 1680px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: stretch;
}

.detail-panel {
  min-height: calc(100vh - 196px);
}

/* search in page-header */
.search-wrap input {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .82rem;
  width: 220px;
  background: white;
}

/* segmented filter in page-header */
.segmented { display: flex; gap: 4px; flex-wrap: wrap; }

.filter-group label,
.filter-label {
  display: block;
  margin-bottom: 8px;
  color: var(--navy);
  font-size: .76rem;
  font-weight: 800;
}

.search-wrap {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #fbfcfe;
}

.search-wrap span {
  color: var(--gray);
  font-weight: 800;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: .78rem;
  min-width: 0;
}

.segment-btn {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  text-align: left;
  font-size: .76rem;
  font-weight: 700;
  cursor: pointer;
}

.segment-btn.active,
.segment-btn:hover {
  color: white;
  border-color: var(--navy);
  background: var(--navy);
}

.legend {
  display: grid;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .74rem;
  font-weight: 600;
}

.dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 50%;
  margin-right: 8px;
}

.dot.live { background: var(--green); }
.dot.development { background: var(--blue); }
.dot.planned { background: var(--yellow); }
.dot.attention { background: var(--red); }

.map-frame {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-toolbar {
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}

.map-toolbar strong {
  display: block;
  color: var(--navy);
  font-size: .86rem;
}

.map-toolbar span {
  color: var(--muted);
  font-size: .72rem;
}

.map-canvas {
  position: relative;
  min-height: calc(100vh - 255px);
  overflow: auto;
  background-color: #fbfcfe;
  background-image:
    linear-gradient(#edf1f6 1px, transparent 1px),
    linear-gradient(90deg, #edf1f6 1px, transparent 1px);
  background-size: 42px 42px;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-btn {
  min-width: 34px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.zoom-level {
  min-width: 42px;
  text-align: center;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
}

.map-zoom-layer {
  position: relative;
  width: 1600px;
  height: 1200px;
  transform-origin: top left;
  transition: transform .15s ease;
}

.connections {
  position: absolute;
  top: 0;
  left: 0;
  width: 1600px;
  height: 1200px;
  pointer-events: none;
}

.connections path {
  stroke: #98a5b6;
  stroke-width: 2;
  fill: none;
}

.connections path.active {
  stroke: var(--orange);
  stroke-width: 3;
}

.system-grid {
  position: relative;
  width: 1600px;
  height: 1200px;
}

.zone-label {
  position: absolute;
  color: rgba(29, 52, 97, .42);
  font-weight: 800;
  font-size: .88rem;
  text-transform: uppercase;
  pointer-events: none;
}

.system-card {
  position: absolute;
  width: 135px;
  height: 135px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-top: 4px solid var(--blue);
  border-radius: 10px;
  background: white;
  box-shadow: 0 6px 16px rgba(29, 52, 97, .07);
  text-align: center;
  cursor: grab;
  user-select: none;
  transition: box-shadow .15s ease, border-color .15s ease;
}

.system-card:hover,
.system-card.selected {
  border-color: var(--blue);
  box-shadow: 0 14px 26px rgba(29, 52, 97, .16);
}

.system-card.dragging {
  cursor: grabbing;
  box-shadow: 0 20px 40px rgba(29, 52, 97, .22);
  z-index: 100;
}

.system-card.hidden {
  display: none;
}

.system-card[data-status="live"] { border-top-color: var(--green); }
.system-card[data-status="development"] { border-top-color: var(--blue); }
.system-card[data-status="planned"] { border-top-color: var(--yellow); }
.system-card[data-status="attention"] { border-top-color: var(--red); }

.card-title {
  color: var(--navy);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.system-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--navy);
  font-size: .75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.status-pill {
  height: 18px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 7px;
  color: white;
  font-size: .58rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.live { background: var(--green); }
.status-pill.development { background: var(--blue); }
.status-pill.planned { background: var(--yellow); color: #4f3600; }
.status-pill.attention { background: var(--red); }

.system-card h3 {
  margin-bottom: 5px;
  color: var(--navy);
  font-size: .88rem;
  line-height: 1.25;
}

.system-card p {
  margin: 0;
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.45;
}

.detail-panel {
  overflow: hidden;
}

.detail-panel:not(.open) {
  display: none;
}

.detail-empty {
  height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 34px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--blue);
  font-weight: 800;
}

.detail-empty h2 {
  margin-bottom: 8px;
  color: var(--navy);
  font-size: 1.05rem;
}

.detail-empty p {
  margin-bottom: 0;
  font-size: .82rem;
  line-height: 1.6;
}

.detail-content {
  height: 100%;
  overflow-y: auto;
}

.detail-hero {
  padding: 22px;
  color: white;
  background: var(--navy);
}

.detail-hero .status-pill {
  margin-bottom: 14px;
}

.detail-hero h2 {
  margin-bottom: 8px;
  font-size: 1.25rem;
}

.detail-hero p {
  margin-bottom: 0;
  color: rgba(255, 255, 255, .78);
  font-size: .84rem;
  line-height: 1.6;
}

.detail-section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.detail-section h3 {
  margin-bottom: 12px;
  color: var(--navy);
  font-size: .82rem;
  text-transform: uppercase;
}

.meta-list,
.link-list,
.impact-list,
.todo-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.meta-list li,
.link-list li,
.impact-list li,
.todo-list li {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.5;
}

.meta-list strong {
  color: var(--text);
}

.link-list button {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--navy);
  font-weight: 700;
  text-align: left;
  padding: 0 10px;
  cursor: pointer;
}

.link-list button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.completion-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.completion-row .progress-track {
  flex: 1;
  margin: 0;
}

.completion-row strong {
  color: var(--navy);
  min-width: 44px;
  text-align: right;
}

.flow-mode .system-card:not(.selected):not(.related) {
  opacity: .32;
}

.system-card.related {
  border-color: var(--orange);
}

@media (max-width: 1180px) {
  .overview-band,
  .workspace {
    grid-template-columns: 1fr;
  }

  .filters,
  .detail-panel {
    min-height: auto;
  }

  .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px 180px;
    gap: 16px;
  }

  .filter-group + .filter-group,
  .legend {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px;
  }

  .brand,
  .main-nav {
    min-width: 0;
    width: 100%;
  }

  .main-nav {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .page-shell {
    padding: 14px;
  }

  .overview-band > div:first-child,
  .progress-panel {
    padding: 18px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .filters {
    display: block;
  }

  .filter-group + .filter-group,
  .legend {
    margin-top: 18px;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }
}
