* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1220;
  --panel: #11192a;
  --text: #e8eef6;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --tree: #22c55e;
  --disease: #ef4444;
  --nutrient: #f59e0b;
  --weather: #8b5cf6;
  --condition: #06b6d4;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

#app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  height: 100%;
  min-height: 500px;
}

header {
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 1rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid #1e293b;
}

header h1 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

header p {
  color: var(--muted);
  font-size: 0.85rem;
}

aside#controls {
  grid-column: 1;
  grid-row: 2;
  background: var(--panel);
  border-right: 1px solid #1e293b;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

aside#controls h2 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.8rem;
  color: var(--muted);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  background: #1e293b;
  color: var(--muted);
  border: 1px solid #334155;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 36px;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chip.active {
  background: #2563eb; /* darker than --accent so white text passes 4.5:1 */
  color: #fff;
  border-color: #2563eb;
}

/* The mouse hint injected by 3d-force-graph defaults to faded 10px text. */
body .scene-nav-info {
  font-size: 12px;
  color: var(--muted);
  opacity: 1;
}

.control-group select,
.control-group input {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: #0f172a;
  border: 1px solid #334155;
  color: var(--text);
  border-radius: 6px;
  min-height: 40px;
}

.control-group input:focus,
.control-group select:focus {
  outline: none;
  border-color: var(--accent);
}

button#reset-view,
button#close-info {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 40px;
}

button#reset-view:hover,
button#close-info:hover {
  background: #334155;
  border-color: var(--accent);
}

.stats {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid #1e293b;
  font-size: 0.8rem;
  color: var(--muted);
}

main#graph-container {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 500px;
  overflow: hidden;
  background: #0a0f1a;
  border: 1px solid #1e293b;
}

#graph-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#info-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--panel), transparent);
  padding: 1rem;
  display: none;
  backdrop-filter: blur(8px);
  max-height: 45vh;
  overflow-y: auto;
  z-index: 10;
}

#info-panel h2 {
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
}

#info-panel p {
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
  font-size: 0.9rem;
}

#info-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.detail-chip {
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  background: #1e293b;
  color: var(--muted);
  border: 1px solid #334155;
  border-radius: 999px;
}

footer {
  grid-column: 1 / -1;
  grid-row: 3;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-top: 1px solid #1e293b;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* Node color classes (applied via JS) */
.node-tree { color: var(--tree); }
.node-disease { color: var(--disease); }
.node-nutrient { color: var(--nutrient); }
.node-weather { color: var(--weather); }
.node-condition { color: var(--condition); }

/* ============ Mobile: stack controls above graph ============ */
@media (max-width: 701px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto;
    min-height: 650px;
  }

  header {
    grid-row: 1;
    padding: 0.85rem 1rem;
  }

  header h1 {
    font-size: 1.1rem;
  }

  aside#controls {
    grid-column: 1;
    grid-row: 2;
    border-right: none;
    border-bottom: 1px solid #1e293b;
    padding: 0.85rem 1rem;
    max-height: 40vh;
    overflow-y: auto;
  }

  aside#controls h2 {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
  }

  .control-group {
    gap: 0.4rem;
  }

  .control-group label {
    font-size: 0.75rem;
  }

  .chip {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    min-height: 34px;
  }

  main#graph-container {
    grid-column: 1;
    grid-row: 3;
    min-height: 320px;
    height: 100%;
  }

  #info-panel {
    padding: 0.85rem 1rem;
    max-height: 40vh;
  }

  #info-panel h2 {
    font-size: 1rem;
  }

  footer {
    grid-row: 4;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
  }
}
