/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --primary: #c4577c;
  --primary-dark: #9f365f;
  --primary-text: #fff;
  --bg: #170d14;
  --bg-accent: #3d1d32;
  --surface: rgba(34, 18, 29, 0.8);
  --surface-2: rgba(50, 26, 40, 0.86);
  --surface-3: rgba(75, 38, 57, 0.76);
  --border: rgba(229, 176, 198, 0.18);
  --text: #fff4f8;
  --text-muted: #d5b1bf;
  --danger: #e26767;
  --danger-dark: #bf4a56;
  --success: #54b88b;
  --shadow-sm: 0 16px 40px rgba(17, 5, 12, 0.28);
  --shadow: 0 32px 80px rgba(14, 4, 10, 0.5);
  --radius: 22px;
  --radius-sm: 12px;
  --toolbar-h: 48px;
  --header-h: 60px;
  --panel-w: 280px;
  --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Cormorant Garamond', 'Manrope', serif;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(circle at 12% 8%, rgba(232, 141, 173, 0.22), transparent 26%),
    radial-gradient(circle at 84% 14%, rgba(242, 202, 148, 0.12), transparent 22%),
    radial-gradient(circle at 50% 100%, rgba(122, 46, 82, 0.18), transparent 30%),
    linear-gradient(180deg, #24111c 0%, var(--bg) 46%, #130a11 100%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; }

/* ── App header (index page) ──────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 24px;
  background: rgba(26, 13, 22, 0.62);
  border-bottom: 1px solid rgba(255, 232, 240, 0.08);
  backdrop-filter: blur(18px);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 40;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--text);
  text-decoration: none;
}
.logo-img {
  height: 38px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(196, 87, 124, 0.35));
}
.logo-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, #e07aa0 0%, #c4577c 60%, #9c3a5e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.editor-logo-img {
  height: 30px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(196, 87, 124, 0.4));
}
.logo svg { opacity: 0.95; filter: drop-shadow(0 10px 18px rgba(196, 87, 124, 0.28)); }

/* ── Main content (index page) ────────────────────────────────────────────── */
.main-content {
  padding: 40px 24px 56px;
  max-width: 1100px;
  margin: 0 auto;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, opacity 0.18s, transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  border: 1px solid transparent;
  line-height: 1;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, #d76a90 0%, var(--primary) 52%, #8b2f57 100%);
  color: #fff;
  border-color: rgba(255, 207, 223, 0.34);
  box-shadow: 0 14px 30px rgba(133, 38, 77, 0.32);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #e07fa2 0%, var(--primary-dark) 100%);
  border-color: rgba(255, 223, 232, 0.42);
}
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border-color: var(--border);
  backdrop-filter: blur(12px);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Map grid (index page) ────────────────────────────────────────────────── */
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.map-card {
  background: linear-gradient(180deg, rgba(51, 25, 40, 0.94), rgba(27, 12, 21, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
  backdrop-filter: blur(18px);
}
.map-card:hover {
  border-color: rgba(233, 176, 198, 0.4);
  box-shadow: var(--shadow-sm);
  transform: translateY(-3px);
}
.map-card-body { padding: 18px; flex: 1; }
.map-card-title { font-family: var(--font-display); font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.map-card-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; line-clamp: 2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.map-card-meta { font-size: 12px; color: var(--text-muted); }
.map-card-actions {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 8px;
  background: linear-gradient(180deg, rgba(84, 40, 60, 0.36), rgba(28, 12, 21, 0.5));
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 24px;
  color: var(--text-muted);
  text-align: center;
  background: linear-gradient(180deg, rgba(54, 26, 41, 0.6), rgba(25, 11, 20, 0.44));
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.empty-state svg { opacity: 0.5; }
.empty-state h2 { font-family: var(--font-display); font-size: 24px; color: var(--text); }
.empty-state p { font-size: 14px; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-error { background: rgba(231, 76, 60, 0.15); border: 1px solid rgba(231, 76, 60, 0.4); color: #ff6b6b; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: linear-gradient(180deg, rgba(58, 28, 44, 0.97), rgba(23, 10, 19, 0.95));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.modal h2 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input,
.form-group textarea,
.form-group select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  transition: border-color 0.15s;
  width: 100%;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}
.required { color: var(--danger); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Dropdown ─────────────────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #1e0d18;
  border: 1px solid rgba(255, 233, 240, 0.18);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 160px;
  z-index: 9999;
  overflow: hidden;
  isolation: isolate;
}
.dropdown-menu-right { left: auto; right: 0; }
.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  text-align: left;
  font-size: 13px;
  color: #fff4f8;
  background: transparent;
  border: none;
  transition: background 0.1s;
}
.dropdown-menu button:hover { background: rgba(255, 255, 255, 0.08); }
.dropdown:focus-within .dropdown-menu,
.dropdown.open .dropdown-menu { display: block; }

/* ═══════════════════════════════════════════════════════════════════════════ */
/* EDITOR LAYOUT                                                              */
/* ═══════════════════════════════════════════════════════════════════════════ */
.editor-page { overflow: hidden; }
.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Editor header ────────────────────────────────────────────────────────── */
.editor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
  background: rgba(27, 12, 22, 0.66);
  border-bottom: 1px solid rgba(255, 233, 240, 0.08);
  backdrop-filter: blur(18px);
  flex-shrink: 0;
  z-index: 20;
}
.editor-logo { opacity: 0.7; transition: opacity 0.15s; }
.editor-logo:hover { opacity: 1; }
.editor-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.03em;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editor-header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--toolbar-h);
  padding: 0 12px;
  background: rgba(37, 17, 29, 0.72);
  border-bottom: 1px solid rgba(255, 233, 240, 0.06);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
  z-index: 10;
  overflow-x: auto;
}
.toolbar-group { display: flex; align-items: center; gap: 2px; }
.toolbar-label {
  padding: 0 6px 0 2px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 224, 233, 0.62);
}
.template-btn { color: var(--text); background: rgba(255,255,255,0.04); }
.template-btn:hover { background: rgba(91,138,240,0.16); }
.template-menu {
  position: relative;
  flex-shrink: 0;
}
.template-menu[open] .template-menu-toggle {
  background: rgba(212, 117, 151, 0.16);
  color: var(--text);
  border-color: rgba(231, 179, 198, 0.24);
}
.template-menu-toggle {
  list-style: none;
}
.template-menu-toggle::-webkit-details-marker { display: none; }
#btn-legend.active {
  background: rgba(212, 117, 151, 0.16);
  border-color: rgba(231, 179, 198, 0.24);
}
.template-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 340px;
  padding: 10px;
  display: grid;
  gap: 6px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(30, 14, 24, 0.97);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.32);
}
/* ── Legend canvas overlay (bottom-left) ─────────────────────────────────── */
.legend-overlay {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 20;
  min-width: 190px;
  padding: 12px 14px;
  display: grid;
  gap: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(22, 10, 18, 0.88);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.42);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.legend-overlay.hidden {
  display: none;
}
.legend-overlay-title {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 224, 233, 0.55);
  margin-bottom: 2px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1);
}
.template-menu-section {
  display: grid;
  gap: 6px;
}
.template-menu-heading {
  padding: 4px 6px 2px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 224, 233, 0.62);
}
.template-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.template-menu-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: rgba(255, 245, 248, 0.04);
  color: var(--text);
}
.template-menu-item:hover {
  background: rgba(212, 117, 151, 0.12);
  border-color: rgba(231, 179, 198, 0.24);
}
.template-menu-item.wide {
  grid-column: 1 / -1;
}
.template-menu-item strong {
  font-size: 12px;
  font-weight: 600;
}
.template-menu-item span {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Starters modal ─────────────────────────────────────────────────────── */
.starters-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.starters-modal.hidden { display: none; }
.starters-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 4, 8, 0.72);
  backdrop-filter: blur(4px);
}
.starters-modal-box {
  position: relative;
  width: min(680px, 94vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(28, 12, 22, 0.98);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.starters-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.starters-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}
.starters-modal-close {
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.starters-modal-close:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.starters-modal-body {
  overflow-y: auto;
  padding: 16px 20px 20px;
  display: grid;
  gap: 18px;
}

.toolbar-divider { width: 1px; height: 24px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.toolbar-spacer { flex: 1; }

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
}
.filter-btn {
  padding-inline: 12px;
}
.tool-btn:hover { background: rgba(255, 245, 248, 0.08); color: var(--text); border-color: rgba(255, 233, 240, 0.06); }
.tool-btn.active {
  background: linear-gradient(135deg, rgba(214, 113, 149, 0.92), rgba(165, 53, 96, 0.9));
  color: #fff;
  border-color: rgba(255, 220, 231, 0.34);
  box-shadow: 0 12px 24px rgba(114, 29, 61, 0.28);
}
.tool-btn.active:hover { background: linear-gradient(135deg, rgba(228, 132, 166, 0.96), rgba(150, 43, 84, 0.92)); }

.zoom-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
  user-select: none;
}

/* ── Editor body ──────────────────────────────────────────────────────────── */
.editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Canvas container ─────────────────────────────────────────────────────── */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(231, 171, 193, 0.28), transparent 22%),
    radial-gradient(circle at 78% 14%, rgba(244, 210, 168, 0.18), transparent 20%),
    linear-gradient(180deg, #fff4f3 0%, #f2dede 100%);
}
#canvas-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.38), rgba(255,255,255,0));
  pointer-events: none;
}
#mindmap-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  cursor: default;
}
.canvas-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(77, 38, 53, 0.56);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  transition: opacity 0.3s;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(255, 248, 249, 0.66);
  border: 1px solid rgba(135, 79, 100, 0.1);
  backdrop-filter: blur(12px);
}

