:root {
  --bg: #1a1b26;
  --bg-surface: #24283b;
  --bg-highlight: #292e42;
  --fg: #c0caf5;
  --fg-dim: #565f89;
  --fg-bright: #e0e6ff;
  --accent: #7aa2f7;
  --green: #9ece6a;
  --red: #f7768e;
  --orange: #e0af68;
  --yellow: #e0af68;
  --purple: #bb9af7;
  --teal: #73daca;
  --border: #3b4261;
  --radius: 6px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--bg);
  color: var(--fg);
}

body {
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg-bright);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  font-size: 12px;
  color: var(--fg-dim);
}

.status.ready {
  color: var(--green);
}

.status.error {
  color: var(--red);
}

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

.panel-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}

/* Editor */
.editor-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#editor {
  width: 100%;
  height: 100%;
}

.cm-editor {
  height: 100%;
  font-size: 14px;
}

.cm-editor .cm-scroller {
  font-family: var(--font-mono) !important;
}

.cm-editor .cm-content {
  padding: 12px 0;
}

.cm-editor .cm-gutters {
  background: var(--bg) !important;
  border-right: 1px solid var(--border) !important;
  color: var(--fg-dim) !important;
}

.cm-editor .cm-activeLineGutter {
  background: var(--bg-highlight) !important;
  color: var(--fg) !important;
}

.cm-editor .cm-activeLine {
  background: var(--bg-highlight) !important;
}

.cm-editor .cm-selectionBackground {
  background: rgba(122, 162, 247, 0.2) !important;
}

.cm-editor.cm-focused .cm-selectionBackground {
  background: rgba(122, 162, 247, 0.3) !important;
}

.cm-editor .cm-cursor {
  border-left-color: var(--accent) !important;
}

/* Syntax highlighting */
.cm-editor .tok-keyword { color: var(--purple); font-weight: 500; }
.cm-editor .tok-typeName { color: var(--teal); }
.cm-editor .tok-string { color: var(--orange); }
.cm-editor .tok-number { color: var(--orange); }
.cm-editor .tok-comment { color: var(--fg-dim); font-style: italic; }
.cm-editor .tok-docComment { color: var(--green); font-style: italic; }
.cm-editor .tok-operator { color: var(--red); }
.cm-editor .tok-propertyName { color: var(--fg); }
.cm-editor .tok-variableName { color: var(--fg-bright); }
.cm-editor .tok-labelName { color: var(--yellow); }

/* Editor toolbar */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.diagnostics {
  flex: 1;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diagnostics.ok {
  color: var(--green);
}

.diagnostics.err {
  color: var(--red);
}

/* Right panel sections */
.section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  margin-bottom: 8px;
}

.placeholder {
  color: var(--fg-dim);
  font-size: 12px;
  font-style: italic;
}

/* Module info */
.module-entity, .module-action, .module-invariant {
  margin-bottom: 8px;
}

.module-entity .entity-name,
.module-action .action-name,
.module-invariant .invariant-name {
  font-weight: 600;
  color: var(--teal);
  font-size: 13px;
}

.module-action .action-name {
  color: var(--purple);
}

.module-invariant .invariant-name {
  color: var(--yellow);
}

.field-list {
  padding-left: 16px;
  font-size: 12px;
  color: var(--fg-dim);
}

.field-list .field-name {
  color: var(--fg);
}

.field-list .field-type {
  color: var(--teal);
}

.counts {
  font-size: 11px;
  color: var(--fg-dim);
  padding-left: 16px;
}

/* Request builder */
.request-controls {
  margin-bottom: 8px;
}

.request-sub-examples {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.sub-example-btn {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg-highlight);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg-dim);
  cursor: pointer;
  font-family: var(--font-mono);
}

.sub-example-btn:hover {
  color: var(--fg);
  border-color: var(--accent);
}

.sub-example-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

#request-editor {
  min-height: 120px;
  max-height: 250px;
  overflow: auto;
}

#request-editor .cm-editor {
  min-height: 120px;
}

/* Response */
#response pre {
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.response-ok {
  border-left: 3px solid var(--green);
  padding-left: 12px;
}

.response-fail {
  border-left: 3px solid var(--red);
  padding-left: 12px;
}

.violation {
  color: var(--red);
  margin-top: 4px;
  font-size: 12px;
}

.violation .violation-kind {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
}

.new-value {
  color: var(--green);
}

.old-value {
  color: var(--fg-dim);
  text-decoration: line-through;
}

/* Buttons */
button {
  background: var(--bg-highlight);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--fg-bright);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#btn-execute {
  margin-top: 8px;
  background: rgba(122, 162, 247, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

#btn-execute:hover:not(:disabled) {
  background: rgba(122, 162, 247, 0.2);
}

select {
  background: var(--bg-highlight);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}

select:hover {
  border-color: var(--accent);
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  flex-shrink: 0;
}

.generate-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.generate-input-wrap {
  display: flex;
  flex: 1;
  gap: 8px;
}

.generate-input-wrap input {
  flex: 1;
  background: var(--bg-surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.generate-input-wrap input:focus {
  outline: none;
  border-color: var(--accent);
}

.generate-input-wrap input:disabled {
  opacity: 0.4;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  padding: 4px;
  color: var(--fg-dim);
}

.icon-btn:hover {
  color: var(--fg);
}

/* 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: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
}

.modal-content h2 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--fg-bright);
}

.settings-note {
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 12px;
}

.modal-content label {
  display: block;
  font-size: 12px;
  color: var(--fg-dim);
  margin-bottom: 12px;
}

.modal-content input {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
}

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

/* Responsive: stack on small screens */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 300px;
  }
}
