:root {
  --bg-dark: #0f1115;
  --panel-bg: rgba(22, 25, 31, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --neon-blue: #3b82f6;
  --neon-blue-hover: #60a5fa;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --shape-bg: #1e293b;
  --shape-border: #475569;
  --shape-selected: #3b82f6;
}

body.light-mode {
  --bg-dark: #f8fafc;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(0, 0, 0, 0.1);
  --neon-blue: #2563eb;
  --neon-blue-hover: #1d4ed8;
  --text-main: #0f172a;
  --text-muted: #475569;
  
  --shape-bg: #ffffff;
  --shape-border: #cbd5e1;
  --shape-selected: #2563eb;
}

body.light-mode .custom-select {
  color: var(--text-main);
  background: #ffffff;
}

body.light-mode .btn-secondary {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.05);
}

body.light-mode .btn-secondary:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.1);
}

body.light-mode .palette-item {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.1);
}

body.light-mode .palette-item:hover {
  background: #f1f5f9;
}

body.light-mode .modal {
  background: #ffffff;
}

body.light-mode .modal-body select option {
  background: #ffffff;
  color: var(--text-main);
}

body.light-mode #wysiwyg-toolbar {
  background: rgba(255, 255, 255, 0.95);
}

body.light-mode kbd {
  background: rgba(0,0,0,0.05);
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}

/* Database Table Styles */
.db-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  color: var(--text-main);
  background: var(--shape-bg);
}

.db-table th {
  background: rgba(0,0,0,0.2);
  padding: 8px;
  text-align: left;
  border-bottom: 2px solid var(--shape-border);
  font-weight: 600;
}

body.light-mode .db-table th {
  background: rgba(0,0,0,0.05);
}

.db-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--glass-border);
}

.db-table tr:last-child td {
  border-bottom: none;
}

.db-pk {
  font-weight: bold;
  color: var(--neon-blue);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Toolbar --- */
.toolbar {
  height: 60px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.custom-select {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 1px solid var(--glass-border);
  padding: 6px 12px;
  border-radius: 6px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
}

.divider {
  width: 1px;
  height: 24px;
  background: var(--glass-border);
}

.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  color: #fff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--neon-blue);
}
.btn-primary:hover:not(:disabled) {
  background: var(--neon-blue-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
}

/* --- App Container --- */
.app-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Help Tab --- */
.help-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.help-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--glass-border);
}

.help-icon {
  font-size: 18px;
  min-width: 24px;
  text-align: center;
}

.help-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.help-text strong {
  color: var(--text-main);
  display: block;
  margin-bottom: 2px;
}

kbd {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: monospace;
  box-shadow: 0 1px 0 rgba(255,255,255,0.1);
}

/* --- Node Handles --- */
.sidebar {
  width: 300px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--glass-border);
  padding: 24px 16px 24px 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* --- Sidebar Tabs --- */
.sidebar-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255,255,255,0.05);
}

.btn-primary:hover {
  background: var(--neon-blue-hover);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.project-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s;
}
.project-item:hover {
  border-color: var(--neon-blue);
}
.project-item-title {
  font-weight: 500;
  margin-bottom: 4px;
}
.project-item-date {
  font-size: 11px;
  color: var(--text-muted);
}
.btn-delete-project {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.btn-delete-project:hover {
  background: rgba(239, 68, 68, 0.1);
}

.tab-btn.active {
  color: var(--neon-blue);
  background: rgba(59, 130, 246, 0.1);
}

.full-width {
  width: 100%;
  display: block;
}

.line-settings label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sidebar-help {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* --- Sidebar Layout & Shapes --- */
details {
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  overflow: hidden;
}

summary {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-main);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.02);
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "▼";
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

details[open] summary::after {
  transform: rotate(-180deg);
}

details .shape-palette {
  padding: 12px;
  border-top: 1px solid var(--glass-border);
}

.shape-palette {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.palette-item {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: grab;
  transition: background 0.2s;
  min-width: 0; /* Prevents text from forcing column expansion */
}

.palette-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item span {
  font-size: 11px;
  color: var(--text-main);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
  text-align: center;
}

/* --- Workspace SVG --- */
.workspace {
  flex: 1;
  position: relative;
  background: var(--bg-dark);
  overflow: hidden;
}

.grid-svg {
  cursor: crosshair;
}

.grid-svg.panning {
  cursor: grabbing;
}

/* --- Shape SVG Classes --- */
.shape-node {
  cursor: pointer;
}

.shape-bg {
  fill: var(--shape-bg);
  stroke: var(--shape-border);
  stroke-width: 2px;
  transition: stroke 0.1s;
}

.shape-node:hover .shape-bg {
  stroke: #94a3b8;
}

.shape-node.selected .shape-bg {
  stroke: var(--shape-selected);
  stroke-width: 3px;
  filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.5));
}

