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

:root {
  --bg-toolbar: #2d2d30;
  --bg-left: #1e1e1e;
  --bg-right: #252526;
  --bg-btn: #3e3e42;
  --bg-btn-hover: #505055;
  --bg-divider: #454545;
  --accent: #4fc3f7;
  --accent-dim: rgba(79,195,247,0.12);
  --text: #cccccc;
  --text-dim: #888;
  --error-bg: #3b1111;
  --error-fg: #f48771;
  --border: #444;
}

html, body {
  height: 100%;
  background: var(--bg-left);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

/* ── TOOLBAR ── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 44px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid #1c1c1c;
  flex-shrink: 0;
  user-select: none;
  position: relative;
  z-index: 50;
}

.app-logo {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-right: 6px;
}

.toolbar-group { display: flex; align-items: center; gap: 4px; }
.toolbar-right { margin-left: auto; }

.sep {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ── BUTTONS ── */
button {
  background: var(--bg-btn);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12.5px;
  transition: background 0.1s;
  white-space: nowrap;
}
button:hover { background: var(--bg-btn-hover); border-color: #666; }
button:active { background: #666; }

/* ── DROPDOWN ── */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #2a2a2d;
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 200;
  min-width: 160px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  overflow: hidden;
}

.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  padding: 9px 14px;
  background: transparent;
  font-size: 13px;
}

.dropdown-menu button:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.hidden { display: none !important; }

/* ── LAYOUT ── */
#app {
  display: flex;
  height: calc(100vh - 44px);
  overflow: hidden;
}

/* ── LEFT PANEL ── */
#panel-left {
  width: 45%;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: var(--bg-left);
  overflow: hidden;
  flex-shrink: 0;
}

#editor-wrapper { flex: 1; overflow: hidden; position: relative; }

#editor-wrapper .CodeMirror {
  height: 100%;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--bg-left);
}

#editor-wrapper .CodeMirror-scroll { padding-bottom: 20px; }

#error-bar {
  background: var(--error-bg);
  color: var(--error-fg);
  padding: 7px 12px;
  font-size: 12px;
  border-top: 1px solid #5a2020;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.4;
}

/* ── DIVIDER ── */
#divider {
  width: 5px;
  cursor: col-resize;
  background: var(--bg-divider);
  flex-shrink: 0;
  transition: background 0.15s;
}
#divider:hover, #divider.dragging { background: var(--accent); }

/* ── RIGHT PANEL ── */
#panel-right {
  flex: 1;
  min-width: 200px;
  background: var(--bg-right);
  position: relative;
  overflow: hidden;
}

#diagram-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 20px;
  cursor: grab;
}
#diagram-wrapper.panning { cursor: grabbing; }

#diagram-container {
  display: inline-block;
  transform-origin: top left;
}

#diagram-container svg {
  display: block;
  overflow: visible;
}

/* Node styles */
#diagram-container .node { cursor: grab; }
#diagram-container .node.draggable { cursor: grab; }
#diagram-container .node.dragging { cursor: grabbing !important; }

/* ── OVERLAYS ── */
#zoom-info {
  position: absolute;
  bottom: 10px;
  right: 12px;
  background: rgba(0,0,0,0.55);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  pointer-events: none;
  user-select: none;
}

#diagram-hint {
  position: absolute;
  bottom: 10px;
  left: 12px;
  background: rgba(0,0,0,0.45);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  pointer-events: none;
  user-select: none;
}

/* ── EDIT OVERLAY ── */
#edit-overlay {
  position: fixed;
  z-index: 1000;
}

#label-input {
  background: #1c2a3a;
  color: #e8f4ff;
  border: 2px solid var(--accent);
  border-radius: 5px;
  padding: 5px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 80px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6), 0 0 0 3px rgba(79,195,247,0.2);
}

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #777; }

/* ── CODEMIRROR MERMAID TOKEN COLORS ── */
.cm-s-material-darker .cm-keyword { color: #c792ea; font-weight: bold; }
.cm-s-material-darker .cm-operator { color: #89ddff; }
.cm-s-material-darker .cm-string  { color: #c3e88d; }
.cm-s-material-darker .cm-def     { color: #82aaff; }
.cm-s-material-darker .cm-comment { color: #546e7a; font-style: italic; }
