/* ─── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg: #f7f8fa;
  --bg-surface: #ffffff;
  --bg-surface2: #f0f1f5;
  --border: #d0d3da;
  --text: #1a1c23;
  --text-muted: #6b7280;
  --text-code: #1a1c23;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --tab-active-bg: #2563eb;
  --tab-active-text: #fff;
  --error-bg: #fef2f2;
  --error-text: #dc2626;
  --error-border: #fca5a5;

  /* Syntax highlight */
  --hl-keyword: #7c3aed;
  --hl-str: #059669;
  --hl-comment: #9ca3af;
  --hl-number: #d97706;

  --radius: 8px;
  --font-code: "JetBrains Mono", "Fira Code", "Cascadia Code", "Menlo", "Consolas", monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-surface2: #22273a;
  --border: #2e3348;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --text-code: #cdd6f4;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --tab-active-bg: #2563eb;
  --tab-active-text: #fff;
  --error-bg: #2d0a0a;
  --error-text: #fca5a5;
  --error-border: #7f1d1d;

  --hl-keyword: #c084fc;
  --hl-str: #34d399;
  --hl-comment: #4b5563;
  --hl-number: #fbbf24;

  --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.header-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.header-title p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-surface2);
}

/* ─── Main layout ────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ─── Input section ──────────────────────────────────────────────────────── */
.input-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.input-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.input-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.btn {
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.15s, color 0.15s;
  background: var(--bg-surface);
  color: var(--text);
}
.btn:hover { background: var(--bg-surface2); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
#curl-input {
  width: 100%;
  min-height: 120px;
  max-height: 280px;
  resize: vertical;
  font-family: var(--font-code);
  font-size: 0.82rem;
  line-height: 1.55;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  tab-size: 2;
}
#curl-input:focus { border-color: var(--accent); }
#curl-input::placeholder { color: var(--text-muted); opacity: 0.7; }

/* ─── Error ───────────────────────────────────────────────────────────────── */
#error-msg {
  font-size: 0.82rem;
  color: var(--error-text);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  display: none;
}
#error-msg:not(:empty) { display: block; }

/* ─── Output section ─────────────────────────────────────────────────────── */
.output-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Tab bar ─────────────────────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0.5rem 0.75rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface2);
}
.tab-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 0.8rem;
  font-family: var(--font-ui);
  cursor: pointer;
  background: none;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.tab-btn:hover {
  background: var(--bg-surface);
  color: var(--text);
}
.tab-btn.active {
  background: var(--bg-surface);
  color: var(--accent);
  border-color: var(--border);
  font-weight: 600;
  position: relative;
  bottom: -1px;
  border-bottom-color: var(--bg-surface);
}

/* ─── Output header ──────────────────────────────────────────────────────── */
.output-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}
#copy-btn {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}
#copy-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ─── Code block ─────────────────────────────────────────────────────────── */
#output-area {
  overflow: auto;
  padding: 0;
}
.code-block {
  margin: 0;
  padding: 1rem 1.25rem;
  font-family: var(--font-code);
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--text-code);
  background: transparent;
  white-space: pre;
  min-height: 200px;
}
.output-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 1rem;
  text-align: center;
}
.error-msg {
  padding: 1rem 1.25rem;
  color: var(--error-text);
  font-size: 0.85rem;
}

/* ─── Syntax highlight ───────────────────────────────────────────────────── */
.hl-keyword { color: var(--hl-keyword); font-weight: 600; }
.hl-str     { color: var(--hl-str); }
.hl-comment { color: var(--hl-comment); font-style: italic; }
.hl-number  { color: var(--hl-number); }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}
.app-footer a { color: var(--text-muted); }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .app-main { padding: 1rem 0.75rem; }
  #tab-bar { gap: 2px; padding: 0.4rem 0.5rem 0; }
  .tab-btn { padding: 0.3rem 0.55rem; font-size: 0.75rem; }
}
