:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --ink: #1a1a2e;
  --ink-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-subtle: #eef2ff;
  --warn: #dc2626;
  --warn-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --border: #e5e7eb;
  --border-focus: #6366f1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --text-muted: #888;
  --input-bg: #ffffff;
  --defaults-bg: #f9fafb;
  --drop-overlay: rgba(238, 242, 255, 0.92);
  --hero-from: #1e1b4b;
  --hero-mid: #312e81;
  --hero-to: #3730a3;
  --hl-key: #005cc5;
  --hl-string: #22863a;
  --hl-number: #b33000;
  --hl-null: #6a737d;
  --hl-comment: #6a737d;
  --hl-punctuation: #24292e;
  --hl-anchor: #6f42c1;
  --diag-error-bg: rgba(220, 38, 38, 0.08);
  --diag-error-border: #dc2626;
  --diag-error-ink: #b91c1c;
  --diag-warn-bg: rgba(217, 119, 6, 0.08);
  --diag-warn-border: #d97706;
  --diag-warn-ink: #b45309;
  --diag-info-bg: rgba(59, 130, 246, 0.08);
  --diag-info-border: #3b82f6;
  --diag-info-ink: #6a737d;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --ink: #e6edf3;
  --ink-muted: #8b949e;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-subtle: rgba(99, 102, 241, 0.15);
  --warn: #f87171;
  --warn-bg: rgba(248, 113, 113, 0.1);
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.1);
  --border: #30363d;
  --border-focus: #818cf8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --text-muted: #8b949e;
  --input-bg: #0d1117;
  --defaults-bg: #1c2129;
  --drop-overlay: rgba(22, 27, 34, 0.92);
  --hero-from: #0d1117;
  --hero-mid: #161b22;
  --hero-to: #1c2129;
  --hl-key: #79c0ff;
  --hl-string: #a5d6ff;
  --hl-number: #ffa657;
  --hl-null: #8b949e;
  --hl-comment: #8b949e;
  --hl-punctuation: #e6edf3;
  --hl-anchor: #d2a8ff;
  --diag-error-bg: rgba(248, 113, 113, 0.1);
  --diag-error-border: #f87171;
  --diag-error-ink: #fca5a5;
  --diag-warn-bg: rgba(251, 191, 36, 0.1);
  --diag-warn-border: #fbbf24;
  --diag-warn-ink: #fcd34d;
  --diag-info-bg: rgba(96, 165, 250, 0.1);
  --diag-info-border: #60a5fa;
  --diag-info-ink: #93c5fd;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  display: grid;
  gap: 1.25rem;
}

/* --- hero / header --- */
.hero {
  margin: 0 -1.5rem;
  padding: 1.5rem 1.5rem 1.25rem;
  background: linear-gradient(135deg, var(--hero-from) 0%, var(--hero-mid) 50%, var(--hero-to) 100%);
  color: #fff;
  border-radius: 0;
  border: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.hero-text {
  flex: 1;
}

.hero-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.hero-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  color: #fff;
  transition: background 0.15s;
  text-decoration: none;
}

.hero-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0.35rem 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
  line-height: 1.5;
}

.hero code {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85em;
}

/* --- panels / cards --- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}

.panel:hover {
  box-shadow: var(--shadow-md);
}

details.collapsible {
  cursor: default;
}

details.collapsible > .panel-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

details.collapsible > .panel-summary::-webkit-details-marker {
  display: none;
}

details.collapsible > .panel-summary h2,
details.collapsible > .panel-summary > span {
  display: inline;
}

details.collapsible > .panel-summary h2::before,
details.collapsible > .panel-summary > span::before {
  content: "▶ ";
  font-size: 0.75em;
  margin-right: 0.35rem;
}

details.collapsible[open] > .panel-summary h2::before,
details.collapsible[open] > .panel-summary > span::before {
  content: "▼ ";
}

details.collapsible.nested {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

details.collapsible.nested > .panel-summary > span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.panel h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-actions {
  display: flex;
  gap: 0.4rem;
}

.two-col {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* --- text inputs / editors --- */
.editor,
.text {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--surface);
  color: var(--ink);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.editor:focus,
.text:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.editor {
  min-height: 260px;
  resize: vertical;
}

.editor.small {
  min-height: 150px;
}

/* --- drop zone --- */
.drop-zone {
  position: relative;
  border-radius: var(--radius-sm);
  transition: box-shadow 0.15s;
}

.drop-zone.dragging {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.drop-zone.dragging::after {
  content: "Drop files here";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--drop-overlay);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* --- buttons --- */
.actions {
  display: flex;
  justify-content: flex-start;
}

.convert {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.5rem;
  color: #fff;
  background: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
}

.convert:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}

.convert:active {
  transform: translateY(1px);
}

