:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c9cfd7;
  --text: #171a1f;
  --muted: #5f6b7a;
  --accent: #e2591b;
  --accent-hover: #c94c13;
  --accent-text: #ffffff;
  --focus: rgba(226, 89, 27, 0.35);
  --ok: #18804b;
  --redirect: #2f6fd6;
  --client-err: #b7791f;
  --server-err: #c53030;
  --code-bg: #f7f8fa;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --m-get: #18804b;
  --m-post: #b7791f;
  --m-put: #2f6fd6;
  --m-patch: #7c4dce;
  --m-delete: #c53030;
  --m-other: #5f6b7a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #161920;
    --surface-2: #1d212a;
    --border: #2a2f3a;
    --border-strong: #3a4150;
    --text: #e6e8ec;
    --muted: #949cab;
    --accent: #f26b2d;
    --accent-hover: #ff8048;
    --accent-text: #160b05;
    --focus: rgba(242, 107, 45, 0.4);
    --ok: #3ecf8e;
    --redirect: #6ea8ff;
    --client-err: #f0b44c;
    --server-err: #ff6b6b;
    --code-bg: #12151b;
    --shadow: none;
    --m-get: #3ecf8e;
    --m-post: #f0b44c;
    --m-put: #6ea8ff;
    --m-patch: #b48cff;
    --m-delete: #ff6b6b;
    --m-other: #949cab;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
}

code, kbd, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 4px;
}

kbd {
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  background: var(--surface);
}

.hidden { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand svg { width: 26px; height: 26px; }
.brand-bg { fill: var(--accent); }
.brand-arrows { fill: none; stroke: var(--accent-text); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

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

/* ---------- buttons & fields ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--server-err); }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  height: 36px;
  padding: 0 10px;
  min-width: 0;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; max-width: 520px; }
.field input { color: var(--text); font-size: 14px; }
.field.narrow { max-width: 180px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }

.field-error { color: var(--server-err); font-size: 12.5px; margin: 6px 0 0; }

/* ---------- layout ---------- */

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 280px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow: auto;
}

/* ---------- sidebar ---------- */

.side-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; }

.side-tab {
  flex: 1;
  border: 0;
  background: none;
  padding: 12px 0 10px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}

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

.side-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 8px 0; gap: 8px; }

.side-search { height: 32px !important; font-size: 13px; }

.side-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; min-height: 0; }

.side-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.side-item:hover, .side-item:focus-visible { background: var(--surface-2); }

.side-item .method { width: 52px; flex: none; }

.side-item-main { min-width: 0; flex: 1; }

.side-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.side-item-sub {
  color: var(--muted);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-item-delete {
  visibility: hidden;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1;
}

.side-item:hover .side-item-delete, .side-item:focus-within .side-item-delete { visibility: visible; }
.side-item-delete:hover { color: var(--server-err); background: var(--surface); }

.side-empty { color: var(--muted); font-size: 13px; padding: 8px; margin: 0; }

.side-actions { display: flex; gap: 4px; padding-bottom: 4px; }

.side-note { color: var(--muted); font-size: 11.5px; padding: 10px 16px 14px; margin: 0; border-top: 1px solid var(--border); }

.method { font: 600 11.5px var(--mono); letter-spacing: 0.02em; }
.method[data-method="GET"] { color: var(--m-get); }
.method[data-method="POST"] { color: var(--m-post); }
.method[data-method="PUT"] { color: var(--m-put); }
.method[data-method="PATCH"] { color: var(--m-patch); }
.method[data-method="DELETE"] { color: var(--m-delete); }
.method[data-method="HEAD"], .method[data-method="OPTIONS"] { color: var(--m-other); }

.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; background: var(--muted); }
.dot.s2 { background: var(--ok); }
.dot.s3 { background: var(--redirect); }
.dot.s4 { background: var(--client-err); }
.dot.s5, .dot.err { background: var(--server-err); }

/* ---------- request ---------- */

.request, .response {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}

.request-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.name-input {
  flex: 1;
  border-color: transparent !important;
  background: transparent !important;
  font-weight: 600;
  font-size: 15px;
  padding-left: 4px !important;
}

.name-input:hover { border-color: var(--border) !important; }
.name-input:focus { border-color: var(--accent) !important; }

.title-actions { display: flex; gap: 4px; }

.url-bar { display: flex; gap: 8px; }

.url-bar select {
  width: 112px;
  flex: none;
  font: 600 13px var(--mono);
  cursor: pointer;
}

.url-bar input { flex: 1; font-family: var(--mono); font-size: 13.5px; }

