:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1f2329;
  --muted: #8a9099;
  --accent: #6366f1;
  --accent-d: #4f46e5;
  --ok: #16a34a;
  --redirect: #2563eb;
  --client: #d97706;
  --server: #dc2626;
  --err: #dc2626;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Topbar */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.proxy-toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.lp-toggle { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.top-divider { width: 1px; height: 18px; background: var(--border); }
.lp-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lp-input {
  width: 180px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 12px; color: var(--text); background: #fff;
}
.lp-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hint { font-size: 12px; color: var(--muted); }

/* Layout */
.layout { display: flex; height: calc(100vh - 52px); }

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.side-title { font-weight: 700; font-size: 14px; }
.icon-plus {
  width: 26px; height: 26px; border: none; background: #f0f1f4; border-radius: 6px;
  cursor: pointer; font-size: 17px; color: var(--text); line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.icon-plus:hover { background: var(--accent); color: #fff; }
.btn-ghost {
  padding: 8px 16px; background: #f0f1f4; border: 1px solid var(--border);
  border-radius: 7px; cursor: pointer; color: var(--text); font-size: 13px;
}
.btn-ghost:hover { background: #e7e9ee; }
.side-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.side-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 8px; border-radius: 6px;
  cursor: pointer; margin-bottom: 2px;
}
.side-item:hover { background: #f0f1f4; }
.side-item .si-main { flex: 1; min-width: 0; }
.si-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-url { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.si-del {
  border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px;
  opacity: 0; padding: 2px 4px;
}
.side-item:hover .si-del { opacity: 1; }
.si-del:hover { color: var(--err); }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 13px; }

.m-badge {
  flex: none; font-size: 10px; font-weight: 700; color: #fff; border-radius: 4px;
  padding: 3px 5px; min-width: 38px; text-align: center;
}
.m-GET { background: #16a34a; }
.m-POST { background: #2563eb; }
.m-PUT { background: #d97706; }
.m-PATCH { background: #9333ea; }
.m-DELETE { background: #dc2626; }
.m-HEAD, .m-OPTIONS { background: #64748b; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 14px; gap: 14px; }

/* Request card */
.request-card, .response-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden;
}
.request-card { flex: none; }
.response-card { flex: 1; min-height: 0; }

.url-row { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.method-select {
  flex: none; width: 96px; padding: 9px; border: 1px solid var(--border); border-radius: 6px;
  background: #f7f8fa; font-weight: 600; color: var(--accent);
}
.url-input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.url-input:focus, .method-select:focus, .body-type:focus, textarea:focus, .kv-key:focus, .kv-value:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send-btn {
  flex: none; padding: 9px 32px; background: var(--accent); color: #fff; border: none;
  border-radius: 6px; font-weight: 600; cursor: pointer;
}
.send-btn:hover { background: var(--accent-d); }
.send-btn:disabled { opacity: 0.6; cursor: default; }
.save-btn {
  flex: none; padding: 9px 14px; background: #fff; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; cursor: pointer; font-weight: 600;
}
.save-btn:hover { background: #eef0ff; }

.req-tabs, .resp-tabs { display: flex; gap: 4px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.req-tab, .resp-tab {
  padding: 6px 10px; background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--muted); font-size: 12px;
}
.req-tab.active, .resp-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.resp-tabs { margin-left: auto; }

.req-panels, .resp-panels { flex: 1; min-height: 0; }
.req-panel { display: none; padding: 12px; }
.req-panel.active { display: block; }
.panel-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.btn-small {
  padding: 3px 10px; border: 1px solid var(--border); background: #f7f8fa; border-radius: 5px;
  cursor: pointer; font-size: 12px; color: var(--text);
}
.btn-small:hover { background: #eceef2; }

/* KV table */
.kv-table { display: flex; flex-direction: column; gap: 6px; }
.kv-row { display: flex; gap: 6px; align-items: center; }
.kv-enabled { flex: none; width: 16px; height: 16px; }
.kv-key, .kv-value {
  flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px;
}
.kv-del {
  flex: none; width: 28px; height: 28px; border: 1px solid var(--border); background: #fff;
  border-radius: 5px; cursor: pointer; color: var(--muted);
}
.kv-del:hover { color: var(--err); border-color: var(--err); }

/* Body */
.body-toolbar { margin-bottom: 4px; }
.body-type { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: #f7f8fa; }
.body-editor { position: relative; border: 1px solid var(--border); border-radius: 6px; }
.body-edit {
  margin: 0; width: 100%; min-height: 180px; max-height: 360px; padding: 10px 12px; border: none; border-radius: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  outline: none; overflow: auto; scrollbar-gutter: stable; background: #fff; color: var(--text);
}
.body-edit:empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.body-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Response */
.resp-header {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border);
}
.status-badge {
  font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 6px; background: #eef0f3; color: var(--muted);
}
.status-badge.ok { background: #dcfce7; color: var(--ok); }
.status-badge.redirect { background: #dbeafe; color: var(--redirect); }
.status-badge.client { background: #fef3c7; color: var(--client); }
.status-badge.server { background: #fee2e2; color: var(--server); }
.status-badge.err { background: #fee2e2; color: var(--err); }
.resp-meta { color: var(--muted); font-size: 13px; }

.resp-panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.resp-panel.active { display: flex; }
.resp-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.fmt-info { font-size: 12px; color: var(--muted); margin-right: auto; }
.resp-body {
  margin: 0; padding: 12px 14px; overflow: auto; flex: 1; min-height: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.j-key { color: #2563eb; }
.j-str { color: #16a34a; }
.j-num { color: #d97706; }
.j-bool { color: #9333ea; }
.j-null { color: #dc2626; }

.hdr-table { width: 100%; border-collapse: collapse; }
.hdr-table td { padding: 7px 14px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
.hdr-key { color: var(--accent); font-weight: 600; width: 240px; word-break: break-all; }
.hdr-val { word-break: break-all; font-family: "SFMono-Regular", Consolas, monospace; }

.resp-error {
  padding: 12px 14px; background: #fef2f2; color: var(--err); border-top: 1px solid #fecaca; font-size: 13px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.s-2 { color: var(--ok); }
.s-3 { color: var(--redirect); }
.s-4 { color: var(--client); }
.s-5 { color: var(--server); }

/* Project collections */
.coll { margin-bottom: 4px; }
.coll-head {
  display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 6px; cursor: pointer;
}
.coll-head:hover { background: #f0f1f4; }
.coll-caret { color: var(--muted); width: 14px; font-size: 11px; }
.coll-name { flex: 1; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coll-count {
  flex: none; font-size: 11px; color: var(--muted); background: #eef0f3; border-radius: 10px; padding: 1px 7px;
}
.coll-actions { display: flex; gap: 4px; opacity: 0; }
.coll-head:hover .coll-actions { opacity: 1; }
.link-btn {
  border: none; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 2px 4px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--err); }
.coll-reqs { padding: 0 0 4px 14px; }
.coll-req { padding-left: 8px; }
.empty.small { padding: 10px; font-size: 12px; }
.coll-add { padding: 6px 8px; }
.coll-add input { width: 100%; }

/* Body tools */
.body-msg { font-size: 12px; color: var(--muted); }
.body-msg.err { color: var(--err); }

/* Save modal */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  width: 380px; max-width: 90vw; background: var(--panel); border-radius: 12px; padding: 18px 20px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-x {
  width: 28px; height: 28px; border: none; background: none; cursor: pointer; font-size: 15px;
  color: var(--muted); border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
.modal-x:hover { background: #f0f1f4; color: var(--text); }
.field-label { display: block; font-size: 13px; color: var(--text); font-weight: 600; margin: 14px 0 6px; }
.field-label:first-of-type { margin-top: 0; }
.field-input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13px; background: #fbfbfc; color: var(--text);
}
.field-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.save-coll-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.save-coll-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  text-align: left; padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px;
  background: #fbfbfc; cursor: pointer; font-size: 13px; color: var(--text);
}
.save-coll-item:hover { background: #eef0ff; border-color: var(--accent); }
.save-coll-item.selected { background: #eef0ff; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.save-coll-count {
  flex: none; font-size: 11px; color: var(--muted); background: #eef0f3; border-radius: 10px; padding: 1px 8px;
}
.new-coll-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.new-coll-row .field-input { flex: 1; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.modal-msg { font-size: 12px; color: var(--err); margin-right: auto; }
.btn-primary {
  padding: 8px 18px; background: var(--accent); color: #fff; border: none; border-radius: 7px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-primary:hover { background: var(--accent-d); }
.btn-primary.sm { padding: 9px 12px; font-size: 12px; white-space: nowrap; }

/* Light UI polish */
.request-card, .response-card { box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05); }
.send-btn { background: linear-gradient(180deg, #6d70f5, #4f46e5); }
.send-btn:hover { background: linear-gradient(180deg, #5f62ec, #443bd6); }