/* ── Side panel ───────────────────────────────────────────────────────────── */
.side-panel {
  width: var(--panel-w);
  background: linear-gradient(180deg, rgba(42, 20, 33, 0.84), rgba(23, 10, 19, 0.94));
  border-left: 1px solid rgba(255, 233, 240, 0.08);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 5;
  transition: width 0.2s;
}
.side-panel.hidden { display: none; }
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.side-panel-close {
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 3px;
}
.side-panel-close:hover { background: var(--surface-2); color: var(--text); }
.side-panel-body { padding: 16px; flex: 1; overflow-y: auto; }

.selection-intro {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 244, 247, 0.04);
  border: 1px solid rgba(233, 182, 200, 0.1);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.color-presets { display: flex; gap: 5px; flex-wrap: wrap; }
.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.active { border-color: #fff; }

#node-properties,
#edge-properties {
  display: flex;
  flex-direction: column;
}

/* ── Node edit overlay ────────────────────────────────────────────────────── */
.node-edit-overlay {
  position: fixed;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 4px;
  filter: drop-shadow(var(--shadow));
}
.node-edit-overlay.hidden { display: none; }
.node-edit-input {
  background: rgba(36, 16, 27, 0.92);
  border: 1px solid rgba(229, 182, 200, 0.28);
  border-radius: 14px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  min-width: 160px;
  max-width: 260px;
  outline: none;
  box-shadow: 0 24px 54px rgba(2, 8, 18, 0.35);
}
.node-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}
.node-edit-actions button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.node-edit-actions button:first-child:hover { background: var(--success); border-color: var(--success); }
.node-edit-actions button:last-child:hover { background: var(--danger); border-color: var(--danger); }