.url-bar .btn { min-width: 88px; }

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin: 14px 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab {
  border: 0;
  background: none;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}

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

.count { color: var(--accent); font-size: 12px; }

.tabs-end { margin-left: auto; display: flex; align-items: center; gap: 4px; padding-bottom: 4px; }

/* key/value editor */

.kv { display: flex; flex-direction: column; gap: 6px; }

.kv-row { display: grid; grid-template-columns: 22px 1fr 1.6fr 30px; gap: 6px; align-items: center; }

.kv-row input[type="text"] { height: 32px; font-family: var(--mono); font-size: 12.5px; width: 100%; }

.kv-row input[type="checkbox"] { margin: 0 auto; width: 15px; height: 15px; accent-color: var(--accent); }

.kv-row.disabled input[type="text"] { opacity: 0.5; }

.kv-remove {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  height: 30px;
  border-radius: 6px;
  font-size: 16px;
}

.kv-remove:hover { color: var(--server-err); background: var(--surface-2); }

.radio-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-bottom: 10px; }

.radio-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.radio-row input { accent-color: var(--accent); margin: 0; }

.radio-row .btn { margin-left: auto; }

.body-editor textarea {
  width: 100%;
  height: 200px;
  min-height: 90px;
  padding: 10px 12px;
  resize: vertical;
  font: 12.5px/1.55 var(--mono);
  background: var(--code-bg);
  tab-size: 2;
}

.auth-fields { display: flex; flex-direction: column; gap: 10px; }

.tab-pane[data-pane="options"] { display: flex; flex-direction: column; gap: 12px; }
.tab-pane[data-pane="options"].hidden { display: none; }

/* ---------- response ---------- */

.response { flex: 1; min-height: 240px; display: flex; flex-direction: column; }

.response-empty, .response-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.response-error h2 { margin: 4px 0 6px; font-size: 16px; color: var(--server-err); }
.response-error p { margin: 0 0 8px; }
.error-causes { margin: 0; padding-left: 20px; color: var(--muted); }
.error-causes li { margin: 4px 0; }

#response-result { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.response-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }

.status {
  font: 600 13px var(--mono);
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--surface-2);
}

.status.s2 { color: var(--ok); }
.status.s3 { color: var(--redirect); }
.status.s4 { color: var(--client-err); }
.status.s5 { color: var(--server-err); }

.meta-item { font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.meta-label { color: var(--muted); }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; margin-right: 4px; }
.seg { border: 0; background: none; padding: 3px 10px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.seg.active { background: var(--surface-2); color: var(--text); }

.code {
  margin: 0;
  padding: 12px 14px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
  max-height: 70vh;
  min-height: 80px;
  tab-size: 2;
}

.code .j-key { color: var(--m-patch); }
.code .j-str { color: var(--m-get); }
.code .j-num { color: var(--m-put); }
.code .j-lit { color: var(--m-post); }

.res-image { max-width: 100%; max-height: 60vh; border-radius: 8px; border: 1px solid var(--border); background: var(--code-bg); }

.headers-table { width: 100%; border-collapse: collapse; font: 12.5px/1.5 var(--mono); }
.headers-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.headers-table td:first-child { color: var(--muted); width: 32%; }

/* ---------- dialog & toast ---------- */

.dialog {
  max-width: 560px;
  width: calc(100% - 32px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 20px 24px;
}

.dialog::backdrop { background: rgba(10, 12, 16, 0.5); }
.dialog h2 { margin: 0 0 10px; font-size: 18px; }
.dialog li { margin: 6px 0; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  max-width: calc(100% - 32px);
}

/* ---------- narrow screens ---------- */

.only-narrow { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  .only-narrow { display: inline-grid; }
  .tagline { display: none; }
  .topbar { padding: 0 8px; }
  .brand { margin-right: auto; }

  .sidebar {
    position: fixed;
    top: 52px;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(320px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }

  .sidebar.open { transform: none; }

  .scrim { display: block; position: fixed; inset: 52px 0 0 0; background: rgba(10, 12, 16, 0.4); z-index: 20; }

  .workspace { padding: 12px 16px; gap: 12px; }

  .request, .response { padding: 12px; }

  .request-title { flex-wrap: wrap; }
  .title-actions { width: 100%; justify-content: flex-end; }

  .url-bar { flex-wrap: wrap; }
  .url-bar select { width: 100px; }
  .url-bar input { flex-basis: calc(100% - 108px); }
  .url-bar .btn { flex: 1; }

  .kv-row { grid-template-columns: 20px 1fr 1fr 28px; gap: 4px; }

  .side-item-delete { visibility: visible; }

  .tabs-end .btn.small { padding: 0 6px; }
}
