/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Palette – VS Code-ish, a bit lighter */
  --bg: #020617;
  --bg-elevated: #0b1120;
  --bg-elevated-soft: #111827;
  --bg-elevated-strong: #020617;
  --accent: #2563eb;           /* blue */
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-strong: #60a5fa;
  --accent-alt: #a855f7;       /* purple */
  --accent-teal: #14b8a6;      /* teal for variety */
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --border-subtle: rgba(30, 41, 59, 0.9);
  --danger: #ef4444;

  --radius-lg: 14px;
  --shadow-soft: 0 4px 14px rgba(0, 0, 0, 0.45); /* lighter */

  --canvas-border-radius: 18px;
  --node-radius: 999px;
  --node-shadow: none; /* no glow */

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: radial-gradient(circle at top, #020617 0, #020617 40%, #020617 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Layout */

.app {
  height: 100vh;
  width: 100%;
  max-width: none; /* fill the screen */
  margin: 0;       /* remove side gutters */
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-main {
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-height: 0; /* important so flex children can scroll */
}

/* Sidebar */

.sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 100%;
  overflow-y: auto; /* scroll inside sidebar instead of full page */
  padding-right: 2px;
}

.panel {
  background: var(--bg-elevated-soft);
  border-radius: var(--radius-lg);
  padding: 10px 11px 9px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
}

.panel h2 {
  font-size: 0.9rem;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  color: var(--accent-strong);
}

.selected-info {
  font-size: 0.82rem;
  color: var(--text-soft);
  margin-bottom: 8px;
}

#selected-node-label {
  color: var(--accent-strong);
  font-weight: 500;
}

/* Inputs */

.field-label {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 3px;
  color: var(--text-soft);
}

.field-input {
  width: 100%;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid rgba(51, 65, 85, 0.9);
  background: #020617;
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out,
    background 150ms ease-out, transform 150ms ease-out;
}

.field-input::placeholder {
  color: #4b5563;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.5);
  background: #020617;
  transform: translateY(-0.5px);
}

.field-textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.4;
  font-family: var(--font-sans);
}

/* Buttons */

.button-row {
  display: flex;
  gap: 6px;
  margin-top: 7px;
}

.btn {
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: transform 150ms ease-out, box-shadow 150ms ease-out,
    background 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}

/* Primary – solid blue (Add child, etc.) */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f9fafb;
}

.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  transform: translateY(-1px);
}

/* Warning – solid dark yellow (Update node) */
.btn-warning {
  background: #f59e0b;
  border-color: #d97706;
  color: #111827;
}

.btn-warning:hover {
  background: #d97706;
  border-color: #b45309;
  transform: translateY(-1px);
}

/* Danger – solid red (Delete node) */
.btn-danger {
  background: var(--danger);
  border-color: #dc2626;
  color: #111827;
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #b91c1c;
  transform: translateY(-1px);
}

/* Secondary – solid purple (if you ever use it) */
.btn-secondary {
  background: var(--accent-alt);
  border-color: var(--accent-alt);
  color: #f9fafb;
}

.btn-secondary:hover {
  background: #9333ea;
  border-color: #9333ea;
}

/* Ghost – solid grey/blue */
.btn-ghost {
  background: #1f2937;
  border-color: #374151;
  color: var(--text-soft);
}

.btn-ghost:hover {
  background: #111827;
  color: var(--text);
  border-color: #4b5563;
}

/* Outline – transparent with blue border */
.btn-outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent-strong);
  margin-top: 6px;
  width: 100%;
}

.btn-outline:hover {
  background: rgba(37, 99, 235, 0.08);
}

/* Optional teal variant (not used by default) */
.btn-teal {
  background: var(--accent-teal);
  border-color: var(--accent-teal);
  color: #022c22;
}

.btn-teal:hover {
  background: #0d9488;
  border-color: #0d9488;
}

.btn-icon {
  padding-inline: 9px;
  min-width: 30px;
}

.hint {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-soft);
}

/* Custom file inputs: hide native and use our own button */

.file-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.file-input-button {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
  background: #f97316; /* solid orange */
  border: 1px solid #ea580c;
  color: #111827;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.file-input-button:hover {
  background: #ea580c;
  border-color: #c2410c;
}

