:root {
  --bg-dark: #1a1d23;
  --bg-panel: #252932;
  --bg-input: #2d3139;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --text: #e4e7eb;
  --text-muted: #9ca3af;
  --border: #3f4551;
  --grid-line: #3f4551;
  --danger: #ef4444;
  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
}

.header-logo {
  height: 64px;
  width: auto;
  display: block;
  object-fit: contain;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.project-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 140px;
}

.floor-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  min-width: 140px;
}

.main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  min-height: 0;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.panel {
  margin-bottom: 1.5rem;
}

.panel-project .project-select.full-width {
  width: 100%;
}

.panel-project .project-actions {
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.panel-project .project-actions .btn-icon {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.panel-project .project-storage-hint {
  margin-top: 0.75rem;
  margin-bottom: 0;
  line-height: 1.4;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: -0.5rem 0 0.75rem;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}

.form-group input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

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

.building-list {
  margin-top: 0.5rem;
}

.building-block {
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.building-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.building-block-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.building-block-actions {
  display: flex;
  gap: 0.25rem;
}

.building-block-actions .building-edit,
.building-block-actions .building-delete {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  min-height: auto;
}

.building-floors {
  margin-bottom: 0.5rem;
}

.building-block .add-floor-in-building {
  width: 100%;
  margin-top: 0.25rem;
}

.floor-list {
  margin-top: 0.25rem;
}

.floor-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.floor-item .floor-info {
  flex: 1;
  min-width: 0;
}

.floor-item .floor-dims {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.floor-item .floor-utilized {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 0.2rem;
}

.floor-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.floor-edit {
  background: var(--border);
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 4px;
}

.floor-edit:hover {
  background: var(--accent);
}

.floor-item .floor-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1rem;
  line-height: 1;
}

.floor-item .floor-delete:hover {
  color: var(--danger);
}

.space-palette {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.space-def {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border-radius: 6px;
  cursor: grab;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.space-def:hover {
  border-color: var(--accent);
}

.space-def:active {
  cursor: grabbing;
}

.space-def .swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  flex-shrink: 0;
}

.space-def .space-info {
  flex: 1;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.space-def .space-name {
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.4;
}

.space-def .space-dims {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.space-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.space-edit {
  background: var(--border);
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 4px;
}

.space-edit:hover {
  background: var(--accent);
}

.space-def .space-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.6;
}

.space-def .space-remove:hover {
  color: var(--danger);
  opacity: 1;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #363b45;
}

#addSpace,
#addFloor,
#addBuilding {
  width: 100%;
}

.canvas-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #1e2128;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.hint-inline {
  font-size: 0.8rem;
  color: var(--text-muted);
}

#floorDimensions {
  font-weight: 500;
  color: var(--text);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.zoom-controls button:hover {
  background: #363b45;
}

#zoomLevel {
  min-width: 3rem;
  text-align: center;
}

.canvas-container {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 2rem 0.5rem 2rem;
}

.building-canvas-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.25rem 1rem 1.25rem;
  background: var(--bg-panel);
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 100%;
  box-sizing: border-box;
}

.building-canvas-group-title {
  margin: 0 0 0.15rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.building-canvas-floors {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
  row-gap: 1rem;
}

.floor-canvas-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.floor-canvas-header {
  height: 3.25rem;
  min-height: 3.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  align-content: center;
  gap: 0.25rem 0.5rem;
  flex-shrink: 0;
}

.floor-canvas-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.floor-canvas-dims {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.floor-canvas-utilized {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--accent);
  margin-left: 0.5rem;
}

.floor-canvas-wrap canvas {
  margin-top: 0.5rem;
  background: var(--bg-dark);
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-panel);
  border-radius: 8px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
}

.modal-content h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* Confirm / alert modal */
.confirm-modal-content {
  max-width: 400px;
}

.confirm-modal-content .confirm-message {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
}

.confirm-modal-content .confirm-detail {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.confirm-modal-content .confirm-detail.hidden {
  display: none;
}

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
}

.btn-danger:hover {
  background: #dc2626;
}

.context-menu {
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem;
  min-width: 140px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 2000;
}

.context-menu.hidden {
  display: none;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 4px;
}

.context-menu button:hover {
  background: var(--bg-input);
}

.context-menu button[data-action="remove"]:hover {
  color: var(--danger);
}
