:root {
  --bg: #0f141b;
  --panel: #1a212c;
  --accent: #3a7bd5;
  --text: #e5e9ef;
  --muted: #9aa6b8;
  --good: #3ac177;
  --marginal: #f2c14e;
  --unlikely: #f07f3c;
  --none: #7a7f87;
  --sensor: #55c57a;
  --controller: #4c82ff;
  --relay: #f0a500;
  --client: #b7b7b7;
  --uxs: #f38ba8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.demo-banner {
  position: relative;
  margin: 1.5rem;
  background: #f5f5f7;
  color: #0f141b;
  border: 1px solid #d8d8db;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
  max-height: 50vh;
  overflow: auto;
}

.demo-banner.hidden {
  display: none;
}

#demo-banner-close {
  position: absolute;
  right: 0.75rem;
  top: 0.65rem;
  background: transparent;
  color: #0f141b;
  border: none;
  width: auto;
  padding: 0.35rem 0.5rem;
  font-weight: 600;
  cursor: pointer;
}

.demo-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #0b1016;
  border-bottom: 1px solid #1f2a36;
}

.demo-flow span {
  color: var(--muted);
  font-size: 0.95rem;
}

.stack-callout {
  margin: 0.75rem 1rem 0;
  background: #0b1016;
  border: 1px solid #1f2a36;
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.stack-callout ul {
  margin: 0.5rem 0 0 1rem;
  padding: 0;
}

.stack-callout li {
  margin-bottom: 0.35rem;
  line-height: 1.4;
}

h1, h2, h3 {
  margin: 0 0 0.5rem 0;
}

.subtitle {
  color: var(--muted);
  margin: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #0b1016;
  border-bottom: 1px solid #1f2a36;
}

.import-export button {
  margin-left: 0.5rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 2fr 1.2fr;
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid #222c37;
  border-radius: 6px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 78vh;
}

.section {
  margin-bottom: 1rem;
}

.import-mode {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0;
  flex-wrap: wrap;
}

.import-files {
  display: grid;
  gap: 0.35rem;
  margin: 0.5rem 0 0.5rem;
}

.import-mode input[type="radio"] {
  width: auto;
  margin-right: 0.35rem;
}

.file-like {
  display: inline-block;
  text-align: center;
  cursor: pointer;
}

#integration-mission-file {
  display: none;
}

label {
  display: block;
  margin: 0.5rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

input, select, button, textarea {
  width: 100%;
  background: #0d131a;
  color: var(--text);
  border: 1px solid #2a3644;
  border-radius: 4px;
  padding: 0.5rem;
  font-size: 0.95rem;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

button {
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

button:hover {
  background: #15202b;
}

button:active {
  transform: translateY(1px);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
}

.summary-card {
  border: 1px solid #2a3644;
  background: #0d131a;
  border-radius: 6px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

#mesh-link-micro-summary {
  list-style: none;
  padding-left: 1rem;
  margin: 0.25rem 0 0;
}

#mesh-link-micro-summary li {
  margin-bottom: 0.15rem;
}

.summary-title {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

#canvas-container {
  background: #0c1017;
  border: 1px solid #222c37;
  border-radius: 6px;
  flex: 1;
  position: relative;
}

#mesh-map {
  width: 100%;
  height: 70vh;
  min-height: 480px;
  border-radius: 6px;
  overflow: hidden;
}

#fallback-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 420px;
  border-radius: 6px;
}

.node-label {
  fill: var(--text);
  font-size: 12px;
  text-anchor: middle;
  pointer-events: none;
}

.link-line {
  stroke-width: 3;
  fill: none;
}

.link-tooltip {
  background: #0b1016;
  border: 1px solid #2a3644;
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.node-circle {
  stroke: #000;
  stroke-width: 1;
  cursor: pointer;
  filter: drop-shadow(0 0 4px rgba(0,0,0,0.45));
}

#link-summary-section table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#link-summary-section th, #link-summary-section td {
  padding: 0.35rem;
  border-bottom: 1px solid #2a3644;
}

#link-summary-section thead {
  background: #111722;
}

#recommendations {
  min-height: 48px;
}

#coverage-hints {
  margin: 0;
  padding-left: 1.2rem;
}

#coverage-hints li {
  margin-bottom: 0.3rem;
}

#node-detail-section input, #node-detail-section select {
  margin-bottom: 0.35rem;
}

.leaflet-container {
  background: #0c1017;
}

.node-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #000;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.45);
}

.node-marker.unplaced {
  border-style: dashed;
  opacity: 0.7;
}

.node-marker.selected {
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.6);
  border-color: #fff;
}

.node-controller { background: var(--controller); }
.node-relay { background: var(--relay); }
.node-uxs { background: var(--uxs); }
.node-sensor { background: var(--sensor); }
.node-client { background: var(--client); }

.quality-good { color: var(--good); }
.quality-marginal { color: var(--marginal); }
.quality-unlikely { color: var(--unlikely); }
.quality-none { color: var(--none); }

.inline-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

#file-input {
  padding: 0.4rem;
  background: none;
}

#placement-hint {
  margin-top: 0.35rem;
}

.add-node.active {
  outline: 2px solid var(--accent);
  background: #132033;
}

#map-helper {
  margin-bottom: 0.25rem;
}

.error-banner {
  background: #3c1d1d;
  color: #ffb3b3;
  border: 1px solid #803333;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

.status-message {
  margin-top: 0.5rem;
  min-height: 1.2rem;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .demo-banner {
    margin: 0.75rem;
    max-height: 45vh;
  }
  #mesh-map {
    min-height: 420px;
  }
  .demo-flow {
    flex-direction: column;
    align-items: flex-start;
  }
}