.file-input-button input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Text that shows the chosen file name */
.file-input-label {
  font-size: 0.78rem;
  color: var(--text-soft);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Import / Export */

.io-row {
  margin-bottom: 6px;
}

.format-details {
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.format-details summary {
  cursor: pointer;
}

.format-example {
  margin-top: 5px;
  font-size: 0.72rem;
  background: #020617;
  padding: 7px;
  border-radius: 9px;
  border: 1px dashed rgba(55, 65, 81, 0.9);
  overflow-x: auto;
}

/* Images input */

.image-input-row {
  display: flex;
  gap: 5px;
  margin-top: 3px;
}

.images-preview {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.image-chip {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: #020617;
}

.image-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: none;
  background: #020617;
  color: #e5e7eb;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Workspace */

.workspace {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

/* Canvas */

.canvas-wrapper {
  flex: 3; /* bigger center block */
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.canvas-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 4px 4px 2px;
}

.canvas-header h2 {
  font-size: 0.9rem;
  color: var(--accent-strong);
}

.canvas-subtitle {
  font-size: 0.76rem;
  color: var(--text-soft);
}

.canvas {
  position: relative;
  flex: 1;
  border-radius: var(--canvas-border-radius);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  background: #020617; /* flat, no glow */
  box-shadow: none; /* no glow */
  cursor: grab;
  min-height: 0;
}

.canvas.is-panning {
  cursor: grabbing;
}

/* Subtle grid */

.canvas::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(
    circle at 1px 1px,
    rgba(31, 41, 55, 0.5) 1px,
    transparent 0
  );
  background-size: 22px 22px;
  opacity: 0.25;
  pointer-events: none;
}

/* Layers */

#links-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

#nodes-layer {
  position: absolute;
  inset: 0;
}

/* Nodes – flat, no glow */

.node {
  position: absolute;
  min-width: 90px;
  max-width: 160px;
  padding: 6px 9px;
  border-radius: var(--node-radius);
  background: #111827; /* solid */
  border: 1px solid #374151; /* solid */
  color: var(--text);
  font-size: 0.78rem;
  text-align: center;
  cursor: pointer;
  box-shadow: none; /* no glow */
  transform: translate(-50%, -50%);
  transition: transform 150ms ease-out, background 130ms ease-out,
    border-color 130ms ease-out, color 130ms ease-out;
  backdrop-filter: none; /* no blur */
  user-select: none;
}

.node:hover {
  transform: translate(-50%, -50%) translateY(-1px);
  background: #1f2937;
  border-color: #4b5563;
}

/* Root node – flat highlight */
.node-root {
  border-width: 1px;
  border-color: var(--accent);
  background: #1d2a41;
  font-weight: 600;
  color: var(--accent-strong);
}

/* Selected node – flat blue border, no glow */
.node.selected {
  border-color: var(--accent-strong);
  background: #1e293b;
}

/* Links */

.link-line {
  stroke: rgba(75, 85, 99, 0.9);
  stroke-width: 1.3;
  stroke-linecap: round;
}

/* Detail panel */

.detail-panel {
  flex: 1; /* smaller than canvas */
  min-width: 220px;
  max-width: 280px; /* slightly narrower */
  background: var(--bg-elevated-soft);
  border-radius: var(--radius-lg);
  padding: 10px 11px 8px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.detail-header h2 {
  font-size: 0.9rem;
  color: var(--accent-strong);
}

.detail-node-label {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.detail-content {
  flex: 1;
  overflow: auto;
  padding-right: 3px;
}

.detail-description {
  font-size: 0.83rem;
  line-height: 1.45;
}

.detail-description h1,
.detail-description h2,
.detail-description h3 {
  font-weight: 600;
  margin-top: 7px;
  margin-bottom: 3px;
}

.detail-description h1 {
  font-size: 1rem;
}
.detail-description h2 {
  font-size: 0.95rem;
}
.detail-description h3 {
  font-size: 0.9rem;
}

.detail-description p {
  margin-bottom: 5px;
}

.detail-description ul {
  padding-left: 15px;
  margin: 3px 0 5px;
}

.detail-description li {
  margin-bottom: 2px;
}

.detail-description code {
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  background: #020617;
  padding: 1px 3px;
  border-radius: 4px;
  border: 1px solid rgba(30, 64, 175, 0.7);
}

/* images rendered from markdown */
.detail-description img {
  max-width: 100%;
  margin-top: 5px;
  border-radius: 9px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  display: block;
}

.detail-description-empty {
  color: var(--text-soft);
  font-style: italic;
}

.detail-images {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.detail-images img {
  width: 76px;
  height: 76px;
  border-radius: 9px;
  object-fit: cover;
  border: 1px solid rgba(55, 65, 81, 0.9);
}

/* Footer – small */
.app-footer {
  font-size: 0.75rem;
  color: var(--text-soft);
  display: flex;
  justify-content: center;
  padding-top: 2px;
  padding-bottom: 2px;
}

/* Responsive */

@media (max-width: 1024px) {
  .workspace {
    flex-direction: column;
  }

  .detail-panel {
    max-width: 100%;
    width: 100%;
  }
}

@media (max-width: 880px) {
  .app-main {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: visible;
  }

  .panel {
    min-width: 260px;
  }
}

@media (max-width: 640px) {
  .sidebar {
    flex-direction: column;
  }

  .canvas {
    min-height: 360px;
  }
}