/* ── Gallery panel ────────────────────────────────────────────────────────── */
.gallery-panel {
  width: 320px;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 5;
  overflow: hidden;
}
.gallery-panel.hidden { display: none !important; }

.gallery-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #e5e7eb;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  flex-shrink: 0;
  background: #f9fafb;
}

.gallery-cat-row {
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}
.gallery-cat-select {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  cursor: pointer;
  outline: none;
  appearance: auto;
}
.gallery-cat-select:focus {
  border-color: #c4577c;
  box-shadow: 0 0 0 2px rgba(196,87,124,0.15);
}

.gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-content: start;
}

.gallery-item {
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  cursor: grab;
  transition: border-color 0.15s, transform 0.12s;
  user-select: none;
}
.gallery-item:hover {
  border-color: #c4577c;
  transform: translateY(-1px);
}
.gallery-item:active { cursor: grabbing; transform: scale(0.96); }

.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #ffffff;
  display: block;
  pointer-events: none;
  padding: 4px;
}
.gallery-item-label {
  font-size: 10px;
  color: #6b7280;
  padding: 3px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
  text-align: center;
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 24px 12px;
  font-size: 12px;
  color: #9ca3af;
}
.gallery-empty a { color: #c4577c; }

/* ── Mode hint bar ────────────────────────────────────────────────────────── */
.mode-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 4px 16px;
  font-size: 11px;
  color: rgba(16, 31, 52, 0.52);
  pointer-events: none;
  user-select: none;
  background: rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(10px);
  height: 30px;
  display: flex;
  align-items: center;
}

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

@media (max-width: 980px) {
  :root { --panel-w: 300px; }

  .toolbar {
    padding: 6px 10px;
    height: auto;
    min-height: var(--toolbar-h);
    flex-wrap: wrap;
  }

  .template-menu-panel {
    left: auto;
    right: 0;
    min-width: min(340px, calc(100vw - 32px));
  }

  .template-menu-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .editor-body { flex-direction: column; }

  .side-panel {
    width: 100%;
    max-height: 42vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .canvas-hint,
  .mode-hint {
    display: none;
  }
}

/* ── Minimap ──────────────────────────────────────────────────────────────── */
#minimap-canvas {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  height: 100px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  pointer-events: auto;
  cursor: crosshair;
  background: rgba(23,13,20,0.88);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  z-index: 10;
}

/* ── Search modal (Ctrl+K palette) ───────────────────────────────────────── */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.search-modal.hidden { display: none; }
.search-modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 92vw);
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  overflow: hidden;
}
.search-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-body);
}
.search-input::placeholder { color: var(--text-muted); }
.search-results {
  margin: 0;
  padding: 4px 0;
  max-height: 340px;
  overflow-y: auto;
}
.search-results li {
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  list-style: none;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background 0.1s;
}
.search-results li:hover { background: rgba(196,87,124,0.18); }

/* ── Layout option buttons ───────────────────────────────────────────────── */
.layout-option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  transition: background 0.15s, border-color 0.15s;
}
.layout-option-btn:hover {
  background: var(--surface-2);
  border-color: var(--primary);
}
.layout-option-btn .layout-option-icon {
  font-size: 24px;
  line-height: 1;
  flex-shrink: 0;
}
.layout-option-btn strong {
  display: block;
  font-size: 14px;
  margin-bottom: 2px;
}
.layout-option-btn p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── AI modal wider box ───────────────────────────────────────────────────── */
.ai-modal-box {
  max-width: 640px;
  width: min(640px, 96vw);
}

/* ── Versions / generic modal backdrop ───────────────────────────────────── */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,5,10,0.72);
  backdrop-filter: blur(3px);
}

/* ── Canvas context menu ──────────────────────────────────────────────────── */
#canvas-ctx-menu {
  font-family: var(--font-body);
  font-size: 13px;
}
