/* ===== Mind-Mapper — Hebrew-first RTL mind mapping tool ===== */
:root {
  --ui-font: 'Assistant', 'Heebo', system-ui, sans-serif;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1f2738;
  --muted: #6b7488;
  --line: #e4e8f2;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #e23b5a;
  --shadow: 0 8px 30px rgba(24, 32, 60, .12);
  --shadow-sm: 0 2px 10px rgba(24, 32, 60, .08);
  --radius: 14px;
  --tb-h: 56px;
  --rail-w: 50px;
  --panel-w: 300px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui-font);
  color: var(--ink);
  background: var(--bg);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }

/* ===== Toolbar ===== */
.toolbar {
  flex: none;
  height: var(--tb-h);
  display: flex; align-items: center; gap: 6px;
  padding-inline: 12px;
  background: var(--panel);
  border-block-end: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  z-index: 40;
  overflow: visible;
}
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-sep { width: 1px; height: 28px; background: var(--line); margin-inline: 6px; flex: none; }
.tb-spacer { flex: 1 1 auto; }

.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: transparent;
  border-radius: 10px; padding: 7px 10px;
  color: var(--ink); font-size: 14px; font-weight: 600;
  white-space: nowrap; line-height: 1; transition: background .15s, border-color .15s;
}
.tb-btn:hover { background: var(--accent-soft); }
.tb-btn:active { transform: translateY(1px); }
.tb-btn .ic { font-size: 17px; }
.tb-btn .lbl { font-size: 13.5px; }
.tb-btn[disabled] { opacity: .4; pointer-events: none; }

