:root {
  --search-width: 640px;
}

#menu-layer {
  position: fixed;
  inset: 0;
  z-index: 64;
  pointer-events: none;
}

.popup-menu {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 208px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  padding: 6px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px var(--shadow);
  pointer-events: auto;
  overflow: auto;
  animation: menu-enter var(--transition-normal) var(--transition-ease) both;
}

.popup-menu.closing {
  pointer-events: none;
  animation: menu-exit var(--transition-fast) ease both;
}

.menu-label {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  text-align: left;
}

.menu-item.active,
.menu-item:hover {
  background: var(--selected);
}

.menu-item-label {
  flex: 1;
  min-width: 0;
}

.menu-item > svg,
.menu-item > .icon svg {
  width: 16px;
  height: 16px;
  color: var(--secondary);
}

.menu-item .submenu-arrow {
  width: 14px;
  height: 14px;
  color: var(--muted);
}

.menu-item.danger,
.menu-item.danger svg {
  color: var(--danger);
}

.menu-separator {
  height: 2px;
  margin: 4px 0;
  background: var(--border);
  flex-shrink: 0;
}

.format-menu {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 60;
  padding: 4px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 8px 24px var(--shadow);
  animation: format-enter var(--transition-fast) var(--transition-ease) both;
}

.format-menu button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
}

.format-menu button.active {
  color: var(--brand);
  background: var(--hover);
}

.format-menu svg {
  width: 16px;
  height: 16px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 80;
  padding: 80px 24px 24px;
  background: var(--overlay);
  backdrop-filter: blur(8px);
  overflow: auto;
  animation: overlay-enter var(--transition-slow) ease both;
}

.modal-overlay.closing {
  pointer-events: none;
  animation: overlay-exit var(--transition-normal) ease both;
}

.search-window,
.dialog-window {
  background: var(--sidebar);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 64px var(--shadow);
  animation: window-enter var(--transition-slow) var(--transition-ease) both;
}

.modal-overlay.closing .search-window,
.modal-overlay.closing .dialog-window {
  animation: window-exit var(--transition-normal) ease both;
}

.search-window {
  display: flex;
  flex-direction: column;
  width: var(--search-width);
  max-width: 100%;
  max-height: calc(100dvh - 104px);
  min-height: 240px;
  overflow: hidden;
}

.search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 20px;
  border-bottom: 2px solid var(--border);
}

.search-header > .icon {
  color: var(--muted);
}

.search-header > .icon svg {
  width: 20px;
  height: 20px;
}

#search {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 36px;
  padding: 0;
  border: 0;
  outline: none;
  background: var(--transparent);
  font-size: 16px;
}

#search::-webkit-search-cancel-button {
  display: none;
}

#search::placeholder {
  color: var(--muted);
}

#search-close svg {
  width: 20px;
  height: 20px;
}

#search-results {
  flex: 1;
  min-height: 120px;
  padding: 12px;
  overflow: auto;
  scrollbar-width: thin;
}

.search-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.search-group:last-child {
  margin-bottom: 0;
}

.search-group-title {
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 12px;
  border-radius: 6px;
  text-align: left;
}

.search-result.active {
  background: var(--selected);
}

.search-result > svg {
  width: 20px;
  height: 20px;
  color: var(--secondary);
}

.search-result.active > svg {
  color: var(--brand);
}

.search-result-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.search-result-title,
.search-result-path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-title {
  font-size: 14px;
}

.search-result-path {
  font-size: 12px;
  color: var(--muted);
}

.search-result-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--brand);
  background: var(--brand-soft);
  opacity: 0;
  transition: opacity var(--transition-fast) ease;
}

.search-result-action svg {
  width: 16px;
  height: 16px;
}

.search-result.active .search-result-action {
  opacity: 1;
}

.search-empty {
  padding: 40px 16px;
  color: var(--muted);
  text-align: center;
}

.search-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  min-height: 48px;
  padding: 12px 20px;
  border-top: 2px solid var(--border);
}

.search-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.search-key-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.search-key {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--secondary);
}

.search-key svg {
  width: 14px;
  height: 14px;
}

#dialog-overlay {
  align-items: center;
  z-index: 84;
  padding: 24px;
}

.dialog-window {
  width: 440px;
  max-width: 100%;
  max-height: 100%;
  padding: 24px;
  overflow: auto;
}

#dialog-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#dialog-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

#dialog-description {
  margin: 0;
  color: var(--secondary);
}

#dialog-input {
  width: 100%;
  height: 44px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 6px;
  outline: none;
  background: var(--background);
  transition: border-color var(--transition-fast) ease;
}

#dialog-input:focus {
  border-color: var(--brand);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-button {
  min-width: 80px;
  min-height: 40px;
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: 6px;
}

.dialog-button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--black);
  font-weight: 600;
}

.dialog-button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--white);
}

.dialog-button.primary:hover,
.dialog-button.danger:hover {
  opacity: 0.8;
}

@keyframes menu-enter {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes menu-exit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(-4px) scale(0.96);
  }
}

@keyframes format-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes overlay-enter {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes overlay-exit {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

@keyframes window-enter {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes window-exit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
  }
}