.btn-secondary {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-link {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.btn-link:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

/* --- hints / status --- */
.hint,
.status {
  margin: 0.5rem 0 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.defaults-toggle {
  margin: 0.35rem 0 0.5rem;
}

.defaults-preview {
  margin: 0 0 0.6rem;
  padding: 0.6rem 0.75rem;
  background: var(--defaults-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
}

/* --- diagnostics --- */
.diagnostics-panel .panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.diagnostics-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  height: 1.6em;
  padding: 0 0.3em;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.diagnostics {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.diag-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.5;
  border-left: 3px solid transparent;
}

.diag-item.diag-error {
  background: var(--diag-error-bg);
  border-left-color: var(--diag-error-border);
  color: var(--diag-error-ink);
}

.diag-item.diag-warn {
  background: var(--diag-warn-bg);
  border-left-color: var(--diag-warn-border);
  color: var(--diag-warn-ink);
}

.diag-item.diag-info {
  background: var(--diag-info-bg);
  border-left-color: var(--diag-info-border);
  color: var(--diag-info-ink);
}

.diag-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.diag-text {
  word-break: break-word;
}

/* --- traces --- */
.traces-panel .traces-content {
  max-height: 280px;
  overflow-y: auto;
}

.traces-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.25rem;
}

.traces-list li {
  color: var(--success);
  font-size: 0.85rem;
}

/* --- output panel --- */
.output-panel .editor {
  background: var(--defaults-bg);
}

/* --- git repo panel --- */
.git-repo-form {
  display: grid;
  gap: 0.5rem;
}

.git-repo-row {
  display: flex;
  gap: 0.5rem;
}

.git-repo-details {
  flex-wrap: wrap;
}

.git-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  color: var(--ink);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  flex: 1;
  min-width: 140px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.git-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.git-input.git-url {
  flex: 1 1 100%;
}

/* --- include files panel --- */
.include-panel .panel-header {
  cursor: pointer;
  user-select: none;
}

.include-panel .badge {
  display: inline-block;
  vertical-align: middle;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.5rem;
}

.include-body {
  padding: 0.5rem 0;
}

.include-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.include-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.include-list li:last-child {
  border-bottom: none;
}

.include-path {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--warn);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.4rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.btn-remove:hover {
  opacity: 1;
}

/* --- responsive --- */
@media (max-width: 700px) {
  .page {
    padding: 0 0.75rem 1.5rem;
  }

  .hero {
    margin: 0 -0.75rem;
    padding: 1.25rem 0.75rem 1rem;
  }

  .panel {
    padding: 1rem;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* --- rule editor --- */
.rule-editor {
  display: grid;
  gap: 1rem;
}

.rule-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 0;
}

.rule-section legend {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  padding: 0 0.4rem;
}

.rule-fields {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.rule-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.rule-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.rule-input {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.rule-checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  margin-top: 0.3rem;
}

.rule-checkbox input[type="checkbox"] {
  accent-color: var(--accent);
}

.env-rules-list {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.env-rule-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.env-rule-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  background: var(--accent-subtle);
  border-bottom: 1px solid var(--border);
}

.env-rule-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

.env-rule-body {
  display: grid;
  gap: 0.5rem;
  padding: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.ide-override-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.ide-override-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

/* ── Service Refs Panel ──────────── */
.service-refs-panel .hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.ref-overrides-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ref-override-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.ref-target-name {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  min-width: 10ch;
}

.ref-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 6ch;
}

.ref-select {
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 0.85rem;
}

.ref-custom-input {
  flex: 1;
  min-width: 16ch;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 0.85rem;
}

/* ── YAML syntax highlighting ───── */
.yaml-highlighted {
  overflow-x: auto;
  white-space: pre;
}

.yaml-highlighted code {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.85rem;
  line-height: 1.55;
}

/* Editor overlay: highlighted pre behind transparent textarea */
.editor-highlight-wrap {
  position: relative;
  min-height: 16rem;
}

.editor-highlight-wrap .editor-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  pointer-events: none;
  overflow: auto;
  background: transparent;
}

.editor-highlight-wrap .editor-overlay {
  position: relative;
  color: transparent;
  caret-color: var(--ink);
  background: transparent;
  resize: vertical;
}

.editor-highlight-wrap .editor-overlay::placeholder {
  color: var(--text-muted);
}

.hl-key {
  color: var(--hl-key);
}

.hl-string {
  color: var(--hl-string);
}

.hl-number {
  color: var(--hl-number);
}

.hl-boolean {
  color: var(--hl-number);
}

.hl-null {
  color: var(--hl-null);
  font-style: italic;
}

.hl-comment {
  color: var(--hl-comment);
  font-style: italic;
}

.hl-punctuation {
  color: var(--hl-punctuation);
}

.hl-separator {
  color: var(--hl-comment);
}

.hl-anchor {
  color: var(--hl-anchor);
}

/* ── Footer ──────────────────────── */
.site-footer {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  margin-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
}

.site-footer p {
  margin: 0;
}

.site-footer .commit-ref {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  opacity: 0.6;
  margin-top: 0.25rem;
}

.site-footer .commit-ref a {
  color: inherit;
  text-decoration: none;
}

.site-footer .commit-ref a:hover {
  text-decoration: underline;
}