/* Version 2.0 update */

/* ═══════════════════════════════════════════════════════════════
  BASE — #app container + dark fallback vars
  Fallback covers Halcyon installs without a data-mode attribute.
  All variables cascade to every descendant of #app.
═══════════════════════════════════════════════════════════════ */
#app {
  font-family: 'United Sans', sans-serif;
  color: var(--text-primary);
  background: var(--bg-deep);
  /* Dark defaults — apply when data-mode is absent or "dark" */
  --bg-deep: #0a0a0a;
  --bg-base: #111111;
  --bg-card: #181818;
  --bg-raised: #222222;
  --bg-hover: #2c2c2c;
  --border-subtle: rgba(207, 185, 145, 0.08);
  --border-mid: rgba(207, 185, 145, 0.15);
  --text-primary: #f0ece4;
  --text-secondary: #a69e90;
  --text-muted: #b8aca0;
  --accent: #CFB991;
  --accent-dim: #B89A5A;
  --warn: #e8a838;
}

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

/* ═══════════════════════════════════════════════════════════════
  DESIGN TOKENS — explicit dark mode (Halcyon data-mode="dark")
═══════════════════════════════════════════════════════════════ */
#app[data-mode="dark"] {
  --bg-deep: #0a0a0a;
  --bg-base: #111111;
  --bg-card: #181818;
  --bg-raised: #222222;
  --bg-hover: #2c2c2c;
  --border-subtle: rgba(207, 185, 145, 0.08);
  --border-mid: rgba(207, 185, 145, 0.15);
  --text-primary: #f0ece4;
  --text-secondary: #a69e90;
  --text-muted: #b8aca0;
  --accent: #CFB991;
  --accent-dim: #B89A5A;
  --warn: #e8a838;
}

/* ═══════════════════════════════════════════════════════════════
  DESIGN TOKENS — light mode (Halcyon data-mode="light")
═══════════════════════════════════════════════════════════════ */
#app[data-mode="light"] {
  --bg-deep: #f8f6f3;
  --bg-base: #f2efe9;
  --bg-card: #ffffff;
  --bg-raised: #ede9e2;
  --bg-hover: #e4dfd6;
  --border-subtle: rgba(142, 111, 62, 0.10);
  --border-mid: rgba(142, 111, 62, 0.22);
  --text-primary: #1a1714;
  --text-secondary: #3d3830;
  --text-muted: #6b6560;
  --accent: #8e6f3e;
  --accent-dim: #6b5230;
  --warn: #b5620a;
}

/* active button and skip-nav use --accent as bg — needs white text in light mode */
#app[data-mode="light"] .view-btn.active,
#app[data-mode="light"] .view-btn[aria-pressed="true"],
#app[data-mode="light"] .skip-nav {
  color: #ffffff;
}

#app[data-mode="light"] ::selection {
  background: var(--accent);
  color: #ffffff;
}

#app[data-mode="light"] .header {
  background: linear-gradient(160deg, #f8f6f3 0%, #ede8de 50%, #f8f6f3 100%);
}

/* ═══════════════════════════════════════════════════════════════
  ACCESSIBILITY UTILITIES
═══════════════════════════════════════════════════════════════ */
#app .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app .skip-nav {
  position: absolute;
  top: -100%;
  left: 16px;
  padding: 8px 18px;
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 700;
  font-size: 13px;
  border-radius: 0 0 6px 6px;
  z-index: 9999;
  text-decoration: none;
  transition: top 0.15s;
}

#app .skip-nav:focus {
  top: 0;
}

/* ═══════════════════════════════════════════════════════════════
  FOCUS STYLES — visible for keyboard users, suppressed for mouse
═══════════════════════════════════════════════════════════════ */
#app :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

#app :focus:not(:focus-visible) {
  outline: none;
}

/* SVG node focus — outline doesn't render on SVG elements in all browsers */
#app .node-group:focus {
  outline: none;
}

#app .node-group:focus-visible .node-circle {
  stroke: var(--accent) !important;
  stroke-width: 3px !important;
}

/* ═══════════════════════════════════════════════════════════════
  SELECTION
═══════════════════════════════════════════════════════════════ */
#app ::selection {
  background: var(--accent);
  color: #0a0a0a;
}

/* ═══════════════════════════════════════════════════════════════
  REDUCED MOTION
═══════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  #app .layer-group {
    animation: none !important;
  }

  #app .skip-nav {
    transition: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
  HEADER
═══════════════════════════════════════════════════════════════ */
#app .header {
  background: linear-gradient(160deg, #0a0a0a 0%, #1a1610 50%, #0a0a0a 100%);
  border-bottom: 1px solid var(--border-subtle);
  padding: 26px 32px 18px;
  position: relative;
}

#app .header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(207, 185, 145, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

#app .header-inner {
  max-width: 1260px;
  margin: 0 auto;
  position: relative;
}

#app .header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

#app .header-label {
  font-size: 11px;
  letter-spacing: 2.5px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 5px;
}

#app .header h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
  background: linear-gradient(90deg, var(--text-primary) 30%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#app .header-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 5px;
  max-width: 540px;
  line-height: 1.5;
}

#app .header-sub strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
  VIEW TOGGLE  (nav element)
