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

:root {
  --bg: #ededeb;
  --surface: #ffffff;
  --surface2: #f5f5f3;
  --border: rgba(0,0,0,0.09);
  --border-mid: rgba(0,0,0,0.17);
  --text: #1a1a1a;
  --text2: #6b6b6b;
  --text3: #aaaaaa;
  --danger-bg: #FEF2F2;
  --danger-text: #B91C1C;
  --accent: #2563EB;
  --accent-light: #EFF6FF;
  --success: #16a34a;
  --error: #dc2626;
  --radius: 7px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --shadow: 0 1px 4px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --surface: #1c1c1c;
    --surface2: #242424;
    --border: rgba(255,255,255,0.08);
    --border-mid: rgba(255,255,255,0.15);
    --text: #e8e8e8;
    --text2: #888;
    --text3: #4a4a4a;
    --danger-bg: #2D1515;
    --danger-text: #FCA5A5;
    --accent: #3B82F6;
    --accent-light: #172347;
    --success: #4ade80;
    --error: #f87171;
    --shadow: 0 1px 4px rgba(0,0,0,.3);
  }
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  flex-shrink: 0;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #2563EB 0%, #7C3AED 100%);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 14px; flex-shrink: 0;
}
.header-inner h1 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.tag {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 20px;
  background: #EFF6FF; color: #1D4ED8; letter-spacing: .03em;
}
@media (prefers-color-scheme: dark) {
  .tag { background: #172347; color: #93C5FD; }
}
.powered { margin-left: auto; font-size: 11px; color: var(--text3); }

/* ── Layout: flex with drag handle ── */
main {
  flex: 1; display: flex;
  padding: 1rem 1.25rem;
  overflow: hidden; min-height: 0;
}
.layout {
  display: flex;
  gap: 0;
  width: 100%; max-width: 1400px;
  margin: 0 auto; min-height: 0;
}

/* ── Resize handle ── */
.resize-handle {
  width: 10px;
  flex-shrink: 0;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 10;
}
.resize-handle::after {
  content: '';
  width: 3px; height: 36px;
  background: var(--border-mid);
  border-radius: 2px;
  transition: background .15s, height .15s;
}
.resize-handle:hover::after,
.resize-handle.dragging::after {
  background: var(--accent);
  height: 56px;
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  overflow: hidden; min-height: 0;
  box-shadow: var(--shadow);
}
.panel-form {
  width: 420px;
  flex-shrink: 0;
  min-width: 280px;
}
.panel-output {
  flex: 1;
  min-width: 300px;
  overflow: hidden;
}

.panel-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.panel-head > i { font-size: 15px; color: var(--text2); }
.panel-head > span { font-size: 13px; font-weight: 500; flex: 1; }

/* ── Mode toggle ── */
.mode-toggle-wrap {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mode-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px; gap: 2px;
}
.mode-btn {
  flex: 1; padding: 6px 10px;
  font-size: 12px; font-weight: 500;
  font-family: var(--font);
  border: none; border-radius: 6px;
  background: none; cursor: pointer;
  color: var(--text2);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: all .15s;
}
.mode-btn i { font-size: 13px; }
.mode-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.mode-btn:hover:not(.active) { color: var(--text); }

/* ── Scrollable form ── */
.scroll { flex: 1; overflow-y: auto; padding: 12px 14px; }
.field { margin-bottom: 10px; }
.field label {
  font-size: 10px; font-weight: 600;
  color: var(--text3); display: block;
  margin-bottom: 3px; text-transform: uppercase; letter-spacing: .06em;
}

input, select, textarea {
  font-family: var(--font);
  font-size: 13px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius);
  padding: 7px 10px; outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; font-family: var(--mono); font-size: 12px; min-height: 60px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ── Section headers ── */
.section-label {
  font-size: 10px; font-weight: 600;
  color: var(--text3); text-transform: uppercase;
  letter-spacing: .08em; margin: 14px 0 8px;
}
.section-label:first-child { margin-top: 4px; }
.section-header-row {
  display: flex; align-items: center;
  justify-content: space-between; margin: 14px 0 8px;
}

.add-link {
  font-size: 12px; font-family: var(--font);
  color: var(--accent); background: var(--accent-light);
  border: none; border-radius: var(--radius);
  padding: 4px 10px; cursor: pointer; font-weight: 500;
  display: flex; align-items: center; gap: 4px;
}
.add-link:hover { opacity: 0.8; }

/* ── Endpoint card ── */
.endpoint-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--method-color, var(--border-mid));
  border-radius: var(--radius);
  padding: 10px; margin-bottom: 8px;
  background: var(--surface2);
}
.ep-header {
  display: flex; align-items: center;
  gap: 6px; margin-bottom: 8px;
}
.ep-path { flex: 1; font-size: 12px; font-family: var(--mono); }
.rm-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text3); font-size: 16px;
  padding: 2px 4px; border-radius: 4px; flex-shrink: 0;
}
.rm-btn:hover { color: var(--danger-text); background: var(--danger-bg); }

