:root {
  --app-bg: #f2f5f4;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --surface-hover: #eef6f3;
  --line: #dce5e2;
  --line-strong: #cbd8d4;
  --text: #20312f;
  --muted: #6d7e7a;
  --accent: #0f7468;
  --accent-strong: #0b5d54;
  --accent-soft: #dff1ec;
  --danger-soft: #fff1ef;
  --shadow-menu: 0 18px 45px rgba(25, 48, 44, .16);
  color: var(--text);
  background: var(--app-bg);
}

body {
  background: var(--app-bg);
}

button,
input,
select,
textarea {
  transition: border-color .16s ease, background-color .16s ease, box-shadow .16s ease, color .16s ease;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(48, 158, 139, .22);
  outline-offset: 2px;
}

.primary {
  box-shadow: 0 4px 12px rgba(15, 116, 104, .14);
}

.brand-mark {
  border-radius: 10px;
  background: linear-gradient(145deg, #128579, #0b6259);
  box-shadow: 0 7px 18px rgba(15, 116, 104, .2);
}

.topbar {
  position: relative;
  z-index: 8;
  min-height: 76px;
  height: 76px;
  padding: 10px 18px;
  gap: 24px;
  border-bottom-color: var(--line);
  box-shadow: 0 1px 0 rgba(26, 49, 44, .02);
}

.brand {
  min-width: max-content;
  color: #173b36;
  letter-spacing: -.01em;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  overflow: visible;
}

.context-switcher,
.toolbar-menu {
  position: relative;
  flex: none;
}

.context-switcher > summary,
.toolbar-menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.context-switcher > summary::-webkit-details-marker,
.toolbar-menu > summary::-webkit-details-marker {
  display: none;
}

.context-switcher > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 205px;
  min-height: 48px;
  padding: 7px 10px 7px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

#environment-switcher > summary {
  width: 190px;
}

.context-switcher > summary:hover,
.context-switcher[open] > summary {
  border-color: #a9c9c1;
  background: var(--surface-hover);
}

.context-icon {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: -.04em;
}

.project-context-icon::before {
  content: "P";
}

.environment-context-icon::before {
  content: "{}";
}

.context-copy {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}

.context-copy small {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.context-copy strong {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-chevron {
  margin-left: auto;
  color: #82918e;
  font-size: 20px;
  transform: rotate(90deg);
  transition: transform .16s ease;
}

.context-switcher[open] .context-chevron {
  transform: rotate(-90deg);
}

.context-menu,
.toolbar-menu-items {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 25;
  width: 280px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-menu);
}

.context-menu-title {
  margin: 4px 6px 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.context-options {
  display: grid;
  gap: 3px;
  max-height: min(42vh, 320px);
  overflow: auto;
}

.context-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.context-option:hover {
  background: var(--surface-hover);
}

.context-option.selected {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.context-check {
  width: 18px;
  color: var(--accent);
  text-align: center;
}

.context-menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e9efed;
}

.context-menu-actions button {
  padding: 8px;
  border: 0;
  background: var(--surface-soft);
  font-size: 12px;
}

.toolbar-menu > summary {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: #40514e;
  white-space: nowrap;
}

.toolbar-menu[open] > summary,
.toolbar-menu > summary:hover {
  border-color: #b8cbc6;
  background: var(--surface-hover);
}

.toolbar-menu-items {
  display: grid;
  gap: 3px;
  width: 200px;
}

.toolbar-menu-items button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  text-align: left;
}

.layout {
  --sidebar-width: 300px;
  --results-width: 410px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 6px minmax(360px, 1fr) 6px var(--results-width);
  min-width: 0;
  height: calc(100vh - 76px);
}

.layout > .sidebar { grid-column: 1; grid-row: 1; }
.layout > #resize-left { grid-column: 2; grid-row: 1; }
.layout > .main { grid-column: 3; grid-row: 1; min-height: 0; }
.layout > #resize-right { grid-column: 4; grid-row: 1; }
.layout > .results { grid-column: 5; grid-row: 1; }

.sidebar,
.results {
  background: var(--surface);
}

.sidebar {
  border-right-color: var(--line);
}

.results {
  padding: 0 16px 18px;
  border-left-color: var(--line);
}

.main {
  padding: 26px clamp(18px, 2.3vw, 34px);
  background: linear-gradient(180deg, #f7f9f8 0, var(--app-bg) 180px);
}

.side-head,
.results-head {
  min-height: 76px;
  padding: 15px 14px;
  border-bottom-color: #e8eeec;
}

.results-head {
  margin: 0 -16px 12px;
  padding-right: 16px;
  padding-left: 16px;
}

.section-kicker {
  display: block;
  margin-bottom: 3px;
  color: #83918e;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.side-head h2,
.results-head h2 {
  color: var(--text);
  font-size: 17px;
  letter-spacing: -.015em;
}

.side-actions {
  display: flex;
  gap: 5px;
}

.side-head button {
  padding: 6px 8px;
}

.tree-search {
  width: calc(100% - 24px);
  margin: 12px;
  padding-left: 34px;
  border-color: #e0e8e5;
  border-radius: 10px;
  background: #f7f9f8
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23778985' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E")
    no-repeat 11px center;
}

.root-drop {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  margin: 0 8px 7px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #53635f;
}

.root-drop:hover {
  background: var(--surface-soft);
}

.root-icon {
  position: relative;
  width: 17px;
  height: 14px;
  border: 2px solid #8ca19b;
  border-radius: 3px;
}

.root-icon::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 7px;
  height: 4px;
  border-bottom: 2px solid #8ca19b;
}

.root-drop-hint {
  display: none;
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
}

body.resizing {
  user-select: none;
  cursor: col-resize;
}

.resize-handle {
  position: relative;
  background: #e5ebe9;
  cursor: col-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  inset: 0 2px;
  background: transparent;
  transition: background .16s ease;
}

.resize-handle:hover::after,
.resize-handle.dragging::after {
  background: #74b7a8;
}

.resize-handle:focus-visible {
  outline: 2px solid var(--accent);
  z-index: 2;
}

.tree-row {
  position: relative;
  min-height: 38px;
  margin: 2px 7px;
  padding-right: 6px;
  border-radius: 9px;
}

.tree-row:hover {
  background: var(--surface-hover);
}

.tree-row.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 var(--accent);
  color: var(--accent-strong);
}

.tree-row .item-label {
  min-height: 34px;
  padding: 6px 2px;
  color: inherit;
  font-weight: 560;
}

.folder-row .item-label {
  font-weight: 690;
}

.tree-row .folder-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  width: 24px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
}

