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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #1e1e1e;
  color: #d4d4d4;
  overflow: hidden;
}

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

/* === Toolbar === */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #2d2d2d;
  border-bottom: 1px solid #404040;
  flex-shrink: 0;
}

.toolbar-brand {
  font-weight: 700;
  font-size: 15px;
  color: #e0e0e0;
  margin-right: 8px;
}

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

.toolbar-group + .toolbar-group {
  padding-left: 8px;
  border-left: 1px solid #404040;
}

.toolbar-right {
  margin-left: auto;
  border-left: none !important;
}

.toolbar-label {
  font-size: 12px;
  color: #888;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  background: #3c3c3c;
  color: #d4d4d4;
  border: 1px solid #505050;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover:not(:disabled) {
  background: #4c4c4c;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: #0e639c;
  border-color: #1177bb;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #1177bb;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  padding: 2px 6px;
  line-height: 1;
}

/* === Main layout === */
#main {
  display: flex;
  flex: 1;
  min-height: 0;
}

#editor-pane {
  width: 50%;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-container {
  flex: 1;
  overflow: auto;
}

/* CodeMirror takes full height */
#editor-container .cm-editor {
  height: 100%;
}

#editor-container .cm-scroller {
  overflow: auto;
}

/* === Splitter === */
#splitter {
  width: 5px;
  background: #404040;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
}

#splitter:hover, #splitter.dragging {
  background: #0e639c;
}

/* === Preview pane === */
#preview-pane {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#preview-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  position: relative;
}

#slide-canvas {
  display: none;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  background: #fff;
}

#slide-canvas.visible {
  display: block;
}

#preview-message {
  color: #666;
  text-align: center;
  font-size: 15px;
}

#preview-message.hidden {
  display: none;
}

#preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px;
  background: #2d2d2d;
  border-top: 1px solid #404040;
  flex-shrink: 0;
}

#slide-info {
  min-width: 60px;
  text-align: center;
  font-size: 13px;
  color: #999;
}

/* === Error panel === */
#error-panel {
  background: #1e1e1e;
  border-top: 1px solid #404040;
  max-height: 150px;
  overflow-y: auto;
  flex-shrink: 0;
  font-size: 13px;
  font-family: monospace;
}

#error-panel.hidden {
  display: none;
}

.error-item {
  display: flex;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid #2a2a2a;
  line-height: 1.4;
}

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

.error-level {
  flex-shrink: 0;
  font-weight: 600;
  font-size: 12px;
}

.error-level.error {
  color: #f48771;
}

.error-level.warning {
  color: #cca700;
}

.error-rule {
  color: #888;
  flex-shrink: 0;
}

.error-path {
  color: #569cd6;
  flex-shrink: 0;
}

.error-message {
  color: #d4d4d4;
}

/* === Status bar === */
#statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 3px 12px;
  background: #007acc;
  color: #fff;
  font-size: 12px;
  flex-shrink: 0;
}

#statusbar .error {
  color: #f48771;
  cursor: pointer;
  text-decoration: underline;
}

#statusbar .error:hover {
  color: #ff9d8a;
}

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

.modal.hidden {
  display: none;
}

.modal-content {
  background: #2d2d2d;
  border: 1px solid #505050;
  border-radius: 8px;
  width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #404040;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

#image-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.image-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  background: #3c3c3c;
  border-radius: 4px;
}

.image-item img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: #555;
}

.image-item .image-path {
  flex: 1;
  font-size: 13px;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-item .btn-delete {
  color: #f48771;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

#image-drop-zone {
  border: 2px dashed #505050;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: #888;
}

#image-drop-zone.drag-over {
  border-color: #0e639c;
  background: rgba(14, 99, 156, 0.1);
}

/* === Thumbnail strip === */
#thumbnail-strip {
  display: none;
  gap: 6px;
  padding: 6px 8px;
  background: #252525;
  border-top: 1px solid #404040;
  overflow-x: auto;
  flex-shrink: 0;
}

#thumbnail-strip.visible {
  display: flex;
}

.thumbnail-item {
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: border-color 0.15s;
}

.thumbnail-item:hover {
  border-color: #555;
}

.thumbnail-item.active {
  border-color: #0e639c;
}

/* === Nav separator === */
.nav-separator {
  width: 1px;
  height: 20px;
  background: #404040;
  margin: 0 4px;
}

/* === Inspect panel === */
#inspect-panel {
  background: #252525;
  border-top: 1px solid #404040;
  overflow-y: auto;
  max-height: 40vh;
  padding: 12px;
  flex-shrink: 0;
}

#inspect-panel.hidden {
  display: none;
}

.inspect-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.inspect-header {
  font-size: 13px;
  color: #888;
}

.inspect-section {
  margin-bottom: 10px;
}

.inspect-section-title {
  font-size: 12px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.inspect-schema {
  font-size: 12px;
  color: #bbb;
  background: #2d2d2d;
  border: 1px solid #404040;
  border-radius: 4px;
  padding: 8px 10px;
  line-height: 1.6;
}

.inspect-schema code {
  color: #569cd6;
  font-family: monospace;
}

.inspect-schema em {
  color: #888;
  font-style: normal;
  font-size: 11px;
}

.layout-card {
  background: #2d2d2d;
  border: 1px solid #404040;
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 6px;
}

.layout-card-name {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 4px;
}

.layout-card-type {
  font-size: 11px;
  color: #888;
  font-family: monospace;
  margin-left: 6px;
  font-weight: 400;
}

.layout-card-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.layout-field {
  font-size: 12px;
  font-family: monospace;
  color: #569cd6;
  background: #1e1e2e;
  padding: 2px 6px;
  border-radius: 3px;
}

.layout-no-fields {
  font-size: 12px;
  color: #666;
  font-style: italic;
}

/* === Code snippet modal === */
.code-modal-content {
  width: 700px;
}

.code-modal-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  align-items: end;
}

.code-modal-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #999;
}

.code-modal-controls select,
.code-modal-controls input[type="text"],
.code-modal-controls input[type="number"] {
  background: #1e1e1e;
  color: #d4d4d4;
  border: 1px solid #505050;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
}

#code-input {
  width: 100%;
  background: #1e1e1e;
  color: #d4d4d4;
  border: 1px solid #505050;
  border-radius: 4px;
  padding: 10px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  tab-size: 4;
}

#code-input:focus {
  outline: none;
  border-color: #0e639c;
}

.code-modal-preview {
  display: none;
  background: #1e1e1e;
  border: 1px solid #505050;
  border-radius: 4px;
  padding: 10px;
  margin-top: 8px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre;
}

.code-modal-preview.visible {
  display: block;
}

.code-mode-toggle {
  display: flex;
  border: 1px solid #505050;
  border-radius: 4px;
  overflow: hidden;
}

.code-mode-btn {
  border: none;
  border-radius: 0;
  padding: 4px 12px;
  font-size: 13px;
  background: #1e1e1e;
  color: #888;
  cursor: pointer;
}

.code-mode-btn + .code-mode-btn {
  border-left: 1px solid #505050;
}

.code-mode-btn.active {
  background: #0e639c;
  color: #fff;
}

.code-mode-hint {
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
}

.code-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