/* ── Method dropdown ── */
.method-select {
  font-size: 11px; font-weight: 700;
  padding: 6px 22px 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
  font-family: var(--font);
  letter-spacing: .04em;
  width: auto !important;          /* override global width:100% */
  min-width: 80px;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.7)'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
}
.method-select:focus { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,.25); }

/* ── Endpoint body ── */
.ep-body { display: flex; flex-direction: column; gap: 8px; }
.ep-body label {
  font-size: 10px; color: var(--text2);
  margin-bottom: 3px; display: block;
  font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.ep-body input, .ep-body textarea { width: 100%; font-size: 12px; }
.ep-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* ── Param section ── */
.ep-param-section { display: flex; flex-direction: column; gap: 4px; }
.ep-param-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 2px;
}
.param-add-btn {
  font-size: 11px; font-family: var(--font);
  color: var(--accent); background: none;
  border: none; cursor: pointer; padding: 0 2px;
  font-weight: 500;
}
.param-add-btn:hover { opacity: 0.7; }
.param-list { display: flex; flex-direction: column; gap: 4px; }
.param-row {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 6px;
  flex-wrap: wrap;
}
.param-name {
  flex: 1 1 80px; min-width: 60px;
  font-size: 11px; padding: 4px 6px;
  font-family: var(--mono);
}
.param-type {
  flex: 0 0 80px;
  font-size: 11px; padding: 4px 4px;
  cursor: pointer;
}
.param-req {
  display: flex; align-items: center; gap: 3px;
  font-size: 10px; color: var(--text2); white-space: nowrap;
  flex-shrink: 0; cursor: pointer;
}
.param-req input[type=checkbox] { width: auto; cursor: pointer; }
.param-req span { font-size: 10px; }
.param-desc {
  flex: 2 1 100px; min-width: 80px;
  font-size: 11px; padding: 4px 6px;
}
.param-enum {
  flex: 1 1 100px;
  font-size: 11px; padding: 4px 6px;
  font-family: var(--mono);
  border-color: #F59E0B;
}
.param-rm {
  background: none; border: none; cursor: pointer;
  color: var(--text3); font-size: 14px;
  padding: 1px 3px; border-radius: 3px; flex-shrink: 0;
  line-height: 1;
}
.param-rm:hover { color: var(--danger-text); background: var(--danger-bg); }

/* ── Success code inline ── */
.ep-code-row {
  display: flex; align-items: center; gap: 8px;
}
.ep-code-row label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text2); white-space: nowrap;
}
.ep-code-row input { width: 72px !important; flex-shrink: 0; }

