* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #1e1e2e;
  color: #cdd6f4;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Tab bar ────────────────────────────────────────── */
#tab-bar {
  display: flex;
  align-items: center;
  background: #181825;
  border-bottom: 2px solid #313244;
  padding: 4px 8px 0;
  gap: 6px;
  min-height: 38px;
  flex-shrink: 0;
}

#tabs {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  overflow-x: auto;
  flex: 1;
}

.tab {
  background: #313244;
  border: 1px solid #45475a;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 5px 14px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.tab:hover { background: #45475a; }

.tab.active {
  background: #1e1e2e;
  border-color: #89b4fa;
  color: #89b4fa;
}

.tab .tab-close {
  font-size: 15px;
  color: #6c7086;
  line-height: 1;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0 2px;
}
.tab .tab-close:hover { color: #f38ba8; }

#btn-new-project {
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
#btn-new-project:hover { background: #45475a; }

/* ── Toolbar ────────────────────────────────────────── */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  background: #24273a;
  padding: 6px 10px;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 0;
  border-right: 1px solid #45475a;
}
.toolbar-section:last-child { border-right: none; }

.section-label {
  font-size: 10px;
  color: #6c7086;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
  white-space: nowrap;
}

#toolbar button {
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 5px;
  color: #cdd6f4;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
  white-space: nowrap;
}
#toolbar button:hover { background: #45475a; }
#toolbar button.active {
  background: #89b4fa;
  color: #1e1e2e;
  border-color: #89b4fa;
}

.element-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 8px !important;
  font-size: 11px !important;
  gap: 2px;
  min-width: 58px;
}
.element-btn svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.element-btn span { font-size: 10px; }

#toggle-legend { cursor: pointer; }

/* ── Main area (canvas + side panel) ───────────────── */
#main-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Canvas wrapper ─────────────────────────────────── */
#canvas-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #11111b;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 16px;
}

#zoom-scroll-area {
  position: relative;
  flex-shrink: 0;
  /* width / height set by JS to imageW*zoom × imageH*zoom */
}

#zoom-container {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
}

#drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #585b70;
  font-size: 18px;
  pointer-events: none;
  text-align: center;
  z-index: 1;
}

#zoom-level-display {
  font-size: 12px;
  color: #cdd6f4;
  min-width: 38px;
  text-align: center;
  display: inline-block;
}

#main-canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
  cursor: default;
}

#overlay-svg {
  position: absolute;
  top: 0; left: 0;
  overflow: visible;
  pointer-events: all;
}

/* ── Side panel ────────────────────────────────────── */
#side-panel {
  width: 280px;
  flex-shrink: 0;
  background: #1e1e2e;
  border-left: 2px solid #313244;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#side-panel-header {
  font-size: 11px;
  font-weight: bold;
  color: #89b4fa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 12px;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

#side-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.panel-item {
  background: #24273a;
  border: 1px solid #313244;
  border-radius: 6px;
  padding: 7px 8px;
  transition: border-color 0.15s;
}
.panel-item-selected { border-color: #89b4fa; }

.panel-item-header {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  margin-bottom: 5px;
}
.panel-item-header:hover .panel-item-type { color: #89b4fa; }

.panel-icon { flex-shrink: 0; }

.panel-icon-fallback {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  flex-shrink: 0;
}

.panel-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.panel-item-num {
  font-size: 10px;
  color: #6c7086;
}

.panel-item-type {
  font-size: 11px;
  color: #cdd6f4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-desc {
  width: 100%;
  background: #181825;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #a6adc8;
  font-size: 11px;
  font-family: inherit;
  padding: 5px 7px;
  resize: vertical;
  min-height: 40px;
  box-sizing: border-box;
}
.panel-desc:focus {
  outline: none;
  border-color: #89b4fa;
}

.panel-size-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.panel-size-label {
  font-size: 10px;
  color: #6c7086;
  flex-shrink: 0;
}
.panel-size-slider {
  flex: 1;
  height: 4px;
  cursor: pointer;
  accent-color: #89b4fa;
}
.panel-size-value {
  font-size: 10px;
  color: #a6adc8;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}
.panel-rot-value {
  font-size: 10px;
  color: #a6adc8;
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
}
.panel-stroke-value {
  font-size: 10px;
  color: #a6adc8;
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
}
.panel-duplicate-btn {
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #89b4fa;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
  margin-left: auto;
}
.panel-duplicate-btn:hover { background: #45475a; }

.panel-badge-toggle {
  font-size: 10px;
  color: #a6adc8;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.panel-badge-toggle input { cursor: pointer; accent-color: #89b4fa; }

.panel-empty {
  color: #6c7086;
  font-size: 12px;
  text-align: center;
  padding: 24px 12px;
}

/* ── Legend box ─────────────────────────────────────── */
#legend-box {
  position: absolute;
  background: rgba(30, 30, 46, 0.92);
  border: 1.5px solid #89b4fa;
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 160px;
  max-width: 260px;
  cursor: grab;
  z-index: 100;
  user-select: none;
  backdrop-filter: blur(4px);
  top: 20px;
  left: 20px;
}
#legend-box:active { cursor: grabbing; }
#legend-box.hidden { display: none; }

#legend-title {
  font-weight: bold;
  font-size: 13px;
  color: #89b4fa;
  margin-bottom: 6px;
  border-bottom: 1px solid #45475a;
  padding-bottom: 4px;
}

#legend-items {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.legend-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.legend-label {
  color: #cdd6f4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── SVG placed elements ────────────────────────────── */
.placed-element {
  cursor: move;
}
.placed-element.selected .element-frame {
  stroke: #f9e2af !important;
  stroke-width: 2.5;
}

.element-label-text {
  font-size: 11px;
  fill: #cdd6f4;
  font-family: 'Segoe UI', Arial, sans-serif;
  pointer-events: none;
}

.comment-node {
  cursor: move;
}
.comment-node.selected .comment-bubble {
  stroke: #f9e2af !important;
}
.comment-text {
  font-size: 11px;
  fill: #cdd6f4;
  font-family: 'Segoe UI', Arial, sans-serif;
  pointer-events: none;
}

/* ── Dialogs ────────────────────────────────────────── */
.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.dialog.hidden { display: none; }

.dialog-box {
  background: #24273a;
  border: 1.5px solid #45475a;
  border-radius: 10px;
  padding: 24px 28px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dialog-box h3 {
  color: #89b4fa;
  font-size: 16px;
}
.dialog-box textarea,
.dialog-box input[type="text"] {
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  width: 100%;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.dialog-actions button {
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 6px;
  color: #cdd6f4;
  padding: 7px 18px;
  cursor: pointer;
  font-size: 13px;
}
.dialog-actions button:first-child {
  background: #89b4fa;
  color: #1e1e2e;
  border-color: #89b4fa;
}
.dialog-actions button:hover { opacity: 0.85; }
