:root {
  --bg: #f8f9fa;
  --fg: #212529;
  --muted: #6c757d;
  --card: #ffffff;
  --border: #dee2e6;
  --accent: #0d6efd;
  --accent-hover: #0b5ed7;
  --danger: #dc3545;
  --shadow: 0 2px 8px rgba(0,0,0,0.05);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.5; }

.site-header { padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.site-header h1 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--fg); }
.site-footer { padding: 24px; text-align: center; color: var(--muted); font-size: 0.875rem; border-top: 1px solid var(--border); margin-top: auto; }

.content { padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }
.card { display: block; text-decoration: none; color: var(--fg); background: var(--card); padding: 24px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-color: var(--accent); }
.card h2 { margin-top: 0; color: var(--accent); }

/* Buttons & Inputs */
button, .btn { cursor: pointer; font-family: inherit; font-size: 0.9rem; border-radius: 6px; border: 1px solid transparent; padding: 8px 16px; transition: all 0.2s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-warn { background: var(--danger); color: #fff; }
.btn-warn:hover { background: #bb2d3b; }
input, select, textarea { font-family: inherit; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--fg); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15); }

/* Loader */
.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 20px auto;
  text-indent: -9999px; /* Hide text */
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Grid / Media */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.grid-item { background: var(--card); padding: 16px; border-radius: 8px; border: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.grid-item strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-item a { color: var(--accent); text-decoration: none; font-weight: 500; }
.grid-item a:hover { text-decoration: underline; }

/* Search */
.search-bar { display: flex; gap: 8px; margin-bottom: 24px; max-width: 600px; }
.search-bar input { flex: 1; }

/* Tree Visualization */
.tree-container { position: relative; height: 70vh; background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.tree-svg { width: 100%; height: 100%; cursor: grab; }
.tree-svg:active { cursor: grabbing; }
.node rect { fill: #fff; stroke: var(--border); stroke-width: 2px; transition: all 0.3s; }
.node:hover rect { stroke: var(--accent); }
.node.current rect { stroke: var(--accent); stroke-width: 3px; fill: #f0f7ff; }
.node text { font-size: 14px; font-weight: 500; fill: var(--fg); pointer-events: none; text-anchor: middle; }
.node image { pointer-events: none; }
.link { fill: none; stroke: #cbd5e1; stroke-width: 2px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 2000; backdrop-filter: blur(2px); }
.modal-content { background: #fff; color: var(--fg); padding: 32px; border-radius: 16px; max-width: 600px; width: 90%; max-height: 90vh; overflow-y: auto; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
.modal-close { position: absolute; top: 16px; right: 16px; background: transparent; border: none; font-size: 1.5rem; color: var(--muted); padding: 4px; line-height: 1; }
.modal-close:hover { color: var(--fg); }
.modal h2 { margin-top: 0; margin-bottom: 8px; }
[contenteditable]:empty::before { content: attr(placeholder); color: var(--muted); font-style: italic; display: block; }
[contenteditable] { border: 1px dashed transparent; padding: 4px; border-radius: 4px; transition: border-color 0.2s; }
[contenteditable]:focus { outline: none; border-color: var(--accent); background: #f8f9fa; }

/* Image Upload */
.image-upload-container {
  width: 120px; height: 120px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
  background: #f8f9fa;
  transition: border-color 0.2s;
}
.image-upload-container:hover { border-color: var(--accent); }
.image-placeholder { font-size: 32px; color: var(--muted); user-select: none; }
.image-preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-upload-container.has-image .image-placeholder { display: none; }
.image-upload-container:not(.has-image) .image-preview { display: none; }

/* Link Editor */
.link-list { list-style: none; padding: 0; margin: 0 0 16px 0; }
.link-item { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; background: #f8f9fa; padding: 8px; border-radius: 4px; }
.link-item a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); text-decoration: none; }
.link-item .btn-icon { padding: 4px 8px; color: var(--danger); background: none; border: none; cursor: pointer; }
.add-link-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.add-link-form input { flex: 1; min-width: 120px; }

/* Gate & Auth */
.gate-overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.gate-box { background: #fff; padding: 40px; border-radius: 16px; border: 1px solid var(--border); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.1); max-width: 400px; width: 90%; }
.auth-controls { position: fixed; top: 16px; right: 16px; z-index: 1000; }

/* Utilities */
[hidden] { display: none !important; }
[data-mode="edit"] .edit-only { display: block !important; }
.edit-only { display: none; }

