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

:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --text: #1f2328;
  --text-muted: #656d76;
  --success: #1a7f37;
  --error: #cf222e;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --header-h: 56px;
  --tabs-h: 44px;
  --radius: 6px;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.5px;
  color: var(--text);
}

.tagline {
  font-size: 13px;
  color: var(--text-muted);
}

.github-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.github-link:hover {
  color: var(--accent);
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
  height: var(--tabs-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 24px;
  gap: 2px;
  flex-shrink: 0;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 14px;
  font-size: 13px;
  font-family: var(--font-ui);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab.libre {
  margin-left: auto;
  color: var(--text-muted);
}

.tab.libre.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Workspace ───────────────────────────────────────────────────────────── */

.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  padding: 16px;
  gap: 12px;
  min-height: 0;
}

.editor-pane,
.output-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

.editor-pane {
  flex: 1;
}

#editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.output-pane {
  flex: 1;
}

.pane-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Info icon & tooltip ─────────────────────────────────────────────────── */

.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 11px;
  font-style: normal;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.info-icon:hover,
.info-icon:focus {
  color: var(--accent);
  border-color: var(--accent);
  outline: none;
}

.info-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  padding: 12px;
  min-width: 240px;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  pointer-events: none;
}

.info-icon:hover .info-tooltip,
.info-icon:focus .info-tooltip {
  display: block;
}

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

.tooltip-section:last-child {
  margin-bottom: 0;
}

.tooltip-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.tooltip-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
}

.tooltip-row code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  background: #f0f6ff;
  border-radius: 3px;
  padding: 0 4px;
  min-width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.tooltip-row span {
  color: var(--text-muted);
}

/* ── CodeMirror overrides ────────────────────────────────────────────────── */

.CodeMirror-wrap,
.CodeMirror {
  flex: 1;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface);
}

.CodeMirror-scroll {
  padding: 8px 0;
}

.CodeMirror-lines {
  padding: 0 6px;
}

.CodeMirror-gutters {
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.CodeMirror-linenumber {
  color: var(--text-muted);
  font-size: 12px;
}

.CodeMirror-cursor {
  border-left: 2px solid var(--accent);
}

.CodeMirror-selected {
  background: #dbeafe !important;
}

/* Flux syntax tokens */
.cm-flux-keyword  { color: #8250df; font-weight: 600; }
.cm-flux-builtin  { color: #0550ae; }
.cm-flux-string   { color: #0a3069; }
.cm-flux-number   { color: #953800; }
.cm-flux-bool     { color: #116329; font-weight: 600; }
.cm-flux-operator { color: #cf222e; }
.cm-flux-comment  { color: var(--text-muted); font-style: italic; }

/* ── Editor footer ───────────────────────────────────────────────────────── */

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
}

#run-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s;
}

#run-btn:hover {
  background: var(--accent-hover);
}

#run-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

#run-btn svg {
  flex-shrink: 0;
}

/* ── Output ──────────────────────────────────────────────────────────────── */

#output {
  flex: 1;
  overflow: auto;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

#output-status {
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

#output-status.ok    { color: var(--success); }
#output-status.error { color: var(--error); }

/* JSON syntax highlighting in output */
.j-key    { color: #0550ae; }
.j-str    { color: #0a3069; }
.j-num    { color: #953800; }
.j-bool   { color: #116329; font-weight: 600; }
.j-null   { color: var(--text-muted); font-style: italic; }

/* Error output */
.output-error {
  color: var(--error);
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */

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

/* ── APIs strip ──────────────────────────────────────────────────────────── */

.apis {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.apis-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.api-cards {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.api-cards::-webkit-scrollbar {
  display: none;
}

.api-card {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
  min-width: 180px;
}

.api-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #dbeafe;
}

.api-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.api-fields {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 6px;
}

.api-url {
  font-size: 11px;
  color: var(--accent);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-copy {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.api-card:hover .api-copy {
  opacity: 1;
}

.api-copy.copied {
  color: var(--success);
  border-color: var(--success);
  opacity: 1;
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}