/* ── Body fields ── */
.ep-bodies { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ep-bodies textarea { min-height: 100px; line-height: 1.5; }
.single-ep-card .ep-bodies textarea { min-height: 170px; }

.ep-hint {
  font-size: 10px; color: var(--text2);
  margin-top: 3px; display: flex; align-items: center; gap: 3px;
}
.ep-hint i { font-size: 11px; }

/* ── Additional details ── */
.details-textarea {
  min-height: 72px;
  font-family: var(--font) !important;
  font-size: 12px; line-height: 1.5;
}

/* ── Edit mode ── */
/* Monospace textarea for pasting existing YAML specs */
.edit-yaml-textarea {
  min-height: 240px;
  max-height: 400px;
  font-family: var(--mono) !important;
  font-size: 11px;
  line-height: 1.5;
  resize: vertical;
}

/* Apply Edit button uses a teal/cyan gradient to distinguish it
   from the blue/purple Generate button — different action, different colour */
.gen-btn.edit-mode {
  background: linear-gradient(135deg, #059669 0%, #0891b2 100%);
}

/* ── Generate button ── */
.gen-btn {
  margin: 10px 14px; padding: 10px;
  font-size: 13px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer; border-radius: var(--radius);
  background: linear-gradient(135deg, #2563EB 0%, #7C3AED 100%);
  border: none; color: #fff; flex-shrink: 0;
  display: flex; align-items: center;
  justify-content: center; gap: 6px;
  letter-spacing: .01em;
  transition: opacity .15s, transform .1s;
}
.gen-btn:hover:not(:disabled) { opacity: 0.88; }
.gen-btn:active:not(:disabled) { transform: scale(0.99); }
.gen-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Output panel ── */
.tab-switcher {
  display: flex; gap: 3px;
  margin-left: auto; flex-wrap: wrap; align-items: center;
}
.tab {
  font-size: 11px; padding: 3px 8px;
  border-radius: 5px; cursor: pointer;
  background: none; border: 1px solid var(--border-mid);
  color: var(--text2); font-family: var(--font);
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.icon-btn {
  background: none; border: 1px solid var(--border-mid);
  border-radius: var(--radius); cursor: pointer;
  padding: 4px 8px; color: var(--text2);
  font-size: 13px; margin-left: 3px; font-family: var(--font);
}
.icon-btn:hover { background: var(--surface2); }

/* ── Status bar ── */
.status-bar {
  padding: 6px 14px; font-size: 12px;
  color: var(--text2); border-bottom: 1px solid var(--border);
  min-height: 30px; background: var(--surface2);
  flex-shrink: 0; display: flex; align-items: center; gap: 6px;
  transition: color .2s;
}
.status-bar.status-loading { color: var(--accent); }
.status-bar.status-success { color: var(--success); }
.status-bar.status-error   { color: var(--error); }

/* ── YAML output ── */
.output-wrap {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-height: 0;
}
.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--text3);
}
.empty > i { font-size: 40px; }
.empty-title { font-size: 14px; font-weight: 500; color: var(--text2); }
.empty-sub { font-size: 12px; }

pre#yamlOut {
  display: none; flex: 1;
  overflow: auto; margin: 0;
}
pre#yamlOut > code {
  display: block !important;
  padding: 14px 14px 14px 0 !important;
  font-family: var(--mono) !important;
  font-size: 12px !important;
  line-height: 1.7 !important;
  background: var(--surface) !important;
  min-height: 100%;
  white-space: normal !important;  /* per-line spans own their whitespace */
  counter-reset: line;
}
@media (prefers-color-scheme: dark) {
  pre#yamlOut > code.hljs {
    background: var(--surface) !important;
    color: #abb2bf;
  }
}

/* ── Line numbers ── */
.code-line {
  display: block;
  white-space: pre;           /* preserves indentation within each line */
  counter-increment: line;
}
.code-line::before {
  content: counter(line);
  display: inline-block;
  min-width: 40px;
  padding: 0 10px 0 14px;
  margin-right: 12px;
  text-align: right;
  color: var(--text2);
  font-size: 11px;
  opacity: 0.55;
  border-right: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
}

/* ── Refine bar ── */
.refine-bar {
  border-top: 1px solid var(--border);
  padding: 8px 10px; display: flex; gap: 6px;
  background: var(--surface2); flex-shrink: 0;
}
.refine-bar input { flex: 1; font-size: 12px; }
.refine-bar button {
  font-size: 12px; padding: 6px 12px;
  cursor: pointer; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-mid);
  color: var(--text); font-family: var(--font);
  display: flex; align-items: center; gap: 4px;
}
.refine-bar button:hover { background: var(--bg); }
#resetBtn { color: var(--text3); margin-left: 8px; border-left: 1px solid var(--border); padding-left: 10px; }
#resetBtn:hover { color: var(--danger-text); background: var(--danger-bg); }

@media (max-width: 860px) {
  main { padding: .75rem; }
  .layout { flex-direction: column; }
  .resize-handle { display: none; }
  .panel-form { width: 100% !important; min-width: 0; }
}
