/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1e1e2e;
  color: #cdd6f4;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header / Toolbar ===== */
#header {
  display: flex;
  align-items: center;
  height: 48px;
  background: #181825;
  border-bottom: 1px solid #313244;
  padding: 0 16px;
  flex-shrink: 0;
  gap: 12px;
  z-index: 10;
}

#header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #cba6f7;
  letter-spacing: 0.05em;
  margin-right: auto;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.15s, border-color 0.15s;
}

.toolbar-btn:hover {
  background: #45475a;
  border-color: #cba6f7;
}

.toolbar-btn.active {
  background: #cba6f7;
  color: #1e1e2e;
  border-color: #cba6f7;
}

/* ===== Main Layout ===== */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Left Pane ===== */
#left-pane {
  width: 220px;
  flex-shrink: 0;
  background: #181825;
  border-right: 1px solid #313244;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#left-pane .pane-header {
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c7086;
  border-bottom: 1px solid #313244;
}

.menu-section {
  padding: 8px 0;
  border-bottom: 1px solid #313244;
}

.menu-section-title {
  padding: 6px 16px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6c7086;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.875rem;
  border-radius: 0;
  transition: background 0.1s;
  user-select: none;
}

.menu-item:hover {
  background: #313244;
}

.menu-item.active {
  background: #313244;
  color: #cba6f7;
}

.menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

/* Rectangle list */
#rect-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

#rect-list .rect-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  cursor: pointer;
  font-size: 0.8rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

#rect-list .rect-item:hover {
  background: #313244;
}

#rect-list .rect-item.selected {
  background: #313244;
  border-left-color: #cba6f7;
  color: #cba6f7;
}

#rect-list .rect-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

#rect-list .rect-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.empty-list-msg {
  padding: 12px 16px;
  font-size: 0.78rem;
  color: #6c7086;
  font-style: italic;
}

/* ===== Middle Pane (Canvas) ===== */
#canvas-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #24273a;
  position: relative;
}

#canvas-toolbar {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: #1e1e2e;
  border-bottom: 1px solid #313244;
  gap: 8px;
  flex-shrink: 0;
}

#canvas-toolbar .tool-group {
  display: flex;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid #313244;
}

#canvas-toolbar .tool-group:last-child {
  border-right: none;
}

.canvas-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #cdd6f4;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.canvas-tool-btn:hover {
  background: #313244;
  border-color: #45475a;
}

.canvas-tool-btn.active {
  background: #cba6f7;
  color: #1e1e2e;
  border-color: #cba6f7;
}

.canvas-tool-btn svg {
  width: 16px;
  height: 16px;
}

#canvas-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: default;
}

#canvas-wrapper.tool-select { cursor: default; }
#canvas-wrapper.tool-add { cursor: crosshair; }
#canvas-wrapper.tool-connect { cursor: cell; }
#canvas-wrapper.tool-pan { cursor: grab; }
#canvas-wrapper.tool-pan.panning { cursor: grabbing; }

#main-canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

/* ===== Right Pane ===== */
#right-pane {
  width: 280px;
  flex-shrink: 0;
  background: #181825;
  border-left: 1px solid #313244;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tab bar */
#tab-bar {
  display: flex;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  padding: 10px 6px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #6c7086;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  transition: color 0.1s, border-color 0.1s;
}

.tab-btn:hover {
  color: #cdd6f4;
}

.tab-btn.active {
  color: #cba6f7;
  border-bottom-color: #cba6f7;
}

/* Tab panels */
.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel.active {
  display: block;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c7086;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 7px 10px;
  background: #24273a;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus {
  border-color: #cba6f7;
}

.form-control::placeholder {
  color: #45475a;
}

textarea.form-control {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row .form-group {
  flex: 1;
}

.color-preview {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #45475a;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 22px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 8px;
  background: #cba6f7;
  border: none;
  border-radius: 6px;
  color: #1e1e2e;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.btn-primary:hover {
  opacity: 0.85;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.btn-secondary:hover {
  background: #313244;
}

.btn-danger {
  display: block;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid #f38ba8;
  border-radius: 6px;
  color: #f38ba8;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.btn-danger:hover {
  background: rgba(243, 139, 168, 0.1);
}

.info-box {
  background: #24273a;
  border: 1px solid #313244;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: #a6adc8;
  line-height: 1.5;
}

.info-box p + p {
  margin-top: 6px;
}

.prop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #313244;
  font-size: 0.82rem;
}

.prop-row:last-child {
  border-bottom: none;
}

.prop-key {
  color: #6c7086;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prop-val {
  color: #cdd6f4;
  text-align: right;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Connections list */
.conn-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: #24273a;
  border: 1px solid #313244;
  border-radius: 5px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.conn-item-label {
  color: #a6adc8;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conn-delete-btn {
  background: transparent;
  border: none;
  color: #f38ba8;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
}

.conn-delete-btn:hover {
  background: rgba(243, 139, 168, 0.1);
}

/* ===== URL Modal / Overlay ===== */
#url-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

#url-modal.open {
  display: flex;
}

#url-modal-box {
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 10px;
  width: min(90vw, 1000px);
  height: min(85vh, 700px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

#url-modal-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #181825;
  border-bottom: 1px solid #313244;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#url-modal-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #cdd6f4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: auto;
}

#url-modal-url {
  font-size: 0.75rem;
  color: #6c7086;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

/* Action buttons in the URL modal header */
.modal-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  cursor: pointer;
  font-size: 0.76rem;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.modal-action-btn:hover {
  background: #45475a;
  border-color: #cba6f7;
  color: #cba6f7;
}

.modal-action-btn-cancel:hover {
  border-color: #f38ba8;
  color: #f38ba8;
}

/* Inline add-node bar */
#modal-add-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #24273a;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

#modal-add-label {
  flex: 1;
  min-width: 80px;
  padding: 5px 8px;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 5px;
  color: #cdd6f4;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
}