.folder-chevron {
  color: #72827e;
  font-size: 21px;
  line-height: 1;
  transition: transform .15s ease;
}

.folder-toggle[aria-expanded="true"] .folder-chevron {
  transform: rotate(90deg);
}

.tree-row .folder-toggle:hover,
.tree-row .folder-actions:hover {
  background: rgba(15, 116, 104, .1);
}

.folder-icon {
  position: relative;
  flex: 0 0 19px;
  width: 19px;
  height: 13px;
  margin: 2px 3px 0 0;
  border: 1px solid #d39a2d;
  border-radius: 2px 3px 3px 3px;
  background: #f3c35f;
  box-shadow: inset 0 -2px rgba(172, 111, 11, .08);
}

.folder-icon::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -5px;
  width: 9px;
  height: 5px;
  border: 1px solid #d39a2d;
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  background: #f3c35f;
}

.folder-count {
  min-width: 21px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf1f0;
  color: #70807c;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.tree-row .folder-actions {
  flex: 0 0 24px;
  width: 24px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #5e746f;
  font-size: 16px;
  font-weight: 800;
}

.method-tag {
  flex: 0 0 45px;
  width: 45px;
  padding: 3px 4px;
  border-radius: 5px;
  background: #edf1f0;
  font-size: 9px;
  letter-spacing: .02em;
  text-align: center;
}