.tb-brand .tb-maps { background: var(--accent-soft); border-color: #dfe2ff; max-width: 230px; }
.tb-brand .lbl { overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.tb-side-toggle .ic { font-size: 16px; transition: transform .2s; }
body.side-collapsed .tb-side-toggle .ic { transform: scaleX(-1); }

/* ===== Export popover ===== */
.tb-pop-wrap { position: relative; }
.popover {
  position: absolute; inset-block-start: calc(100% + 8px); inset-inline-start: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 10px;
  z-index: 60; min-width: 190px;
}
.popover.popover-end { inset-inline-start: auto; inset-inline-end: 0; }
.popover[hidden] { display: none; }
.link-btn {
  display: block; width: 100%; text-align: start;
  background: transparent; border: 0; border-radius: 8px;
  padding: 9px 10px; font-size: 14px; font-weight: 600; color: var(--ink);
}
.link-btn:hover { background: var(--accent-soft); }

/* ===== Workspace (map + sidebar) ===== */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

.map {
  flex: 1 1 auto; min-width: 0; min-height: 0; position: relative;
  background:
    radial-gradient(circle at 1px 1px, #d9deec 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  outline: none;
  cursor: grab;
  overflow: hidden;
}
.map.is-panning { cursor: grabbing; }
/* smooth, but only for one-off camera moves (zoom buttons / fit / jump-to-node) */
.map .map-canvas.animate { transition: transform .22s cubic-bezier(.22,.61,.36,1); }

/* mind-elixir's pan/centre math assumes an LTR canvas; force the map subtree LTR
   (fixes the map drifting off-screen on RTL pages) — node TEXT stays RTL below. */
#map, .map-container, .map-canvas { direction: ltr; }

/* ===== Node drag affordance (grab nodes to reorganize) ===== */
me-tpc { cursor: grab; direction: rtl; transition: box-shadow .15s, transform .08s; }
me-tpc:hover { box-shadow: 0 4px 14px rgba(24, 32, 60, .16); }
me-tpc:active { cursor: grabbing; transform: scale(.98); }
me-tpc[contenteditable="true"], me-tpc[contenteditable="true"]:active { cursor: text; transform: none; }

/* the dragged copy that follows the cursor */
.mind-elixir-ghost {
  opacity: .92 !important;
  box-shadow: 0 14px 30px rgba(24, 32, 60, .3) !important;
  transform: rotate(-2deg) scale(1.04);
}

/* clearer, on-brand drop indicators */
.insert-preview.show { background: var(--accent) !important; opacity: .9 !important; border-radius: 4px; }
.insert-preview.before, .insert-preview.after { height: 5px !important; }
.insert-preview.before { top: -9px !important; }
.insert-preview.after { bottom: -9px !important; }
.insert-preview.in {
  background: transparent !important; opacity: 1 !important;
  outline: 2.5px dashed var(--accent); outline-offset: 3px; border-radius: 12px;
}

/* ===== Sidebar ===== */
.sidebar {
  flex: none; display: flex; height: 100%;
  background: var(--panel);
  border-inline-start: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(24,32,60,.06);
  width: calc(var(--rail-w) + var(--panel-w));
  transition: width .22s ease;
  z-index: 30;
}
body.side-collapsed .sidebar { width: var(--rail-w); }

.side-rail {
  flex: none; width: var(--rail-w);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 0;
  background: var(--bg);
  border-inline-start: 1px solid var(--line);
}
.rail-btn {
  width: 38px; height: 38px; border: 0; border-radius: 11px; background: transparent;
  font-size: 19px; display: grid; place-items: center; transition: background .15s;
}
.rail-btn:hover { background: var(--accent-soft); }
.rail-btn.active { background: var(--accent-soft); box-shadow: inset 0 0 0 2px #d7daff; }

.side-body { flex: 1 1 auto; min-width: 0; overflow-y: auto; padding: 16px; }
body.side-collapsed .side-body { display: none; }

.side-pane[hidden] { display: none; }
.pane-head { margin-block-end: 12px; }
.pane-head h2 { margin: 0; font-size: 18px; }
.pane-hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; line-height: 1.5; }
.pane-div { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.pane-cta {
  display: block; width: 100%; text-align: center;
  border: 1px dashed #c7ccdd; background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: 10px; font-weight: 700; margin-block-end: 12px;
}
.pane-cta.alt { border-style: solid; }
.pane-cta:hover { filter: brightness(.98); }

/* Maps list */
.maps-list, .outline-list { list-style: none; margin: 0; padding: 0; }
.map-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 8px;
  border-radius: 10px; margin-block-end: 4px; border: 1px solid transparent;
}
.map-item:hover { background: var(--bg); }
.map-item.active { border-color: var(--accent); background: var(--accent-soft); }
.map-item .mi-main { flex: 1; min-width: 0; cursor: pointer; }
.map-item .mi-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-item .mi-date { font-size: 11.5px; color: var(--muted); }
.map-item .mi-actions { display: flex; gap: 2px; }
.mi-actions button { border: 0; background: transparent; font-size: 14px; padding: 5px; border-radius: 7px; }
.mi-actions button:hover { background: var(--panel); }

/* Format pane */
.fmt-target {
  font-weight: 700; font-size: 14px; background: var(--bg); border-radius: 10px;
  padding: 9px 12px; margin: 0 0 14px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fmt-block { margin-block-end: 18px; }
.fmt-block > label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-block-end: 8px; }
.fmt-row { display: flex; gap: 8px; }
.mini-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 9px; padding: 7px 12px; font-weight: 700; font-size: 13px;
}
.mini-btn:hover { background: var(--accent-soft); border-color: #d7daff; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-block-end: 10px; }
.swatch { width: 100%; aspect-ratio: 1; border-radius: 8px; border: 2px solid rgba(0,0,0,.06); }
.swatch:hover { transform: scale(1.1); }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-block-end: 10px; }
.emoji-grid button { font-size: 20px; background: transparent; border: 0; border-radius: 8px; padding: 5px; }
.emoji-grid button:hover { background: var(--accent-soft); }

.theme-opts { display: flex; flex-direction: column; gap: 8px; }
.theme-opt {
  text-align: start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px;
}
.theme-opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.theme-opt b { display: block; font-size: 14px; }
.theme-opt small { color: var(--muted); font-size: 12px; }

/* AI pane */
.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin-block-end: 12px; }
.seg-btn { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg-btn.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); }
#aiInput {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  font-family: inherit; font-size: 15px; resize: vertical; color: var(--ink); background: #fff;
}
#aiInput:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn-primary {
  width: 100%; margin-block-start: 12px;
  background: linear-gradient(135deg, #6366f1, #a855f7); color: #fff; border: 0;
  border-radius: 12px; padding: 12px; font-weight: 800; font-size: 15px;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary[disabled] { opacity: .55; pointer-events: none; }
.ai-busy { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 700; margin-block-start: 12px; }
.ai-busy[hidden] { display: none; }
.spinner { width: 16px; height: 16px; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Outline */
.outline-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-radius: 8px; cursor: pointer; font-size: 14px; border: 1px solid transparent;
}
.outline-item:hover { background: var(--bg); }
.outline-item.root { font-weight: 800; }
.outline-item .o-emoji { flex: none; }
.outline-item .o-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Toasts ===== */
.toasts { position: fixed; inset-block-end: 20px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: #1f2738; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: toastIn .2s ease; }
.toast.err { background: var(--danger); }
.toast.ok { background: #18a957; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Playful theme accent for chrome ===== */
body[data-theme="playful"] { --accent: #ec4899; --accent-soft: #fdeefb; }

/* ===== Narrow screens: sidebar overlays the map ===== */
@media (max-width: 760px) {
  .sidebar { position: absolute; inset-block: 0; inset-inline-start: 0; }
  .tb-btn .lbl { display: none; }
  .tb-brand .lbl { display: inline; }
}