#modal-add-url {
  flex: 2;
  min-width: 120px;
  padding: 5px 8px;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 5px;
  color: #cdd6f4;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
}

#modal-add-label:focus,
#modal-add-url:focus {
  border-color: #cba6f7;
}

#url-modal-close {
  width: 28px;
  height: 28px;
  background: #313244;
  border: none;
  border-radius: 50%;
  color: #cdd6f4;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  flex-shrink: 0;
}

#url-modal-close:hover {
  background: #f38ba8;
  color: #1e1e2e;
}

#url-modal-iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: #fff;
}

#url-modal-error {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: #a6adc8;
  font-size: 0.9rem;
  padding: 32px;
  text-align: center;
}

#url-modal-error svg {
  opacity: 0.4;
}

/* ===== Burst Links Modal ===== */
#burst-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 1100;
  align-items: center;
  justify-content: center;
}

#burst-modal.open {
  display: flex;
}

#burst-modal-box {
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 10px;
  width: min(90vw, 620px);
  max-height: min(80vh, 600px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

#burst-modal-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: #181825;
  border-bottom: 1px solid #313244;
  gap: 10px;
  flex-shrink: 0;
}

#burst-modal-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #cdd6f4;
}

#burst-modal-source {
  flex: 1;
  font-size: 0.72rem;
  color: #6c7086;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#burst-modal-close {
  width: 28px;
  height: 28px;
  background: #313244;
  border: none;
  border-radius: 50%;
  color: #cdd6f4;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  flex-shrink: 0;
}

#burst-modal-close:hover {
  background: #f38ba8;
  color: #1e1e2e;
}

#burst-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

#burst-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 32px;
  color: #6c7086;
  font-size: 0.875rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#burst-loading svg {
  animation: spin 1s linear infinite;
  opacity: 0.5;
}

#burst-error {
  display: none;
  padding: 40px 32px;
  text-align: center;
  color: #a6adc8;
  font-size: 0.875rem;
  line-height: 1.5;
}

#burst-link-list {
  display: none;
}

.burst-link-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 1px solid #313244;
  transition: background 0.1s;
}

.burst-link-item:last-child {
  border-bottom: none;
}

.burst-link-item:hover {
  background: #24273a;
}

.burst-checkbox {
  margin-top: 3px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #cba6f7;
}

.burst-link-info {
  flex: 1;
  min-width: 0;
}

.burst-link-text {
  font-size: 0.84rem;
  color: #cdd6f4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.burst-link-url {
  font-size: 0.71rem;
  color: #6c7086;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#burst-modal-footer {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #181825;
  border-top: 1px solid #313244;
  flex-shrink: 0;
}

#burst-create-nodes {
  display: inline-block;
  width: auto;
  margin: 0 0 0 auto;
  padding: 6px 16px;
  font-size: 0.82rem;
}

/* ===== Resize Handles ===== */
.resize-handle {
  flex-shrink: 0;
  z-index: 5;
}

.resize-handle-v {
  width: 4px;
  cursor: col-resize;
  background: #313244;
  transition: background 0.1s;
}

.resize-handle-v:hover {
  background: #cba6f7;
}

/* ===== Context Menu ===== */
#context-menu {
  display: none;
  position: fixed;
  background: #24273a;
  border: 1px solid #45475a;
  border-radius: 7px;
  padding: 4px 0;
  z-index: 500;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#context-menu.open {
  display: block;
}

.ctx-item {
  padding: 8px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cdd6f4;
}

.ctx-item:hover {
  background: #313244;
}

.ctx-item.danger {
  color: #f38ba8;
}

.ctx-separator {
  height: 1px;
  background: #313244;
  margin: 3px 0;
}

/* ===== Zoom indicator ===== */
#zoom-indicator {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(24, 24, 37, 0.85);
  border: 1px solid #313244;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: #6c7086;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #45475a;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #6c7086; }

/* ===== Tooltip ===== */
[title] { cursor: help; }
.canvas-tool-btn[title] { cursor: pointer; }