.method-GET { color: #08755a; background: #e2f3ed; }
.method-POST { color: #93600a; background: #fff0ce; }
.method-PUT { color: #256896; background: #e6f1f8; }
.method-DELETE { color: #a13f3f; background: #fbe8e6; }

.root-drop.drop-target,
.tree-row.drop-target {
  background: #d6eee7;
  outline: 2px solid #45a78e;
  outline-offset: -2px;
}

.root-drop.drop-target .root-drop-hint {
  display: inline;
}

.tree-row[draggable="true"] {
  cursor: grab;
}

.tree-row.dragging {
  opacity: .45;
}

.editor-head {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.editor-head input {
  color: #1e302d;
  font-size: 20px;
  letter-spacing: -.02em;
}

.request-line {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(26, 49, 44, .04);
}

.request-line select,
.request-line input {
  border-color: transparent;
  background: #f5f8f7;
}

.request-line .primary {
  min-width: 102px;
  border-radius: 9px;
}

.field-label {
  margin: 14px 2px 20px;
}

.panel {
  border-color: var(--line);
  border-radius: 13px;
  box-shadow: 0 4px 16px rgba(28, 52, 47, .025);
}

.panel-title {
  padding-bottom: 9px;
  border-bottom: 1px solid #edf1f0;
}

.empty {
  margin-top: 19vh;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: var(--accent-soft);
  font-size: 30px;
}

#compare-help {
  margin: 2px 2px 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f3f7f6;
}

.history-item {
  gap: 8px;
  margin: 5px 0;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #fafbfb;
}

.history-item:hover {
  border-color: var(--line);
  background: var(--surface);
}

.history-item > button:not(.danger) {
  flex: 1;
  margin: -4px 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.history-item > .danger {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  opacity: .55;
}

.history-item:hover > .danger {
  opacity: 1;
}

.history-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.compare-actions {
  padding: 10px 0;
  border-bottom-color: var(--line);
}

.compare-actions button {
  width: 100%;
}

.response-view {
  padding-top: 16px;
}

.response-view pre {
  border-color: var(--line);
  border-radius: 10px;
  background: #f6f8f7;
}

.response-view details {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfc;
}

.response-view summary {
  cursor: pointer;
  padding: 10px 12px;
  color: #536b68;
  font-weight: 650;
}

.response-view details pre {
  margin: 0 9px 9px;
}

.response-view .response-body {
  max-height: 62vh;
}

.comparison {
  gap: 14px;
}

dialog {
  border-color: var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 90px rgba(19, 42, 38, .26);
}

dialog::backdrop {
  background: rgba(18, 37, 34, .62);
  backdrop-filter: blur(2px);
}

dialog h2 {
  margin-bottom: 4px;
  font-size: 20px;
  letter-spacing: -.02em;
}

#folder-dialog,
#settings-dialog {
  width: min(95vw, 470px);
}

#delete-project,
#delete-env,
#delete-folder {
  margin-right: auto;
}

.setting-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  cursor: pointer;
}

.setting-toggle span {
  display: grid;
  gap: 4px;
}

.setting-toggle small {
  color: var(--muted);
  font-weight: 450;
  line-height: 1.35;
}

.setting-toggle input {
  appearance: none;
  position: relative;
  flex: 0 0 42px;
  width: 42px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #c9d3d0;
  cursor: pointer;
}

.setting-toggle input::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(28, 44, 41, .25);
  transition: transform .18s ease;
}

.setting-toggle input:checked {
  background: var(--accent);
}

.setting-toggle input:checked::after {
  transform: translateX(18px);
}

#notice {
  z-index: 50;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 11px;
  box-shadow: 0 14px 40px rgba(16, 36, 32, .22);
}

@media (max-width: 1200px) {
  .brand strong {
    display: none;
  }

  .context-switcher > summary {
    width: 180px;
  }

  #environment-switcher > summary {
    width: 170px;
  }
}

@media (max-width: 1000px) {
  .topbar {
    height: auto;
    min-height: 76px;
    flex-wrap: wrap;
  }

  .top-actions {
    flex: 1;
  }

  .layout {
    grid-template-columns: 230px minmax(0, 1fr);
    height: auto;
  }

  .resize-handle {
    display: none;
  }

  .layout > .main {
    grid-column: 2;
    grid-row: 1;
    min-height: 70vh;
  }

  .layout > .results {
    grid-column: 2;
    grid-row: 2;
    min-height: 340px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .layout > .sidebar {
    grid-column: 1;
    grid-row: 1 / 3;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 10px 12px;
  }

  .brand {
    padding-top: 7px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto auto;
    width: calc(100% - 52px);
    overflow: visible;
  }

  .context-switcher > summary,
  #environment-switcher > summary {
    width: 100%;
  }

  .context-menu {
    left: 0;
    right: auto;
    width: min(290px, calc(100vw - 24px));
  }

  .toolbar-menu-items {
    position: fixed;
    right: 12px;
    top: 76px;
  }
}

@media (max-width: 650px) {
  .topbar {
    display: block;
  }

  .brand {
    margin-bottom: 10px;
  }

  .brand strong {
    display: inline;
  }

  .top-actions {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-menu,
  #settings,
  #logout {
    width: 100%;
  }

  .toolbar-menu > summary,
  #settings,
  #logout {
    text-align: center;
  }

  .layout {
    display: block;
  }

  .sidebar,
  .main,
  .results {
    height: auto;
    min-height: 300px;
  }

  .main {
    padding: 20px 14px;
  }

  .request-line {
    flex-wrap: wrap;
  }

  .request-line input {
    flex-basis: 100%;
    order: -1;
  }

  .request-line select,
  .request-line .primary {
    flex: 1;
  }

  .comparison {
    grid-template-columns: 1fr;
  }
}