═══════════════════════════════════════════════════════════════ */
#app .view-toggle {
  display: flex;
  gap: 3px;
  background: var(--bg-card);
  border-radius: 9px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
}

#app .view-btn {
  padding: 8px 20px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  transition: all 0.2s;
  font-family: 'United Sans', sans-serif;
}

#app .view-btn.active,
#app .view-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #0a0a0a;
}

#app .view-btn:hover:not(.active):not([aria-pressed="true"]) {
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════
  FILTERS
═══════════════════════════════════════════════════════════════ */
#app .filters {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  align-items: center;
  background: transparent;
}

#app .filter-input,
#app .filter-select {
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--border-mid) !important;
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  font-size: 12.5px;
  font-family: 'United Sans', sans-serif;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#app .filter-input:focus,
#app .filter-select:focus {
  border-color: var(--accent-dim);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#app .filter-input {
  width: 210px;
}

#app .filter-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
  LAYOUT
═══════════════════════════════════════════════════════════════ */
#app .main {
  max-width: 1260px;
  margin: 0 auto;
  padding: 22px 32px;
  display: flex;
  gap: 22px;
}

#app .content {
  flex: 1;
  min-width: 0;
}

#app .sidebar {
  width: 330px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
  LAYER VIEW
═══════════════════════════════════════════════════════════════ */
#app .layer-group {
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  animation: aiex-fadeIn 0.3s ease both;
}

@keyframes aiex-fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#app .layer-header {
  padding: 11px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
}

#app .layer-bar {
  width: 4px;
  height: 26px;
  border-radius: 2px;
  flex-shrink: 0;
}

#app .layer-title {
  font-size: 13.5px;
  font-weight: 700;
}

#app .layer-count {
  font-size: 12px;
  color: var(--text-muted);
}

#app .layer-items {
  padding: 10px 14px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

#app .chip {
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--border-mid);
  background: var(--bg-raised);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  font-family: 'United Sans', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

#app .chip:hover {
  background: var(--bg-hover);
}

#app .chip.selected,
#app .chip[aria-pressed="true"] {
  font-weight: 700;
}

#app .chip.faded {
  opacity: 0.2;
}

#app .dot-warn {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
  NETWORK VIEW
═══════════════════════════════════════════════════════════════ */
#app .network-wrap {
  background: var(--bg-base);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  position: relative;
}

#app .network-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

#app .node-group {
  cursor: pointer;
}

#app .node-group:hover .node-halo {
  opacity: 0.15;
}

#app .node-circle {
  fill: var(--bg-card);
}

/* Raise edge visibility in light mode — 0.2 blends into the cream background */
#app[data-mode="light"] #net-edges line {
  opacity: 0.5;
}

/* ═══════════════════════════════════════════════════════════════
  DETAIL PANEL
═══════════════════════════════════════════════════════════════ */
#app .detail-panel {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
}

#app .detail-head {
  padding: 15px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

#app .detail-layer-label {
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

#app .detail-name {
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.3;
}

#app .detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
}

#app .detail-close:hover {
  background: var(--bg-hover);
}

#app .detail-body {
  padding: 14px 18px;
}

#app .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}

#app .tag {
  padding: 2.5px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

#app .detail-desc {
  font-size: 12.8px;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 14px;
}

#app .detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

#app .detail-meta strong {
  color: var(--text-secondary);
}

#app .detail-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

#app .detail-link:hover,
#app .detail-link:focus {
  text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════════
  CONNECTIONS
═══════════════════════════════════════════════════════════════ */
#app .conn-section {
  margin-top: 12px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}

#app .conn-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 7px;
}

#app .conn-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  width: 100%;
  margin-bottom: 4px;
  text-align: left;
  color: var(--text-primary);
  font-family: 'United Sans', sans-serif;
}

#app .conn-btn:hover {
  background: var(--bg-hover);
}

#app .conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

#app .conn-name {
  font-size: 12px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#app .conn-rel {
  font-size: 11px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
  LEGEND PANEL
═══════════════════════════════════════════════════════════════ */
#app .legend-panel {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  padding: 20px;
}

#app .legend-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 14px;
}

#app .legend-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 11px;
}

#app .legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 1px;
}

#app .legend-item-label {
  font-size: 12px;
  font-weight: 600;
}

#app .legend-item-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

#app .legend-hint {
  margin-top: 18px;
  padding: 13px 14px;
  background: var(--bg-raised);
  border-radius: 8px;
  border: 1px solid rgba(207, 185, 145, 0.12);
}

#app .legend-hint-title {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 3px;
}

#app .legend-hint-text {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════
  ERROR BANNER
═══════════════════════════════════════════════════════════════ */
#app .error-banner {
  max-width: 600px;
  margin: 80px auto;
  padding: 32px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid #e17055;
  text-align: center;
}

#app .error-banner h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: #e17055;
}

#app .error-banner p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

#app .error-banner code {
  display: block;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg-deep);
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════
  RESPONSIVE
═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  #app .main {
    flex-direction: column;
  }

  #app .sidebar {
    width: 100%;
  }

  #app .header {
    padding: 18px 16px 14px;
  }

  #app .main {
    padding: 16px;
  }
}