.shape-text {
  fill: var(--text-main);
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  pointer-events: none;
  user-select: none;
}

/* --- Connectors --- */
.connector {
  fill: var(--neon-blue);
  stroke: var(--bg-dark);
  stroke-width: 1.5px;
  cursor: crosshair;
  transition: r 0.1s;
}

.resizer {
  fill: #fff;
  stroke: var(--neon-blue);
  stroke-width: 1.5px;
}

.resizer[data-corner="nw"], .resizer[data-corner="se"] {
  cursor: nwse-resize;
}

.resizer[data-corner="ne"], .resizer[data-corner="sw"] {
  cursor: nesw-resize;
}

/* --- Edges --- */
.edge-path {
  fill: none;
  stroke: var(--shape-border);
  stroke-width: 2px;
  cursor: pointer;
  pointer-events: stroke;
}

.edge-path:hover {
  stroke: #94a3b8;
  stroke-width: 3px;
}

.edge-path.selected {
  stroke: #fff;
  stroke-width: 3px;
}

.edge-path.drawing {
  stroke: var(--neon-blue);
  stroke-dasharray: 5, 5;
  pointer-events: none;
}

/* --- Text Editor Overlay --- */
.edge-text-bg {
  fill: var(--bg-dark);
  opacity: 0.8;
}

.edge-text {
  fill: var(--text-main);
  font-family: 'Outfit', sans-serif;
  font-size: 12px;
  pointer-events: none;
  user-select: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

#text-editor {
  position: absolute;
  background: transparent;
  border: none;
  color: transparent; /* Hide raw textarea text so SVG text shows below perfectly */
  caret-color: var(--text-main); /* Keep blinking cursor visible */
  outline: 2px solid var(--neon-blue);
  resize: none;
  overflow: hidden;
  text-align: center;
  z-index: 1000;
}

#text-editor::selection {
  background: rgba(144, 202, 249, 0.3); /* Selection highlight matches neon-blue */
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
}

.tab-content::-webkit-scrollbar {
  width: 6px;
}
.tab-content::-webkit-scrollbar-track {
  background: transparent;
}
.tab-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.tab-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hide {
  display: none !important;
}
/* --- Note Shapes --- */
.note-content {
  width: 100%;
  height: 100%;
  color: var(--text-main);
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  padding: 12px;
  box-sizing: border-box;
  overflow: hidden;
  word-wrap: break-word;
}
.note-content.has-border {
  border: 1px solid var(--shape-border);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}
.note-content[contenteditable="true"] {
  outline: 2px solid var(--neon-blue);
  background: rgba(0, 0, 0, 0.5);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal {
  background: var(--bg-dark);
  border: 1px solid var(--glass-border);
  padding: 24px;
  border-radius: 8px;
  width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 {
  margin: 0;
  color: var(--text-main);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.modal-close:hover {
  color: var(--text-main);
}
.modal h3 {
  margin: 0 0 16px 0;
  color: var(--text-main);
}
.modal-body label {
  display: block;
  margin: 12px 0 4px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.modal-body select {
  width: 100%;
  padding: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  border-radius: 4px;
}
.modal-body select option {
  background-color: var(--bg-dark);
  color: var(--text-main);
}
.modal-note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}
.modal-footer {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- WYSIWYG --- */
#wysiwyg-toolbar {
  position: absolute;
  background: rgba(20, 20, 30, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  gap: 4px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: auto;
}
#wysiwyg-toolbar button {
  background: transparent;
  border: none;
  color: var(--text-main);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
}
#wysiwyg-toolbar button:hover {
  background: rgba(255, 255, 255, 0.1);
}
#wysiwyg-toolbar .toolbar-divider {
  width: 1px;
  background: var(--glass-border);
  margin: 4px;
}

/* --- Context Menu --- */
.context-menu {
  background: rgba(15, 17, 21, 0.98);
  border: 1px solid var(--shape-border);
  border-radius: 6px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.8);
  padding: 4px 0;
  min-width: 150px;
  backdrop-filter: blur(12px);
}
.context-menu.hide {
  display: none !important;
}
.context-menu-item {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: background 0.2s;
}
.context-menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}
body.light-mode .context-menu {
  background: rgba(255, 255, 255, 0.98);
  border-color: #cbd5e1;
  box-shadow: 0 12px 36px rgba(0,0,0,0.2);
}
body.light-mode .context-menu-item {
  color: #0f172a;
}
body.light-mode .context-menu-item:hover {
  background: #f1f5f9;
}
