:root {
  --bg: #0c1016;
  --bg-elev: #141a22;
  --bg-soft: #1a2230;
  --line: #2a3545;
  --line-soft: #232d3c;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #3d9cf0;
  --accent-dim: #1e4f7a;
  --ok: #3ecf8e;
  --warn: #e6b84d;
  --err: #f07178;
  --method-get: #3ecf8e;
  --method-post: #3d9cf0;
  --method-patch: #e6b84d;
  --method-delete: #f07178;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

body {
  background:
    radial-gradient(1100px 520px at 8% -12%, #16324f 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #152232 0%, transparent 48%),
    var(--bg);
}

.top {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 1.25rem;
  align-items: end;
  padding: 0.95rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 90%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: flex-start;
  justify-content: flex-end;
  min-height: 4rem;
}

.brand-logo {
  display: block;
  height: 42px;
  width: auto;
  max-width: 210px;
  object-fit: contain;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.brand-limits {
  color: var(--muted);
  font-size: 0.72rem;
  opacity: 0.9;
}

.connect {
  display: grid;
  grid-template-columns: 1.35fr 1.35fr auto;
  gap: 0.55rem 0.85rem;
  align-items: end;
}

.connect label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}

input, textarea, button {
  font: inherit;
}

input[type="url"],
input[type="password"],
input[type="text"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
  min-height: 4rem;
}

.editor-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
  min-height: 4rem;
}

.editor-wrap--sm { min-height: 7.5rem; }
.editor-wrap--lg { min-height: 18rem; }

.editor-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.editor-hl,
.editor-input {
  margin: 0;
  padding: 0.7rem 0.75rem;
  border: none;
  border-radius: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  box-sizing: border-box;
}

.editor-hl {
  position: absolute;
  inset: 0;
  color: #c5d0dc;
  pointer-events: none;
  background: transparent;
}

.editor-input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: inherit;
  color: transparent;
  caret-color: #e8eef6;
  background: transparent;
  resize: vertical;
  outline: none;
  box-shadow: none;
}

.editor-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.editor-input::selection {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  color: transparent;
}

.editor-hl .j-key,
.res-body .j-key { color: #7ec8ff; }
.editor-hl .j-str,
.res-body .j-str { color: #9fd89f; }
.editor-hl .j-num,
.res-body .j-num { color: #e6b84d; }
.editor-hl .j-bool,
.res-body .j-bool { color: #d2a8ff; }
.editor-hl .j-null,
.res-body .j-null { color: #d2a8ff; }

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

button {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 6px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.08s ease;
}

button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--bg-soft) 80%, var(--accent-dim));
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

button.primary, #btn-connect {
  background: var(--accent);
  border-color: var(--accent);
  color: #061018;
  font-weight: 650;
}

button.ghost {
  background: transparent;
}

button.tiny, .icon-btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
}

button.happy {
  width: 100%;
  background: linear-gradient(180deg, #2a6a4a, #1d4a35);
  border-color: #3a7a58;
  font-weight: 600;
}

.connect-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.connect-status.ok { color: var(--ok); }
.connect-status.err { color: var(--err); }

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: calc(100vh - 108px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 108px);
  position: sticky;
  top: 108px;
}

.sidebar-search {
  padding: 0.7rem 0.65rem 0.35rem;
}

#ops-nav {
  overflow: auto;
  padding: 0.35rem 0.5rem 1rem;
  flex: 1;
}

.op-group {
  margin-bottom: 0.85rem;
}

.op-group.hidden {
  display: none;
}

.op-group h3 {
  margin: 0 0 0.35rem 0.4rem;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 650;
}

.op-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.42rem 0.55rem;
  margin-bottom: 0.12rem;
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.25;
}

.op-btn.hidden {
  display: none;
}

.op-btn:hover {
  background: var(--bg-soft);
  border-color: var(--line-soft);
}

.op-btn.active {
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-soft));
  border-color: var(--accent-dim);
}

.op-btn .m {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  margin-right: 0.35rem;
}

.op-btn .m.GET { color: var(--method-get); }
.op-btn .m.POST { color: var(--method-post); }
.op-btn .m.PATCH { color: var(--method-patch); }
.op-btn .m.DELETE { color: var(--method-delete); }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--line);
}

.workspace {
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.request-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.request-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.method {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  min-width: 4.5rem;
  text-align: center;
}

.method.GET { color: var(--method-get); }
.method.POST { color: var(--method-post); }
.method.PATCH { color: var(--method-patch); }

#req-path {
  font-family: var(--mono);
  font-size: 0.84rem;
}

.session-panel,
.pane {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  min-width: 0;
  box-shadow: var(--shadow);
}

.session-head,
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 1.7rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.22rem 0.35rem 0.22rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.72rem;
}

.chip.empty {
  opacity: 0.55;
}

.chip label {
  color: var(--muted);
}

.chip input {
  width: 12rem;
  border: none;
  background: transparent;
  padding: 0.15rem 0;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

.chip input:focus {
  box-shadow: none;
  outline: none;
}

.chip .chip-btn {
  padding: 0.1rem 0.4rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  border-radius: 999px;
}

.chip .chip-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.editors {
  display: grid;
  grid-template-columns: minmax(200px, 0.55fr) 1.45fr;
  gap: 0.75rem;
}

.response {
  min-height: 240px;
}

.res-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  min-width: 0;
}

.res-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.res-badge.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.res-badge.err {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 45%, var(--line));
  background: color-mix(in srgb, var(--err) 12%, transparent);
}

.res-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 46vw;
}

.res-meta.ok { color: var(--ok); }
.res-meta.err { color: var(--err); }

.res-body {
  margin: 0;
  padding: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  max-height: 440px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c5d0dc;
}

.res-headers {
  margin-top: 0.55rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
}

.happy-log {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  box-shadow: var(--shadow);
}

.happy-log pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  background: #102033;
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease;
}

.toast.err {
  border-color: color-mix(in srgb, var(--err) 50%, var(--line));
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
  .top {
    grid-template-columns: 1fr;
  }
  .connect {
    grid-template-columns: 1fr;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  #ops-nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.35rem;
  }
  .editors {
    grid-template-columns: 1fr;
  }
  .request-bar {
    grid-template-columns: auto 1fr;
  }
  .request-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
  .res-meta {
    max-width: 100%;
    white-space: normal;
  }
}
